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 "tile_seq" ) { script_tile_seq( $in, $out, $options ) }
139 elsif ( $script eq "soap_seq" ) { script_soap_seq( $in, $out, $options ) }
140 elsif ( $script eq "write_bed" ) { script_write_bed( $in, $out, $options ) }
141 elsif ( $script eq "write_psl" ) { script_write_psl( $in, $out, $options ) }
142 elsif ( $script eq "write_fixedstep" ) { script_write_fixedstep( $in, $out, $options ) }
143 elsif ( $script eq "write_2bit" ) { script_write_2bit( $in, $out, $options ) }
144 elsif ( $script eq "write_solid" ) { script_write_solid( $in, $out, $options ) }
145 elsif ( $script eq "write_ucsc_config" ) { script_write_ucsc_config( $in, $out, $options ) }
146 elsif ( $script eq "remove_keys" ) { script_remove_keys( $in, $out, $options ) }
147 elsif ( $script eq "remove_adaptor" ) { script_remove_adaptor( $in, $out, $options ) }
148 elsif ( $script eq "remove_mysql_tables" ) { script_remove_mysql_tables( $in, $out, $options ) }
149 elsif ( $script eq "remove_ucsc_tracks" ) { script_remove_ucsc_tracks( $in, $out, $options ) }
150 elsif ( $script eq "rename_keys" ) { script_rename_keys( $in, $out, $options ) }
151 elsif ( $script eq "uniq_vals" ) { script_uniq_vals( $in, $out, $options ) }
152 elsif ( $script eq "plot_histogram" ) { script_plot_histogram( $in, $out, $options ) }
153 elsif ( $script eq "plot_lendist" ) { script_plot_lendist( $in, $out, $options ) }
154 elsif ( $script eq "plot_chrdist" ) { script_plot_chrdist( $in, $out, $options ) }
155 elsif ( $script eq "plot_karyogram" ) { script_plot_karyogram( $in, $out, $options ) }
156 elsif ( $script eq "plot_matches" ) { script_plot_matches( $in, $out, $options ) }
157 elsif ( $script eq "plot_seqlogo" ) { script_plot_seqlogo( $in, $out, $options ) }
158 elsif ( $script eq "plot_phastcons_profiles" ) { script_plot_phastcons_profiles( $in, $out, $options ) }
159 elsif ( $script eq "upload_to_ucsc" ) { script_upload_to_ucsc( $in, $out, $options ) }
161 close $in if defined $in;
164 $t1 = gettimeofday();
166 print STDERR "Program: $script" . ( " " x ( 25 - length( $script ) ) ) . sprintf( "Run time: %.4f\n", ( $t1 - $t0 ) ) if $options->{ 'verbose' };
172 # Martin A. Hansen, February 2008.
174 # Gets options from commandline and checks these vigerously.
176 my ( $script, # name of script
181 my ( %options, @options, $opt, @genomes, $real );
183 if ( $script eq "print_usage" )
189 elsif ( $script eq "read_psl" )
196 elsif ( $script eq "read_bed" )
205 elsif ( $script eq "read_fixedstep" )
212 elsif ( $script eq "read_blast_tab" )
219 elsif ( $script eq "read_embl" )
229 elsif ( $script eq "read_stockholm" )
236 elsif ( $script eq "read_phastcons" )
247 elsif ( $script eq "read_soft" )
255 elsif ( $script eq "read_gff" )
262 elsif ( $script eq "read_2bit" )
270 elsif ( $script eq "read_solexa" )
279 elsif ( $script eq "read_solid" )
287 elsif ( $script eq "read_mysql" )
296 elsif ( $script eq "read_ucsc_config" )
303 elsif ( $script eq "get_genome_align" )
314 elsif ( $script eq "get_genome_phastcons" )
325 elsif ( $script eq "tile_seq" )
332 elsif ( $script eq "soap_seq" )
343 elsif ( $script eq "write_bed" )
353 elsif ( $script eq "write_psl" )
361 elsif ( $script eq "write_fixedstep" )
369 elsif ( $script eq "write_2bit" )
377 elsif ( $script eq "write_solid" )
386 elsif ( $script eq "write_ucsc_config" )
393 elsif ( $script eq "plot_seqlogo" )
400 elsif ( $script eq "plot_phastcons_profiles" )
415 elsif ( $script eq "remove_keys" )
422 elsif ( $script eq "remove_adaptor" )
431 elsif ( $script eq "remove_mysql_tables" )
442 elsif ( $script eq "remove_ucsc_tracks" )
454 elsif ( $script eq "rename_keys" )
460 elsif ( $script eq "uniq_vals" )
467 elsif ( $script eq "plot_histogram" )
480 elsif ( $script eq "plot_lendist" )
492 elsif ( $script eq "plot_chrdist" )
503 elsif ( $script eq "plot_karyogram" )
512 elsif ( $script eq "plot_matches" )
524 elsif ( $script eq "upload_to_ucsc" )
548 # print STDERR Dumper( \@options );
555 # print STDERR Dumper( \%options );
557 if ( -t STDIN && scalar( keys %options ) == 0 or $options{ "help" } ) {
558 return wantarray ? %options : \%options;
561 $options{ "cols" } = [ split ",", $options{ "cols" } ] if defined $options{ "cols" };
562 $options{ "keys" } = [ split ",", $options{ "keys" } ] if defined $options{ "keys" };
563 $options{ "no_keys" } = [ split ",", $options{ "no_keys" } ] if defined $options{ "no_keys" };
564 $options{ "save_keys" } = [ split ",", $options{ "save_keys" } ] if defined $options{ "save_keys" };
565 $options{ "quals" } = [ split ",", $options{ "quals" } ] if defined $options{ "quals" };
566 $options{ "feats" } = [ split ",", $options{ "feats" } ] if defined $options{ "feats" };
567 $options{ "frames" } = [ split ",", $options{ "frames" } ] if defined $options{ "frames" };
568 $options{ "samples" } = [ split ",", $options{ "samples" } ] if defined $options{ "samples" };
569 $options{ "tables" } = [ split ",", $options{ "tables" } ] if defined $options{ "tables" };
570 $options{ "tracks" } = [ split ",", $options{ "tracks" } ] if defined $options{ "tracks" };
572 # ---- check arguments ----
574 if ( $options{ 'data_in' } )
576 $options{ "files" } = Maasha::Biopieces::getopt_files( $options{ 'data_in' } );
578 Maasha::Common::error( qq(Argument to --data_in must be a valid file or fileglob expression) ) if scalar @{ $options{ "files" } } == 0;
581 map { Maasha::Common::error( qq(Argument to --cols must be a whole numbers - not "$_") ) if $_ !~ /^\d+$/ } @{ $options{ "cols" } } if $options{ "cols" };
583 # print STDERR Dumper( \%options );
585 $real = "beg|end|word_size|wrap|tile_size|len|prefix_length|mismatches|offset|num|skip|cpus|window_size|step_size";
587 foreach $opt ( keys %options )
589 if ( $opt =~ /stream_in|pattern_in|exact_in/ and not -f $options{ $opt } )
591 Maasha::Common::error( qq(Argument to --$opt must be a valid file or fileglob expression - not "$options{ $opt }") );
593 elsif ( $opt =~ /$real/ and $options{ $opt } !~ /^\d+$/ )
595 Maasha::Common::error( qq(Argument to --$opt must be a whole number - not "$options{ $opt }") );
597 elsif ( $opt =~ /max_hits|max_hits|max_misses|dist|edit_dist|flank|gap|hamming_dist|priority/ and $options{ $opt } !~ /^-?\d+$/ )
599 Maasha::Common::error( qq(Argument to --$opt must be an integer - not "$options{ $opt }") );
601 elsif ( $opt =~ /identity|threshold/ and $options{ $opt } !~ /^-?(?:\d+(?:\.\d*)?|\.\d+)$/ )
603 Maasha::Common::error( qq(Argument to --$opt must be a decimal number - not "$options{ $opt }") );
605 elsif ( $opt =~ /e_val/ and $options{ $opt } !~ /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/ )
607 Maasha::Common::error( qq(Argument to --$opt must be a float - not "$options{ $opt }") );
609 elsif ( $opt =~ /strand/ and $options{ $opt } !~ /^(\+|-)$/ )
611 Maasha::Common::error( qq(Argument to --$opt must be "+" or "-" - not "$options{ $opt }") );
613 elsif ( $opt eq "genome" )
615 @genomes = Maasha::Common::ls_dirs( "$ENV{ 'BP_DATA' }/genomes" );
616 map { $_ =~ s/.*\/(.+)$/$1/ } @genomes;
618 if ( not grep { $_ =~ /^$options{ $opt }$/ } @genomes ) {
619 Maasha::Common::error( qq(Genome $options{ $opt } not found in "$ENV{ 'BP_DATA' }/genomes/") );
622 elsif ( $opt eq "terminal" and not $options{ $opt } =~ /^(svg|post|dumb|x11)/ )
624 Maasha::Common::error( qq(Bad --$opt argument "$options{ $opt }") );
626 elsif ( $opt eq "table" and $options{ $opt } =~ /(-|\.)/ )
628 Maasha::Common::error( qq(Character '$1' is not allowed in table name: $options{ $opt }) );
630 elsif ( $opt eq "merge" and $options{ $opt } !~ /^(AandB|AorB|BorA|AnotB|BnotA)$/ )
632 Maasha::Common::error( qq(Argument to --$opt must be AandB, AorB, BorA, AnotB, or BnotA - not "$options{ $opt }") );
634 elsif ( $opt eq "format" and $script eq "read_solexa" and $options{ $opt } !~ /octal|decimal/ )
636 Maasha::Common::error( qq(Argument to --$opt must be octal or decimal - not "$options{ $opt }") );
638 elsif ( $opt eq "remove" and $script eq "remove_adaptor" and $options{ $opt } !~ /before|after|skip/ )
640 Maasha::Common::error( qq(Argument to --$opt must be before, after, or skip - not "$options{ $opt }") );
644 Maasha::Common::error( qq(no --database specified) ) if $script eq "remove_ucsc_tracks" and not $options{ "database" };
645 Maasha::Common::error( qq(no --in_file or --genome specified) ) if $script eq "soap_seq" and not $options{ "genome" } and not $options{ "in_file" };
646 Maasha::Common::error( qq(both --in_file and --genome specified) ) if $script eq "soap_seq" and $options{ "genome" } and $options{ "in_file" };
647 Maasha::Common::error( qq(no --genome specified) ) if $script =~ /get_genome_align|get_genome_phastcons|plot_phastcons_profiles|plot_karyogram/ and not $options{ "genome" };
648 Maasha::Common::error( qq(no --key specified) ) if $script =~ /plot_lendist|plot_histogram/ and not $options{ "key" };
650 if ( $script eq "upload_to_ucsc" )
652 Maasha::Common::error( qq(no --database specified) ) if not $options{ "database" };
653 Maasha::Common::error( qq(no --table specified) ) if not $options{ "table" };
656 return wantarray ? %options : \%options;
660 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> SCRIPTS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
663 sub script_print_usage
665 # Martin A. Hansen, January 2008.
667 # Retrieves usage information from file and
668 # prints this nicely formatted.
670 my ( $in, # handle to in stream
671 $out, # handle to out stream
672 $options, # options hash
677 my ( $file, $wiki, $lines );
679 if ( $options->{ 'data_in' } ) {
680 $file = $options->{ 'data_in' };
682 $file = join "", $ENV{ 'BP_DIR' }, "/bp_usage/", $options->{ 'SCRIPT' }, ".wiki";
685 $wiki = Maasha::Gwiki::gwiki_read( $file );
687 ( $wiki->[ 2 ], $wiki->[ 3 ], $wiki->[ 0 ], $wiki->[ 1 ] ) = ( $wiki->[ 0 ], $wiki->[ 1 ], $wiki->[ 2 ], $wiki->[ 3 ] );
689 if ( not $options->{ "help" } ) {
690 @{ $wiki } = grep { $_->[ 0 ]->{ 'SECTION' } =~ /Biopiece|summary|Usage|Options|Help/ } @{ $wiki };
693 $lines = Maasha::Gwiki::gwiki2ascii( $wiki );
695 print STDERR "$_\n" foreach @{ $lines };
703 # Martin A. Hansen, August 2007.
705 # Read psl table from stream or file.
707 my ( $in, # handle to in stream
708 $out, # handle to out stream
709 $options, # options hash
714 my ( $record, $file, $data_in, $num );
716 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
717 Maasha::Biopieces::put_record( $record, $out );
722 foreach $file ( @{ $options->{ "files" } } )
724 $data_in = Maasha::Common::read_open( $file );
726 while ( $record = Maasha::UCSC::psl_get_entry( $data_in ) )
728 Maasha::Biopieces::put_record( $record, $out );
730 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
742 # Martin A. Hansen, August 2007.
744 # Read bed table from stream or file.
746 my ( $in, # handle to in stream
747 $out, # handle to out stream
748 $options, # options hash
753 my ( $cols, $file, $record, $bed_entry, $data_in, $num );
755 $cols = $options->{ 'cols' }->[ 0 ];
757 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
758 Maasha::Biopieces::put_record( $record, $out );
763 foreach $file ( @{ $options->{ "files" } } )
765 $data_in = Maasha::Common::read_open( $file );
767 while ( $bed_entry = Maasha::UCSC::BED::bed_entry_get( $data_in, $cols, $options->{ 'check' } ) )
769 $record = Maasha::UCSC::BED::bed2biopiece( $bed_entry );
771 Maasha::Biopieces::put_record( $record, $out );
773 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
783 close $data_in if $data_in;
787 sub script_read_fixedstep
789 # Martin A. Hansen, Juli 2008.
791 # Read fixedstep wiggle format from stream or file.
793 my ( $in, # handle to in stream
794 $out, # handle to out stream
795 $options, # options hash
800 my ( $file, $record, $entry, $data_in, $num );
802 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
803 Maasha::Biopieces::put_record( $record, $out );
808 foreach $file ( @{ $options->{ "files" } } )
810 $data_in = Maasha::Common::read_open( $file );
812 while ( $entry = Maasha::UCSC::Wiggle::fixedstep_entry_get( $data_in ) )
814 $record = Maasha::UCSC::Wiggle::fixedstep2biopiece( $entry );
816 Maasha::Biopieces::put_record( $record, $out );
818 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
828 close $data_in if $data_in;
832 sub script_read_blast_tab
834 # Martin A. Hansen, September 2007.
836 # Read tabular BLAST output from NCBI blast run with -m8 or -m9.
838 my ( $in, # handle to in stream
839 $out, # handle to out stream
840 $options, # options hash
845 my ( $file, $line, @fields, $strand, $record, $data_in, $num );
847 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
848 Maasha::Biopieces::put_record( $record, $out );
853 foreach $file ( @{ $options->{ "files" } } )
855 $data_in = Maasha::Common::read_open( $file );
857 while ( $line = <$data_in> )
861 next if $line =~ /^#/;
863 @fields = split /\t/, $line;
865 $record->{ "REC_TYPE" } = "BLAST";
866 $record->{ "Q_ID" } = $fields[ 0 ];
867 $record->{ "S_ID" } = $fields[ 1 ];
868 $record->{ "IDENT" } = $fields[ 2 ];
869 $record->{ "ALIGN_LEN" } = $fields[ 3 ];
870 $record->{ "MISMATCHES" } = $fields[ 4 ];
871 $record->{ "GAPS" } = $fields[ 5 ];
872 $record->{ "Q_BEG" } = $fields[ 6 ] - 1; # BLAST is 1-based
873 $record->{ "Q_END" } = $fields[ 7 ] - 1; # BLAST is 1-based
874 $record->{ "S_BEG" } = $fields[ 8 ] - 1; # BLAST is 1-based
875 $record->{ "S_END" } = $fields[ 9 ] - 1; # BLAST is 1-based
876 $record->{ "E_VAL" } = $fields[ 10 ];
877 $record->{ "BIT_SCORE" } = $fields[ 11 ];
879 if ( $record->{ "S_BEG" } > $record->{ "S_END" } )
881 $record->{ "STRAND" } = '-';
883 ( $record->{ "S_BEG" }, $record->{ "S_END" } ) = ( $record->{ "S_END" }, $record->{ "S_BEG" } );
887 $record->{ "STRAND" } = '+';
890 Maasha::Biopieces::put_record( $record, $out );
892 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
902 close $data_in if $data_in;
908 # Martin A. Hansen, August 2007.
912 my ( $in, # handle to in stream
913 $out, # handle to out stream
914 $options, # options hash
919 my ( %options2, $file, $data_in, $num, $entry, $record );
921 map { $options2{ "keys" }{ $_ } = 1 } @{ $options->{ "keys" } };
922 map { $options2{ "feats" }{ $_ } = 1 } @{ $options->{ "feats" } };
923 map { $options2{ "quals" }{ $_ } = 1 } @{ $options->{ "quals" } };
925 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
926 Maasha::Biopieces::put_record( $record, $out );
931 foreach $file ( @{ $options->{ "files" } } )
933 $data_in = Maasha::Common::read_open( $file );
935 while ( $entry = Maasha::EMBL::get_embl_entry( $data_in ) )
937 $record = Maasha::EMBL::parse_embl_entry( $entry, \%options2 );
939 my ( $feat, $feat2, $qual, $qual_val, $record_copy );
941 $record_copy = dclone $record;
943 delete $record_copy->{ "FT" };
945 Maasha::Biopieces::put_record( $record_copy, $out );
947 delete $record_copy->{ "SEQ" };
949 foreach $feat ( keys %{ $record->{ "FT" } } )
951 $record_copy->{ "FEAT_TYPE" } = $feat;
953 foreach $feat2 ( @{ $record->{ "FT" }->{ $feat } } )
955 foreach $qual ( keys %{ $feat2 } )
957 $qual_val = join "; ", @{ $feat2->{ $qual } };
962 $record_copy->{ $qual } = $qual_val;
965 Maasha::Biopieces::put_record( $record_copy, $out );
969 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
979 close $data_in if $data_in;
983 sub script_read_stockholm
985 # Martin A. Hansen, August 2007.
987 # Read Stockholm format.
989 my ( $in, # handle to in stream
990 $out, # handle to out stream
991 $options, # options hash
996 my ( $data_in, $file, $num, $entry, $record, $record_anno, $record_align, $key, $seq );
998 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
999 Maasha::Biopieces::put_record( $record, $out );
1004 foreach $file ( @{ $options->{ "files" } } )
1006 $data_in = Maasha::Common::read_open( $file );
1008 while ( $entry = Maasha::Stockholm::get_stockholm_entry( $data_in ) )
1010 $record = Maasha::Stockholm::parse_stockholm_entry( $entry );
1014 foreach $key ( keys %{ $record->{ "GF" } } ) {
1015 $record_anno->{ $key } = $record->{ "GF" }->{ $key };
1018 $record_anno->{ "ALIGN" } = $num;
1020 Maasha::Biopieces::put_record( $record_anno, $out );
1022 foreach $seq ( @{ $record->{ "ALIGN" } } )
1024 undef $record_align;
1027 SEQ_NAME => $seq->[ 0 ],
1031 Maasha::Biopieces::put_record( $record_align, $out );
1034 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
1044 close $data_in if $data_in;
1048 sub script_read_phastcons
1050 # Martin A. Hansen, December 2007.
1052 # Read PhastCons format.
1054 my ( $in, # handle to in stream
1055 $out, # handle to out stream
1056 $options, # options hash
1061 my ( $data_in, $file, $num, $entry, @records, $record );
1063 $options->{ "min" } ||= 10;
1064 $options->{ "dist" } ||= 25;
1065 $options->{ "threshold" } ||= 0.8;
1066 $options->{ "gap" } ||= 5;
1068 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
1069 Maasha::Biopieces::put_record( $record, $out );
1074 foreach $file ( @{ $options->{ "files" } } )
1076 $data_in = Maasha::Common::read_open( $file );
1078 while ( $entry = Maasha::UCSC::fixedstep_get_entry( $data_in ) )
1080 @records = Maasha::UCSC::phastcons_parse_entry( $entry, $options );
1082 foreach $record ( @records )
1084 $record->{ "REC_TYPE" } = "BED";
1085 $record->{ "BED_LEN" } = $record->{ "CHR_END" } - $record->{ "CHR_BEG" } + 1;
1087 Maasha::Biopieces::put_record( $record, $out );
1089 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
1100 close $data_in if $data_in;
1104 sub script_read_soft
1106 # Martin A. Hansen, December 2007.
1109 # http://www.ncbi.nlm.nih.gov/geo/info/soft2.html
1111 my ( $in, # handle to in stream
1112 $out, # handle to out stream
1113 $options, # options hash
1118 my ( $data_in, $file, $num, $records, $record, $soft_index, $fh, @platforms, $plat_table, @samples, $sample, $old_end, $skip );
1120 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
1121 Maasha::Biopieces::put_record( $record, $out );
1126 foreach $file ( @{ $options->{ "files" } } )
1128 print STDERR "Creating index for file: $file\n" if $options->{ "verbose" };
1130 $soft_index = Maasha::NCBI::soft_index_file( $file );
1132 $fh = Maasha::Common::read_open( $file );
1134 @platforms = grep { $_->{ "SECTION" } =~ /PLATFORM/ } @{ $soft_index };
1136 print STDERR "Getting platform tables for file: $file\n" if $options->{ "verbose" };
1138 $plat_table = Maasha::NCBI::soft_get_platform( $fh, $platforms[ 0 ]->{ "LINE_BEG" }, $platforms[ -1 ]->{ "LINE_END" } );
1140 @samples = grep { $_->{ "SECTION" } =~ /SAMPLE/ } @{ $soft_index };
1142 $old_end = $platforms[ -1 ]->{ "LINE_END" };
1144 foreach $sample ( @samples )
1147 $skip = 1 if ( $options->{ "samples" } and grep { $sample->{ "SECTION" } !~ /$_/ } @{ $options->{ "samples" } } );
1149 print STDERR "Getting samples for dataset: $sample->{ 'SECTION' }\n" if $options->{ "verbose" } and not $skip;
1151 $records = Maasha::NCBI::soft_get_sample( $fh, $plat_table, $sample->{ "LINE_BEG" } - $old_end - 1, $sample->{ "LINE_END" } - $old_end - 1, $skip );
1153 foreach $record ( @{ $records } )
1155 Maasha::Biopieces::put_record( $record, $out );
1157 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
1162 $old_end = $sample->{ "LINE_END" };
1170 close $data_in if $data_in;
1177 # Martin A. Hansen, February 2008.
1180 # http://www.ncbi.nlm.nih.gov/geo/info/soft2.html
1182 my ( $in, # handle to in stream
1183 $out, # handle to out stream
1184 $options, # options hash
1189 my ( $data_in, $file, $fh, $num, $record, $entry );
1191 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
1192 Maasha::Biopieces::put_record( $record, $out );
1197 foreach $file ( @{ $options->{ "files" } } )
1199 $fh = Maasha::Common::read_open( $file );
1201 while ( $entry = Maasha::GFF::get_entry( $fh ) )
1203 Maasha::Biopieces::put_record( $entry, $out );
1205 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
1215 close $data_in if $data_in;
1219 sub script_read_2bit
1221 # Martin A. Hansen, March 2008.
1223 # Read sequences from 2bit file.
1225 my ( $in, # handle to in stream
1226 $out, # handle to out stream
1227 $options, # options hash
1232 my ( $record, $file, $data_in, $mask, $toc, $line, $num );
1234 $mask = 1 if not $options->{ "no_mask" };
1236 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
1237 Maasha::Biopieces::put_record( $record, $out );
1242 foreach $file ( @{ $options->{ "files" } } )
1244 $data_in = Maasha::Common::read_open( $file );
1246 $toc = Maasha::TwoBit::twobit_get_TOC( $data_in );
1248 foreach $line ( @{ $toc } )
1250 $record->{ "SEQ_NAME" } = $line->[ 0 ];
1251 $record->{ "SEQ" } = Maasha::TwoBit::twobit_get_seq( $data_in, $line->[ 1 ], undef, undef, $mask );
1252 $record->{ "SEQ_LEN" } = length $record->{ "SEQ" };
1254 Maasha::Biopieces::put_record( $record, $out );
1256 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
1266 close $data_in if $data_in;
1270 sub script_read_solexa
1272 # Martin A. Hansen, March 2008.
1274 # Read Solexa sequence reads from file.
1276 my ( $in, # handle to in stream
1277 $out, # handle to out stream
1278 $options, # options hash
1283 my ( $record, $file, $data_in, $entry, $num, @seqs, @scores, $i );
1285 $options->{ "format" } ||= "octal";
1286 $options->{ "quality" } ||= 20;
1288 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
1289 Maasha::Biopieces::put_record( $record, $out );
1294 foreach $file ( @{ $options->{ "files" } } )
1296 $data_in = Maasha::Common::read_open( $file );
1298 if ( $options->{ "format" } eq "octal" )
1300 while ( $entry = Maasha::Solexa::solexa_get_entry_octal( $data_in ) )
1302 $record = Maasha::Solexa::solexa2biopiece( $entry, $options->{ "quality" } );
1304 Maasha::Biopieces::put_record( $record, $out );
1306 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
1313 while ( $entry = Maasha::Solexa::solexa_get_entry_decimal( $data_in ) )
1315 $record = Maasha::Solexa::solexa2biopiece( $entry, $options->{ "quality" } );
1317 Maasha::Biopieces::put_record( $record, $out );
1319 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
1330 close $data_in if $data_in;
1334 sub script_read_solid
1336 # Martin A. Hansen, April 2008.
1338 # Read Solid sequence from file.
1340 my ( $in, # handle to in stream
1341 $out, # handle to out stream
1342 $options, # options hash
1347 my ( $record, $file, $data_in, $line, $num, $seq_name, $seq_cs, $seq_qual, @scores, @seqs, $i );
1349 $options->{ "quality" } ||= 15;
1351 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
1352 Maasha::Biopieces::put_record( $record, $out );
1357 foreach $file ( @{ $options->{ "files" } } )
1359 $data_in = Maasha::Common::read_open( $file );
1361 while ( $line = <$data_in> )
1365 ( $seq_name, $seq_cs, $seq_qual ) = split /\t/, $line;
1367 @scores = split /,/, $seq_qual;
1368 @seqs = split //, Maasha::Solid::color_space2seq( $seq_cs );
1370 for ( $i = 0; $i < @seqs; $i++ ) {
1371 $seqs[ $i ] = lc $seqs[ $i ] if $scores[ $i ] < $options->{ "quality" };
1375 REC_TYPE => 'SOLID',
1376 SEQ_NAME => $seq_name,
1378 SEQ_QUAL => join( ";", @scores ),
1379 SEQ_LEN => length $seq_cs,
1380 SEQ => join( "", @seqs ),
1381 SCORE_MEAN => sprintf( "%.2f", Maasha::Calc::mean( \@scores ) ),
1384 Maasha::Biopieces::put_record( $record, $out );
1386 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
1396 close $data_in if $data_in;
1400 sub script_read_mysql
1402 # Martin A. Hansen, May 2008.
1404 # Read a MySQL query into stream.
1406 my ( $in, # handle to in stream
1407 $out, # handle to out stream
1408 $options, # options hash
1413 my ( $record, $dbh, $results );
1415 $options->{ "user" } ||= Maasha::UCSC::ucsc_get_user();
1416 $options->{ "password" } ||= Maasha::UCSC::ucsc_get_password();
1418 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
1419 Maasha::Biopieces::put_record( $record, $out );
1422 $dbh = Maasha::SQL::connect( $options->{ "database" }, $options->{ "user" }, $options->{ "password" } );
1424 $results = Maasha::SQL::query_hashref_list( $dbh, $options->{ "query" } );
1426 Maasha::SQL::disconnect( $dbh );
1428 map { Maasha::Biopieces::put_record( $_ ) } @{ $results };
1432 sub script_read_ucsc_config
1434 # Martin A. Hansen, November 2008.
1436 # Read track entries from UCSC Genome Browser '.ra' files.
1438 my ( $in, # handle to in stream
1439 $out, # handle to out stream
1440 $options, # options hash
1445 my ( $record, $file, $data_in, $entry, $num );
1447 while ( $record = Maasha::Biopieces::get_record( $in ) ) {
1448 Maasha::Biopieces::put_record( $record, $out );
1453 foreach $file ( @{ $options->{ "files" } } )
1455 $data_in = Maasha::Common::read_open( $file );
1457 while ( $record = Maasha::UCSC::ucsc_config_entry_get( $data_in ) )
1459 $record->{ 'REC_TYPE' } = "UCSC Config";
1461 Maasha::Biopieces::put_record( $record, $out );
1463 goto NUM if $options->{ "num" } and $num == $options->{ "num" };
1473 close $data_in if $data_in;
1477 sub script_complexity_seq
1479 # Martin A. Hansen, May 2008.
1481 # Generates an index calculated as the most common di-residue over
1482 # the sequence length for all sequences in stream.
1484 my ( $in, # handle to in stream
1485 $out, # handle to out stream
1490 my ( $record, $index );
1492 while ( $record = Maasha::Biopieces::get_record( $in ) )
1494 $record->{ "SEQ_COMPLEXITY" } = sprintf( "%.2f", Maasha::Seq::seq_complexity( $record->{ "SEQ" } ) ) if $record->{ "SEQ" };
1496 Maasha::Biopieces::put_record( $record, $out );
1501 sub script_remove_indels
1503 # Martin A. Hansen, August 2007.
1505 # Remove indels from sequences in stream.
1507 my ( $in, # handle to in stream
1508 $out, # handle to out stream
1515 while ( $record = Maasha::Biopieces::get_record( $in ) )
1517 $record->{ 'SEQ' } =~ tr/-~.//d if $record->{ "SEQ" };
1519 Maasha::Biopieces::put_record( $record, $out );
1524 sub script_get_genome_align
1526 # Martin A. Hansen, April 2008.
1528 # Gets a subalignment from a multiple genome alignment.
1530 my ( $in, # handle to in stream
1531 $out, # handle to out stream
1532 $options, # options hash
1537 my ( $record, $maf_track, $align, $align_num, $beg, $end, $len, $entry );
1539 $options->{ "strand" } ||= "+";
1543 $maf_track = Maasha::Config::maf_track( $options->{ "genome" } );
1545 if ( $options->{ "chr" } and $options->{ "beg" } and ( $options->{ "end" } or $options->{ "len" } ) )
1547 $beg = $options->{ "beg" } - 1;
1549 if ( $options->{ "end" } ) {
1550 $end = $options->{ "end" };
1551 } elsif ( $options->{ "len" } ) {
1552 $end = $beg + $options->{ "len" };
1555 $align = Maasha::UCSC::maf_extract( $BP_TMP, $options->{ "genome" }, $maf_track, $options->{ "chr" }, $beg, $end, $options->{ "strand" } );
1557 foreach $entry ( @{ $align } )
1559 $entry->{ "CHR" } = $record->{ "CHR" };
1560 $entry->{ "CHR_BEG" } = $record->{ "CHR_BEG" };
1561 $entry->{ "CHR_END" } = $record->{ "CHR_END" };
1562 $entry->{ "STRAND" } = $record->{ "STRAND" } || '+';
1563 $entry->{ "Q_ID" } = $record->{ "Q_ID" };
1564 $entry->{ "SCORE" } = $record->{ "SCORE" };
1566 Maasha::Biopieces::put_record( $entry, $out );
1570 while ( $record = Maasha::Biopieces::get_record( $in ) )
1572 if ( $record->{ "REC_TYPE" } eq "BED" )
1574 $align = Maasha::UCSC::maf_extract( $BP_TMP, $options->{ "genome" }, $maf_track, $record->{ "CHR" }, $record->{ "CHR_BEG" }, $record->{ "CHR_END" }, $record->{ "STRAND" } );
1576 elsif ( $record->{ "REC_TYPE" } eq "VMATCH" )
1578 $align = Maasha::UCSC::maf_extract( $BP_TMP, $options->{ "genome" }, $maf_track, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" } + 1, $record->{ "STRAND" } );
1580 elsif ( $record->{ "REC_TYPE" } eq "PSL" )
1582 $align = Maasha::UCSC::maf_extract( $BP_TMP, $options->{ "genome" }, $maf_track, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" }, $record->{ "STRAND" } );
1584 elsif ( $record->{ "REC_TYPE" } eq "BLAST" )
1586 $align = Maasha::UCSC::maf_extract( $BP_TMP, $options->{ "genome" }, $maf_track, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" }, $record->{ "STRAND" } );
1589 foreach $entry ( @{ $align } )
1591 $entry->{ "CHR" } = $record->{ "CHR" };
1592 $entry->{ "CHR_BEG" } = $record->{ "CHR_BEG" };
1593 $entry->{ "CHR_END" } = $record->{ "CHR_END" };
1594 $entry->{ "STRAND" } = $record->{ "STRAND" };
1595 $entry->{ "Q_ID" } = $record->{ "Q_ID" };
1596 $entry->{ "SCORE" } = $record->{ "SCORE" };
1598 Maasha::Biopieces::put_record( $entry, $out );
1606 sub script_get_genome_phastcons
1608 # Martin A. Hansen, February 2008.
1610 # Get phastcons scores from genome intervals.
1612 my ( $in, # handle to in stream
1613 $out, # handle to out stream
1614 $options, # options hash
1619 my ( $phastcons_file, $phastcons_index, $index, $fh_phastcons, $scores, $record );
1621 $options->{ "flank" } ||= 0;
1623 $phastcons_file = Maasha::Config::genome_phastcons( $options->{ "genome" } );
1624 $phastcons_index = Maasha::Config::genome_phastcons_index( $options->{ "genome" } );
1626 $index = Maasha::UCSC::fixedstep_index_retrieve( $phastcons_index );
1627 $fh_phastcons = Maasha::Common::read_open( $phastcons_file );
1629 if ( defined $options->{ "chr" } and defined $options->{ "beg" } and ( defined $options->{ "end" } or defined $options->{ "len" } ) )
1631 $options->{ "beg" } -= 1; # request is 1-based
1632 $options->{ "end" } -= 1; # request is 1-based
1634 if ( $options->{ "len" } ) {
1635 $options->{ "end" } = $options->{ "beg" } + $options->{ "len" } - 1;
1638 $scores = Maasha::UCSC::fixedstep_index_lookup( $index, $fh_phastcons, $options->{ "chr" }, $options->{ "beg" }, $options->{ "end" }, $options->{ "flank" } );
1640 $record->{ "CHR" } = $options->{ "chr" };
1641 $record->{ "CHR_BEG" } = $options->{ "beg" } - $options->{ "flank" };
1642 $record->{ "CHR_END" } = $options->{ "end" } + $options->{ "flank" };
1644 $record->{ "PHASTCONS" } = join ",", @{ $scores };
1645 $record->{ "PHAST_COUNT" } = scalar @{ $scores }; # DEBUG
1647 Maasha::Biopieces::put_record( $record, $out );
1650 while ( $record = Maasha::Biopieces::get_record( $in ) )
1652 if ( $record->{ "REC_TYPE" } eq "BED" )
1654 $scores = Maasha::UCSC::fixedstep_index_lookup( $index, $fh_phastcons, $record->{ "CHR" }, $record->{ "CHR_BEG" }, $record->{ "CHR_END" }, $options->{ "flank" } );
1656 elsif ( $record->{ "REC_TYPE" } eq "PSL" )
1658 $scores = Maasha::UCSC::fixedstep_index_lookup( $index, $fh_phastcons, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" }, $options->{ "flank" } );
1660 elsif ( $record->{ "REC_TYPE" } eq "BLAST" )
1662 $scores = Maasha::UCSC::fixedstep_index_lookup( $index, $fh_phastcons, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" }, $options->{ "flank" } );
1665 $record->{ "PHASTCONS" } = join ",", @{ $scores } if @{ $scores };
1666 # $record->{ "PHAST_COUNT" } = @{ $scores } if @{ $scores }; # DEBUG
1668 Maasha::Biopieces::put_record( $record, $out );
1671 close $fh_phastcons if $fh_phastcons;
1677 # Martin A. Hansen, February 2008.
1679 # Using the first sequence in stream as reference, tile
1680 # all subsequent sequences based on pairwise alignments.
1682 my ( $in, # handle to in stream
1683 $out, # handle to out stream
1684 $options, # options hash
1689 my ( $record, $first, $ref_entry, @entries );
1693 while ( $record = Maasha::Biopieces::get_record( $in ) )
1695 if ( $record->{ "SEQ_NAME" } and $record->{ "SEQ" } )
1699 $ref_entry = [ $record->{ "SEQ_NAME" }, $record->{ "SEQ" } ];
1705 push @entries, [ $record->{ "SEQ_NAME" }, $record->{ "SEQ" } ];
1710 Maasha::Biopieces::put_record( $record, $out );
1714 @entries = Maasha::Align::align_tile( $ref_entry, \@entries, $options );
1716 map { Maasha::Biopieces::put_record( { SEQ_NAME => $_->[ SEQ_NAME ], SEQ => $_->[ SEQ ] }, $out ) } @entries;
1722 # Martin A. Hansen, July 2008.
1724 # soap sequences in stream against a given file or genome.
1726 my ( $in, # handle to in stream
1727 $out, # handle to out stream
1728 $options, # options hash
1733 my ( $genome, $tmp_in, $tmp_out, $fh_in, $fh_out, $record, $line, @fields, $entry, $count, $args );
1735 $options->{ "seed_size" } ||= 10;
1736 $options->{ "mismatches" } ||= 2;
1737 $options->{ "gap_size" } ||= 0;
1738 $options->{ "cpus" } ||= 1;
1740 if ( $options->{ "genome" } ) {
1741 $options->{ "in_file" } = "$ENV{ 'BP_DATA' }/genomes/$options->{ 'genome' }/fasta/$options->{ 'genome' }.fna";
1744 $tmp_in = "$BP_TMP/soap_query.seq";
1745 $tmp_out = "$BP_TMP/soap.result";
1747 $fh_out = Maasha::Common::write_open( $tmp_in );
1751 while ( $record = Maasha::Biopieces::get_record( $in ) )
1753 if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) )
1755 Maasha::Fasta::put_entry( $entry, $fh_out );
1760 Maasha::Biopieces::put_record( $record, $out );
1768 "-s $options->{ 'seed_size' }",
1771 "-v $options->{ 'mismatches' }",
1772 "-g $options->{ 'gap_size' }",
1773 "-p $options->{ 'cpus' }",
1774 "-d $options->{ 'in_file' }",
1778 $args .= " > /dev/null 2>&1" if not $options->{ 'verbose' };
1780 Maasha::Common::run( "soap", $args, 1 );
1784 $fh_out = Maasha::Common::read_open( $tmp_out );
1788 while ( $line = <$fh_out> )
1792 @fields = split /\t/, $line;
1794 $record->{ "REC_TYPE" } = "SOAP";
1795 $record->{ "Q_ID" } = $fields[ 0 ];
1796 $record->{ "SCORE" } = $fields[ 3 ];
1797 $record->{ "STRAND" } = $fields[ 6 ];
1798 $record->{ "S_ID" } = $fields[ 7 ];
1799 $record->{ "S_BEG" } = $fields[ 8 ] - 1; # soap is 1-based
1800 $record->{ "S_END" } = $fields[ 8 ] + $fields[ 5 ] - 2;
1802 Maasha::Biopieces::put_record( $record, $out );
1812 sub script_write_bed
1814 # Martin A. Hansen, August 2007.
1816 # Write BED format for the UCSC genome browser using records in stream.
1818 my ( $in, # handle to in stream
1819 $out, # handle to out stream
1820 $options, # options hash
1825 my ( $cols, $fh, $record, $bed_entry, $new_record );
1827 $cols = $options->{ 'cols' }->[ 0 ];
1829 $fh = Maasha::Biopieces::write_stream( $options->{ 'data_out' }, $options->{ 'compress' } );
1831 while ( $record = Maasha::Biopieces::get_record( $in ) )
1833 $record = Maasha::UCSC::psl2record( $record ) if $record->{ 'tBaseInsert' }; # Dirty addition to allow Affy data from MySQL to be dumped
1835 if ( $bed_entry = Maasha::UCSC::BED::biopiece2bed( $record, $cols ) ) {
1836 Maasha::UCSC::BED::bed_entry_put( $bed_entry, $fh, $cols, $options->{ 'check' } );
1839 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ 'no_stream' };
1846 sub script_write_psl
1848 # Martin A. Hansen, August 2007.
1850 # Write PSL output from stream.
1852 my ( $in, # handle to in stream
1853 $out, # handle to out stream
1854 $options, # options hash
1859 my ( $fh, $record, @output, $first );
1863 $fh = write_stream( $options->{ "data_out" }, $options->{ "compress" } );
1865 while ( $record = Maasha::Biopieces::get_record( $in ) )
1867 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
1869 if ( $record->{ "REC_TYPE" } and $record->{ "REC_TYPE" } eq "PSL" )
1871 Maasha::UCSC::psl_put_header( $fh ) if $first;
1872 Maasha::UCSC::psl_put_entry( $record, $fh );
1881 sub script_write_fixedstep
1883 # Martin A. Hansen, Juli 2008.
1885 # Write fixedStep entries from recrods in the stream.
1887 my ( $in, # handle to in stream
1888 $out, # handle to out stream
1889 $options, # options hash
1894 my ( $fh, $record, $entry );
1896 $fh = write_stream( $options->{ "data_out" }, $options->{ "compress" } );
1898 while ( $record = Maasha::Biopieces::get_record( $in ) )
1900 if ( $entry = Maasha::UCSC::Wiggle::biopiece2fixedstep( $record ) ) {
1901 Maasha::UCSC::Wiggle::fixedstep_entry_put( $entry, $fh );
1904 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
1911 sub script_write_2bit
1913 # Martin A. Hansen, March 2008.
1915 # Write sequence entries from stream in 2bit format.
1917 my ( $in, # handle to in stream
1918 $out, # handle to out stream
1919 $options, # options hash
1924 my ( $record, $mask, $tmp_file, $fh_tmp, $fh_in, $fh_out, $entry );
1926 $mask = 1 if not $options->{ "no_mask" };
1928 $tmp_file = "$BP_TMP/write_2bit.fna";
1929 $fh_tmp = Maasha::Common::write_open( $tmp_file );
1931 $fh_out = write_stream( $options->{ "data_out" } );
1933 while ( $record = Maasha::Biopieces::get_record( $in ) )
1935 if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) ) {
1936 Maasha::Fasta::put_entry( $entry, $fh_tmp );
1939 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
1944 $fh_in = Maasha::Common::read_open( $tmp_file );
1946 Maasha::TwoBit::fasta2twobit( $fh_in, $fh_out, $mask );
1955 sub script_write_solid
1957 # Martin A. Hansen, April 2008.
1959 # Write di-base encoded Solid sequence from entries in stream.
1961 my ( $in, # handle to in stream
1962 $out, # handle to out stream
1963 $options, # options hash
1968 my ( $record, $fh, $entry );
1970 $fh = write_stream( $options->{ "data_out" }, $options->{ "compress" } );
1972 while ( $record = Maasha::Biopieces::get_record( $in ) )
1974 if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) )
1976 $entry->[ SEQ ] = Maasha::Solid::seq2color_space( uc $entry->[ SEQ ] );
1978 Maasha::Fasta::put_entry( $entry, $fh, $options->{ "wrap" } );
1981 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
1988 sub script_write_ucsc_config
1990 # Martin A. Hansen, November 2008.
1992 # Write UCSC Genome Broser configuration (.ra file type) from
1993 # records in the stream.
1995 my ( $in, # handle to in stream
1996 $out, # handle to out stream
1997 $options, # options hash
2002 my ( $record, $fh );
2004 $fh = write_stream( $options->{ "data_out" } );
2006 while ( $record = Maasha::Biopieces::get_record( $in ) )
2008 Maasha::UCSC::ucsc_config_entry_put( $record, $fh ) if $record->{ "REC_TYPE" } eq "UCSC Config";
2010 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
2017 sub script_plot_seqlogo
2019 # Martin A. Hansen, August 2007.
2021 # Calculates and writes a sequence logo for alignments.
2023 my ( $in, # handle to in stream
2024 $out, # handle to out stream
2025 $options, # options hash
2030 my ( $record, @entries, $logo, $fh );
2032 while ( $record = Maasha::Biopieces::get_record( $in ) )
2034 if ( $record->{ "SEQ_NAME" } and $record->{ "SEQ" } ) {
2035 push @entries, [ $record->{ "SEQ_NAME" }, $record->{ "SEQ" } ];
2038 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
2041 $logo = Maasha::Plot::seq_logo( \@entries );
2043 $fh = write_stream( $options->{ "data_out" } );
2051 sub script_plot_phastcons_profiles
2053 # Martin A. Hansen, January 2008.
2055 # Plots PhastCons profiles.
2057 my ( $in, # handle to in stream
2058 $out, # handle to out stream
2059 $options, # options hash
2064 my ( $phastcons_file, $phastcons_index, $index, $fh_phastcons, $record, $scores, $AoA, $plot, $fh );
2066 $options->{ "title" } ||= "PhastCons Profiles";
2068 $phastcons_file = Maasha::Config::genome_phastcons( $options->{ "genome" } );
2069 $phastcons_index = Maasha::Config::genome_phastcons_index( $options->{ "genome" } );
2071 $index = Maasha::UCSC::fixedstep_index_retrieve( $phastcons_index );
2072 $fh_phastcons = Maasha::Common::read_open( $phastcons_file );
2074 while ( $record = Maasha::Biopieces::get_record( $in ) )
2076 if ( $record->{ "CHR" } and $record->{ "CHR_BEG" } and $record->{ "CHR_END" } )
2078 $scores = Maasha::UCSC::fixedstep_index_lookup( $index, $fh_phastcons, $record->{ "CHR" },
2079 $record->{ "CHR_BEG" },
2080 $record->{ "CHR_END" },
2081 $options->{ "flank" } );
2083 push @{ $AoA }, [ @{ $scores } ];
2086 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
2089 Maasha::UCSC::phastcons_normalize( $AoA );
2091 $AoA = [ [ Maasha::UCSC::phastcons_mean( $AoA ) ] ] if $options->{ "mean" };
2092 $AoA = [ [ Maasha::UCSC::phastcons_median( $AoA ) ] ] if $options->{ "median" };
2094 $AoA = Maasha::Matrix::matrix_flip( $AoA );
2096 $plot = Maasha::Plot::lineplot_simple( $AoA, $options, $BP_TMP );
2098 $fh = write_stream( $options->{ "data_out" } );
2100 print $fh "$_\n" foreach @{ $plot };
2106 sub script_remove_keys
2108 # Martin A. Hansen, August 2007.
2110 # Remove keys from stream.
2112 my ( $in, # handle to in stream
2113 $out, # handle to out stream
2114 $options, # options hash
2119 my ( $record, $new_record );
2121 while ( $record = Maasha::Biopieces::get_record( $in ) )
2123 if ( $options->{ "keys" } )
2125 map { delete $record->{ $_ } } @{ $options->{ "keys" } };
2127 elsif ( $options->{ "save_keys" } )
2129 map { $new_record->{ $_ } = $record->{ $_ } if exists $record->{ $_ } } @{ $options->{ "save_keys" } };
2131 $record = $new_record;
2134 Maasha::Biopieces::put_record( $record, $out ) if keys %{ $record };
2139 sub script_remove_adaptor
2141 # Martin A. Hansen, August 2008.
2143 # Find and remove adaptor from sequences in the stream.
2145 my ( $in, # handle to in stream
2146 $out, # handle to out stream
2147 $options, # options hash
2152 my ( $record, $adaptor, $seq, $adaptor_len, $seq_len, $offset, $max_match, $max_mismatch, $pos );
2154 $options->{ "remove" } ||= "after";
2156 $max_mismatch = $options->{ "mismatches" } || 0;
2157 $offset = $options->{ "offset" };
2159 if ( not defined $offset ) {
2165 $adaptor = uc $options->{ "adaptor" };
2166 $adaptor_len = length $adaptor;
2168 while ( $record = Maasha::Biopieces::get_record( $in ) )
2170 if ( $record->{ "SEQ" } )
2172 $seq = uc $record->{ "SEQ" };
2173 $seq_len = length $seq;
2175 $pos = Maasha::Common::index_m( $seq, $adaptor, $seq_len, $adaptor_len, $offset, $max_mismatch );
2177 $record->{ "ADAPTOR_POS" } = $pos;
2179 if ( $pos >= 0 and $options->{ "remove" } ne "skip" )
2181 if ( $options->{ "remove" } eq "after" )
2183 $record->{ "SEQ" } = substr $record->{ "SEQ" }, 0, $pos;
2184 $record->{ "SEQ_LEN" } = $pos;
2188 $record->{ "SEQ" } = substr $record->{ "SEQ" }, $pos + $adaptor_len;
2189 $record->{ "SEQ_LEN" } = length $record->{ "SEQ" };
2193 Maasha::Biopieces::put_record( $record, $out );
2197 Maasha::Biopieces::put_record( $record, $out );
2203 sub script_remove_mysql_tables
2205 # Martin A. Hansen, November 2008.
2207 # Remove MySQL tables from values in stream.
2209 my ( $in, # handle to in stream
2210 $out, # handle to out stream
2211 $options, # options hash
2216 my ( $record, %table_hash, $dbh, $table );
2218 $options->{ "user" } ||= Maasha::UCSC::ucsc_get_user();
2219 $options->{ "password" } ||= Maasha::UCSC::ucsc_get_password();
2221 map { $table_hash{ $_ } = 1 } @{ $options->{ 'tables' } };
2223 while ( $record = Maasha::Biopieces::get_record( $in ) )
2225 map { $table_hash{ $record->{ $_ } } = 1 } @{ $options->{ 'keys' } };
2227 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ 'no_stream' };
2230 $dbh = Maasha::SQL::connect( $options->{ "database" }, $options->{ "user" }, $options->{ "password" } );
2232 foreach $table ( sort keys %table_hash )
2234 if ( Maasha::SQL::table_exists( $dbh, $table ) )
2236 print STDERR qq(Removing table "$table" from database "$options->{ 'database' }" ... ) if $options->{ 'verbose' };
2237 Maasha::SQL::delete_table( $dbh, $table );
2238 print STDERR "done.\n" if $options->{ 'verbose' };
2242 print STDERR qq(WARNING: table "$table" not found in database "$options->{ 'database' }\n");
2246 Maasha::SQL::disconnect( $dbh );
2250 sub script_remove_ucsc_tracks
2252 # Martin A. Hansen, November 2008.
2254 # Remove track from MySQL tables and config file.
2256 my ( $in, # handle to in stream
2257 $out, # handle to out stream
2258 $options, # options hash
2263 my ( $record, %track_hash, $fh_in, $fh_out, $track, @tracks, @new_tracks, $dbh );
2265 $options->{ 'user' } ||= Maasha::UCSC::ucsc_get_user();
2266 $options->{ 'password' } ||= Maasha::UCSC::ucsc_get_password();
2267 $options->{ 'config_file' } ||= "$ENV{ 'HOME' }/ucsc/my_tracks.ra";
2269 map { $track_hash{ $_ } = 1 } @{ $options->{ 'tracks' } };
2271 while ( $record = Maasha::Biopieces::get_record( $in ) )
2273 map { $track_hash{ $record->{ $_ } } = 1 } @{ $options->{ 'keys' } };
2275 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ 'no_stream' };
2278 $fh_in = Maasha::Filesys::file_read_open( $options->{ 'config_file' } );
2280 while ( $track = Maasha::UCSC::ucsc_config_entry_get( $fh_in ) ) {
2281 push @tracks, $track;
2286 foreach $track ( @tracks )
2288 if ( $track->{ 'database' } eq $options->{ 'database' } and exists $track_hash{ $track->{ 'track' } } ) {
2289 print STDERR qq(Removing track "$track->{ 'track' }" from config file.\n) if $options->{ 'verbose' };
2291 push @new_tracks, $track;
2295 rename "$options->{ 'config_file' }", "$options->{ 'config_file' }~";
2297 $fh_out = Maasha::Filesys::file_write_open( $options->{ 'config_file' } );
2299 map { Maasha::UCSC::ucsc_config_entry_put( $_, $fh_out ) } @new_tracks;
2303 # ---- locate track in database ----
2305 $dbh = Maasha::SQL::connect( $options->{ "database" }, $options->{ "user" }, $options->{ "password" } );
2307 foreach $track ( sort keys %track_hash )
2309 if ( Maasha::SQL::table_exists( $dbh, $track ) )
2311 print STDERR qq(Removing table "$track" from database "$options->{ 'database' }" ... ) if $options->{ 'verbose' };
2312 Maasha::SQL::delete_table( $dbh, $track );
2313 print STDERR "done.\n" if $options->{ 'verbose' };
2317 print STDERR qq(WARNING: table "$track" not found in database "$options->{ 'database' }\n");
2321 Maasha::SQL::disconnect( $dbh );
2323 Maasha::Common::run( "ucscMakeTracks.pl", "-b > /dev/null 2>&1" );
2327 sub script_rename_keys
2329 # Martin A. Hansen, August 2007.
2331 # Rename keys in stream.
2333 my ( $in, # handle to in stream
2334 $out, # handle to out stream
2335 $options, # options hash
2342 while ( $record = Maasha::Biopieces::get_record( $in ) )
2344 if ( exists $record->{ $options->{ "keys" }->[ 0 ] } )
2346 $record->{ $options->{ "keys" }->[ 1 ] } = $record->{ $options->{ "keys" }->[ 0 ] };
2348 delete $record->{ $options->{ "keys" }->[ 0 ] };
2351 Maasha::Biopieces::put_record( $record, $out );
2356 sub script_uniq_vals
2358 # Martin A. Hansen, August 2007.
2360 # Find unique values in stream.
2362 my ( $in, # handle to in stream
2363 $out, # handle to out stream
2364 $options, # options hash
2369 my ( %hash, $record );
2371 while ( $record = Maasha::Biopieces::get_record( $in ) )
2373 if ( $record->{ $options->{ "key" } } )
2375 if ( not $hash{ $record->{ $options->{ "key" } } } and not $options->{ "invert" } )
2377 Maasha::Biopieces::put_record( $record, $out );
2379 $hash{ $record->{ $options->{ "key" } } } = 1;
2381 elsif ( $hash{ $record->{ $options->{ "key" } } } and $options->{ "invert" } )
2383 Maasha::Biopieces::put_record( $record, $out );
2387 $hash{ $record->{ $options->{ "key" } } } = 1;
2392 Maasha::Biopieces::put_record( $record, $out );
2398 sub script_plot_histogram
2400 # Martin A. Hansen, September 2007.
2402 # Plot a simple histogram for a given key using GNU plot.
2404 my ( $in, # handle to in stream
2405 $out, # handle to out stream
2406 $options, # options hash
2411 my ( $record, %data_hash, $max, @data_list, $i, $result, $fh );
2413 $options->{ "title" } ||= "Histogram";
2414 $options->{ "sort" } ||= "num";
2416 while ( $record = Maasha::Biopieces::get_record( $in ) )
2418 $data_hash{ $record->{ $options->{ "key" } } }++ if defined $record->{ $options->{ "key" } };
2420 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
2423 if ( $options->{ "sort" } eq "num" ) {
2424 map { push @data_list, [ $_, $data_hash{ $_ } ] } sort { $a <=> $b } keys %data_hash;
2426 map { push @data_list, [ $_, $data_hash{ $_ } ] } sort keys %data_hash;
2429 $result = Maasha::Plot::histogram_simple( \@data_list, $options );
2431 $fh = write_stream( $options->{ "data_out" } );
2433 print $fh "$_\n" foreach @{ $result };
2439 sub script_plot_lendist
2441 # Martin A. Hansen, August 2007.
2443 # Plot length distribution using GNU plot.
2445 my ( $in, # handle to in stream
2446 $out, # handle to out stream
2447 $options, # options hash
2452 my ( $record, %data_hash, $max, @data_list, $i, $result, $fh );
2454 $options->{ "title" } ||= "Length Distribution";
2456 while ( $record = Maasha::Biopieces::get_record( $in ) )
2458 $data_hash{ $record->{ $options->{ "key" } } }++ if defined $record->{ $options->{ "key" } };
2460 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
2463 $max = Maasha::Calc::list_max( [ keys %data_hash ] );
2465 for ( $i = 0; $i < $max; $i++ ) {
2466 push @data_list, [ $i, $data_hash{ $i } || 0 ];
2469 $result = Maasha::Plot::histogram_lendist( \@data_list, $options );
2471 $fh = write_stream( $options->{ "data_out" } );
2473 print $fh "$_\n" foreach @{ $result };
2479 sub script_plot_chrdist
2481 # Martin A. Hansen, August 2007.
2483 # Plot chromosome distribution using GNU plot.
2485 my ( $in, # handle to in stream
2486 $out, # handle to out stream
2487 $options, # options hash
2492 my ( $record, %data_hash, @data_list, $elem, $sort_key, $count, $result, $fh );
2494 $options->{ "title" } ||= "Chromosome Distribution";
2496 while ( $record = Maasha::Biopieces::get_record( $in ) )
2498 if ( $record->{ "CHR" } ) { # generic
2499 $data_hash{ $record->{ "CHR" } }++;
2500 } elsif ( $record->{ "REC_TYPE" } eq "PATSCAN" and $record->{ "S_ID" } =~ /^chr/i ) { # patscan
2501 $data_hash{ $record->{ "S_ID" } }++;
2502 } elsif ( $record->{ "REC_TYPE" } eq "PSL" and $record->{ "S_ID" } =~ /^chr/i ) { # BLAT / PSL
2503 $data_hash{ $record->{ "S_ID" } }++;
2504 } elsif ( $record->{ "REC_TYPE" } eq "BLAST" and $record->{ "S_ID" } =~ /^chr/i ) { # BLAST
2505 $data_hash{ $record->{ "S_ID" } }++;
2508 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
2511 foreach $elem ( keys %data_hash )
2515 $sort_key =~ s/chr//i;
2517 $sort_key =~ s/^X(.*)/99$1/;
2518 $sort_key =~ s/^Y(.*)/99$1/;
2519 $sort_key =~ s/^Z(.*)/999$1/;
2520 $sort_key =~ s/^M(.*)/9999$1/;
2521 $sort_key =~ s/^U(.*)/99999$1/;
2523 $count = $sort_key =~ tr/_//;
2525 $sort_key =~ s/_.*/"999999" x $count/ex;
2527 push @data_list, [ $elem, $data_hash{ $elem }, $sort_key ];
2530 @data_list = sort { $a->[ 2 ] <=> $b->[ 2 ] } @data_list;
2532 $result = Maasha::Plot::histogram_chrdist( \@data_list, $options );
2534 $fh = write_stream( $options->{ "data_out" } );
2536 print $fh "$_\n" foreach @{ $result };
2542 sub script_plot_karyogram
2544 # Martin A. Hansen, August 2007.
2546 # Plot hits on karyogram.
2548 my ( $in, # handle to in stream
2549 $out, # handle to out stream
2550 $options, # options hash
2555 my ( %options, $record, @data, $fh, $result, %data_hash );
2557 $options->{ "genome" } ||= "human";
2558 $options->{ "feat_color" } ||= "black";
2560 while ( $record = Maasha::Biopieces::get_record( $in ) )
2562 if ( $record->{ "CHR" } and $record->{ "CHR_BEG" } and $record->{ "CHR_END" } )
2564 push @{ $data_hash{ $record->{ "CHR" } } }, [ $record->{ "CHR_BEG" }, $record->{ "CHR_END" }, $options->{ "feat_color" } ];
2567 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
2570 $result = Maasha::Plot::karyogram( \%data_hash, \%options );
2572 $fh = write_stream( $options->{ "data_out" } );
2580 sub script_plot_matches
2582 # Martin A. Hansen, August 2007.
2584 # Plot matches in 2D generating a dotplot.
2586 my ( $in, # handle to in stream
2587 $out, # handle to out stream
2588 $options, # options hash
2593 my ( $record, @data, $fh, $result, %data_hash );
2595 $options->{ "direction" } ||= "both";
2597 while ( $record = Maasha::Biopieces::get_record( $in ) )
2599 if ( defined $record->{ "Q_BEG" } and defined $record->{ "S_BEG" } and $record->{ "Q_END" } and $record->{ "S_END" } ) {
2600 push @data, $record;
2603 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
2606 $options->{ "title" } ||= "plot_matches";
2607 $options->{ "xlabel" } ||= $data[ 0 ]->{ "Q_ID" };
2608 $options->{ "ylabel" } ||= $data[ 0 ]->{ "S_ID" };
2610 $result = Maasha::Plot::dotplot_matches( \@data, $options, $BP_TMP );
2612 $fh = write_stream( $options->{ "data_out" } );
2614 print $fh "$_\n" foreach @{ $result };
2620 sub script_upload_to_ucsc
2622 # Martin A. Hansen, August 2007.
2624 # Calculate the mean of values of given keys.
2626 # This routine has developed into the most ugly hack. Do something!
2628 my ( $in, # handle to in stream
2629 $out, # handle to out stream
2630 $options, # options hash
2635 my ( $record, $file, $wib_file, $wig_file, $wib_dir, $fh_out, $i, $first, $format, $type, $columns, $append, $entry );
2637 $options->{ "short_label" } ||= $options->{ 'table' };
2638 $options->{ "long_label" } ||= $options->{ 'table' };
2639 $options->{ "group" } ||= $ENV{ "LOGNAME" };
2640 $options->{ "priority" } ||= 1;
2641 $options->{ "visibility" } ||= "pack";
2642 $options->{ "color" } ||= join( ",", int( rand( 255 ) ), int( rand( 255 ) ), int( rand( 255 ) ) );
2643 $options->{ "chunk_size" } ||= 10_000_000_000; # Due to 32-bit UCSC compilation really large tables cannot be loaded in one go.
2645 $file = "$BP_TMP/ucsc_upload.tmp";
2650 $fh_out = Maasha::Common::write_open( $file );
2652 while ( $record = Maasha::Biopieces::get_record( $in ) )
2654 Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
2656 if ( $record->{ "REC_TYPE" } eq "fixed_step" )
2660 if ( $entry = Maasha::UCSC::Wiggle::biopiece2fixedstep( $record ) ) {
2661 Maasha::UCSC::Wiggle::fixedstep_entry_put( $entry, $fh_out );
2664 elsif ( $record->{ "REC_TYPE" } eq "PSL" )
2668 Maasha::UCSC::psl_put_header( $fh_out ) if $first;
2669 Maasha::UCSC::psl_put_entry( $record, $fh_out );
2673 elsif ( $record->{ "REC_TYPE" } eq "BED" and $record->{ "SEC_STRUCT" } )
2675 # chrom chromStart chromEnd name score strand size secStr conf
2679 print $fh_out join ( "\t",
2681 $record->{ "CHR_BEG" },
2682 $record->{ "CHR_END" } + 1,
2683 $record->{ "Q_ID" },
2684 $record->{ "SCORE" },
2685 $record->{ "STRAND" },
2686 $record->{ "SIZE" },
2687 $record->{ "SEC_STRUCT" },
2688 $record->{ "CONF" },
2691 elsif ( $record->{ "REC_TYPE" } eq "BED" )
2694 $columns = $record->{ "BED_COLS" };
2696 if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) {
2697 Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } );
2700 elsif ( $record->{ "REC_TYPE" } eq "PATSCAN" and $record->{ "CHR" } )
2705 if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) {
2706 Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } );
2709 elsif ( $record->{ "REC_TYPE" } eq "BLAST" and $record->{ "S_ID" } =~ /^chr/ )
2714 $record->{ "SCORE" } = $record->{ "BIT_SCORE" } * 1000;
2716 if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) {
2717 Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } );
2720 elsif ( $record->{ "REC_TYPE" } eq "VMATCH" and $record->{ "S_ID" } =~ /^chr/i )
2725 if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) {
2726 Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } );
2730 if ( $i == $options->{ "chunk_size" } )
2734 if ( $format eq "BED" ) {
2735 Maasha::UCSC::bed_upload_to_ucsc( $BP_TMP, $file, $options, $append );
2736 } elsif ( $format eq "PSL" ) {
2737 Maasha::UCSC::psl_upload_to_ucsc( $file, $options, $append );
2746 $fh_out = Maasha::Common::write_open( $file );
2754 if ( exists $options->{ "database" } and $options->{ "table" } )
2756 if ( $format eq "BED" )
2758 $type = "bed $columns";
2760 Maasha::UCSC::bed_upload_to_ucsc( $BP_TMP, $file, $options, $append );
2762 elsif ( $format eq "BED_SS" )
2764 $type = "type bed 6 +";
2766 Maasha::UCSC::bed_upload_to_ucsc( $BP_TMP, $file, $options, $append );
2768 elsif ( $format eq "PSL" )
2772 Maasha::UCSC::psl_upload_to_ucsc( $file, $options, $append );
2774 elsif ( $format eq "WIGGLE" )
2776 $options->{ "visibility" } = "full";
2778 $wig_file = "$options->{ 'table' }.wig";
2779 $wib_file = "$options->{ 'table' }.wib";
2781 $wib_dir = "$ENV{ 'HOME' }/ucsc/wib";
2783 Maasha::Common::dir_create_if_not_exists( $wib_dir );
2785 if ( $options->{ 'verbose' } ) {
2786 `cd $BP_TMP && wigEncode $file $wig_file $wib_file`;
2788 `cd $BP_TMP && wigEncode $file $wig_file $wib_file > /dev/null 2>&1`;
2791 Maasha::Common::run( "mv", "$BP_TMP/$wib_file $wib_dir" );
2799 Maasha::UCSC::wiggle_upload_to_ucsc( $BP_TMP, $wib_dir, $file, $options );
2804 Maasha::UCSC::ucsc_update_config( $options, $type );
2809 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<