-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch_and_monitor_chromoseq.pl
117 lines (73 loc) · 3.99 KB
/
launch_and_monitor_chromoseq.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/perl
use strict;
use JSON;
use YAML::Tiny;
my $BS = '/usr/local/bin/bs';
my $DRAGENAPP = 6495489;
my $CHROMOSEQAPP = 6984978;
my $RefId = 14321367413;
my $debug = "";
my $ProjectName = shift @ARGV;
#my $ProjectId = 126915789; # a dummy project
my $outdir = shift @ARGV;
mkdir $outdir if !-e $outdir;
my @dirs = @ARGV;
map { die "$_ doesnt exist" if ! -e $_ } @dirs;
# go through datasets and make sure they're all from the same library
my %datasets = ();
foreach my $dir (@dirs){
# parse manifest.
my $yaml = `ls $dir/*.yaml`;
chomp $yaml;
my $y = new YAML::Tiny;
my %dat = %{($y->read($yaml))->[0]};
my $name = $dat{library_summary}{full_name};
$datasets{$name} = \%dat;
}
die "Multiple directories with different sample/library information detected!" if scalar keys %datasets > 1;
# get dataset info, make biosample, and upload
my %manifest = %{$datasets{(keys %datasets)[0]}};
my $biosamplename = $debug . $manifest{sample}{full_name};
# first check to see if biosample is present and create it if necessary
my $biosample_json = '';
my @biosample_check = `$BS list biosample --project-name $ProjectName -f csv`;
chomp @biosample_check;
my %biosamples = map { my @l = split(",",$_); $l[0] => $l[1] } @biosample_check[1..$#biosample_check];
if (!defined($biosamples{$biosamplename})){
print STDERR "No samples called $biosamplename found. Creating it...\n";
my $metadata = join(" ",(map { "--metadata Sample.$_:$manifest{sample}{$_}" } keys %{$manifest{sample}}),
(map { "--metadata LibrarySummary.$_:$manifest{library_summary}{$_}" } keys %{$manifest{library_summary}}));
`$BS create biosample -n $biosamplename $manifest{library}{full_name} -p $ProjectName $metadata | tee $biosamplename.$manifest{index_illumina}{analysis_id}.create_biosample.json`;
}
sleep 10;
my $biosample_json = from_json(`$BS biosample get -n $biosamplename -f json`);
# get project id
my $ProjectId = `bs project list --filter-term \"^$ProjectName\$\" --terse`;
chomp $ProjectId;
my $dirs = join(" ", @dirs);
my $label = "Upload $biosamplename " . localtime();
print STDERR "Uploading $biosamplename...\n";
my $upload_json = `$BS upload dataset -p $ProjectId --recursive --biosample-name=$biosamplename --library-name=$manifest{library_summary}{full_name} -l \"$label\" $dirs`;
sleep 30;
$label = "Dragen $biosamplename " . localtime();
my $align_json = from_json(`$BS launch application -i $DRAGENAPP -o app-session-name:\"$label\" -o project-id:$ProjectId -o ht-ref:custom.v7 -o ht-id:$RefId -o input_list.tumor-sample:$biosample_json->{Id} -o dupmark_checkbox:1 -o bai_checkbox:1 -o output_format:CRAM -f json | tee $biosamplename.$manifest{index_illumina}{analysis_id}.dragen.json`);
print STDERR "Launched Dragen: $label. Waiting...\n";
# now wait
#my $align_result = from_json(`$BS await appsession $align_json->{Id} -f json`);
#die "Dragen failed! Check logs for AppSession: $align_result->{AppSession}{Name}" if ($align_result->{AppSession}{ExecutionStatus} !~ /Complete/);
#print STDERR "Dragen finished.\n";
# get cram files
#my @cram = `$BS contents dataset -i $align_result->{Id} -f csv | grep cram | cut -d ',' -f 1`;
#chomp @cram;
#my $files = join(",",@cram);
# launch chromoseq
#$label = "Chromoseq $biosamplename " . localtime();
#my $chromoseq_session = from_json(`$BS launch application -i $CHROMOSEQAPP -o app-session-name:\"$label\" -o project-id:$ProjectId -o file-id:$files -f json`);
#$chromoseq_result = from_json(`$BS await appsession $chromoseq_session->{Id} -f json`);
#print STDERR "Launched Chromoseq: $label. Waiting...\n";
#die "Chromoseq failed! Check logs for AppSession: $chromoseq_result->{AppSession}{Name}" if ($chromoseq_result->{AppSession}{ExecutionStatus} !~ /Complete/);
#print STDERR "Chromoseq finished.\nDownloading files to $outdir.\n";
# download files
#`$BS download dataset -i $align_json->{Id} --extension=csv -o \"$ProjectName/$dataset_json->{Name}\"`;
#`$BS download dataset -i $chromoseq_result->{Id} -o $outdir`;
#print STDERR "Done.\n";