-
Notifications
You must be signed in to change notification settings - Fork 1
/
create.igv.pl
185 lines (146 loc) · 5.71 KB
/
create.igv.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/local/biotools/perl/5.10.0/bin/perl
use strict;
use warnings;
use Getopt::Std;
## INFO
## script to create IGV session for NGS visualization
our ( $opt_o, $opt_r );
print "RAW paramters: @ARGV\n";
getopt('or');
## Check usage and exit if incorrect
if ( ( !defined $opt_o ) && ( !defined $opt_r ) ) {
die("Usage: $0 \n\t -o [ output folder] \n\t -r [ run info file ]\n");
}
my $output = $opt_o; # output folder
my $run_info = $opt_r;
## Split each line of the run_info on '=' and take the last element
## uses command line perl to grep out the line of interest
my @line = split( /=/, `perl -ne "/^TOOL_INFO/ && print" $run_info` );
my $tool_info = $line[$#line];
chomp $tool_info;
@line = split( /=/, `perl -ne "/^SAMPLE_INFO/ && print" $run_info` );
my $sample_info = $line[$#line];
chomp $sample_info;
@line = split( /=/, `perl -ne "/^SAMPLENAMES/ && print" $run_info` );
my $samples = $line[$#line];
chomp $samples;
@line = split( /=/, `perl -ne "/^PI/ && print" $run_info` );
my $PI = $line[$#line];
chomp $PI;
@line = split( /=/, `perl -ne "/^GENOMEBUILD/ && print" $run_info` );
my $genome = $line[$#line];
chomp $genome;
@line = split( /=/, `perl -ne "/^UCSC_TRACKS/ && print" $tool_info` );
my $tracks = $line[$#line];
chomp $tracks;
@line = split( /=/, `perl -ne "/^HTTP_SERVER/ && print" $tool_info` );
my $server = $line[$#line];
chomp $server;
@line = split( /=/, `perl -ne "/^OUTPUT_FOLDER/ && print" $run_info` );
my $folder = $line[$#line];
chomp $folder;
@line = split( /=/, `perl -ne "/^DELIVERY_FOLDER/ && print" $run_info` );
my $delivery_folder = $line[$#line];
chomp $delivery_folder;
my $dest = $output . "/igv_session.xml";
@line = split( /=/, `perl -ne "/^ANALYSIS/ && print" $run_info` );
my $analysis = $line[$#line];
chomp $analysis;
@line = split( /=/, `perl -ne "/^MULTISAMPLE/ && print" $run_info` );
my $multi = $line[$#line];
chomp $multi;
@line = split( /=/, `perl -ne "/^GROUPNAMES/ && print" $run_info` );
my $groups = $line[$#line];
chomp $groups;
@line = split( /=/, `perl -ne "/^SOMATIC_CALLING/ && print" $tool_info` );
my $somatic = $line[$#line];
chomp $somatic;
$tracks = $tracks . "/ucsc_tracks.bed";
### <?xml version="1.0' encoding="UTF-8" standaling="no"?>
### <Global genome="$genome" locus="All" version="4">
### <Resources>
### <Resource name="" path="" />
### </Resources>
### </Global>
open FH, ">$dest" or die "can not open $dest : $! \n";
print FH "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>
<Global genome=\"$genome\" locus=\"All\" version=\"4\">
<Resources> ";
my @sampleNames = split( /:/, $samples );
my @trackNames = split( /:/, $tracks );
my @groupNames = split( /:/, $groups );
if ( $multi eq 'YES' )
{
## Loop over all groups
for ( my $i = 0 ; $i <= $#groupNames ; $i++ ) {
## get samples for group
@line = split( /=/, `cat $sample_info | grep "^$groupNames[$i]"` );
my $sam = $line[$#line];
chomp $sam;
## split on sample list on tabs
my @sam1 = split( /\t/, $sam );
## For each sample in the group
for ( my $j = 0 ; $j <= $#sam1 ; $j++ ) {
if ( $analysis eq "mayo" || $analysis eq "realign-mayo" )
{
## Since we're delivering, point to the delivery folder
$delivery_folder =~ s/\/data2/ftp:\/\/rcfisinl1-212/g;
print FH
"\n<Resource name=\"$sam1[$j].igv-sorted.bam\" path=\"$delivery_folder/IGV_BAM/$groupNames[$i]/$sampleNames[$j].igv-sorted.bam\" />";
}
else
{
print FH
"\n<Resource name=\"$sam1[$j].igv-sorted.bam\" path=\"http://$server/secondary/$PI/$folder/IGV_BAM/$groupNames[$i]/$sampleNames[$j].igv-sorted.bam\" />";
}
}
### Now insert the vcfs for each group
if ( $analysis eq "mayo" || $analysis eq "realign-mayo" )
{
## Since we're delivering, point to the delivery folder
$delivery_folder =~ s/\/data2/ftp:\/\/rcfisinl1-212/g;
print FH
"\n<Resource name=\"$groupNames[$i].variants.filter.final.vcf\" path=\"$delivery_folder/Reports_per_sample/$groupNames[$i].variants.filter.final.vcf\" />";
if ($somatic eq "YES")
{
print FH
"\n<Resource name=\"$groupNames[$i].somatic.variants.filter.final.vcf\" path=\"$delivery_folder/Reports_per_sample/$groupNames[$i].somatic.variants.filter.final.vcf\" />";
}
}
else
{
print FH
"\n<Resource name=\"$groupNames[$i].variants.filter.final.vcf\" path=\"http://$server/secondary/$PI/$folder/Reports_per_sample/$groupNames[$i].variants.filter.final.vcf\" />";
if ($somatic eq "YES")
{
print FH
"\n<Resource name=\"$groupNames[$i].somatic.variants.filter.final.vcf\" path=\"http://$server/secondary/$PI/$folder/Reports_per_sample/$groupNames[$i].somatic.variants.filter.final.vcf\" />";
}
}
} ## For each group
} ## End Multisample Section
else
{
for ( my $i = 0 ; $i <= $#sampleNames ; $i++ ) {
if ( $analysis eq "mayo" || $analysis eq "realign-mayo" ) {
$delivery_folder =~ s/\/data2/ftp:\/\/rcfisinl1-212/g;
print FH
"\n<Resource name=\"$sampleNames[$i].igv-sorted.bam\" path=\"$delivery_folder/IGV_BAM/$sampleNames[$i].igv-sorted.bam\" />";
print FH
"\n<Resource name=\"$sampleNames[$i].variants.filter.final.vcf\" path=\"$delivery_folder/Reports_per_sample/$sampleNames[$i].variants.filter.final.vcf\" />";
}
else {
print FH
"\n<Resource name=\"$sampleNames[$i].igv-sorted.bam\" path=\"http://$server/secondary/$PI/$folder/IGV_BAM/$sampleNames[$i].igv-sorted.bam\" />";
print FH
"\n<Resource name=\"$sampleNames[$i].variants.filter.final.vcf\" path=\"http://$server/secondary/$PI/$folder/Reports_per_sample/$sampleNames[$i].variants.filter.final.vcf\" />";
}
}
} ## Single Samples
for ( my $i = 0 ; $i <= $#trackNames ; $i++ ) {
$tracks =~ s/\/data2\/bsi/http:\/\/$server/g;
print FH "\n<Resource path=\"$tracks\" />";
}
print FH " </Resources>
</Global>";
close FH;