blib/lib/Bio/ViennaNGS/UCSC.pm

filter: Statementstmt 12.0% 50 / 415 Branchbran 0.0% 0 / 114 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 44.1% 15 / 34 Podpod 11.1% 2 / 18 totaltotal 11.5% 67 / 581 CC 66 SCAR 51.0
CC
66
Cov
9%
make_assembly_hub
506.0
make_track_hub
272.0
convert_tracks
30.0
CRAP 164.2
« blib/lib/Bio/ViennaNGS/AnnoC.pm ↑ Summary blib/lib/Bio/ViennaNGS/Util.pm »
1 # -*-CPerl-*-
2 # Last changed Time-stamp: <2017-06-26 17:28:26 mtw>
3  
4 package Bio::ViennaNGS::UCSC;
5  
6 1 ▶use Bio::ViennaNGS;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use IPC::Cmd qw(can_run run);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use File::Share ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Bio::ViennaNGS::Util qw(fetch_chrom_sizes bed2bigBed);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use version; our $VERSION = version->declare("$Bio::ViennaNGS::VERSION");
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 our @ISA = qw(Exporter);
23  
24 1 our @EXPORT_OK = qw( make_assembly_hub make_track_hub retrieve_color
25 make_track make_multi_bigwig_container_track
26 make_bigwig_container_track retrieve_bigwig_tracks
27 retrieve_bigbed_url_tracks parse_fasta_header valid_ncbi_accession
28 modify_fasta_header make_group retrieve_chromosome_size
29 write_chromosome_size_file convert_tracks);
30  
31 1 our @EXPORT = ();
32  
33 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
34 #^^^^^^^^^^^ Subroutines ^^^^^^^^^^#
35 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
36  
37 sub make_assembly_hub{
38 0 ▶ my ($fasta_path, $filesdir, $basedir, $baseURL, $big_wig_ids, $log) = @_;
Subroutine make_assembly_hub: not called CC=22 SCAR=62.3
Pod documented
39 0 my ($basename,$dir,$ext);
40 0 my $this_function = (caller(0))[3];
41 #check arguments
42 0 ▶ croak ("ERROR [$this_function] \$fasta_path does not exist\n")
Branch: 1 branch
BranchTrueFalseTotal
unless -e $fasta_path 0 0 0
43 unless (-e $fasta_path);
44 0 ▶ croak ("ERROR [$this_function] \$basedir does not exist\n")
Branch: 1 branch
BranchTrueFalseTotal
unless -d $basedir 0 0 0
45 unless (-d $basedir);
46 0 ▶ croak ("ERROR [$this_function]: no URL (network location for upload to UCSC) provided")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $baseURL 0 0 0
47 unless(defined $baseURL);
48  
49 0 ▶ unless ($baseURL =~ /\/$/) { $baseURL .= "/"; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($baseURL =~ m[/$]) 0 0 0
50  
51 0 my $tmp_path = dist_file('Bio-ViennaNGS', "hub.txt" );
52 0 ($basename,$dir,$ext) = fileparse($tmp_path,qr/\..*/);
53 0 my $template_path = dir($dir,"template-AssemblyHub");
54  
55 0 ▶ croak ("ERROR [$this_function] template directory not found\n")
Branch: 1 branch
BranchTrueFalseTotal
unless -d $template_path 0 0 0
56 unless (-d $template_path);
57 0 ▶ my $faToTwoBit = can_run('faToTwoBit') or
Branch: 1 branch
BranchTrueFalseTotal
my $faToTwoBit = can_run("faToTwoBit") or croak("ERROR [$this_function] faToTwoBit is not installed!") 0 0 0
58 croak ("ERROR [$this_function] faToTwoBit is not installed!");
59  
60 # bedfiles path
61 0 my $parsedHeaderRef = parse_fasta_header($fasta_path,$this_function);
62 0 my @parsedHeader = @$parsedHeaderRef;
63 0 my $unchecked_accession = $parsedHeader[0];
64 0 my $scientificName = $parsedHeader[1];
65 0 my $accession = valid_ncbi_accession($unchecked_accession);
66 # create assembly hub directory structure
67 0 my $assembly_hub_name = "assemblyHub";
68 0 my $assembly_hub_directory = dir($basedir, $assembly_hub_name);
69 0 my $genome_assembly_name = $accession;
70 0 my $genome_assembly_directory = dir($assembly_hub_directory,$genome_assembly_name);
71 0 mkdir $assembly_hub_directory;
72 0 mkdir $genome_assembly_directory;
73  
74 0 ▶ if (defined $log){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
75 0 ▶ open(LOG, ">>", $log) or croak "$!";
Branch: 1 branch
BranchTrueFalseTotal
open LOG, ">>", $log or croak("$!") 0 0 0
76 0 print LOG "LOG Base directory: $assembly_hub_directory\n";
77 0 print LOG "LOG Assembly Hub directory: $genome_assembly_directory\n";
78 0 close(LOG);
79 }
80  
81 #2-bit fasta file conversion
82 0 my $fa_modified = file($assembly_hub_directory, $accession.".fa");
83 0 modify_fasta_header($fasta_path,$fa_modified,$accession);
84 0 my $twoBit = file($genome_assembly_directory, $accession.".2bit");
85 0 my $fastaToTwobit_cmd = "$faToTwoBit $fa_modified $twoBit";
86  
87 0 ▶ if (defined $log){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
88 0 ▶ open(LOG, ">>", $log) or croak "$!";
Branch: 1 branch
BranchTrueFalseTotal
open LOG, ">>", $log or croak("$!") 0 0 0
89 0 print LOG "LOG [$this_function] $fastaToTwobit_cmd\n";
90 0 close(LOG);
91 }
92  
93 0 my( $success, $error_message, $full_buf, $stdout_buf, $stderr_buf ) =
94 run( command => $fastaToTwobit_cmd, verbose => 0 );
95 0 ▶ if( !$success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($success) 0 0 0
96 0 print STDERR "ERROR [$this_function] External command call unsuccessful\n";
97 0 print STDERR "ERROR: this is what the command printed:\n";
98 0 print join "", @$full_buf;
99 0 croak $!;
100 }
101  
102 #template definition
103 0 my $template = Template->new({
104 INCLUDE_PATH => ["$template_path"],
105 RELATIVE=>1,
106 });
107  
108 #construct hub.txt
109 0 my $hubtxt_path = file($assembly_hub_directory,"hub.txt")->stringify;
110 0 my $hubtxt_file = "hub.txt";
111 0 my $hubtxt_vars =
112 {
113 hubName => $accession,
114 shortLabel => $accession,
115 longLabel => $accession,
116 genomesFile => "genome.txt",
117 email => 'email',
118 descriptionURL => "$baseURL" . "description.html"
119 };
120 0 ▶ $template->process($hubtxt_file,$hubtxt_vars,"$hubtxt_path") ||
Branch: 1 branch
BranchTrueFalseTotal
$template->process($hubtxt_file, $hubtxt_vars, "$hubtxt_path") or croak("Template process failed: ", $template->error, "\n") 0 0 0
121 croak "Template process failed: ", $template->error(), "\n";
122  
123 #construct genome.txt
124 0 my $genometxt_path = file($assembly_hub_directory, "genome.txt")->stringify;
125 0 my $genometxt_file = "genome.txt";
126 0 my $genometxt_vars =
127 {
128 genome => $accession,
129 trackDb => file($accession, "trackDb.txt"),
130 groups => file($accession, "groups.txt"),
131 description => "$accession",
132 twoBitPath => file($accession,$accession.".2bit"),
133 organism => "organism",
134 defaultPos => $accession,
135 orderKey => "10",
136 scientificName => "$scientificName",
137 htmlPath => file($accession,"description.html")
138 };
139 0 ▶ $template->process($genometxt_file,$genometxt_vars,$genometxt_path) or
Branch: 1 branch
BranchTrueFalseTotal
$template->process($genometxt_file, $genometxt_vars, $genometxt_path) or croak("Template process failed: ", $template->error, "\n") 0 0 0
140 croak "Template process failed: ", $template->error(), "\n";
141  
142 #construct description.html
143 0 my $description_html_path = file($genome_assembly_directory, "description.html")->stringify;
144 0 my $description_html_file = "description.html";
145 0 my $description_html_vars =
146 {
147 imageLink => "imageLink",
148 imageSource => "imageSource",
149 imageAlternative => "imageAlternative",
150 taxonomicName => "taxonomicName",
151 imageOrigin => "imageOrigin",
152 imageOriginDescription => "imageOriginDescription",
153 ucscId => "ucscId",
154 sequencingId => "sequencingId",
155 assemblyDate => "assemblyDate",
156 genbankAccessionId => "genbankAccessionId",
157 ncbiGenomeInformationLink => "ncbiGenomeInformationLink",
158 ncbiGenomeInformationDescription => "ncbiGenomeInformationDescription",
159 ncbiAssemblyInformationLink => "ncbiAssemblyInformationLink",
160 ncbiAssemblyInformationDescription => "ncbiAssemblyInformationDescription",
161 bioProjectInformationLink => "bioProjectInformationLink",
162 bioProjectInformationDescription => "bioProjectInformationDescription",
163 sequenceAnnotationLink => "sequenceAnnotationLink"
164 };
165 0 ▶ $template->process($description_html_file,$description_html_vars,$description_html_path) or
Branch: 1 branch
BranchTrueFalseTotal
$template->process($description_html_file, $description_html_vars, $description_html_path) or croak("Template process failed: ", $template->error, "\n") 0 0 0
166 croak "Template process failed: ", $template->error(), "\n";
167  
168 0 my $groups = make_group("annotation", "Annotation", "1", "0");
169  
170 #construct group.txt
171 0 my $group_txt_path = file($genome_assembly_directory, "groups.txt")->stringify;
172 0 my $group_txt_file = 'groups.txt';
173 0 my $group_txt_vars =
174 {
175 groups => "$groups",
176 };
177 0 ▶ $template->process($group_txt_file,$group_txt_vars,$group_txt_path) or
Branch: 1 branch
BranchTrueFalseTotal
$template->process($group_txt_file, $group_txt_vars, $group_txt_path) or croak("Template process failed: ", $template->error, "\n") 0 0 0
178 croak "Template process failed: ", $template->error(), "\n";
179  
180 #construct big bed
181 0 my $tracksList;
182 #Bigbeds are only created from infolder
183 0 ▶ unless($filesdir =~ /-/){
Branch: 1 branch
BranchTrueFalseTotal
unless ($filesdir =~ /-/) 0 0 0
184 0 my $chromosome_size = retrieve_chromosome_size($fasta_path);
185 0 my $chromosome_size_filepath = file($genome_assembly_directory,"$accession.chrom.sizes");
186 0 write_chromosome_size_file($chromosome_size_filepath,$accession,$chromosome_size);
187 0 convert_tracks($filesdir, $genome_assembly_directory, $chromosome_size_filepath, $log);
188 0 my @trackfiles = retrieve_tracks($genome_assembly_directory, $baseURL, $assembly_hub_name, $accession);
189  
190 0 foreach my $track (@trackfiles){
191 0 my $trackString = make_track(@$track);
192 0 $tracksList .= $trackString;
193 }
194 }
195  
196 #big wigs
197 0 my $bigwig_tracks_string = "";
198 0 ▶ unless($big_wig_ids=~/^-$/){
Branch: 1 branch
BranchTrueFalseTotal
unless ($big_wig_ids =~ /^-$/) 0 0 0
199 0 $bigwig_tracks_string = retrieve_bigwig_tracks($genome_assembly_directory, $baseURL, $assembly_hub_name, $accession, $big_wig_ids);
200 }
201 0 $tracksList .= $bigwig_tracks_string;
202 #construct trackDb.txt
203 0 my $trackDb_txt_path = file($genome_assembly_directory, "trackDb.txt")->stringify;
204 0 my $trackDb_txt_file = 'trackDb.txt';
205 0 my $trackDb_txt_vars =
206 {
207 tracks => "$tracksList"
208 };
209 0 ▶ $template->process($trackDb_txt_file,$trackDb_txt_vars,$trackDb_txt_path) or
Branch: 1 branch
BranchTrueFalseTotal
$template->process($trackDb_txt_file, $trackDb_txt_vars, $trackDb_txt_path) or croak("Template process failed: ", $template->error, "\n") 0 0 0
210 croak "Template process failed: ", $template->error(), "\n";
211  
212 0 ▶ if (defined $log){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
213 0 ▶ open(LOG, ">>", $log) or croak "$!";
Branch: 1 branch
BranchTrueFalseTotal
open LOG, ">>", $log or croak("$!") 0 0 0
214 0 print LOG "LOG Assembly Hub created\n";
215 0 close(LOG);
216 }
217 }
218  
219 sub make_track_hub{
220 0 ▶ my ($species, $basedir, $baseURL, $big_bed_ids, $big_wig_ids, $log) = @_;
Subroutine make_track_hub: not called CC=16 SCAR=56.1
Pod documented
221 0 my ($basename,$dir,$ext);
222 0 my $this_function = (caller(0))[3];
223  
224 #check arguments
225 0 ▶ croak ("ERROR [$this_function] \no species provided\n")
Branch: 1 branch
BranchTrueFalseTotal
unless $species 0 0 0
226 unless ($species);
227 0 ▶ croak ("ERROR [$this_function] \$basedir does not exist\n")
Branch: 1 branch
BranchTrueFalseTotal
unless -d $basedir 0 0 0
228 unless (-d $basedir);
229 0 ▶ croak ("ERROR [$this_function]: no URL (network location for upload to UCSC) provided")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $baseURL 0 0 0
230 unless(defined $baseURL);
231  
232 0 ▶ if (defined $log){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
233 0 ▶ open(LOG, ">>", $log) or croak "$!";
Branch: 1 branch
BranchTrueFalseTotal
open LOG, ">>", $log or croak("$!") 0 0 0
234 }
235  
236 0 ▶ unless ($baseURL =~ /\/$/) { $baseURL .= "/"; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($baseURL =~ m[/$]) 0 0 0
237  
238 0 my $tmp_path = dist_file('Bio-ViennaNGS', "hub.txt" );
239 0 ($basename,$dir,$ext) = fileparse($tmp_path,qr/\..*/);
240 0 my $template_path = dir($dir,"template-TrackHub");
241  
242 0 ▶ croak ("ERROR [$this_function] template directory not found\n")
Branch: 1 branch
BranchTrueFalseTotal
unless -d $template_path 0 0 0
243 unless (-d $template_path);
244 0 ▶ my $faToTwoBit = can_run('faToTwoBit') or
Branch: 1 branch
BranchTrueFalseTotal
my $faToTwoBit = can_run("faToTwoBit") or croak("ERROR [$this_function] faToTwoBit is not installed!") 0 0 0
245 croak ("ERROR [$this_function] faToTwoBit is not installed!");
246  
247 # create track hub directory structure
248 0 my $track_hub_name = "trackHub";
249 0 my $track_hub_directory = dir($basedir, $track_hub_name);
250 0 my $genome_assembly_name = $species;
251 0 my $genome_assembly_directory = dir($track_hub_directory,$genome_assembly_name);
252 0 mkdir $track_hub_directory;
253 0 mkdir $genome_assembly_directory;
254 0 ▶ if (defined $log){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
255 0 print LOG "LOG Base directory: $track_hub_directory\n";
256 0 print LOG "LOG Track Hub directory: $genome_assembly_directory\n";
257 }
258  
259 #template definition
260 0 my $template = Template->new({
261 INCLUDE_PATH => ["$template_path"],
262 RELATIVE=>1,
263 });
264  
265 #construct hub.txt
266 0 my $hubtxt_path = file($track_hub_directory,"hub.txt")->stringify;
267 0 my $hubtxt_file = "hub.txt";
268 0 my $hubtxt_vars =
269 {
270 hubName => $species,
271 shortLabel => $species,
272 longLabel => $species,
273 genomesFile => "genome.txt",
274 email => 'email',
275 descriptionURL => "$baseURL" . "description.html"
276 };
277 0 ▶ $template->process($hubtxt_file,$hubtxt_vars,"$hubtxt_path") ||
Branch: 1 branch
BranchTrueFalseTotal
$template->process($hubtxt_file, $hubtxt_vars, "$hubtxt_path") or croak("Template process failed: ", $template->error, "\n") 0 0 0
278 croak "Template process failed: ", $template->error(), "\n";
279  
280 #construct genome.txt
281 0 my $genometxt_path = file($track_hub_directory, "genome.txt")->stringify;
282 0 my $genometxt_file = "genome.txt";
283 0 my $genometxt_vars =
284 {
285 genome => $species,
286 trackDb => file($species, "trackDb.txt"),
287 groups => file($species, "groups.txt"),
288 description => "$species",
289 twoBitPath => file($species,$species.".2bit"),
290 organism => "organism",
291 defaultPos => $species,
292 orderKey => "10",
293 scientificName => "scientificName",
294 htmlPath => file($species,"description.html")
295 };
296 0 ▶ $template->process($genometxt_file,$genometxt_vars,$genometxt_path) or
Branch: 1 branch
BranchTrueFalseTotal
$template->process($genometxt_file, $genometxt_vars, $genometxt_path) or croak("Template process failed: ", $template->error, "\n") 0 0 0
297 croak "Template process failed: ", $template->error(), "\n";
298  
299 0 my $tracksList;
300 #bigbeds are only created from urls
301 0 my $bigbeds_tracks_string = "";
302 0 ▶ unless($big_bed_ids=~/^-$/){
Branch: 1 branch
BranchTrueFalseTotal
unless ($big_bed_ids =~ /^-$/) 0 0 0
303 0 $bigbeds_tracks_string = retrieve_bigbed_url_tracks($genome_assembly_directory, $baseURL, $track_hub_name, $big_bed_ids);
304 }
305 0 $tracksList .= $bigbeds_tracks_string;
306 #big wigs
307 0 my $bigwig_tracks_string = "";
308 0 ▶ unless($big_wig_ids=~/^-$/){
Branch: 1 branch
BranchTrueFalseTotal
unless ($big_wig_ids =~ /^-$/) 0 0 0
309 0 $bigwig_tracks_string = retrieve_bigwig_tracks($genome_assembly_directory, $baseURL, $track_hub_name, $species, $big_wig_ids);
310 }
311 0 $tracksList .= $bigwig_tracks_string;
312 #construct trackDb.txt
313 0 my $trackDb_txt_path = file($genome_assembly_directory, "trackDb.txt")->stringify;
314 0 my $trackDb_txt_file = 'trackDb.txt';
315 0 my $trackDb_txt_vars =
316 {
317 tracks => "$tracksList"
318 };
319 0 ▶ $template->process($trackDb_txt_file,$trackDb_txt_vars,$trackDb_txt_path) or
Branch: 1 branch
BranchTrueFalseTotal
$template->process($trackDb_txt_file, $trackDb_txt_vars, $trackDb_txt_path) or croak("Template process failed: ", $template->error, "\n") 0 0 0
320 croak "Template process failed: ", $template->error(), "\n";
321  
322 0 ▶ if (defined $log){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
323 0 print LOG "LOG Track Hub created\n";
324 0 close(LOG);
325 }
326 }
327  
328 sub convert_tracks{
329 0 ▶ my ($filesdir,$genome_assembly_directory,$chromosome_size_filepath,$log) = @_;
Subroutine convert_tracks: not called CC=5 SCAR=34.0
Pod undocumented
330 0 my $this_function = (caller(0))[3];
331 0 my @bedfiles = ();
332  
333 find( sub {
334 0 ▶ return unless -f;
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
unless -f $_ 0 0 0
335 0 ▶ return unless /\.bed$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\.bed$/ 0 0 0
336 0 push @bedfiles, $File::Find::name;
337 0 } , $filesdir);
338  
339 0 ▶ if (defined $log){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $log) 0 0 0
340 0 ▶ open(LOG, ">>", $log) or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
open LOG, ">>", $log or croak($!) 0 0 0
341 0 foreach my $bedfile (@bedfiles){
342 0 print LOG "LOG [$this_function] found file $bedfile\n";
343 }
344 0 close(LOG);
345 }
346  
347 0 foreach my $bedfile (@bedfiles){
348 0 bed2bigBed($bedfile,$chromosome_size_filepath,$genome_assembly_directory,$log);
349 }
350 0 return 1;
351 }
352  
353 sub retrieve_tracks{
354 0 ▶ my ($directoryPath,$baseURL,$assembly_hub_name,$accession) = @_;
Subroutine retrieve_tracks: not called CC=4 SCAR=30.0
Pod undocumented
355 0 my $currentDirectory = getcwd;
356 0 ▶ chdir $directoryPath or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
chdir $directoryPath or croak($!) 0 0 0
357 0 my @trackfiles = <*.bb>;
358 0 my @tracks;
359 0 my $counter = 0;
360 0 foreach my $trackfile (@trackfiles){
361 0 my $filename = $trackfile;
362 0 $filename =~ s/.bb$//;
363 0 my @filenameSplit = split(/\./, $filename);
364 0 my $id = lc($filename);
365 0 my $tag = $id;
366 0 my $track = $id . "_bed";
367 0 my $dir = dir($baseURL,$assembly_hub_name,$accession);
368 0 my $bigDataUrl = file($trackfile);
369 0 my $shortLabel = $id;
370 0 my $longLabel = $id;
371 0 my $type = "bigBed 12 .";
372 0 my $autoScale = "off";
373 0 my $bedNameLabel = "Gene Id";
374 0 my $searchIndex = "name";
375 0 my $colorByStrand = retrieve_color($counter);
376 0 my $visibility = "pack";
377 0 my $group = "annotation";
378 0 my $priority = "10";
379 0 my @track = ($tag,$track,$bigDataUrl,$shortLabel,$longLabel,$type,$autoScale,$bedNameLabel,$searchIndex,$colorByStrand,$visibility,$group,$priority);
380 0 my $trackreference = \@track;
381 0 push(@tracks, $trackreference);
382 0 $counter++;
383 }
384 0 ▶ chdir $currentDirectory or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
chdir $currentDirectory or croak($!) 0 0 0
385 0 return @tracks;
386 }
387  
388 sub retrieve_bigbed_url_tracks{
389 0 ▶ my ($directoryPath,$baseURL,$assembly_hub_name,$bigbedpaths) = @_;
Subroutine retrieve_bigbed_url_tracks: not called CC=4 SCAR=30.0
Pod undocumented
390 0 my $currentDirectory = getcwd;
391 0 ▶ chdir $directoryPath or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
chdir $directoryPath or croak($!) 0 0 0
392 0 my @big_bed_array = split('#', $bigbedpaths);
393 0 my $bigbedtracks = "";
394 0 my $counter = 0;
395 0 foreach my $bigbed_entry (@big_bed_array){
396 #construct single big bed track
397 0 my ($basename,$dir,$ext) = fileparse($bigbed_entry,qr/\..*/);
398 0 my $id = lc($basename);
399 0 my $tag = $id . $ext . "_bed";
400 0 my $track = $id . $ext ."_bed";
401 0 my $bigDataUrl = $bigbed_entry;
402 0 my $shortLabel = $id;
403 0 my $longLabel = $id;
404 0 my $type = "bigBed 12 .";
405 0 my $autoScale = "off";
406 0 my $bedNameLabel = "Gene Id";
407 0 my $searchIndex = "name";
408 0 my $colorByStrand = retrieve_color($counter);
409 0 my $visibility = "pack";
410 0 my $group = "annotation";
411 0 my $priority = "10";
412 0 my $track_string = make_track($tag, $track, $bigDataUrl, $shortLabel, $longLabel, $type, $autoScale, $bedNameLabel, $searchIndex, $colorByStrand, $visibility, $group, $priority);
413 0 $bigbedtracks .= $track_string;
414 0 $counter++;
415 }
416 0 ▶ chdir $currentDirectory or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
chdir $currentDirectory or croak($!) 0 0 0
417 0 return $bigbedtracks;
418 }
419  
420 sub retrieve_bigwig_tracks{
421 0 ▶ my ($directoryPath,$baseURL,$assembly_hub_name,$accession,$bigwigpaths) = @_;
Subroutine retrieve_bigwig_tracks: not called CC=5 SCAR=34.0
Pod undocumented
422 0 my $currentDirectory = getcwd;
423 0 ▶ chdir $directoryPath or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
chdir $directoryPath or croak($!) 0 0 0
424 0 my @big_wig_array = split('\#', $bigwigpaths);
425 0 my $bigwigtracks = "";
426 0 foreach my $bigwig_entry (@big_wig_array){
427 0 ▶ if($bigwig_entry=~/,/){
Branch: 1 branch
BranchTrueFalseTotal
if ($bigwig_entry =~ /,/) { } 0 0 0
428 #multi bigwig container detected
429 0 my @big_wig_pair = split(',', $bigwig_entry);
430 0 my $pos_wig=$big_wig_pair[0];
431 0 my $neg_wig=$big_wig_pair[1];
432 0 my ($basename1,$dir1,$ext1) = fileparse($pos_wig,qr/\..*/);
433 0 my ($basename2,$dir2,$ext2) = fileparse($pos_wig,qr/\..*/);
434 #construct container
435 0 my $id = lc($basename1);
436 0 my $tag = $id . "_bw";
437 0 my $track = $id . "_bw";
438 0 my $shortLabel = $tag;
439 0 my $longLabel = $tag;
440 0 my $type = "bigWig";
441 0 my $autoScale = "on";
442 0 my $visibility = "full";
443 0 my $priority = "1500";
444 0 my $container_string = make_multi_bigwig_container_track($tag, $track, $shortLabel, $longLabel, $type, $autoScale, $visibility, $priority);
445 0 $bigwigtracks .= $container_string;
446 #construct positive track
447 0 my $track1 = $track . "_pos";
448 0 my $bigDataUrl1 = $pos_wig;
449 0 my $shortLabel1 = $track1;
450 0 my $longLabel1 = $track1;
451 0 my $type1 = "bigWig";
452 0 my $parent1 = $track;
453 0 my $color1 = "133,154,0";
454 0 my $track1_string = make_bigwig_container_track($track1, $bigDataUrl1, $shortLabel1, $longLabel1, $type1, $parent1, $color1);
455 0 $bigwigtracks .= $track1_string;
456 #construct negative track
457 0 my $track2 = $track . "_neg";
458 0 my $bigDataUrl2 = $neg_wig;
459 0 my $shortLabel2 = $track2;
460 0 my $longLabel2 = $track2;
461 0 my $type2 = "bigWig";
462 0 my $parent2 = $track;
463 0 my $color2 = "220,51,47";
464 0 my $track2_string = make_bigwig_container_track($track2, $bigDataUrl2, $shortLabel2, $longLabel2, $type2, $parent2, $color2);
465 0 $bigwigtracks .= $track2_string;
466 }else{
467 #construct single big wig track
468 0 my ($basename,$dir,$ext) = fileparse($bigwig_entry,qr/\..*/);
469 0 my $id = lc($basename);
470 0 my $tag = $id . "_bw";
471 0 my $track = $id . "_bw";
472 0 my $bigDataUrl = $bigwig_entry;
473 0 my $shortLabel = $tag;
474 0 my $longLabel = $tag;
475 0 my $type = "bigWig";
476 0 my $autoScale = "on";
477 0 my $visibility = "full";
478 0 my $priority = "1500";
479 0 my $color = "38,140,210";
480 0 my $track_string = make_bigwig_track($tag, $track, $bigDataUrl, $shortLabel, $longLabel, $type, $autoScale, $visibility, $priority, $color);
481 0 $bigwigtracks .= $track_string;
482 }
483 }
484 0 ▶ chdir $currentDirectory or croak $!;
Branch: 1 branch
BranchTrueFalseTotal
chdir $currentDirectory or croak($!) 0 0 0
485 0 return $bigwigtracks;
486 }
487  
488  
489 sub retrieve_color{
490 0 ▶ my $counter = shift;
Subroutine retrieve_color: not called CC=2 SCAR=17.9
Pod undocumented
491 0 my $digitnumber = length($counter);
492 0 my $colorcode;
493 0 ▶ if($digitnumber>1){
Branch: 1 branch
BranchTrueFalseTotal
if ($digitnumber > 1) { } 0 0 0
494 0 $colorcode = $counter % 10;
495 }else{
496 0 $colorcode = $counter;
497 }
498 0 my @color;
499 #green
500 0 $color[0] = "133,154,0 133,154,0";
501 #cyan
502 0 $color[1] = "42,162,152 42,162,152";
503 #blue
504 0 $color[2] = "38,140,210 38,140,210";
505 #violet
506 0 $color[3] = "108,114,196 108,114,196";
507 #magenta
508 0 $color[4] = "211,55,130 211,55,130";
509 #red
510 0 $color[5] = "220,51,47 220,51,47";
511 #orange
512 0 $color[6] = "203,76,22 203,76,22";
513 #yellow
514 0 $color[7] = "181,138,0 181,138,0";
515 #black
516 0 $color[8] = "0,44,54 0,44,54";
517 #grey
518 0 $color[9] = "88,111,117 88,111,117";
519  
520 0 return $color[$colorcode];
521 }
522  
523 sub make_group{
524 0 ▶ my ($name, $label, $priority, $defaultIsClosed) = @_;
Subroutine make_group: not called CC=1 SCAR=6.9
Pod undocumented
525 0 my $group ="name $name\nlabel $label\npriority $priority\ndefaultIsClosed $defaultIsClosed\n";
526 0 return $group;
527 }
528  
529 sub make_track{
530 0 ▶ my ($tag, $track, $bigDataUrl, $shortLabel, $longLabel, $type, $autoScale, $bedNameLabel, $searchIndex, $colorByStrand, $visibility, $group, $priority) = @_;
Subroutine make_track: not called CC=1 SCAR=6.9
Pod undocumented
531 0 my $trackEntry ="#$tag\ntrack $track\nbigDataUrl $bigDataUrl\nshortLabel $shortLabel\nlongLabel $longLabel\ntype $type\nautoScale $autoScale\nbedNameLabel $bedNameLabel\nsearchIndex $searchIndex\ncolorByStrand $colorByStrand\nvisibility $visibility\ngroup $group\npriority $priority\n\n";
532 0 return $trackEntry;
533 }
534  
535 sub make_multi_bigwig_container_track{
536 0 ▶ my ($tag, $track, $shortLabel, $longLabel, $type, $autoScale, $visibility, $priority) = @_;
Subroutine make_multi_bigwig_container_track: not called CC=1 SCAR=6.9
Pod undocumented
537 0 my $trackEntry ="#$tag\ntrack $track\ncontainer multiWig\nnoInherit on\nshortLabel $shortLabel\nlongLabel $longLabel\ntype $type\nconfigureable on\nvisibility $visibility\naggregate transparentOverlay\nshowSubtrackColorOnUi on\nautoScale $autoScale\nwindowingFunction maximum\npriority $priority\nalwaysZero on\nyLineMark 0\nyLineOnOff on\nmaxHeightPixels 125:125:11\n\n";
538 0 return $trackEntry;
539 }
540  
541 sub make_bigwig_container_track{
542 0 ▶ my ($track, $bigDataUrl, $shortLabel, $longLabel, $type, $parent, $color) = @_;
Subroutine make_bigwig_container_track: not called CC=1 SCAR=6.9
Pod undocumented
543 0 my $trackEntry = "track $track\nbigDataUrl $bigDataUrl\nshortLabel $shortLabel\nlongLabel $longLabel\ntype $type\nparent $parent\ncolor $color\n\n";
544 0 return $trackEntry;
545 }
546  
547 sub make_bigwig_track{
548 0 ▶ my ($tag, $track, $bigDataUrl, $shortLabel, $longLabel, $type, $autoScale, $visibility, $priority, $color) = @_;
Subroutine make_bigwig_track: not called CC=1 SCAR=6.9
Pod undocumented
549 0 my $trackEntry ="#$tag\ntrack $track\nbigDataUrl $bigDataUrl\nshortLabel $shortLabel\nlongLabel $longLabel\ntype $type\nvisibility $visibility\nautoScale $autoScale\npriority $priority\nalwaysZero on\nyLineMark 0\nyLineOnOff on\nmaxHeightPixels 125:125:11\ncolor $color\n\n";
550 0 return $trackEntry;
551 }
552  
553 sub valid_ncbi_accession{
554 # receives a NCBI accession ID, with or without version number
555 # checks for validity and returns the accession number as is
556 0 ▶ my $acc = shift;
Subroutine valid_ncbi_accession: not called CC=3 SCAR=24.8
Pod undocumented
557 0 ▶ if ($acc =~ /^(N[CSTZ]\_[A-Z]*\d{6})\.\d+?$/){
Branch: 2 branches
BranchTrueFalseTotal
if ($acc =~ /^(N[CSTZ]\_[A-Z]*\d{6})\.\d+?$/) { } 0 0 0
elsif ($acc =~ /^(N[CSTZ]\_[A-Z]*\d{6})$/) { } 0 0 0
558 0 return $acc;
559 }
560 elsif ($acc =~ /^(N[CSTZ]\_[A-Z]*\d{6})$/){
561 0 return $1;
562 }
563 else {
564 0 return 0;
565 }
566 }
567  
568 sub parse_fasta_header{
569 0 ▶ my $filepath = shift;
Subroutine parse_fasta_header: not called CC=4 SCAR=30.0
Pod undocumented
570 0 my $this_function = (caller(0))[3];
571 0 ▶ open my $file, '<', "$filepath" or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $file, "<", "$filepath" or die $! 0 0 0
572 0 my $fastaheader = <$file>;
573 0 chomp $fastaheader;
574 0 close $file;
575 0 my @ids = ();
576 #>gi|556503834|ref|NC_000913.3| Escherichia coli str. K-12 substr. MG1655
577 0 ▶ if($fastaheader=~/^>gi/){
Branch: 1 branch
BranchTrueFalseTotal
if ($fastaheader =~ /^>gi/) { } 0 0 0
578 0 my @headerfields = split(/\|/, $fastaheader);
579 0 my $accession = $headerfields[3];
580 0 my $scientificName = $headerfields[4];
581 0 push(@ids,$accession);
582 0 push(@ids,$scientificName);
583 0 return \@ids;
584 }else{
585 0 $fastaheader=~s/^>//;
586 0 ▶ carp "INFO [$this_function] It looks like your input Fasta header does not contain a valid NCBI accession number. Continuing with:\n $fastaheader\n"
Branch: 1 branch
BranchTrueFalseTotal
unless valid_ncbi_accession($fastaheader) 0 0 0
587 unless ( valid_ncbi_accession($fastaheader) );
588 0 push(@ids,$fastaheader);
589 0 push(@ids,"scientific name not set");
590 0 return \@ids;
591 }
592 }
593  
594 sub write_chromosome_size_file{
595 0 ▶ my $filepath = shift;
Subroutine write_chromosome_size_file: not called CC=2 SCAR=17.9
Pod undocumented
596 0 my $chromosome_name = shift;
597 0 my $chromosome_size = shift;
598 0 my $entry = $chromosome_name . "\t" . $chromosome_size . "\n";
599 0 ▶ open CHROMFILE, '>', "$filepath" or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open CHROMFILE, ">", "$filepath" or die $! 0 0 0
600 0 print CHROMFILE $entry;
601 0 close CHROMFILE;
602 0 return 1;
603 }
604  
605 sub write_chromosome_sizes_file{
606 0 ▶ my $filepath = shift;
Subroutine write_chromosome_sizes_file: not called CC=3 SCAR=24.8
Pod undocumented
607 0 my $chromosome_sizes_reference = shift;
608 0 my %chromosome_sizes = %{$chromosome_sizes_reference};
609 0 ▶ open CHROMFILE, '>', "$filepath" or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open CHROMFILE, ">", "$filepath" or die $! 0 0 0
610 0 foreach my $chromosome_name ( keys %chromosome_sizes){
611 0 my $chromosome_size = $chromosome_sizes{$chromosome_name};
612 0 my $entry = $chromosome_name . "\t" . $chromosome_size . "\n";
613 0 print CHROMFILE $entry;
614 }
615 0 close CHROMFILE;
616 0 return 1;
617 }
618  
619 sub retrieve_chromosome_size{
620 0 ▶ my $inputFilepath = shift;
Subroutine retrieve_chromosome_size: not called CC=3 SCAR=24.8
Pod undocumented
621 0 open INFILE, '<', $inputFilepath;
622 0 my @newfasta;
623 0 my $chromosome_size = 0;
624 0 my $header_skipped = 0;
625 0 ▶ while (<INFILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline INFILE)) 0 0 0
626 0 ▶ if($header_skipped){
Branch: 1 branch
BranchTrueFalseTotal
if ($header_skipped) { } 0 0 0
627 0 chomp;
628 0 $chromosome_size += length($_);
629 }else{
630 0 $header_skipped = 1;
631 }
632 }
633 0 close INFILE;
634 0 return $chromosome_size;
635 }
636  
637 sub modify_fasta_header{
638 0 ▶ my $inputFilepath = shift;
Subroutine modify_fasta_header: not called CC=3 SCAR=24.8
Pod undocumented
639 0 my $outputFilepath = shift;
640 0 my $header = shift;
641  
642 0 open INFILE, '<', "$inputFilepath";
643 0 my @newfasta;
644 0 ▶ while (<INFILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline INFILE)) 0 0 0
645 0 push(@newfasta, $_);
646 }
647 0 close INFILE;
648 #@newfasta = @newfasta[ 1 .. $#newfasta ];
649 0 shift @newfasta;
650 0 unshift(@newfasta,">".$header."\n");
651  
652 0 open OUTFILE, '>', "$outputFilepath";
653 0 foreach my $line (@newfasta) {
654 0 print OUTFILE $line;
655 }
656 0 close OUTFILE;
657 0 return 1;
658 }
659  
660 1 1;
661 __END__
662  
663 =head1 NAME
664  
665 Bio::ViennaNGS::UCSC - Perl extension for easy UCSC Genome Browser
666 integration.
667  
668 =head1 SYNOPSIS
669  
670 use Bio::ViennaNGS::UCSC;
671  
672 =head1 DESCRIPTION
673  
674 L<Bio::ViennaNGS::UCSC> facilitates routine tasks for automatic
675 visualization of next-generation sequencing data in the UCSC Genome
676 Browser.
677  
678 =head2 EXPORT
679  
680 Routines:
681 make_assembly_hub, make_track_hub
682  
683 Variables:
684 none
685  
686 =head3 make_assembly_hub()
687  
688 Build an UCSC Genome Browser Assembly Hub. This function takes 4
689 parameters:
690  
691 =over
692  
693 =item 1 absolute path of input fasta file(e.g. /home/user/input.fa)
694  
695 =item 2 path to the ouput directory (e.g. /home/user/assemblyhubs/)
696  
697 =item 3 base URL under which the new Assembly Hub will be available on
698 the Internet, e.g. http://www.foo.com/folder/. The generated Assembly
699 Hub files must be copied to the corresponding file system location on
700 the Web Server and the URL readable for the UCSC Genome Browser server.
701  
702 =item 4 path for the log file (/home/user/logs/assemblyhubconstructionlog)
703  
704 =back
705  
706 =head3 make_track_hub()
707  
708 Build track hubs for the UCSC genome browser.
709 This function takes 4 parameters:
710  
711 =over
712  
713 =item 1 chromosome id as used in existing ucsc assembly hub (e.g. chr1)
714  
715 =item 2 path to the ouput directory (e.g. /home/user/assemblyhubs/)
716  
717 =item 3 base URL where the output folder will be placed for upload to the UCSC genome browser (e.g. http://www.foo.com/folder/)
718  
719 =item 4 path for the log file (/home/user/logs/assemblyhubconstructionlog)
720  
721 =back
722  
723 =head1 SEE ALSO
724  
725 =over
726  
727 =item L<Bio::ViennaNGS>
728  
729 =back
730  
731 =head1 AUTHORS
732  
733 =over
734  
735 =item Michael T. Wolfinger, E<lt>michael@wolfinger.euE<gt>
736  
737 =item Florian Eggenhofer, E<lt>florian.eggenhofer@univie.ac.atE<gt>
738  
739 =back
740  
741 =head1 COPYRIGHT AND LICENSE
742  
743 Copyright (C) 2014-2017 Michael T. Wolfinger, E<lt>michael@wolfinger.euE<gt>
744  
745 This library is free software; you can redistribute it and/or modify
746 it under the same terms as Perl itself, either Perl version 5.10.0 or,
747 at your option, any later version of Perl 5 you may have available.
748  
749 This program is distributed in the hope that it will be useful,
750 but WITHOUT ANY WARRANTY; without even the implied warranty of
751 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
752  
753  
754 =cut
« blib/lib/Bio/ViennaNGS/AnnoC.pm ↑ Summary blib/lib/Bio/ViennaNGS/Util.pm »