1 package Maasha::BioRun;
4 # Copyright (C) 2007-2009 Martin A. Hansen.
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 # http://www.gnu.org/copyleft/gpl.html
23 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
26 # Routines that contains Biopieces which are run.
29 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
34 use Getopt::Long qw( :config bundling );
35 use Time::HiRes qw( gettimeofday );
36 use Storable qw( dclone );
37 use Maasha::Biopieces;
46 use Maasha::Stockholm;
52 use Maasha::UCSC::BED;
53 use Maasha::UCSC::Wiggle;
62 use vars qw( @ISA @EXPORT_OK );
66 @ISA = qw( Exporter );
74 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> GLOBALS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
77 my ( $script, $BP_TMP );
79 $script = Maasha::Common::get_scriptname();
80 $BP_TMP = Maasha::Common::get_tmpdir();
83 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> RUN SCRIPT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
86 run_script( $script );
89 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SUBROUTINES <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
94 # Martin A. Hansen, August 2007.
96 # Run a specific script.
98 my ( $script, # script name
103 my ( $t0, $t1, $options, $in, $out );
105 Maasha::Biopieces::log_biopiece();
107 $t0 = gettimeofday();
109 $options = get_options( $script );
111 $options->{ "SCRIPT" } = $script;
113 $script = "print_usage" if ( -t STDIN and keys %{ $options } <= 1 or $options->{ 'help' } );
115 $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
116 $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
118 if ( $script eq "print_usage" ) { script_print_usage( $in, $out, $options ) }
119 elsif ( $script eq "read_psl" ) { script_read_psl( $in, $out, $options ) }
120 elsif ( $script eq "read_bed" ) { script_read_bed( $in, $out, $options ) }
121 elsif ( $script eq "read_fixedstep" ) { script_read_fixedstep( $in, $out, $options ) }
122 elsif ( $script eq "read_blast_tab" ) { script_read_blast_tab( $in, $out, $options ) }
123 elsif ( $script eq "read_embl" ) { script_read_embl( $in, $out, $options ) }
124 elsif ( $script eq "read_stockholm" ) { script_read_stockholm( $in, $out, $options ) }
125 elsif ( $script eq "read_phastcons" ) { script_read_phastcons( $in, $out, $options ) }
126 elsif ( $script eq "read_soft" ) { script_read_soft( $in, $out, $options ) }
127 elsif ( $script eq "read_gff" ) { script_read_gff( $in, $out, $options ) }
128 elsif ( $script eq "read_2bit" ) { script_read_2bit( $in, $out, $options ) }
129 elsif ( $script eq "read_solexa" ) { script_read_solexa( $in, $out, $options ) }
130 elsif ( $script eq "read_solid" ) { script_read_solid( $in, $out, $options ) }
131 elsif ( $script eq "read_mysql" ) { script_read_mysql( $in, $out, $options ) }
132 elsif ( $script eq "read_ucsc_config" ) { script_read_ucsc_config( $in, $out, $options ) }
133 elsif ( $script eq "uppercase_seq" ) { script_uppercase_seq( $in, $out, $options ) }
134 elsif ( $script eq "complexity_seq" ) { script_complexity_seq( $in, $out, $options ) }
135 elsif ( $script eq "remove_indels" ) { script_remove_indels( $in, $out, $options ) }
136 elsif ( $script eq "get_genome_align" ) { script_get_genome_align( $in, $out, $options ) }
137 elsif ( $script eq "get_genome_phastcons" ) { script_get_genome_phastcons( $in, $out, $options ) }
138 elsif ( $script eq "soap_seq" ) { script_soap_seq( $in, $out, $options ) }
139 elsif ( $script eq "write_bed" ) { script_write_bed( $in, $out, $options ) }
140 elsif ( $script eq "write_psl" ) { script_write_psl( $in, $out, $options ) }
141 elsif ( $script eq "write_fixedstep" ) { script_write_fixedstep( $in, $out, $options ) }
142 elsif ( $script eq "write_2bit" ) { script_write_2bit( $in, $out, $options ) }
143 elsif ( $script eq "write_solid" ) { script_write_solid( $in, $out, $options ) }
144 elsif ( $script eq "write_ucsc_config" ) { script_write_ucsc_config( $in, $out, $options ) }
145 elsif ( $script eq "remove_keys" ) { script_remove_keys( $in, $out, $options ) }
146 elsif ( $script eq "remove_adaptor" ) { script_remove_adaptor( $in, $out, $options ) }
147 elsif ( $script eq "remove_mysql_tables" ) { script_remove_mysql_tables( $in, $out, $options ) }
148 elsif ( $script eq "remove_ucsc_tracks" ) { script_remove_ucsc_tracks( $in, $out, $options ) }
149 elsif ( $script eq "rename_keys" ) { script_rename_keys( $in, $out, $options ) }
150 elsif ( $script eq "uniq_vals" ) { script_uniq_vals( $in, $out, $options ) }
151 elsif ( $script eq "plot_histogram" ) { script_plot_histogram( $in, $out, $options ) }
152 elsif ( $script eq "plot_lendist" ) { script_plot_lendist( $in, $out, $options ) }
153 elsif ( $script eq "plot_chrdist" ) { script_plot_chrdist( $in, $out, $options ) }
154 elsif ( $script eq "plot_karyogram" ) { script_plot_karyogram( $in, $out, $options ) }
155 elsif ( $script eq "plot_matches" ) { script_plot_matches( $in, $out, $options ) }
156 elsif ( $script eq "plot_seqlogo" ) { script_plot_seqlogo( $in, $out, $options ) }
157 elsif ( $script eq "plot_phastcons_profiles" ) { script_plot_phastcons_profiles( $in, $out, $options ) }
158 elsif ( $script eq "upload_to_ucsc" ) { script_upload_to_ucsc( $in, $out, $options ) }
160 close $in if defined $in;
163 $t1 = gettimeofday();
165 print STDERR "Program: $script" . ( " " x ( 25 - length( $script ) ) ) . sprintf( "Run time: %.4f\n", ( $t1 - $t0 ) ) if $options->{ 'verbose' };
171 # Martin A. Hansen, February 2008.
173 # Gets options from commandline and checks these vigerously.
175 my ( $script, # name of script
180 my ( %options, @options, $opt, @genomes, $real );
182 if ( $script eq "print_usage" )
188 elsif ( $script eq "read_psl" )
195 elsif ( $script eq "read_bed" )
204 elsif ( $script eq "read_fixedstep" )
211 elsif ( $script eq "read_blast_tab" )
218 elsif ( $script eq "read_embl" )
228 elsif ( $script eq "read_stockholm" )
235 elsif ( $script eq "read_phastcons" )
246 elsif ( $script eq "read_soft" )
254 elsif ( $script eq "read_gff" )
261 elsif ( $script eq "read_2bit" )
269 elsif ( $script eq "read_solexa" )
278 elsif ( $script eq "read_solid" )
286 elsif ( $script eq "read_mysql" )
295 elsif ( $script eq "read_ucsc_config" )
302 elsif ( $script eq "get_genome_align" )
313 elsif ( $script eq "get_genome_phastcons" )
324 elsif ( $script eq "soap_seq" )
335 elsif ( $script eq "write_bed" )
345 elsif ( $script eq "write_psl" )
353 elsif ( $script eq "write_fixedstep" )
361 elsif ( $script eq "write_2bit" )
369 elsif ( $script eq "write_solid" )
378 elsif ( $script eq "write_ucsc_config" )
385 elsif ( $script eq "plot_seqlogo" )
392 elsif ( $script eq "plot_phastcons_profiles" )
407 elsif ( $script eq "remove_keys" )
414 elsif ( $script eq "remove_adaptor" )
423 elsif ( $script eq "remove_mysql_tables" )
434 elsif ( $script eq "remove_ucsc_tracks" )
446 elsif ( $script eq "rename_keys" )
452 elsif ( $script eq "uniq_vals" )
459 elsif ( $script eq "plot_histogram" )
472 elsif ( $script eq "plot_lendist" )
484 elsif ( $script eq "plot_chrdist" )
495 elsif ( $script eq "plot_karyogram" )
504 elsif ( $script eq "plot_matches" )
516 elsif ( $script eq "upload_to_ucsc" )
540 # print STDERR Dumper( \@options );
547 # print STDERR Dumper( \%options );
549 if ( -t STDIN && scalar( keys %options ) == 0 or $options{ "help" } ) {
550 return wantarray ? %options : \%options;
553 $options{ "cols" } = [ split ",", $options{ "cols" } ] if defined $options{ "cols" };
554 $options{ "keys" } = [ split ",", $options{ "keys" } ] if defined $options{ "keys" };
555 $options{ "no_keys" } = [ split ",", $options{ "no_keys" } ] if defined $options{ "no_keys" };
556 $options{ "save_keys" } = [ split ",", $options{ "save_keys" } ] if defined $options{ "save_keys" };
557 $options{ "quals" } = [ split ",", $options{ "quals" } ] if defined $options{ "quals" };
558 $options{ "feats" } = [ split ",", $options{ "feats" } ] if defined $options{ "feats" };
559 $options{ "frames" } = [ split ",", $options{ "frames" } ] if defined $options{ "frames" };
560 $options{ "samples" } = [ split ",", $options{ "samples" } ] if defined $options{ "samples" };
561 $options{ "tables" } = [ split ",", $options{ "tables" } ] if defined $options{ "tables" };
562 $options{ "tracks" } = [ split ",", $options{ "tracks" } ] if defined $options{ "tracks" };
564 # ---- check arguments ----
566 if ( $options{ 'data_in' } )
568 $options{ "files" } = Maasha::Biopieces::getopt_files( $options{ 'data_in' } );
570 Maasha::Common::error( qq(Argument to --data_in must be a valid file or fileglob expression) ) if scalar @{ $options{ "files" } } == 0;
573 map { Maasha::Common::error( qq(Argument to --cols must be a whole numbers - not "$_") ) if $_ !~ /^\d+$/ } @{ $options{ "cols" } } if $options{ "cols" };
575 # print STDERR Dumper( \%options );
577 $real = "beg|end|word_size|wrap|len|prefix_length|mismatches|offset|num|skip|cpus|window_size|step_size";
579 foreach $opt ( keys %options )
581 if ( $opt =~ /stream_in|pattern_in|exact_in/ and not -f $options{ $opt } )
583 Maasha::Common::error( qq(Argument to --$opt must be a valid file or fileglob expression - not "$options{ $opt }") );
585 elsif ( $opt =~ /$real/ and $options{ $opt } !~ /^\d+$/ )
587 Maasha::Common::error( qq(Argument to --$opt must be a whole number - not "$options{ $opt }") );
589 elsif ( $opt =~ /max_hits|max_hits|max_misses|dist|edit_dist|flank|gap|hamming_dist|priority/ and $options{ $opt } !~ /^-?\d+$/ )
591 Maasha::Common::error( qq(Argument to --$opt must be an integer - not "$options{ $opt }") );
593 elsif ( $opt =~ /identity|threshold/ and $options{ $opt } !~ /^-?(?:\d+(?:\.\d*)?|\.\d+)$/ )
595 Maasha::Common::error( qq(Argument to --$opt must be a decimal number - not "$options{ $opt }") );
597 elsif ( $opt =~ /e_val/ and $options{ $opt } !~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/ )
599 Maasha::Common::error( qq(Argument to --$opt must be a float - not "$options{ $opt }") );
601 elsif ( $opt =~ /strand/ and $options{ $opt } !~ /^(\+|-)$/ )
603 Maasha::Common::error( qq(Argument to --$opt must be "+" or "-" - not "$options{ $opt }") );
605 elsif ( $opt eq "genome" )
607 @genomes = Maasha::Common::ls_dirs( "$ENV{ 'BP_DATA' }/genomes" );
608 map { $_ =~ s/.*\/(.+)$/$1/ } @genomes;
610 if ( not grep { $_ =~ /^$options{ $opt }$/ } @genomes ) {
611 Maasha::Common::error( qq(Genome $options{ $opt } not found in "$ENV{ 'BP_DATA' }/genomes/") );
614 elsif ( $opt eq "terminal" and not $options{ $opt } =~ /^(svg|post|dumb|x11)/ )
616 Maasha::Common::error( qq(Bad --$opt argument "$options{ $opt }") );
618 elsif ( $opt eq "table" and $options{ $opt } =~ /(-|\.)/ )
620 Maasha::Common::error( qq(Character '$1' is not allowed in table name: $options{ $opt }) );
622 elsif ( $opt eq "merge" and $options{ $opt } !~ /^(AandB|AorB|BorA|AnotB|BnotA)$/ )
624 Maasha::Common::error( qq(Argument to --$opt must be AandB, AorB, BorA, AnotB, or BnotA - not "$options{ $opt }") );
626 elsif ( $opt eq "format" and $script eq "read_solexa" and $options{ $opt } !~ /octal|decimal/ )
628 Maasha::Common::error( qq(Argument to --$opt must be octal or decimal - not "$options{ $opt }") );
630 elsif ( $opt eq "remove" and $script eq "remove_adaptor" and $options{ $opt } !~ /before|after|skip/ )
632 Maasha::Common::error( qq(Argument to --$opt must be before, after, or skip - not "$options{ $opt }") );
636 Maasha::Common::error( qq(no --database specified) ) if $script eq "remove_ucsc_tracks" and not $options{ "database" };
637 Maasha::Common::error( qq(no --in_file or --genome specified) ) if $script eq "soap_seq" and not $options{ "genome" } and not $options{ "in_file" };
638 Maasha::Common::error( qq(both --in_file and --genome specified) ) if $script eq "soap_seq" and $options{ "genome" } and $options{ "in_file" };
639 Maasha::Common::error( qq(no --genome specified) ) if $script =~ /get_genome_align|get_genome_phastcons|plot_phastcons_profiles|plot_karyogram/ and not $options{ "genome" };
640 Maasha::Common::error( qq(no --key specified) ) if $script =~ /plot_lendist|plot_histogram/ and not $options{ "key" };
642 if ( $script eq "upload_to_ucsc" )
644 Maasha::Common::error( qq(no --database specified) ) if not $options{ "database" };
645 Maasha::Common::error( qq(no --table specified) ) if not $options{ "table" };
648 return wantarray ? %options : \%options;
652 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SCRIPTS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
655 sub script_print_usage
657 # Martin A. Hansen, January 2008.
659 # Retrieves usage information from file and
660 # prints this nicely formatted.
662 my ( $in, # handle to in stream
663 $out, # handle to out stream
664 $options, # options hash
669 my ( $file, $wiki, $lines );
671 if ( $options->{ 'data_in' } ) {
672 $file = $options->{ 'data_in' };
674 $file = join "", $ENV{ 'BP_DIR' }, "/bp_usage/", $options->{ 'SCRIPT' }, ".wiki";
677 $wiki = Maasha::Gwiki::gwiki_read( $file );
679 ( $wiki->[ 2 ], $wiki->[ 3 ], $wiki->[ 0 ], $wiki->[ 1 ] ) = ( $wiki->[ 0 ], $wiki->[ 1 ], $wiki->[ 2 ], $wiki->[ 3 ] );
681 if ( not $options->{ "help" } ) {
682 @{ $wiki } = grep { $_->[ 0 ]->{ 'SECTION' } =~ /Biopiece|summary|Usage|Options|Help/ } @{ $wiki };
685 $lines = Maasha::Gwiki::gwiki2ascii( $wiki );
687 print STDERR "$_\n" foreach @{ $lines };
695 # Martin A. Hansen, August 2007.
697 # Read psl table from stream or file.
699 my ( $in, # handle to in stream
700 $out, # handle to out stream
701 $options, # options hash
706 my ( $record, $file, $data_in, $num );
708 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
709 Maasha::Biopieces::put_record( $record, $out );
714 foreach $file ( @{ $options->{ "files" } } )
716 $data_in = Maasha::Common::read_open( $file );
718 while ( $record = Maasha::UCSC::psl_get_entry( $data_in ) )
720 Maasha::Biopieces::put_record( $record, $out );
722 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
734 # Martin A. Hansen, August 2007.
736 # Read bed table from stream or file.
738 my ( $in, # handle to in stream
739 $out, # handle to out stream
740 $options, # options hash
745 my ( $cols, $file, $record, $bed_entry, $data_in, $num );
747 $cols = $options->{ 'cols' }->[ 0 ];
749 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
750 Maasha::Biopieces::put_record( $record, $out );
755 foreach $file ( @{ $options->{ "files" } } )
757 $data_in = Maasha::Common::read_open( $file );
759 while ( $bed_entry = Maasha::UCSC::BED::bed_entry_get( $data_in, $cols, $options->{ 'check' } ) )
761 $record = Maasha::UCSC::BED::bed2biopiece( $bed_entry );
763 Maasha::Biopieces::put_record( $record, $out );
765 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
775 close $data_in if $data_in;
779 sub script_read_fixedstep
781 # Martin A. Hansen, Juli 2008.
783 # Read fixedstep wiggle format from stream or file.
785 my ( $in, # handle to in stream
786 $out, # handle to out stream
787 $options, # options hash
792 my ( $file, $record, $entry, $data_in, $num );
794 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
795 Maasha::Biopieces::put_record( $record, $out );
800 foreach $file ( @{ $options->{ "files" } } )
802 $data_in = Maasha::Common::read_open( $file );
804 while ( $entry = Maasha::UCSC::Wiggle::fixedstep_entry_get( $data_in ) )
806 $record = Maasha::UCSC::Wiggle::fixedstep2biopiece( $entry );
808 Maasha::Biopieces::put_record( $record, $out );
810 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
820 close $data_in if $data_in;
824 sub script_read_blast_tab
826 # Martin A. Hansen, September 2007.
828 # Read tabular BLAST output from NCBI blast run with -m8 or -m9.
830 my ( $in, # handle to in stream
831 $out, # handle to out stream
832 $options, # options hash
837 my ( $file, $line, @fields, $strand, $record, $data_in, $num );
839 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
840 Maasha::Biopieces::put_record( $record, $out );
845 foreach $file ( @{ $options->{ "files" } } )
847 $data_in = Maasha::Common::read_open( $file );
849 while ( $line = <$data_in> )
853 next if $line =~ /^#/;
855 @fields = split /\t/, $line;
857 $record->{ "REC_TYPE" } = "BLAST";
858 $record->{ "Q_ID" } = $fields[ 0 ];
859 $record->{ "S_ID" } = $fields[ 1 ];
860 $record->{ "IDENT" } = $fields[ 2 ];
861 $record->{ "ALIGN_LEN" } = $fields[ 3 ];
862 $record->{ "MISMATCHES" } = $fields[ 4 ];
863 $record->{ "GAPS" } = $fields[ 5 ];
864 $record->{ "Q_BEG" } = $fields[ 6 ] - 1; # BLAST is 1-based
865 $record->{ "Q_END" } = $fields[ 7 ] - 1; # BLAST is 1-based
866 $record->{ "S_BEG" } = $fields[ 8 ] - 1; # BLAST is 1-based
867 $record->{ "S_END" } = $fields[ 9 ] - 1; # BLAST is 1-based
868 $record->{ "E_VAL" } = $fields[ 10 ];
869 $record->{ "BIT_SCORE" } = $fields[ 11 ];
871 if ( $record->{ "S_BEG" } > $record->{ "S_END" } )
873 $record->{ "STRAND" } = '-';
875 ( $record->{ "S_BEG" }, $record->{ "S_END" } ) = ( $record->{ "S_END" }, $record->{ "S_BEG" } );
879 $record->{ "STRAND" } = '+';
882 Maasha::Biopieces::put_record( $record, $out );
884 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
894 close $data_in if $data_in;
900 # Martin A. Hansen, August 2007.
904 my ( $in, # handle to in stream
905 $out, # handle to out stream
906 $options, # options hash
911 my ( %options2, $file, $data_in, $num, $entry, $record );
913 map { $options2{ "keys" }{ $_ } = 1 } @{ $options->{ "keys" } };
914 map { $options2{ "feats" }{ $_ } = 1 } @{ $options->{ "feats" } };
915 map { $options2{ "quals" }{ $_ } = 1 } @{ $options->{ "quals" } };
917 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
918 Maasha::Biopieces::put_record( $record, $out );
923 foreach $file ( @{ $options->{ "files" } } )
925 $data_in = Maasha::Common::read_open( $file );
927 while ( $entry = Maasha::EMBL::get_embl_entry( $data_in ) )
929 $record = Maasha::EMBL::parse_embl_entry( $entry, \%options2 );
931 my ( $feat, $feat2, $qual, $qual_val, $record_copy );
933 $record_copy = dclone $record;
935 delete $record_copy->{ "FT" };
937 Maasha::Biopieces::put_record( $record_copy, $out );
939 delete $record_copy->{ "SEQ" };
941 foreach $feat ( keys %{ $record->{ "FT" } } )
943 $record_copy->{ "FEAT_TYPE" } = $feat;
945 foreach $feat2 ( @{ $record->{ "FT" }->{ $feat } } )
947 foreach $qual ( keys %{ $feat2 } )
949 $qual_val = join "; ", @{ $feat2->{ $qual } };
954 $record_copy->{ $qual } = $qual_val;
957 Maasha::Biopieces::put_record( $record_copy, $out );
961 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
971 close $data_in if $data_in;
975 sub script_read_stockholm
977 # Martin A. Hansen, August 2007.
979 # Read Stockholm format.
981 my ( $in, # handle to in stream
982 $out, # handle to out stream
983 $options, # options hash
988 my ( $data_in, $file, $num, $entry, $record, $record_anno, $record_align, $key, $seq );
990 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
991 Maasha::Biopieces::put_record( $record, $out );
996 foreach $file ( @{ $options->{ "files" } } )
998 $data_in = Maasha::Common::read_open( $file );
1000 while ( $entry = Maasha::Stockholm::get_stockholm_entry( $data_in ) )
1002 $record = Maasha::Stockholm::parse_stockholm_entry( $entry );
1006 foreach $key ( keys %{ $record->{ "GF" } } ) {
1007 $record_anno->{ $key } = $record->{ "GF" }->{ $key };
1010 $record_anno->{ "ALIGN" } = $num;
1012 Maasha::Biopieces::put_record( $record_anno, $out );
1014 foreach $seq ( @{ $record->{ "ALIGN" } } )
1016 undef $record_align;
1019 SEQ_NAME => $seq->[ 0 ],
1023 Maasha::Biopieces::put_record( $record_align, $out );
1026 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
1036 close $data_in if $data_in;
1040 sub script_read_phastcons
1042 # Martin A. Hansen, December 2007.
1044 # Read PhastCons format.
1046 my ( $in, # handle to in stream
1047 $out, # handle to out stream
1048 $options, # options hash
1053 my ( $data_in, $file, $num, $entry, @records, $record );
1055 $options->{ "min" } ||= 10;
1056 $options->{ "dist" } ||= 25;
1057 $options->{ "threshold" } ||= 0.8;
1058 $options->{ "gap" } ||= 5;
1060 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
1061 Maasha::Biopieces::put_record( $record, $out );
1066 foreach $file ( @{ $options->{ "files" } } )
1068 $data_in = Maasha::Common::read_open( $file );
1070 while ( $entry = Maasha::UCSC::fixedstep_get_entry( $data_in ) )
1072 @records = Maasha::UCSC::phastcons_parse_entry( $entry, $options );
1074 foreach $record ( @records )
1076 $record->{ "REC_TYPE" } = "BED";
1077 $record->{ "BED_LEN" } = $record->{ "CHR_END" } - $record->{ "CHR_BEG" } + 1;
1079 Maasha::Biopieces::put_record( $record, $out );
1081 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
1092 close $data_in if $data_in;
1096 sub script_read_soft
1098 # Martin A. Hansen, December 2007.
1101 # http://www.ncbi.nlm.nih.gov/geo/info/soft2.html
1103 my ( $in, # handle to in stream
1104 $out, # handle to out stream
1105 $options, # options hash
1110 my ( $data_in, $file, $num, $records, $record, $soft_index, $fh, @platforms, $plat_table, @samples, $sample, $old_end, $skip );
1112 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
1113 Maasha::Biopieces::put_record( $record, $out );
1118 foreach $file ( @{ $options->{ "files" } } )
1120 print STDERR "Creating index for file: $file\n" if $options->{ "verbose" };
1122 $soft_index = Maasha::NCBI::soft_index_file( $file );
1124 $fh = Maasha::Common::read_open( $file );
1126 @platforms = grep { $_->{ "SECTION" } =~ /PLATFORM/ } @{ $soft_index };
1128 print STDERR "Getting platform tables for file: $file\n" if $options->{ "verbose" };
1130 $plat_table = Maasha::NCBI::soft_get_platform( $fh, $platforms[ 0 ]->{ "LINE_BEG" }, $platforms[ -1 ]->{ "LINE_END" } );
1132 @samples = grep { $_->{ "SECTION" } =~ /SAMPLE/ } @{ $soft_index };
1134 $old_end = $platforms[ -1 ]->{ "LINE_END" };
1136 foreach $sample ( @samples )
1139 $skip = 1 if ( $options->{ "samples" } and grep { $sample->{ "SECTION" } !~ /$_/ } @{ $options->{ "samples" } } );
1141 print STDERR "Getting samples for dataset: $sample->{ 'SECTION' }\n" if $options->{ "verbose" } and not $skip;
1143 $records = Maasha::NCBI::soft_get_sample( $fh, $plat_table, $sample->{ "LINE_BEG" } - $old_end - 1, $sample->{ "LINE_END" } - $old_end - 1, $skip );
1145 foreach $record ( @{ $records } )
1147 Maasha::Biopieces::put_record( $record, $out );
1149 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
1154 $old_end = $sample->{ "LINE_END" };
1162 close $data_in if $data_in;
1169 # Martin A. Hansen, February 2008.
1172 # http://www.ncbi.nlm.nih.gov/geo/info/soft2.html
1174 my ( $in, # handle to in stream
1175 $out, # handle to out stream
1176 $options, # options hash
1181 my ( $data_in, $file, $fh, $num, $record, $entry );
1183 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
1184 Maasha::Biopieces::put_record( $record, $out );
1189 foreach $file ( @{ $options->{ "files" } } )
1191 $fh = Maasha::Common::read_open( $file );
1193 while ( $entry = Maasha::GFF::get_entry( $fh ) )
1195 Maasha::Biopieces::put_record( $entry, $out );
1197 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
1207 close $data_in if $data_in;
1211 sub script_read_2bit
1213 # Martin A. Hansen, March 2008.
1215 # Read sequences from 2bit file.
1217 my ( $in, # handle to in stream
1218 $out, # handle to out stream
1219 $options, # options hash
1224 my ( $record, $file, $data_in, $mask, $toc, $line, $num );
1226 $mask = 1 if not $options->{ "no_mask" };
1228 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
1229 Maasha::Biopieces::put_record( $record, $out );
1234 foreach $file ( @{ $options->{ "files" } } )
1236 $data_in = Maasha::Common::read_open( $file );
1238 $toc = Maasha::TwoBit::twobit_get_TOC( $data_in );
1240 foreach $line ( @{ $toc } )
1242 $record->{ "SEQ_NAME" } = $line->[ 0 ];
1243 $record->{ "SEQ" } = Maasha::TwoBit::twobit_get_seq( $data_in, $line->[ 1 ], undef, undef, $mask );
1244 $record->{ "SEQ_LEN" } = length $record->{ "SEQ" };
1246 Maasha::Biopieces::put_record( $record, $out );
1248 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
1258 close $data_in if $data_in;
1262 sub script_read_solexa
1264 # Martin A. Hansen, March 2008.
1266 # Read Solexa sequence reads from file.
1268 my ( $in, # handle to in stream
1269 $out, # handle to out stream
1270 $options, # options hash
1275 my ( $record, $file, $data_in, $entry, $num, @seqs, @scores, $i );
1277 $options->{ "format" } ||= "octal";
1278 $options->{ "quality" } ||= 20;
1280 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
1281 Maasha::Biopieces::put_record( $record, $out );
1286 foreach $file ( @{ $options->{ "files" } } )
1288 $data_in = Maasha::Common::read_open( $file );
1290 if ( $options->{ "format" } eq "octal" )
1292 while ( $entry = Maasha::Solexa::solexa_get_entry_octal( $data_in ) )
1294 $record = Maasha::Solexa::solexa2biopiece( $entry, $options->{ "quality" } );
1296 Maasha::Biopieces::put_record( $record, $out );
1298 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
1305 while ( $entry = Maasha::Solexa::solexa_get_entry_decimal( $data_in ) )
1307 $record = Maasha::Solexa::solexa2biopiece( $entry, $options->{ "quality" } );
1309 Maasha::Biopieces::put_record( $record, $out );
1311 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
1322 close $data_in if $data_in;
1326 sub script_read_solid
1328 # Martin A. Hansen, April 2008.
1330 # Read Solid sequence from file.
1332 my ( $in, # handle to in stream
1333 $out, # handle to out stream
1334 $options, # options hash
1339 my ( $record, $file, $data_in, $line, $num, $seq_name, $seq_cs, $seq_qual, @scores, @seqs, $i );
1341 $options->{ "quality" } ||= 15;
1343 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
1344 Maasha::Biopieces::put_record( $record, $out );
1349 foreach $file ( @{ $options->{ "files" } } )
1351 $data_in = Maasha::Common::read_open( $file );
1353 while ( $line = <$data_in> )
1357 ( $seq_name, $seq_cs, $seq_qual ) = split /\t/, $line;
1359 @scores = split /,/, $seq_qual;
1360 @seqs = split //, Maasha::Solid::color_space2seq( $seq_cs );
1362 for ( $i = 0; $i < @seqs; $i++ ) {
1363 $seqs[ $i ] = lc $seqs[ $i ] if $scores[ $i ] < $options->{ "quality" };
1367 REC_TYPE => 'SOLID',
1368 SEQ_NAME => $seq_name,
1370 SEQ_QUAL => join( ";", @scores ),
1371 SEQ_LEN => length $seq_cs,
1372 SEQ => join( "", @seqs ),
1373 SCORE_MEAN => sprintf( "%.2f", Maasha::Calc::mean( \@scores ) ),
1376 Maasha::Biopieces::put_record( $record, $out );
1378 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
1388 close $data_in if $data_in;
1392 sub script_read_mysql
1394 # Martin A. Hansen, May 2008.
1396 # Read a MySQL query into stream.
1398 my ( $in, # handle to in stream
1399 $out, # handle to out stream
1400 $options, # options hash
1405 my ( $record, $dbh, $results );
1407 $options->{ "user" } ||= Maasha::UCSC::ucsc_get_user();
1408 $options->{ "password" } ||= Maasha::UCSC::ucsc_get_password();
1410 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
1411 Maasha::Biopieces::put_record( $record, $out );
1414 $dbh = Maasha::SQL::connect( $options->{ "database" }, $options->{ "user" }, $options->{ "password" } );
1416 $results = Maasha::SQL::query_hashref_list( $dbh, $options->{ "query" } );
1418 Maasha::SQL::disconnect( $dbh );
1420 map { Maasha::Biopieces::put_record( $_ ) } @{ $results };
1424 sub script_read_ucsc_config
1426 # Martin A. Hansen, November 2008.
1428 # Read track entries from UCSC Genome Browser '.ra' files.
1430 my ( $in, # handle to in stream
1431 $out, # handle to out stream
1432 $options, # options hash
1437 my ( $record, $file, $data_in, $entry, $num );
1439 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
1440 Maasha::Biopieces::put_record( $record, $out );
1445 foreach $file ( @{ $options->{ "files" } } )
1447 $data_in = Maasha::Common::read_open( $file );
1449 while ( $record = Maasha::UCSC::ucsc_config_entry_get( $data_in ) )
1451 $record->{ 'REC_TYPE' } = "UCSC Config";
1453 Maasha::Biopieces::put_record( $record, $out );
1455 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
1465 close $data_in if $data_in;
1469 sub script_complexity_seq
1471 # Martin A. Hansen, May 2008.
1473 # Generates an index calculated as the most common di-residue over
1474 # the sequence length for all sequences in stream.
1476 my ( $in, # handle to in stream
1477 $out, # handle to out stream
1482 my ( $record, $index );
1484 while ( $record = Maasha::Biopieces::get_record( $in ) )
1486 $record->{ "SEQ_COMPLEXITY" } = sprintf( "%.2f", Maasha::Seq::seq_complexity( $record->{ "SEQ" } ) ) if $record->{ "SEQ" };
1488 Maasha::Biopieces::put_record( $record, $out );
1493 sub script_remove_indels
1495 # Martin A. Hansen, August 2007.
1497 # Remove indels from sequences in stream.
1499 my ( $in, # handle to in stream
1500 $out, # handle to out stream
1507 while ( $record = Maasha::Biopieces::get_record( $in ) )
1509 $record->{ 'SEQ' } =~ tr/-~.//d if $record->{ "SEQ" };
1511 Maasha::Biopieces::put_record( $record, $out );
1516 sub script_get_genome_align
1518 # Martin A. Hansen, April 2008.
1520 # Gets a subalignment from a multiple genome alignment.
1522 my ( $in, # handle to in stream
1523 $out, # handle to out stream
1524 $options, # options hash
1529 my ( $record, $maf_track, $align, $align_num, $beg, $end, $len, $entry );
1531 $options->{ "strand" } ||= "+";
1535 $maf_track = Maasha::Config::maf_track( $options->{ "genome" } );
1537 if ( $options->{ "chr" } and $options->{ "beg" } and ( $options->{ "end" } or $options->{ "len" } ) )
1539 $beg = $options->{ "beg" } - 1;
1541 if ( $options->{ "end" } ) {
1542 $end = $options->{ "end" };
1543 } elsif ( $options->{ "len" } ) {
1544 $end = $beg + $options->{ "len" };
1547 $align = Maasha::UCSC::maf_extract( $BP_TMP, $options->{ "genome" }, $maf_track, $options->{ "chr" }, $beg, $end, $options->{ "strand" } );
1549 foreach $entry ( @{ $align } )
1551 $entry->{ "CHR" } = $record->{ "CHR" };
1552 $entry->{ "CHR_BEG" } = $record->{ "CHR_BEG" };
1553 $entry->{ "CHR_END" } = $record->{ "CHR_END" };
1554 $entry->{ "STRAND" } = $record->{ "STRAND" } || '+';
1555 $entry->{ "Q_ID" } = $record->{ "Q_ID" };
1556 $entry->{ "SCORE" } = $record->{ "SCORE" };
1558 Maasha::Biopieces::put_record( $entry, $out );
1562 while ( $record = Maasha::Biopieces::get_record( $in ) )
1564 if ( $record->{ "REC_TYPE" } eq "BED" )
1566 $align = Maasha::UCSC::maf_extract( $BP_TMP, $options->{ "genome" }, $maf_track, $record->{ "CHR" }, $record->{ "CHR_BEG" }, $record->{ "CHR_END" }, $record->{ "STRAND" } );
1568 elsif ( $record->{ "REC_TYPE" } eq "VMATCH" )
1570 $align = Maasha::UCSC::maf_extract( $BP_TMP, $options->{ "genome" }, $maf_track, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" } + 1, $record->{ "STRAND" } );
1572 elsif ( $record->{ "REC_TYPE" } eq "PSL" )
1574 $align = Maasha::UCSC::maf_extract( $BP_TMP, $options->{ "genome" }, $maf_track, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" }, $record->{ "STRAND" } );
1576 elsif ( $record->{ "REC_TYPE" } eq "BLAST" )
1578 $align = Maasha::UCSC::maf_extract( $BP_TMP, $options->{ "genome" }, $maf_track, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" }, $record->{ "STRAND" } );
1581 foreach $entry ( @{ $align } )
1583 $entry->{ "CHR" } = $record->{ "CHR" };
1584 $entry->{ "CHR_BEG" } = $record->{ "CHR_BEG" };
1585 $entry->{ "CHR_END" } = $record->{ "CHR_END" };
1586 $entry->{ "STRAND" } = $record->{ "STRAND" };
1587 $entry->{ "Q_ID" } = $record->{ "Q_ID" };
1588 $entry->{ "SCORE" } = $record->{ "SCORE" };
1590 Maasha::Biopieces::put_record( $entry, $out );
1598 sub script_get_genome_phastcons
1600 # Martin A. Hansen, February 2008.
1602 # Get phastcons scores from genome intervals.
1604 my ( $in, # handle to in stream
1605 $out, # handle to out stream
1606 $options, # options hash
1611 my ( $phastcons_file, $phastcons_index, $index, $fh_phastcons, $scores, $record );
1613 $options->{ "flank" } ||= 0;
1615 $phastcons_file = Maasha::Config::genome_phastcons( $options->{ "genome" } );
1616 $phastcons_index = Maasha::Config::genome_phastcons_index( $options->{ "genome" } );
1618 $index = Maasha::UCSC::fixedstep_index_retrieve( $phastcons_index );
1619 $fh_phastcons = Maasha::Common::read_open( $phastcons_file );
1621 if ( defined $options->{ "chr" } and defined $options->{ "beg" } and ( defined $options->{ "end" } or defined $options->{ "len" } ) )
1623 $options->{ "beg" } -= 1; # request is 1-based
1624 $options->{ "end" } -= 1; # request is 1-based
1626 if ( $options->{ "len" } ) {
1627 $options->{ "end" } = $options->{ "beg" } + $options->{ "len" } - 1;
1630 $scores = Maasha::UCSC::fixedstep_index_lookup( $index, $fh_phastcons, $options->{ "chr" }, $options->{ "beg" }, $options->{ "end" }, $options->{ "flank" } );
1632 $record->{ "CHR" } = $options->{ "chr" };
1633 $record->{ "CHR_BEG" } = $options->{ "beg" } - $options->{ "flank" };
1634 $record->{ "CHR_END" } = $options->{ "end" } + $options->{ "flank" };
1636 $record->{ "PHASTCONS" } = join ",", @{ $scores };
1637 $record->{ "PHAST_COUNT" } = scalar @{ $scores }; # DEBUG
1639 Maasha::Biopieces::put_record( $record, $out );
1642 while ( $record = Maasha::Biopieces::get_record( $in ) )
1644 if ( $record->{ "REC_TYPE" } eq "BED" )
1646 $scores = Maasha::UCSC::fixedstep_index_lookup( $index, $fh_phastcons, $record->{ "CHR" }, $record->{ "CHR_BEG" }, $record->{ "CHR_END" }, $options->{ "flank" } );
1648 elsif ( $record->{ "REC_TYPE" } eq "PSL" )
1650 $scores = Maasha::UCSC::fixedstep_index_lookup( $index, $fh_phastcons, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" }, $options->{ "flank" } );
1652 elsif ( $record->{ "REC_TYPE" } eq "BLAST" )
1654 $scores = Maasha::UCSC::fixedstep_index_lookup( $index, $fh_phastcons, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" }, $options->{ "flank" } );
1657 $record->{ "PHASTCONS" } = join ",", @{ $scores } if @{ $scores };
1658 # $record->{ "PHAST_COUNT" } = @{ $scores } if @{ $scores }; # DEBUG
1660 Maasha::Biopieces::put_record( $record, $out );
1663 close $fh_phastcons if $fh_phastcons;
1669 # Martin A. Hansen, July 2008.
1671 # soap sequences in stream against a given file or genome.
1673 my ( $in, # handle to in stream
1674 $out, # handle to out stream
1675 $options, # options hash
1680 my ( $genome, $tmp_in, $tmp_out, $fh_in, $fh_out, $record, $line, @fields, $entry, $count, $args );
1682 $options->{ "seed_size" } ||= 10;
1683 $options->{ "mismatches" } ||= 2;
1684 $options->{ "gap_size" } ||= 0;
1685 $options->{ "cpus" } ||= 1;
1687 if ( $options->{ "genome" } ) {
1688 $options->{ "in_file" } = "$ENV{ 'BP_DATA' }/genomes/$options->{ 'genome' }/fasta/$options->{ 'genome' }.fna";
1691 $tmp_in = "$BP_TMP/soap_query.seq";
1692 $tmp_out = "$BP_TMP/soap.result";
1694 $fh_out = Maasha::Common::write_open( $tmp_in );
1698 while ( $record = Maasha::Biopieces::get_record( $in ) )
1700 if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) )
1702 Maasha::Fasta::put_entry( $entry, $fh_out );
1707 Maasha::Biopieces::put_record( $record, $out );
1715 "-s $options->{ 'seed_size' }",
1718 "-v $options->{ 'mismatches' }",
1719 "-g $options->{ 'gap_size' }",
1720 "-p $options->{ 'cpus' }",
1721 "-d $options->{ 'in_file' }",
1725 $args .= " > /dev/null 2>&1" if not $options->{ 'verbose' };
1727 Maasha::Common::run( "soap", $args, 1 );
1731 $fh_out = Maasha::Common::read_open( $tmp_out );
1735 while ( $line = <$fh_out> )
1739 @fields = split /\t/, $line;
1741 $record->{ "REC_TYPE" } = "SOAP";
1742 $record->{ "Q_ID" } = $fields[ 0 ];
1743 $record->{ "SCORE" } = $fields[ 3 ];
1744 $record->{ "STRAND" } = $fields[ 6 ];
1745 $record->{ "S_ID" } = $fields[ 7 ];
1746 $record->{ "S_BEG" } = $fields[ 8 ] - 1; # soap is 1-based
1747 $record->{ "S_END" } = $fields[ 8 ] + $fields[ 5 ] - 2;
1749 Maasha::Biopieces::put_record( $record, $out );
1759 sub script_write_bed
1761 # Martin A. Hansen, August 2007.
1763 # Write BED format for the UCSC genome browser using records in stream.
1765 my ( $in, # handle to in stream
1766 $out, # handle to out stream
1767 $options, # options hash
1772 my ( $cols, $fh, $record, $bed_entry, $new_record );
1774 $cols = $options->{ 'cols' }->[ 0 ];
1776 $fh = Maasha::Biopieces::write_stream( $options->{ 'data_out' }, $options->{ 'compress' } );
1778 while ( $record = Maasha::Biopieces::get_record( $in ) )
1780 $record = Maasha::UCSC::psl2record( $record ) if $record->{ 'tBaseInsert' }; # Dirty addition to allow Affy data from MySQL to be dumped
1782 if ( $bed_entry = Maasha::UCSC::BED::biopiece2bed( $record, $cols ) ) {
1783 Maasha::UCSC::BED::bed_entry_put( $bed_entry, $fh, $cols, $options->{ 'check' } );
1786 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ 'no_stream' };
1793 sub script_write_psl
1795 # Martin A. Hansen, August 2007.
1797 # Write PSL output from stream.
1799 my ( $in, # handle to in stream
1800 $out, # handle to out stream
1801 $options, # options hash
1806 my ( $fh, $record, @output, $first );
1810 $fh = write_stream( $options->{ "data_out" }, $options->{ "compress" } );
1812 while ( $record = Maasha::Biopieces::get_record( $in ) )
1814 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
1816 if ( $record->{ "REC_TYPE" } and $record->{ "REC_TYPE" } eq "PSL" )
1818 Maasha::UCSC::psl_put_header( $fh ) if $first;
1819 Maasha::UCSC::psl_put_entry( $record, $fh );
1828 sub script_write_fixedstep
1830 # Martin A. Hansen, Juli 2008.
1832 # Write fixedStep entries from recrods in the stream.
1834 my ( $in, # handle to in stream
1835 $out, # handle to out stream
1836 $options, # options hash
1841 my ( $fh, $record, $entry );
1843 $fh = write_stream( $options->{ "data_out" }, $options->{ "compress" } );
1845 while ( $record = Maasha::Biopieces::get_record( $in ) )
1847 if ( $entry = Maasha::UCSC::Wiggle::biopiece2fixedstep( $record ) ) {
1848 Maasha::UCSC::Wiggle::fixedstep_entry_put( $entry, $fh );
1851 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
1858 sub script_write_2bit
1860 # Martin A. Hansen, March 2008.
1862 # Write sequence entries from stream in 2bit format.
1864 my ( $in, # handle to in stream
1865 $out, # handle to out stream
1866 $options, # options hash
1871 my ( $record, $mask, $tmp_file, $fh_tmp, $fh_in, $fh_out, $entry );
1873 $mask = 1 if not $options->{ "no_mask" };
1875 $tmp_file = "$BP_TMP/write_2bit.fna";
1876 $fh_tmp = Maasha::Common::write_open( $tmp_file );
1878 $fh_out = write_stream( $options->{ "data_out" } );
1880 while ( $record = Maasha::Biopieces::get_record( $in ) )
1882 if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) ) {
1883 Maasha::Fasta::put_entry( $entry, $fh_tmp );
1886 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
1891 $fh_in = Maasha::Common::read_open( $tmp_file );
1893 Maasha::TwoBit::fasta2twobit( $fh_in, $fh_out, $mask );
1902 sub script_write_solid
1904 # Martin A. Hansen, April 2008.
1906 # Write di-base encoded Solid sequence from entries in stream.
1908 my ( $in, # handle to in stream
1909 $out, # handle to out stream
1910 $options, # options hash
1915 my ( $record, $fh, $entry );
1917 $fh = write_stream( $options->{ "data_out" }, $options->{ "compress" } );
1919 while ( $record = Maasha::Biopieces::get_record( $in ) )
1921 if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) )
1923 $entry->[ SEQ ] = Maasha::Solid::seq2color_space( uc $entry->[ SEQ ] );
1925 Maasha::Fasta::put_entry( $entry, $fh, $options->{ "wrap" } );
1928 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
1935 sub script_write_ucsc_config
1937 # Martin A. Hansen, November 2008.
1939 # Write UCSC Genome Broser configuration (.ra file type) from
1940 # records in the stream.
1942 my ( $in, # handle to in stream
1943 $out, # handle to out stream
1944 $options, # options hash
1949 my ( $record, $fh );
1951 $fh = write_stream( $options->{ "data_out" } );
1953 while ( $record = Maasha::Biopieces::get_record( $in ) )
1955 Maasha::UCSC::ucsc_config_entry_put( $record, $fh ) if $record->{ "REC_TYPE" } eq "UCSC Config";
1957 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
1964 sub script_plot_seqlogo
1966 # Martin A. Hansen, August 2007.
1968 # Calculates and writes a sequence logo for alignments.
1970 my ( $in, # handle to in stream
1971 $out, # handle to out stream
1972 $options, # options hash
1977 my ( $record, @entries, $logo, $fh );
1979 while ( $record = Maasha::Biopieces::get_record( $in ) )
1981 if ( $record->{ "SEQ_NAME" } and $record->{ "SEQ" } ) {
1982 push @entries, [ $record->{ "SEQ_NAME" }, $record->{ "SEQ" } ];
1985 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
1988 $logo = Maasha::Plot::seq_logo( \@entries );
1990 $fh = write_stream( $options->{ "data_out" } );
1998 sub script_plot_phastcons_profiles
2000 # Martin A. Hansen, January 2008.
2002 # Plots PhastCons profiles.
2004 my ( $in, # handle to in stream
2005 $out, # handle to out stream
2006 $options, # options hash
2011 my ( $phastcons_file, $phastcons_index, $index, $fh_phastcons, $record, $scores, $AoA, $plot, $fh );
2013 $options->{ "title" } ||= "PhastCons Profiles";
2015 $phastcons_file = Maasha::Config::genome_phastcons( $options->{ "genome" } );
2016 $phastcons_index = Maasha::Config::genome_phastcons_index( $options->{ "genome" } );
2018 $index = Maasha::UCSC::fixedstep_index_retrieve( $phastcons_index );
2019 $fh_phastcons = Maasha::Common::read_open( $phastcons_file );
2021 while ( $record = Maasha::Biopieces::get_record( $in ) )
2023 if ( $record->{ "CHR" } and $record->{ "CHR_BEG" } and $record->{ "CHR_END" } )
2025 $scores = Maasha::UCSC::fixedstep_index_lookup( $index, $fh_phastcons, $record->{ "CHR" },
2026 $record->{ "CHR_BEG" },
2027 $record->{ "CHR_END" },
2028 $options->{ "flank" } );
2030 push @{ $AoA }, [ @{ $scores } ];
2033 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
2036 Maasha::UCSC::phastcons_normalize( $AoA );
2038 $AoA = [ [ Maasha::UCSC::phastcons_mean( $AoA ) ] ] if $options->{ "mean" };
2039 $AoA = [ [ Maasha::UCSC::phastcons_median( $AoA ) ] ] if $options->{ "median" };
2041 $AoA = Maasha::Matrix::matrix_flip( $AoA );
2043 $plot = Maasha::Plot::lineplot_simple( $AoA, $options, $BP_TMP );
2045 $fh = write_stream( $options->{ "data_out" } );
2047 print $fh "$_\n" foreach @{ $plot };
2053 sub script_remove_keys
2055 # Martin A. Hansen, August 2007.
2057 # Remove keys from stream.
2059 my ( $in, # handle to in stream
2060 $out, # handle to out stream
2061 $options, # options hash
2066 my ( $record, $new_record );
2068 while ( $record = Maasha::Biopieces::get_record( $in ) )
2070 if ( $options->{ "keys" } )
2072 map { delete $record->{ $_ } } @{ $options->{ "keys" } };
2074 elsif ( $options->{ "save_keys" } )
2076 map { $new_record->{ $_ } = $record->{ $_ } if exists $record->{ $_ } } @{ $options->{ "save_keys" } };
2078 $record = $new_record;
2081 Maasha::Biopieces::put_record( $record, $out ) if keys %{ $record };
2086 sub script_remove_adaptor
2088 # Martin A. Hansen, August 2008.
2090 # Find and remove adaptor from sequences in the stream.
2092 my ( $in, # handle to in stream
2093 $out, # handle to out stream
2094 $options, # options hash
2099 my ( $record, $adaptor, $seq, $adaptor_len, $seq_len, $offset, $max_match, $max_mismatch, $pos );
2101 $options->{ "remove" } ||= "after";
2103 $max_mismatch = $options->{ "mismatches" } || 0;
2104 $offset = $options->{ "offset" };
2106 if ( not defined $offset ) {
2112 $adaptor = uc $options->{ "adaptor" };
2113 $adaptor_len = length $adaptor;
2115 while ( $record = Maasha::Biopieces::get_record( $in ) )
2117 if ( $record->{ "SEQ" } )
2119 $seq = uc $record->{ "SEQ" };
2120 $seq_len = length $seq;
2122 $pos = Maasha::Common::index_m( $seq, $adaptor, $seq_len, $adaptor_len, $offset, $max_mismatch );
2124 $record->{ "ADAPTOR_POS" } = $pos;
2126 if ( $pos >= 0 and $options->{ "remove" } ne "skip" )
2128 if ( $options->{ "remove" } eq "after" )
2130 $record->{ "SEQ" } = substr $record->{ "SEQ" }, 0, $pos;
2131 $record->{ "SEQ_LEN" } = $pos;
2135 $record->{ "SEQ" } = substr $record->{ "SEQ" }, $pos + $adaptor_len;
2136 $record->{ "SEQ_LEN" } = length $record->{ "SEQ" };
2140 Maasha::Biopieces::put_record( $record, $out );
2144 Maasha::Biopieces::put_record( $record, $out );
2150 sub script_remove_mysql_tables
2152 # Martin A. Hansen, November 2008.
2154 # Remove MySQL tables from values in stream.
2156 my ( $in, # handle to in stream
2157 $out, # handle to out stream
2158 $options, # options hash
2163 my ( $record, %table_hash, $dbh, $table );
2165 $options->{ "user" } ||= Maasha::UCSC::ucsc_get_user();
2166 $options->{ "password" } ||= Maasha::UCSC::ucsc_get_password();
2168 map { $table_hash{ $_ } = 1 } @{ $options->{ 'tables' } };
2170 while ( $record = Maasha::Biopieces::get_record( $in ) )
2172 map { $table_hash{ $record->{ $_ } } = 1 } @{ $options->{ 'keys' } };
2174 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ 'no_stream' };
2177 $dbh = Maasha::SQL::connect( $options->{ "database" }, $options->{ "user" }, $options->{ "password" } );
2179 foreach $table ( sort keys %table_hash )
2181 if ( Maasha::SQL::table_exists( $dbh, $table ) )
2183 print STDERR qq(Removing table "$table" from database "$options->{ 'database' }" ... ) if $options->{ 'verbose' };
2184 Maasha::SQL::delete_table( $dbh, $table );
2185 print STDERR "done.\n" if $options->{ 'verbose' };
2189 print STDERR qq(WARNING: table "$table" not found in database "$options->{ 'database' }\n");
2193 Maasha::SQL::disconnect( $dbh );
2197 sub script_remove_ucsc_tracks
2199 # Martin A. Hansen, November 2008.
2201 # Remove track from MySQL tables and config file.
2203 my ( $in, # handle to in stream
2204 $out, # handle to out stream
2205 $options, # options hash
2210 my ( $record, %track_hash, $fh_in, $fh_out, $track, @tracks, @new_tracks, $dbh );
2212 $options->{ 'user' } ||= Maasha::UCSC::ucsc_get_user();
2213 $options->{ 'password' } ||= Maasha::UCSC::ucsc_get_password();
2214 $options->{ 'config_file' } ||= "$ENV{ 'HOME' }/ucsc/my_tracks.ra";
2216 map { $track_hash{ $_ } = 1 } @{ $options->{ 'tracks' } };
2218 while ( $record = Maasha::Biopieces::get_record( $in ) )
2220 map { $track_hash{ $record->{ $_ } } = 1 } @{ $options->{ 'keys' } };
2222 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ 'no_stream' };
2225 $fh_in = Maasha::Filesys::file_read_open( $options->{ 'config_file' } );
2227 while ( $track = Maasha::UCSC::ucsc_config_entry_get( $fh_in ) ) {
2228 push @tracks, $track;
2233 foreach $track ( @tracks )
2235 if ( $track->{ 'database' } eq $options->{ 'database' } and exists $track_hash{ $track->{ 'track' } } ) {
2236 print STDERR qq(Removing track "$track->{ 'track' }" from config file.\n) if $options->{ 'verbose' };
2238 push @new_tracks, $track;
2242 rename "$options->{ 'config_file' }", "$options->{ 'config_file' }~";
2244 $fh_out = Maasha::Filesys::file_write_open( $options->{ 'config_file' } );
2246 map { Maasha::UCSC::ucsc_config_entry_put( $_, $fh_out ) } @new_tracks;
2250 # ---- locate track in database ----
2252 $dbh = Maasha::SQL::connect( $options->{ "database" }, $options->{ "user" }, $options->{ "password" } );
2254 foreach $track ( sort keys %track_hash )
2256 if ( Maasha::SQL::table_exists( $dbh, $track ) )
2258 print STDERR qq(Removing table "$track" from database "$options->{ 'database' }" ... ) if $options->{ 'verbose' };
2259 Maasha::SQL::delete_table( $dbh, $track );
2260 print STDERR "done.\n" if $options->{ 'verbose' };
2264 print STDERR qq(WARNING: table "$track" not found in database "$options->{ 'database' }\n");
2268 Maasha::SQL::disconnect( $dbh );
2270 Maasha::Common::run( "ucscMakeTracks.pl", "-b > /dev/null 2>&1" );
2274 sub script_rename_keys
2276 # Martin A. Hansen, August 2007.
2278 # Rename keys in stream.
2280 my ( $in, # handle to in stream
2281 $out, # handle to out stream
2282 $options, # options hash
2289 while ( $record = Maasha::Biopieces::get_record( $in ) )
2291 if ( exists $record->{ $options->{ "keys" }->[ 0 ] } )
2293 $record->{ $options->{ "keys" }->[ 1 ] } = $record->{ $options->{ "keys" }->[ 0 ] };
2295 delete $record->{ $options->{ "keys" }->[ 0 ] };
2298 Maasha::Biopieces::put_record( $record, $out );
2303 sub script_uniq_vals
2305 # Martin A. Hansen, August 2007.
2307 # Find unique values in stream.
2309 my ( $in, # handle to in stream
2310 $out, # handle to out stream
2311 $options, # options hash
2316 my ( %hash, $record );
2318 while ( $record = Maasha::Biopieces::get_record( $in ) )
2320 if ( $record->{ $options->{ "key" } } )
2322 if ( not $hash{ $record->{ $options->{ "key" } } } and not $options->{ "invert" } )
2324 Maasha::Biopieces::put_record( $record, $out );
2326 $hash{ $record->{ $options->{ "key" } } } = 1;
2328 elsif ( $hash{ $record->{ $options->{ "key" } } } and $options->{ "invert" } )
2330 Maasha::Biopieces::put_record( $record, $out );
2334 $hash{ $record->{ $options->{ "key" } } } = 1;
2339 Maasha::Biopieces::put_record( $record, $out );
2345 sub script_plot_histogram
2347 # Martin A. Hansen, September 2007.
2349 # Plot a simple histogram for a given key using GNU plot.
2351 my ( $in, # handle to in stream
2352 $out, # handle to out stream
2353 $options, # options hash
2358 my ( $record, %data_hash, $max, @data_list, $i, $result, $fh );
2360 $options->{ "title" } ||= "Histogram";
2361 $options->{ "sort" } ||= "num";
2363 while ( $record = Maasha::Biopieces::get_record( $in ) )
2365 $data_hash{ $record->{ $options->{ "key" } } }++ if defined $record->{ $options->{ "key" } };
2367 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
2370 if ( $options->{ "sort" } eq "num" ) {
2371 map { push @data_list, [ $_, $data_hash{ $_ } ] } sort { $a <=> $b } keys %data_hash;
2373 map { push @data_list, [ $_, $data_hash{ $_ } ] } sort keys %data_hash;
2376 $result = Maasha::Plot::histogram_simple( \@data_list, $options );
2378 $fh = write_stream( $options->{ "data_out" } );
2380 print $fh "$_\n" foreach @{ $result };
2386 sub script_plot_lendist
2388 # Martin A. Hansen, August 2007.
2390 # Plot length distribution using GNU plot.
2392 my ( $in, # handle to in stream
2393 $out, # handle to out stream
2394 $options, # options hash
2399 my ( $record, %data_hash, $max, @data_list, $i, $result, $fh );
2401 $options->{ "title" } ||= "Length Distribution";
2403 while ( $record = Maasha::Biopieces::get_record( $in ) )
2405 $data_hash{ $record->{ $options->{ "key" } } }++ if defined $record->{ $options->{ "key" } };
2407 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
2410 $max = Maasha::Calc::list_max( [ keys %data_hash ] );
2412 for ( $i = 0; $i < $max; $i++ ) {
2413 push @data_list, [ $i, $data_hash{ $i } || 0 ];
2416 $result = Maasha::Plot::histogram_lendist( \@data_list, $options );
2418 $fh = write_stream( $options->{ "data_out" } );
2420 print $fh "$_\n" foreach @{ $result };
2426 sub script_plot_chrdist
2428 # Martin A. Hansen, August 2007.
2430 # Plot chromosome distribution using GNU plot.
2432 my ( $in, # handle to in stream
2433 $out, # handle to out stream
2434 $options, # options hash
2439 my ( $record, %data_hash, @data_list, $elem, $sort_key, $count, $result, $fh );
2441 $options->{ "title" } ||= "Chromosome Distribution";
2443 while ( $record = Maasha::Biopieces::get_record( $in ) )
2445 if ( $record->{ "CHR" } ) { # generic
2446 $data_hash{ $record->{ "CHR" } }++;
2447 } elsif ( $record->{ "REC_TYPE" } eq "PATSCAN" and $record->{ "S_ID" } =~ /^chr/i ) { # patscan
2448 $data_hash{ $record->{ "S_ID" } }++;
2449 } elsif ( $record->{ "REC_TYPE" } eq "PSL" and $record->{ "S_ID" } =~ /^chr/i ) { # BLAT / PSL
2450 $data_hash{ $record->{ "S_ID" } }++;
2451 } elsif ( $record->{ "REC_TYPE" } eq "BLAST" and $record->{ "S_ID" } =~ /^chr/i ) { # BLAST
2452 $data_hash{ $record->{ "S_ID" } }++;
2455 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
2458 foreach $elem ( keys %data_hash )
2462 $sort_key =~ s/chr//i;
2464 $sort_key =~ s/^X(.*)/99$1/;
2465 $sort_key =~ s/^Y(.*)/99$1/;
2466 $sort_key =~ s/^Z(.*)/999$1/;
2467 $sort_key =~ s/^M(.*)/9999$1/;
2468 $sort_key =~ s/^U(.*)/99999$1/;
2470 $count = $sort_key =~ tr/_//;
2472 $sort_key =~ s/_.*/"999999" x $count/ex;
2474 push @data_list, [ $elem, $data_hash{ $elem }, $sort_key ];
2477 @data_list = sort { $a->[ 2 ] <=> $b->[ 2 ] } @data_list;
2479 $result = Maasha::Plot::histogram_chrdist( \@data_list, $options );
2481 $fh = write_stream( $options->{ "data_out" } );
2483 print $fh "$_\n" foreach @{ $result };
2489 sub script_plot_karyogram
2491 # Martin A. Hansen, August 2007.
2493 # Plot hits on karyogram.
2495 my ( $in, # handle to in stream
2496 $out, # handle to out stream
2497 $options, # options hash
2502 my ( %options, $record, @data, $fh, $result, %data_hash );
2504 $options->{ "genome" } ||= "human";
2505 $options->{ "feat_color" } ||= "black";
2507 while ( $record = Maasha::Biopieces::get_record( $in ) )
2509 if ( $record->{ "CHR" } and $record->{ "CHR_BEG" } and $record->{ "CHR_END" } )
2511 push @{ $data_hash{ $record->{ "CHR" } } }, [ $record->{ "CHR_BEG" }, $record->{ "CHR_END" }, $options->{ "feat_color" } ];
2514 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
2517 $result = Maasha::Plot::karyogram( \%data_hash, \%options );
2519 $fh = write_stream( $options->{ "data_out" } );
2527 sub script_plot_matches
2529 # Martin A. Hansen, August 2007.
2531 # Plot matches in 2D generating a dotplot.
2533 my ( $in, # handle to in stream
2534 $out, # handle to out stream
2535 $options, # options hash
2540 my ( $record, @data, $fh, $result, %data_hash );
2542 $options->{ "direction" } ||= "both";
2544 while ( $record = Maasha::Biopieces::get_record( $in ) )
2546 if ( defined $record->{ "Q_BEG" } and defined $record->{ "S_BEG" } and $record->{ "Q_END" } and $record->{ "S_END" } ) {
2547 push @data, $record;
2550 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
2553 $options->{ "title" } ||= "plot_matches";
2554 $options->{ "xlabel" } ||= $data[ 0 ]->{ "Q_ID" };
2555 $options->{ "ylabel" } ||= $data[ 0 ]->{ "S_ID" };
2557 $result = Maasha::Plot::dotplot_matches( \@data, $options, $BP_TMP );
2559 $fh = write_stream( $options->{ "data_out" } );
2561 print $fh "$_\n" foreach @{ $result };
2567 sub script_upload_to_ucsc
2569 # Martin A. Hansen, August 2007.
2571 # Calculate the mean of values of given keys.
2573 # This routine has developed into the most ugly hack. Do something!
2575 my ( $in, # handle to in stream
2576 $out, # handle to out stream
2577 $options, # options hash
2582 my ( $record, $file, $wib_file, $wig_file, $wib_dir, $fh_out, $i, $first, $format, $type, $columns, $append, $entry );
2584 $options->{ "short_label" } ||= $options->{ 'table' };
2585 $options->{ "long_label" } ||= $options->{ 'table' };
2586 $options->{ "group" } ||= $ENV{ "LOGNAME" };
2587 $options->{ "priority" } ||= 1;
2588 $options->{ "visibility" } ||= "pack";
2589 $options->{ "color" } ||= join( ",", int( rand( 255 ) ), int( rand( 255 ) ), int( rand( 255 ) ) );
2590 $options->{ "chunk_size" } ||= 10_000_000_000; # Due to 32-bit UCSC compilation really large tables cannot be loaded in one go.
2592 $file = "$BP_TMP/ucsc_upload.tmp";
2597 $fh_out = Maasha::Common::write_open( $file );
2599 while ( $record = Maasha::Biopieces::get_record( $in ) )
2601 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
2603 if ( $record->{ "REC_TYPE" } eq "fixed_step" )
2607 if ( $entry = Maasha::UCSC::Wiggle::biopiece2fixedstep( $record ) ) {
2608 Maasha::UCSC::Wiggle::fixedstep_entry_put( $entry, $fh_out );
2611 elsif ( $record->{ "REC_TYPE" } eq "PSL" )
2615 Maasha::UCSC::psl_put_header( $fh_out ) if $first;
2616 Maasha::UCSC::psl_put_entry( $record, $fh_out );
2620 elsif ( $record->{ "REC_TYPE" } eq "BED" and $record->{ "SEC_STRUCT" } )
2622 # chrom chromStart chromEnd name score strand size secStr conf
2626 print $fh_out join ( "\t",
2628 $record->{ "CHR_BEG" },
2629 $record->{ "CHR_END" } + 1,
2630 $record->{ "Q_ID" },
2631 $record->{ "SCORE" },
2632 $record->{ "STRAND" },
2633 $record->{ "SIZE" },
2634 $record->{ "SEC_STRUCT" },
2635 $record->{ "CONF" },
2638 elsif ( $record->{ "REC_TYPE" } eq "BED" )
2641 $columns = $record->{ "BED_COLS" };
2643 if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) {
2644 Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } );
2647 elsif ( $record->{ "REC_TYPE" } eq "PATSCAN" and $record->{ "CHR" } )
2652 if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) {
2653 Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } );
2656 elsif ( $record->{ "REC_TYPE" } eq "BLAST" and $record->{ "S_ID" } =~ /^chr/ )
2661 $record->{ "SCORE" } = $record->{ "BIT_SCORE" } * 1000;
2663 if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) {
2664 Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } );
2667 elsif ( $record->{ "REC_TYPE" } eq "VMATCH" and $record->{ "S_ID" } =~ /^chr/i )
2672 if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) {
2673 Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } );
2677 if ( $i == $options->{ "chunk_size" } )
2681 if ( $format eq "BED" ) {
2682 Maasha::UCSC::bed_upload_to_ucsc( $BP_TMP, $file, $options, $append );
2683 } elsif ( $format eq "PSL" ) {
2684 Maasha::UCSC::psl_upload_to_ucsc( $file, $options, $append );
2693 $fh_out = Maasha::Common::write_open( $file );
2701 if ( exists $options->{ "database" } and $options->{ "table" } )
2703 if ( $format eq "BED" )
2705 $type = "bed $columns";
2707 Maasha::UCSC::bed_upload_to_ucsc( $BP_TMP, $file, $options, $append );
2709 elsif ( $format eq "BED_SS" )
2711 $type = "type bed 6 +";
2713 Maasha::UCSC::bed_upload_to_ucsc( $BP_TMP, $file, $options, $append );
2715 elsif ( $format eq "PSL" )
2719 Maasha::UCSC::psl_upload_to_ucsc( $file, $options, $append );
2721 elsif ( $format eq "WIGGLE" )
2723 $options->{ "visibility" } = "full";
2725 $wig_file = "$options->{ 'table' }.wig";
2726 $wib_file = "$options->{ 'table' }.wib";
2728 $wib_dir = "$ENV{ 'HOME' }/ucsc/wib";
2730 Maasha::Common::dir_create_if_not_exists( $wib_dir );
2732 if ( $options->{ 'verbose' } ) {
2733 `cd $BP_TMP && wigEncode $file $wig_file $wib_file`;
2735 `cd $BP_TMP && wigEncode $file $wig_file $wib_file > /dev/null 2>&1`;
2738 Maasha::Common::run( "mv", "$BP_TMP/$wib_file $wib_dir" );
2746 Maasha::UCSC::wiggle_upload_to_ucsc( $BP_TMP, $wib_dir, $file, $options );
2751 Maasha::UCSC::ucsc_update_config( $options, $type );
2756 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<