3 # Copyright (C) 2007 Martin A. Hansen.
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # http://www.gnu.org/copyleft/gpl.html
22 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
25 # Stuff for interacting with UCSC genome browser
28 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
32 use vars qw ( @ISA @EXPORT );
35 use Time::HiRes qw( gettimeofday );
62 @ISA = qw( Exporter );
64 my $TIME = gettimeofday();
67 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> BED format <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
70 # http://genome.ucsc.edu/goldenPath/help/hgTracksHelp.html#BED
73 sub bed_entry_get_array
75 # Martin A. Hansen, September 2008.
77 # Reads a BED entry given a filehandle.
79 # This is a new _faster_ BED entry parser that
80 # uses arrays and not hashrefs.
82 # IMPORTANT! This function does not correct the
83 # BED_END position that is kept the way UCSC
86 my ( $fh, # file handle
87 $cols, # columns to read - OPTIONAL (3,4,5,6, or 12)
96 $line =~ tr/\n\r//d; # some people have carriage returns in their BED files -> Grrrr
98 return if not defined $line;
100 if ( not defined $cols ) {
101 $cols = 1 + $line =~ tr/\t//;
104 @entry = split "\t", $line, $cols + 1;
106 pop @entry if scalar @entry > $cols;
108 return wantarray ? @entry : \@entry;
114 # Martin A. Hansen, December 2007.
116 # Reads a bed entry given a filehandle.
118 my ( $fh, # file handle
119 $columns, # number of BED columns to read - OPTIONAL
124 my ( $line, @fields, %entry );
128 $line =~ tr/\n\r//d; # some people have carriage returns in their BED files -> Grrrr
130 return if not defined $line;
132 @fields = split "\t", $line;
134 $columns ||= scalar @fields;
139 "CHR" => $fields[ 0 ],
140 "CHR_BEG" => $fields[ 1 ],
141 "CHR_END" => $fields[ 2 ] - 1,
144 elsif ( $columns == 4 )
147 "CHR" => $fields[ 0 ],
148 "CHR_BEG" => $fields[ 1 ],
149 "CHR_END" => $fields[ 2 ] - 1,
150 "Q_ID" => $fields[ 3 ],
153 elsif ( $columns == 5 )
156 "CHR" => $fields[ 0 ],
157 "CHR_BEG" => $fields[ 1 ],
158 "CHR_END" => $fields[ 2 ] - 1,
159 "Q_ID" => $fields[ 3 ],
160 "SCORE" => $fields[ 4 ],
163 elsif ( $columns == 6 )
166 "CHR" => $fields[ 0 ],
167 "CHR_BEG" => $fields[ 1 ],
168 "CHR_END" => $fields[ 2 ] - 1,
169 "Q_ID" => $fields[ 3 ],
170 "SCORE" => $fields[ 4 ],
171 "STRAND" => $fields[ 5 ],
174 elsif ( $columns == 12 )
177 "CHR" => $fields[ 0 ],
178 "CHR_BEG" => $fields[ 1 ],
179 "CHR_END" => $fields[ 2 ] - 1,
180 "Q_ID" => $fields[ 3 ],
181 "SCORE" => $fields[ 4 ],
182 "STRAND" => $fields[ 5 ],
183 "THICK_BEG" => $fields[ 6 ],
184 "THICK_END" => $fields[ 7 ] - 1,
185 "ITEMRGB" => $fields[ 8 ],
186 "BLOCKCOUNT" => $fields[ 9 ],
187 "BLOCKSIZES" => $fields[ 10 ],
188 "Q_BEGS" => $fields[ 11 ],
193 Maasha::Common::error( qq(Bad BED format in line->$line<-) );
196 $entry{ "REC_TYPE" } = "BED";
197 $entry{ "BED_LEN" } = $entry{ "CHR_END" } - $entry{ "CHR_BEG" } + 1;
198 $entry{ "BED_COLS" } = $columns;
200 return wantarray ? %entry : \%entry;
206 # Martin A. Hansen, January 2008.
208 # Given a path to a BED file, read in all entries
211 my ( $path, # full path to BED file
212 $columns, # number of columns in BED file - OPTIONAL (but is faster)
217 my ( $fh, $entry, @list );
219 $fh = Maasha::Common::read_open( $path );
221 while ( $entry = bed_get_entry( $fh ) ) {
227 return wantarray ? @list : \@list;
231 sub bed_entry_put_array
233 # Martin A. Hansen, Septermber 2008.
235 # Writes a BED entry array to file.
237 # IMPORTANT! This function does not correct the
238 # BED_END position that is assumed to be in the
239 # UCSC positions scheme.
242 $fh, # file handle - OPTIONAL
243 $cols, # number of columns in BED file - OPTIONAL
248 $fh = \*STDOUT if not defined $fh;
250 if ( defined $cols ) {
251 print $fh join( "\t", @{ $record }[ 0 .. $cols - 1 ] ), "\n";
253 print $fh join( "\t", @{ $record } ), "\n";
260 # Martin A. Hansen, Septermber 2007.
262 # Writes a BED entry to file.
264 # NB, this could really be more robust!?
266 my ( $record, # hashref
267 $fh, # file handle - OPTIONAL
268 $columns, # number of columns in BED file - OPTIONAL (but is faster)
275 $columns ||= 12; # max number of columns possible
279 push @fields, $record->{ "CHR" };
280 push @fields, $record->{ "CHR_BEG" };
281 push @fields, $record->{ "CHR_END" } + 1;
283 elsif ( $columns == 4 )
285 $record->{ "Q_ID" } =~ s/\s+/_/g;
287 push @fields, $record->{ "CHR" };
288 push @fields, $record->{ "CHR_BEG" };
289 push @fields, $record->{ "CHR_END" } + 1;
290 push @fields, $record->{ "Q_ID" };
292 elsif ( $columns == 5 )
294 $record->{ "Q_ID" } =~ s/\s+/_/g;
295 $record->{ "SCORE" } =~ s/\.\d*//;
297 push @fields, $record->{ "CHR" };
298 push @fields, $record->{ "CHR_BEG" };
299 push @fields, $record->{ "CHR_END" } + 1;
300 push @fields, $record->{ "Q_ID" };
301 push @fields, $record->{ "SCORE" };
303 elsif ( $columns == 6 )
305 $record->{ "Q_ID" } =~ s/\s+/_/g;
306 $record->{ "SCORE" } =~ s/\.\d*//;
308 push @fields, $record->{ "CHR" };
309 push @fields, $record->{ "CHR_BEG" };
310 push @fields, $record->{ "CHR_END" } + 1;
311 push @fields, $record->{ "Q_ID" };
312 push @fields, $record->{ "SCORE" };
313 push @fields, $record->{ "STRAND" };
317 $record->{ "Q_ID" } =~ s/\s+/_/g;
318 $record->{ "SCORE" } =~ s/\.\d*//;
320 push @fields, $record->{ "CHR" };
321 push @fields, $record->{ "CHR_BEG" };
322 push @fields, $record->{ "CHR_END" } + 1;
323 push @fields, $record->{ "Q_ID" };
324 push @fields, $record->{ "SCORE" };
325 push @fields, $record->{ "STRAND" };
326 push @fields, $record->{ "THICK_BEG" } if defined $record->{ "THICK_BEG" };
327 push @fields, $record->{ "THICK_END" } + 1 if defined $record->{ "THICK_END" };
328 push @fields, $record->{ "ITEMRGB" } if defined $record->{ "ITEMRGB" };
329 push @fields, $record->{ "BLOCKCOUNT" } if defined $record->{ "BLOCKCOUNT" };
330 push @fields, $record->{ "BLOCKSIZES" } if defined $record->{ "BLOCKSIZES" };
331 push @fields, $record->{ "Q_BEGS" } if defined $record->{ "Q_BEGS" };
335 print $fh join( "\t", @fields ), "\n";
337 print join( "\t", @fields ), "\n";
344 # Martin A. Hansen, January 2008.
346 # Write a list of BED entries.
348 my ( $entries, # list of entries,
349 $fh, # file handle - OPTIONAL
354 map { bed_put_entry( $_, $fh ) } @{ $entries };
360 # Martin A. Hansen, March 2008.
362 # Given a bed record, analysis this to give information
363 # about intron/exon sizes.
365 my ( $entry, # BED entry
370 my ( $i, @begs, @lens, $exon_max, $exon_min, $exon_len, $exon_tot, $intron_max, $intron_min, $intron_len, $intron_tot );
373 $exon_min = 9999999999;
375 $intron_min = 9999999999;
377 $entry->{ "EXONS" } = $entry->{ "BLOCKCOUNT" };
379 @begs = split /,/, $entry->{ "Q_BEGS" };
380 @lens = split /,/, $entry->{ "BLOCKSIZES" };
382 for ( $i = 0; $i < $entry->{ "BLOCKCOUNT" }; $i++ )
384 $exon_len = @lens[ $i ];
386 $entry->{ "EXON_LEN_$i" } = $exon_len;
388 $exon_max = $exon_len if $exon_len > $exon_max;
389 $exon_min = $exon_len if $exon_len < $exon_min;
391 $exon_tot += $exon_len;
394 $entry->{ "EXON_LEN_-1" } = $exon_len;
395 $entry->{ "EXON_MAX_LEN" } = $exon_max;
396 $entry->{ "EXON_MIN_LEN" } = $exon_min;
397 $entry->{ "EXON_MEAN_LEN" } = int( $exon_tot / $entry->{ "EXONS" } );
399 $entry->{ "INTRONS" } = $entry->{ "BLOCKCOUNT" } - 1;
400 $entry->{ "INTRONS" } = 0 if $entry->{ "INTRONS" } < 0;
402 if ( $entry->{ "INTRONS" } )
404 for ( $i = 1; $i < $entry->{ "BLOCKCOUNT" }; $i++ )
406 $intron_len = @begs[ $i ] - ( @begs[ $i - 1 ] + @lens[ $i - 1 ] );
408 $entry->{ "INTRON_LEN_" . ( $i - 1 ) } = $intron_len;
410 $intron_max = $intron_len if $intron_len > $intron_max;
411 $intron_min = $intron_len if $intron_len < $intron_min;
413 $intron_tot += $intron_len;
416 $entry->{ "INTRON_LEN_-1" } = $intron_len;
417 $entry->{ "INTRON_MAX_LEN" } = $intron_max;
418 $entry->{ "INTRON_MIN_LEN" } = $intron_min;
419 $entry->{ "INTRON_MEAN_LEN" } = int( $intron_tot / $entry->{ "INTRONS" } );
422 return wantarray ? %{ $entry } : $entry;
428 # Martin A. Hansen, Septermber 2008
430 # Sorts a BED file using the c program
431 # "bed_sort" specifing a sort mode:
433 # 1: chr AND chr_beg.
434 # 2: chr AND strand AND chr_beg.
436 # 4: strand AND chr_beg.
438 my ( $bed_file, # BED file to sort
439 $sort_mode, # See above.
440 $cols, # Number of columns in BED file
443 &Maasha::Common::run( "bed_sort", "--sort $sort_mode --cols $cols $bed_file" );
447 sub bed_split_to_files
449 # Martin A. Hansen, Septermber 2008
451 # Given a list of BED files, split these
452 # into temporary files based on the chromosome
453 # name. Returns a list of the temporary files.
455 my ( $bed_files, # list of BED files to split
456 $cols, # number of columns
457 $tmp_dir, # temporary directory
462 my ( $bed_file, $fh_in, $entry, $key, %fh_hash, @tmp_files );
464 foreach $bed_file ( @{ $bed_files } )
466 $fh_in = Maasha::Common::read_open( $bed_file );
468 while ( $entry = bed_entry_get_array( $fh_in, $cols ) )
470 $key = $entry->[ CHR ];
472 $fh_hash{ $key } = Maasha::Common::write_open( "$tmp_dir/$key.temp" ) if not exists $fh_hash{ $key };
474 bed_entry_put_array( $entry, $fh_hash{ $key } );
480 foreach $key ( sort keys %fh_hash )
482 push @tmp_files, "$tmp_dir/$key.temp";
484 close $fh_hash{ $key };
487 return wantarray ? @tmp_files : \@tmp_files;
491 sub bed_merge_entries
493 # Martin A. Hansen, February 2008.
495 # Merge a list of given BED entries in one big entry.
497 my ( $entries, # list of BED entries to be merged
502 my ( $i, @q_ids, @q_begs, @blocksizes, @new_q_begs, @new_blocksizes, %new_entry );
504 @{ $entries } = sort { $a->{ "CHR_BEG" } <=> $b->{ "CHR_BEG" } } @{ $entries };
506 for ( $i = 0; $i < @{ $entries }; $i++ )
508 Maasha::Common::error( qq(Attempted merge of BED entries from different chromosomes) ) if $entries->[ 0 ]->{ "CHR" } ne $entries->[ $i ]->{ "CHR" };
509 Maasha::Common::error( qq(Attempted merge of BED entries from different strands) ) if $entries->[ 0 ]->{ "STRAND" } ne $entries->[ $i ]->{ "STRAND" };
511 push @q_ids, $entries->[ $i ]->{ "Q_ID" } || sprintf( "ID%06d", $i );
513 if ( exists $entries->[ $i ]->{ "Q_BEGS" } )
515 @q_begs = split ",", $entries->[ $i ]->{ "Q_BEGS" };
516 @blocksizes = split ",", $entries->[ $i ]->{ "BLOCKSIZES" };
521 @blocksizes = $entries->[ $i ]->{ "CHR_END" } - $entries->[ $i ]->{ "CHR_BEG" } + 1;
524 map { $_ += $entries->[ $i ]->{ "CHR_BEG" } } @q_begs;
526 push @new_q_begs, @q_begs;
527 push @new_blocksizes, @blocksizes;
530 map { $_ -= $entries->[ 0 ]->{ "CHR_BEG" } } @new_q_begs;
533 CHR => $entries->[ 0 ]->{ "CHR" },
534 CHR_BEG => $entries->[ 0 ]->{ "CHR_BEG" },
535 CHR_END => $entries->[ -1 ]->{ "CHR_END" },
537 BED_LEN => $entries->[ -1 ]->{ "CHR_END" } - $entries->[ 0 ]->{ "CHR_BEG" } + 1,
539 Q_ID => join( ":", @q_ids ),
541 STRAND => $entries->[ 0 ]->{ "STRAND" } || "+",
542 THICK_BEG => $entries->[ 0 ]->{ "THICK_BEG" } || $entries->[ 0 ]->{ "CHR_BEG" },
543 THICK_END => $entries->[ -1 ]->{ "THICK_END" } || $entries->[ -1 ]->{ "CHR_END" },
545 BLOCKCOUNT => scalar @new_q_begs,
546 BLOCKSIZES => join( ",", @new_blocksizes ),
547 Q_BEGS => join( ",", @new_q_begs ),
550 return wantarray ? %new_entry : \%new_entry;
556 # Martin A. Hansen, February 2008.
558 # Splits a given BED entry into a list of blocks,
559 # which are returned. A list of 6 column BED entry is returned.
561 my ( $entry, # BED entry hashref
566 my ( @q_begs, @blocksizes, $block, @blocks, $i );
568 if ( exists $entry->{ "BLOCKCOUNT" } )
570 @q_begs = split ",", $entry->{ "Q_BEGS" };
571 @blocksizes = split ",", $entry->{ "BLOCKSIZES" };
573 for ( $i = 0; $i < @q_begs; $i++ )
577 $block->{ "CHR" } = $entry->{ "CHR" };
578 $block->{ "CHR_BEG" } = $entry->{ "CHR_BEG" } + $q_begs[ $i ];
579 $block->{ "CHR_END" } = $entry->{ "CHR_BEG" } + $q_begs[ $i ] + $blocksizes[ $i ] - 1;
580 $block->{ "Q_ID" } = $entry->{ "Q_ID" } . sprintf( "_%03d", $i );
581 $block->{ "SCORE" } = $entry->{ "SCORE" };
582 $block->{ "STRAND" } = $entry->{ "STRAND" };
583 $block->{ "BED_LEN" } = $block->{ "CHR_END" } - $block->{ "CHR_BEG" } + 1,
584 $block->{ "BED_COLS" } = 6;
585 $block->{ "REC_TYPE" } = "BED";
587 push @blocks, $block;
592 @blocks = @{ $entry };
595 return wantarray ? @blocks : \@blocks;
602 # Martin A. Hansen, February 2008.
604 # Checks if two BED entries overlap and
605 # return 1 if so - else 0;
607 my ( $entry1, # hashref
609 $no_strand, # don't check strand flag - OPTIONAL
614 return 0 if $entry1->{ "CHR" } ne $entry2->{ "CHR" };
615 return 0 if $entry1->{ "STRAND" } ne $entry2->{ "STRAND" };
617 if ( $entry1->{ "CHR_END" } < $entry2->{ "CHR_BEG" } or $entry1->{ "CHR_BEG" } > $entry2->{ "CHR_END" } ) {
625 sub bed_upload_to_ucsc
627 # Martin A. Hansen, September 2007.
629 # Upload a BED file to the UCSC database.
631 my ( $tmp_dir, # temporary directory
632 $file, # file to upload,
633 $options, # argument hashref
634 $append, # flag indicating table should be appended
639 my ( $args, $table, $sql_file, $fh_out, $fh_in );
642 $args = join " ", $options->{ "database" }, $options->{ "table" }, "-tmpDir=$tmp_dir", "-oldTable", $file;
644 $args = join " ", $options->{ "database" }, $options->{ "table" }, "-tmpDir=$tmp_dir", $file;
647 if ( $options->{ "sec_struct" } )
649 $table = $options->{ "table" };
651 Maasha::Common::error( "Attempt to load secondary structure track without 'rnaSecStr' in table name" ) if not $table =~ /rnaSecStr/;
653 $sql_file = "$tmp_dir/upload_RNA_SS.sql";
655 $fh_out = Maasha::Common::write_open( $sql_file );
658 CREATE TABLE $table (
659 bin smallint not null, # Bin number for browser speedup
660 chrom varchar(255) not null, # Chromosome or FPC contig
661 chromStart int unsigned not null, # Start position in chromosome
662 chromEnd int unsigned not null, # End position in chromosome
663 name varchar(255) not null, # Name of item
664 score int unsigned not null, # Score from 0-1000
665 strand char(1) not null, # + or -
666 size int unsigned not null, # Size of element.
667 secStr longblob not null, # Parentheses and '.'s which define the secondary structure
668 conf longblob not null, # Confidence of secondary-structure annotation per position (0.0-1.0).
671 INDEX(chrom(8), bin),
672 INDEX(chrom(8), chromStart)
678 Maasha::Common::run( "hgLoadBed", "-notItemRgb -sqlTable=$sql_file $options->{ 'database' } $options->{ 'table' } -tmpDir=$tmp_dir $file > /dev/null 2>&1" );
684 Maasha::Common::run( "hgLoadBed", "$args > /dev/null 2>&1" );
689 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PSL format <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
694 # Martin A. Hansen, August 2008.
696 # Reads PSL next entry from a PSL file and returns a record.
698 my ( $fh, # file handle of PSL filefull path to PSL file
703 my ( $line, @fields, %record );
705 while ( $line = <$fh> )
709 @fields = split "\t", $line;
711 if ( scalar @fields == 21 )
715 MATCHES => $fields[ 0 ],
716 MISMATCHES => $fields[ 1 ],
717 REPMATCHES => $fields[ 2 ],
718 NCOUNT => $fields[ 3 ],
719 QNUMINSERT => $fields[ 4 ],
720 QBASEINSERT => $fields[ 5 ],
721 SNUMINSERT => $fields[ 6 ],
722 SBASEINSERT => $fields[ 7 ],
723 STRAND => $fields[ 8 ],
724 Q_ID => $fields[ 9 ],
725 Q_LEN => $fields[ 10 ],
726 Q_BEG => $fields[ 11 ],
727 Q_END => $fields[ 12 ] - 1,
728 S_ID => $fields[ 13 ],
729 S_LEN => $fields[ 14 ],
730 S_BEG => $fields[ 15 ],
731 S_END => $fields[ 16 ] - 1,
732 BLOCKCOUNT => $fields[ 17 ],
733 BLOCKSIZES => $fields[ 18 ],
734 Q_BEGS => $fields[ 19 ],
735 S_BEGS => $fields[ 20 ],
738 $record{ "SCORE" } = $record{ "MATCHES" } + int( $record{ "REPMATCHES" } / 2 ) - $record{ "MISMATCHES" } - $record{ "QNUMINSERT" } - $record{ "SNUMINSERT" };
739 $record{ "SPAN" } = $fields[ 12 ] - $fields[ 11 ];
741 return wantarray ? %record : \%record;
751 # Martin A. Hansen, February 2008.
753 # Reads PSL entries and returns a list of records.
755 my ( $path, # full path to PSL file
760 my ( $fh, @lines, @fields, $i, %record, @records );
762 $fh = Maasha::Common::read_open( $path );
770 for ( $i = 5; $i < @lines; $i++ )
772 @fields = split "\t", $lines[ $i ];
774 Maasha::Common::error( qq(Bad PSL format in file "$path") ) if not @fields == 21;
780 MATCHES => $fields[ 0 ],
781 MISMATCHES => $fields[ 1 ],
782 REPMATCHES => $fields[ 2 ],
783 NCOUNT => $fields[ 3 ],
784 QNUMINSERT => $fields[ 4 ],
785 QBASEINSERT => $fields[ 5 ],
786 SNUMINSERT => $fields[ 6 ],
787 SBASEINSERT => $fields[ 7 ],
788 STRAND => $fields[ 8 ],
789 Q_ID => $fields[ 9 ],
790 Q_LEN => $fields[ 10 ],
791 Q_BEG => $fields[ 11 ],
792 Q_END => $fields[ 12 ] - 1,
793 S_ID => $fields[ 13 ],
794 S_LEN => $fields[ 14 ],
795 S_BEG => $fields[ 15 ],
796 S_END => $fields[ 16 ] - 1,
797 BLOCKCOUNT => $fields[ 17 ],
798 BLOCKSIZES => $fields[ 18 ],
799 Q_BEGS => $fields[ 19 ],
800 S_BEGS => $fields[ 20 ],
803 $record{ "SCORE" } = $record{ "MATCHES" } + int( $record{ "REPMATCHES" } / 2 ) - $record{ "MISMATCHES" } - $record{ "QNUMINSERT" } - $record{ "SNUMINSERT" };
805 push @records, { %record };
808 return wantarray ? @records : \@records;
814 # Martin A. Hansen, September 2007.
816 # Write a PSL header to file.
818 my ( $fh, # file handle - OPTIONAL
823 $fh = \*STDOUT if not $fh;
825 print $fh qq(psLayout version 3
826 match mis- rep. N's Q gap Q gap T gap T gap strand Q Q Q Q T T T T block blockSizes qStart match match count bases count bases name size start end name size start end count
827 ---------------------------------------------------------------------------------------------------------------------------------------------------------------
834 # Martin A. Hansen, September 2007.
836 # Write a PSL entry to file.
838 my ( $record, # hashref
839 $fh, # file handle - OPTIONAL
844 $fh = \*STDOUT if not $fh;
848 push @output, $record->{ "MATCHES" };
849 push @output, $record->{ "MISMATCHES" };
850 push @output, $record->{ "REPMATCHES" };
851 push @output, $record->{ "NCOUNT" };
852 push @output, $record->{ "QNUMINSERT" };
853 push @output, $record->{ "QBASEINSERT" };
854 push @output, $record->{ "SNUMINSERT" };
855 push @output, $record->{ "SBASEINSERT" };
856 push @output, $record->{ "STRAND" };
857 push @output, $record->{ "Q_ID" };
858 push @output, $record->{ "Q_LEN" };
859 push @output, $record->{ "Q_BEG" };
860 push @output, $record->{ "Q_END" } + 1;
861 push @output, $record->{ "S_ID" };
862 push @output, $record->{ "S_LEN" };
863 push @output, $record->{ "S_BEG" };
864 push @output, $record->{ "S_END" } + 1;
865 push @output, $record->{ "BLOCKCOUNT" };
866 push @output, $record->{ "BLOCKSIZES" };
867 push @output, $record->{ "Q_BEGS" };
868 push @output, $record->{ "S_BEGS" };
870 print $fh join( "\t", @output ), "\n";
874 sub psl_upload_to_ucsc
876 # Martin A. Hansen, September 2007.
878 # Upload a PSL file to the UCSC database.
880 my ( $file, # file to upload,
881 $options, # argument hashref
882 $append, # flag indicating table should be appended
890 $args = join " ", $options->{ "database" }, "-table=$options->{ 'table' }", "-clientLoad", "-append", $file;
892 $args = join " ", $options->{ "database" }, "-table=$options->{ 'table' }", "-clientLoad", $file;
895 Maasha::Common::run( "hgLoadPsl", "$args > /dev/null 2>&1" );
899 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> TRACK FILE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
902 sub ucsc_config_get_entry
904 # Martin A. Hansen, November 2008.
906 # Given a filehandle to a UCSC Genome Browser
907 # config file (.ra) get the next entry and
908 # return as a hash. Entries are separated by blank
909 # lines. # lines are skipped unless it is the lines:
913 my ( $fh, # file hanlde
918 my ( $line, %record );
920 while ( $line = <$fh> )
922 if ( $line =~ /Track added by 'upload_to_ucsc' (\S+) (\S+)/) {
923 $record{ 'date' } = $1;
924 $record{ 'time' } = $2;
925 } elsif ( $line =~ /^# date: (.+)/ ) {
926 $record{ 'date' } = $1;
927 } elsif ( $line =~ /^# time: (.+)/ ) {
928 $record{ 'time' } = $1;
929 } elsif ( $line =~ /^# (?:database:|Database) (.+)/ ) {
930 $record{ 'database' } = $1;
931 } elsif ( $line =~ /^#/ ) {
933 } elsif ( $line =~ /(\S+)\s+(.+)/ ) {
937 last if $line =~ /^$/ and exists $record{ "track" };
940 return undef if not exists $record{ "track" };
942 return wantarray ? %record : \%record;
946 sub ucsc_config_put_entry
948 # Martin A. Hansen, November 2008.
950 # Outputs a Biopiece record (a hashref)
951 # to a filehandle or STDOUT.
953 my ( $record, # hashref
954 $fh_out, # file handle
961 $fh_out ||= \*STDOUT;
963 ( $date, $time ) = split " ", Maasha::Common::time_stamp();
965 $record->{ "date" } ||= $date;
966 $record->{ "time" } ||= $time;
968 print $fh_out "\n# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n\n";
970 map { print $fh_out "# $_: $record->{ $_ }\n" if exists $record->{ $_ } } qw( date time database );
971 map { print $fh_out "$_ $record->{ $_ }\n" if exists $record->{ $_ } } qw( track
992 # Martin A. Hansen, September 2007.
994 # Update the /home/user/ucsc/my_tracks.ra file and executes makeCustomTracks.pl
996 my ( $options, # hashref
1002 my ( $file, $fh_in, $fh_out, $line, $time );
1004 $file = $ENV{ "HOME" } . "/ucsc/my_tracks.ra";
1006 # ---- create a backup ----
1008 $fh_in = Maasha::Common::read_open( $file );
1009 $fh_out = Maasha::Common::write_open( "$file~" );
1011 while ( $line = <$fh_in> ) {
1012 print $fh_out $line;
1018 # ---- append track ----
1020 $time = Maasha::Common::time_stamp();
1022 $fh_out = Maasha::Common::append_open( $file );
1024 if ( $type eq "sec_struct" )
1026 print $fh_out "\n\n# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
1028 print $fh_out "\n# Track added by 'upload_to_ucsc' $time\n\n";
1030 print $fh_out "# Database $options->{ 'database' }\n\n";
1032 print $fh_out "track $options->{ 'table' }\n";
1033 print $fh_out "shortLabel $options->{ 'short_label' }\n";
1034 print $fh_out "longLabel $options->{ 'long_label' }\n";
1035 print $fh_out "group $options->{ 'group' }\n";
1036 print $fh_out "priority $options->{ 'priority' }\n";
1037 print $fh_out "visibility $options->{ 'visibility' }\n";
1038 print $fh_out "color $options->{ 'color' }\n";
1039 print $fh_out "type bed 6 +\n";
1040 print $fh_out "mafTrack multiz17way\n";
1042 print $fh_out "\n# //\n";
1046 print $fh_out "\n\n# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n";
1048 print $fh_out "\n# Track added by 'upload_to_ucsc' $time\n\n";
1050 print $fh_out "# Database $options->{ 'database' }\n\n";
1052 print $fh_out "track $options->{ 'table' }\n";
1053 print $fh_out "shortLabel $options->{ 'short_label' }\n";
1054 print $fh_out "longLabel $options->{ 'long_label' }\n";
1055 print $fh_out "group $options->{ 'group' }\n";
1056 print $fh_out "priority $options->{ 'priority' }\n";
1057 print $fh_out "useScore 1\n" if $options->{ 'use_score' };
1058 print $fh_out "visibility $options->{ 'visibility' }\n";
1059 print $fh_out "maxHeightPixels 50:50:11\n" if $type eq "wig 0";
1060 print $fh_out "color $options->{ 'color' }\n";
1061 print $fh_out "type $type\n";
1063 print $fh_out "\n# //\n";
1068 Maasha::Common::run( "ucscMakeTracks.pl", "-b > /dev/null 2>&1" );
1072 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> fixedStep format <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
1075 sub fixedstep_get_entry
1077 # Martin A. Hansen, December 2007.
1079 # Given a file handle to a PhastCons file get the
1080 # next entry which is all the lines after a "fixedStep"
1081 # line and until the next "fixedStep" line or EOF.
1083 my ( $fh, # filehandle
1086 # Returns a list of lines
1088 my ( $entry, @lines );
1090 local $/ = "\nfixedStep ";
1096 @lines = split "\n", $entry;
1098 return if @lines == 0;
1100 $lines[ 0 ] =~ s/fixedStep?\s*//;
1102 return wantarray ? @lines : \@lines;
1106 sub fixedstep_index_create
1108 # Martin A. Hansen, January 2008.
1110 # Indexes a concatenated fixedStep file.
1111 # The index consists of a hash with chromosomes as keys,
1112 # and a list of [ chr_beg, next_chr_beg, chr_end, index_beg, index_len ] as values.
1114 my ( $path, # path to fixedStep file
1119 my ( $fh, $pos, $index_beg, $index_len, $entry, $locator, $chr, $step, $beg, $end, $len, %index, $i );
1121 $fh = Maasha::Common::read_open( $path );
1125 while ( $entry = Maasha::UCSC::fixedstep_get_entry( $fh ) )
1127 $locator = shift @{ $entry };
1129 if ( $locator =~ /chrom=([^ ]+) start=(\d+) step=(\d+)/ )
1132 $beg = $2 - 1; # fixedStep files are 1-based
1137 Maasha::Common::error( qq(Could not parse locator: $locator) );
1140 $pos += length( $locator ) + 11;
1144 # map { $pos += length( $_ ) + 1 } @{ $entry };
1146 $pos += 6 * scalar @{ $entry };
1148 $index_len = $pos - $index_beg;
1150 push @{ $index{ $chr } }, [ $beg, undef, $beg + scalar @{ $entry } - 1, $index_beg, $index_len ];
1155 foreach $chr ( keys %index )
1157 for ( $i = 0; $i < @{ $index{ $chr } } - 1; $i++ ) {
1158 $index{ $chr }->[ $i ]->[ FS_NEXT_CHR_BEG ] = $index{ $chr }->[ $i + 1 ]->[ 0 ];
1161 $index{ $chr }->[ -1 ]->[ FS_NEXT_CHR_BEG ] = $index{ $chr }->[ -1 ]->[ FS_CHR_END ] + 1;
1164 return wantarray ? %index : \%index;
1168 sub fixedstep_index_store
1170 # Martin A. Hansen, January 2008.
1172 # Writes a fixedStep index to binary file.
1174 my ( $path, # full path to file
1175 $index, # list with index
1180 Maasha::Common::file_store( $path, $index );
1184 sub fixedstep_index_retrieve
1186 # Martin A. Hansen, January 2008.
1188 # Retrieves a fixedStep index from binary file.
1190 my ( $path, # full path to file
1197 $index = Maasha::Common::file_retrieve( $path );
1199 return wantarray ? %{ $index } : $index;
1203 sub fixedstep_index_lookup
1205 # Martin A. Hansen, January 2008.
1207 # Retrieve fixedStep scores from a indexed
1208 # fixedStep file given a chromosome and
1209 # begin and end positions.
1211 my ( $index, # data structure
1212 $fh, # filehandle to datafile
1214 $chr_beg, # chromosome beg
1215 $chr_end, # chromosome end
1216 $flank, # include flanking region - OPTIONAL
1221 my ( $index_beg, $index_end, $i, $c, $beg, $end, @vals, $scores );
1228 # print "chr_beg->$chr_beg chr_end->$chr_end flank->$flank\n";
1230 if ( exists $index->{ $chr } )
1232 $index_beg = Maasha::Matrix::interval_search( $index->{ $chr }, 0, 1, $chr_beg );
1234 if ( $index_beg < 0 ) {
1235 Maasha::Common::error( qq(Index search failed - begin index position doesn't exists: $chr_beg) );
1238 if ( $chr_end < $index->{ $chr }->[ $index_beg ]->[ 1 ] )
1240 $index_end = $index_beg;
1244 $index_end = Maasha::Matrix::interval_search( $index->{ $chr }, 0, 1, $chr_end );
1246 if ( $index_end < 0 ) {
1247 Maasha::Common::error( qq(Index search failed - end index position doesn't exists: $chr_end) );
1251 map { $scores->[ $_ ] = 0 } 0 .. $chr_end - $chr_beg;
1253 if ( $index_beg == $index_end )
1255 $beg = Maasha::Calc::max( $chr_beg, $index->{ $chr }->[ $index_beg ]->[ FS_CHR_BEG ] );
1256 $end = Maasha::Calc::min( $chr_end, $index->{ $chr }->[ $index_end ]->[ FS_CHR_END ] );
1258 if ( $beg <= $index->{ $chr }->[ $index_beg ]->[ FS_CHR_END ] and $end >= $index->{ $chr }->[ $index_beg ]->[ FS_CHR_BEG ] )
1260 @vals = split "\n", Maasha::Common::file_read(
1262 $index->{ $chr }->[ $index_beg ]->[ FS_INDEX_BEG ] + 6 * ( $beg - $index->{ $chr }->[ $index_beg ]->[ FS_CHR_BEG ] ),
1263 6 * ( $end - $beg + 1 ),
1267 for ( $c = 0; $c < @vals; $c++ ) {
1268 $scores->[ $c + $beg - $chr_beg ] = $vals[ $c ];
1273 $beg = Maasha::Calc::max( $chr_beg, $index->{ $chr }->[ $index_beg ]->[ FS_CHR_BEG ] );
1275 # print Dumper( $beg, $index->{ $chr }->[ $index_beg ] );
1276 # print Dumper( "next", $index->{ $chr }->[ $index_beg ]->[ FS_NEXT_CHR_BEG ] );
1282 if ( $beg <= $index->{ $chr }->[ $index_beg ]->[ FS_CHR_END ] )
1284 @vals = split "\n", Maasha::Common::file_read(
1286 $index->{ $chr }->[ $index_beg ]->[ FS_INDEX_BEG ] + 6 * ( $beg - $index->{ $chr }->[ $index_beg ]->[ FS_CHR_BEG ] ),
1287 6 * ( $index->{ $chr }->[ $index_beg ]->[ FS_CHR_END ] - $beg + 1 ),
1290 for ( $c = 0; $c < @vals; $c++ ) {
1291 $scores->[ $c + $beg - $chr_beg ] = $vals[ $c ];
1295 $end = Maasha::Calc::min( $chr_end, $index->{ $chr }->[ $index_end ]->[ FS_CHR_END ] );
1297 if ( $end <= $index->{ $chr }->[ $index_end ]->[ FS_CHR_END ] )
1299 @vals = split "\n", Maasha::Common::file_read(
1301 $index->{ $chr }->[ $index_end ]->[ FS_INDEX_BEG ],
1302 6 * ( $end - $index->{ $chr }->[ $index_end ]->[ FS_CHR_BEG ] + 1 ),
1305 for ( $c = 0; $c < @vals; $c++ ) {
1306 $scores->[ $c + $index->{ $chr }->[ $index_end ]->[ FS_CHR_BEG ] - $chr_beg ] = $vals[ $c ];
1310 for ( $i = $index_beg + 1; $i <= $index_end - 1; $i++ )
1312 @vals = split "\n", Maasha::Common::file_read(
1314 $index->{ $chr }->[ $i ]->[ FS_INDEX_BEG ],
1315 6 * ( $index->{ $chr }->[ $i ]->[ FS_CHR_END ] - $index->{ $chr }->[ $i ]->[ FS_CHR_BEG ] + 1 ),
1318 for ( $c = 0; $c < @vals; $c++ ) {
1319 $scores->[ $c + $index->{ $chr }->[ $i ]->[ FS_CHR_BEG ] - $chr_beg ] = $vals[ $c ];
1326 Maasha::Common::error( qq(Chromosome "$chr" was not found in index) );
1329 return wantarray ? @{ $scores } : $scores;
1333 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PhastCons format <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
1338 # Martin A. Hansen, July 2008
1340 # Create a fixedStep index for PhastCons data.
1342 my ( $file, # file to index
1343 $dir, # dir with file
1350 $index = fixedstep_index_create( "$dir/$file" );
1352 fixedstep_index_store( "$dir/$file.index", $index );
1356 sub phastcons_parse_entry
1358 # Martin A. Hansen, December 2007.
1360 # Given a PhastCons entry converts this to a
1361 # list of super blocks.
1363 my ( $lines, # list of lines
1364 $args, # argument hash
1369 my ( $info, $chr, $beg, $step, $i, $c, $j, @blocks, @super_blocks, @entries, $super_block, $block, @lens, @begs );
1371 $info = shift @{ $lines };
1373 if ( $info =~ /^chrom=([^ ]+) start=(\d+) step=(\d+)$/ )
1379 die qq(ERROR: step size $step != 1 -> problem!\n) if $step != 1; # in an ideal world should would be fixed ...
1384 while ( $i < @{ $lines } )
1386 if ( $lines->[ $i ] >= $args->{ "threshold" } )
1390 while ( $c < @{ $lines } )
1392 if ( $lines->[ $c ] < $args->{ "threshold" } )
1396 while ( $j < @{ $lines } and $lines->[ $j ] < $args->{ "threshold" } ) {
1400 if ( $j - $c > $args->{ "gap" } )
1402 if ( $c - $i >= $args->{ "min" } )
1406 CHR_BEG => $beg + $i - 1,
1407 CHR_END => $beg + $c - 2,
1425 if ( $c - $i >= $args->{ "min" } )
1429 CHR_BEG => $beg + $i - 1,
1430 CHR_END => $beg + $c - 2,
1445 while ( $i < @blocks )
1449 while ( $c < @blocks and $blocks[ $c ]->{ "CHR_BEG" } - $blocks[ $c - 1 ]->{ "CHR_END" } <= $args->{ "dist" } )
1454 push @super_blocks, [ @blocks[ $i .. $c - 1 ] ];
1459 foreach $super_block ( @super_blocks )
1461 foreach $block ( @{ $super_block } )
1463 push @begs, $block->{ "CHR_BEG" } - $super_block->[ 0 ]->{ "CHR_BEG" };
1464 push @lens, $block->{ "CHR_LEN" } - 1;
1470 CHR => $super_block->[ 0 ]->{ "CHR" },
1471 CHR_BEG => $super_block->[ 0 ]->{ "CHR_BEG" },
1472 CHR_END => $super_block->[ -1 ]->{ "CHR_END" },
1476 THICK_BEG => $super_block->[ 0 ]->{ "CHR_BEG" },
1477 THICK_END => $super_block->[ -1 ]->{ "CHR_END" } + 1,
1478 ITEMRGB => "0,200,100",
1479 BLOCKCOUNT => scalar @{ $super_block },
1480 BLOCKSIZES => join( ",", @lens ),
1481 Q_BEGS => join( ",", @begs ),
1488 return wantarray ? @entries : \@entries;
1492 sub phastcons_normalize
1494 # Martin A. Hansen, January 2008.
1496 # Normalizes a list of lists with PhastCons scores,
1497 # in such a way that each list contains the same number
1498 # or PhastCons scores.
1500 my ( $AoA, # AoA with PhastCons scores
1505 my ( $list, $max, $min, $mean, $diff );
1510 foreach $list ( @{ $AoA } )
1512 $min = scalar @{ $list } if scalar @{ $list } < $min;
1513 $max = scalar @{ $list } if scalar @{ $list } > $max;
1516 $mean = int( ( $min + $max ) / 2 );
1518 # print STDERR "min->$min max->$max mean->$mean\n";
1520 foreach $list ( @{ $AoA } )
1522 $diff = scalar @{ $list } - $mean;
1524 phastcons_list_inflate( $list, abs( $diff ) ) if $diff < 0;
1525 phastcons_list_deflate( $list, $diff ) if $diff > 0;
1528 return wantarray ? @{ $AoA } : $AoA;
1532 sub phastcons_list_inflate
1534 # Martin A. Hansen, January 2008.
1536 # Inflates a list with a given number of elements
1537 # in such a way that the extra elements are introduced
1538 # evenly over the entire length of the list. The value
1539 # of the extra elements is based on a mean of the
1540 # adjacent elements.
1542 my ( $list, # list of elements
1543 $diff, # number of elements to introduce
1548 my ( $len, $space, $i, $pos );
1550 $len = scalar @{ $list };
1552 $space = $len / $diff;
1554 for ( $i = 0; $i < $diff; $i++ )
1556 $pos = int( ( $space / 2 ) + $i * $space );
1558 splice @{ $list }, $pos, 0, ( $list->[ $pos - 1 ] + $list->[ $pos + 1 ] ) / 2;
1559 # splice @{ $list }, $pos, 0, "X";
1562 die qq(ERROR: bad inflate\n) if scalar @{ $list } != $len + $diff;
1566 sub phastcons_list_deflate
1568 # Martin A. Hansen, January 2008.
1570 # Deflates a list by removing a given number of elements
1571 # evenly distributed over the entire list.
1573 my ( $list, # list of elements
1574 $diff, # number of elements to remove
1579 my ( $len, $space, $i, $pos );
1581 $len = scalar @{ $list };
1583 $space = ( $len - $diff ) / $diff;
1585 for ( $i = 0; $i < $diff; $i++ )
1587 $pos = int( ( $space / 2 ) + $i * $space );
1589 splice @{ $list }, $pos, 1;
1592 die qq(ERROR: bad deflate\n) if scalar @{ $list } != $len - $diff;
1598 # Martin A. Hansen, January 2008.
1600 # Given a normalized PhastCons matrix in an AoA,
1601 # calculate the mean for each column and return as a list.
1603 my ( $AoA, # AoA with normalized PhastCons scores
1610 $AoA = Maasha::Matrix::matrix_flip( $AoA );
1612 map { push @list, Maasha::Calc::mean( $_ ) } @{ $AoA };
1614 return wantarray ? @list : \@list;
1618 sub phastcons_median
1620 # Martin A. Hansen, January 2008.
1622 # Given a normalized PhastCons matrix in an AoA,
1623 # calculate the median for each column and return as a list.
1625 my ( $AoA, # AoA with normalized PhastCons scores
1632 $AoA = Maasha::Matrix::matrix_flip( $AoA );
1634 map { push @list, Maasha::Calc::median( $_ ) } @{ $AoA };
1636 return wantarray ? @list : \@list;
1640 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> MULTIPLE ALIGNMENT FILES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
1645 # Martin A. Hansen, April 2008.
1647 # Executes mafFrag to extract a subalignment from a multiz track
1648 # in the UCSC genome browser database.
1650 my ( $tmp_dir, # temporary directory
1651 $database, # genome database
1652 $table, # table with the multiz track
1654 $beg, # begin position
1655 $end, # end position
1659 # Returns a list of record
1661 my ( $tmp_file, $align );
1663 $tmp_file = "$tmp_dir/maf_extract.maf";
1665 Maasha::Common::run( "mafFrag", "$database $table $chr $beg $end $strand $tmp_file" );
1667 $align = maf_parse( $tmp_file );
1671 return wantarray ? @{ $align } : $align;
1677 # Martin A. Hansen, April 2008.
1680 my ( $path, # full path to MAF file
1683 # Returns a list of record.
1685 my ( $fh, $line, @fields, @align );
1687 $fh = Maasha::Common::read_open( $path );
1689 while ( $line = <$fh> )
1693 if ( $line =~ /^s/ )
1695 @fields = split / /, $line;
1698 SEQ_NAME => $fields[ 1 ],
1699 SEQ => $fields[ -1 ],
1701 ALIGN_LEN => length $fields[ -1 ],
1708 return wantarray ? @align : \@align;
1712 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> WIGGLE FORMAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
1715 sub fixedstep_put_entry
1717 # Martin A. Hansen, April 2008.
1719 # Outputs a block of fixedStep values.
1720 # Used for outputting wiggle data.
1722 my ( $chr, # chromosome
1723 $beg, # start position
1724 $block, # list of scores
1725 $fh, # filehandle - OPTIONAL
1726 $log10, # flag indicating that log10 scores should be used
1731 $beg += 1; # fixedStep format is 1 based.
1735 print $fh "fixedStep chrom=$chr start=$beg step=1\n";
1738 map { printf( $fh "%f\n", Maasha::Calc::log10( $_ + 1 ) ) } @{ $block };
1740 map { printf( $fh "%d\n", ( $_ + 1 ) ) } @{ $block };
1745 sub wiggle_upload_to_ucsc
1747 # Martin A. Hansen, May 2008.
1749 # Upload a wiggle file to the UCSC database.
1751 my ( $tmp_dir, # temporary directory
1752 $wib_dir, # wib directory
1753 $wig_file, # file to upload,
1754 $options, # argument hashref
1761 # $args = join " ", "-tmpDir=$tmp_dir", "-pathPrefix=$wib_dir", $options->{ "database" }, $options->{ 'table' }, $wig_file;
1763 # Maasha::Common::run( "hgLoadWiggle", "$args > /dev/null 2>&1" );
1765 if ( $options->{ 'verbose' } ) {
1766 `cd $tmp_dir && hgLoadWiggle -tmpDir=$tmp_dir -pathPrefix=$wib_dir $options->{ 'database' } $options->{ 'table' } $wig_file`;
1768 `cd $tmp_dir && hgLoadWiggle -tmpDir=$tmp_dir -pathPrefix=$wib_dir $options->{ 'database' } $options->{ 'table' } $wig_file > /dev/null 2>&1`;
1773 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> MySQL CONF <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
1778 # Martin A. Hansen, May 2008
1780 # Fetches the MySQL database user name from the
1781 # .hg.conf file in the users home directory.
1785 my ( $fh, $line, $user );
1787 $fh = Maasha::Common::read_open( "$ENV{ 'HOME' }/.hg.conf" );
1789 while ( $line = <$fh> )
1793 if ( $line =~ /^db\.user=(.+)/ )
1807 sub ucsc_get_password
1809 # Martin A. Hansen, May 2008
1811 # Fetches the MySQL database password from the
1812 # .hg.conf file in the users home directory.
1816 my ( $fh, $line, $password );
1818 $fh = Maasha::Common::read_open( "$ENV{ 'HOME' }/.hg.conf" );
1820 while ( $line = <$fh> )
1824 if ( $line =~ /^db\.password=(.+)/ )
1838 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<