elsif ( $script eq "get_genome_phastcons" ) { script_get_genome_phastcons( $in, $out, $options ) }
elsif ( $script eq "remove_mysql_tables" ) { script_remove_mysql_tables( $in, $out, $options ) }
elsif ( $script eq "remove_ucsc_tracks" ) { script_remove_ucsc_tracks( $in, $out, $options ) }
- elsif ( $script eq "upload_to_ucsc" ) { script_upload_to_ucsc( $in, $out, $options ) }
close $in if defined $in;
close $out;
no_stream|x
);
}
- elsif ( $script eq "upload_to_ucsc" )
- {
- @options = qw(
- no_stream|x
- database|d=s
- table|t=s
- short_label|s=s
- long_label|l=s
- group|g=s
- priority|p=f
- use_score|u
- visibility|V=s
- color|c=s
- check|C
- );
- }
push @options, qw(
stream_in|I=s
Maasha::Common::error( qq(no --database specified) ) if $script eq "remove_ucsc_tracks" and not $options{ "database" };
Maasha::Common::error( qq(no --genome specified) ) if $script =~ /get_genome_align|get_genome_phastcons/ and not $options{ "genome" };
- if ( $script eq "upload_to_ucsc" )
- {
- Maasha::Common::error( qq(no --database specified) ) if not $options{ "database" };
- Maasha::Common::error( qq(no --table specified) ) if not $options{ "table" };
- }
-
return wantarray ? %options : \%options;
}
}
-sub script_upload_to_ucsc
-{
- # Martin A. Hansen, August 2007.
-
- # Calculate the mean of values of given keys.
-
- # This routine has developed into the most ugly hack. Do something!
-
- my ( $in, # handle to in stream
- $out, # handle to out stream
- $options, # options hash
- ) = @_;
-
- # Returns nothing.
-
- my ( $record, $file, $wib_file, $wig_file, $wib_dir, $fh_out, $i, $first, $format, $type, $columns, $append, $entry );
-
- $options->{ "short_label" } ||= $options->{ 'table' };
- $options->{ "long_label" } ||= $options->{ 'table' };
- $options->{ "group" } ||= $ENV{ "LOGNAME" };
- $options->{ "priority" } ||= 1;
- $options->{ "visibility" } ||= "pack";
- $options->{ "color" } ||= join( ",", int( rand( 255 ) ), int( rand( 255 ) ), int( rand( 255 ) ) );
- $options->{ "chunk_size" } ||= 10_000_000_000; # Due to 32-bit UCSC compilation really large tables cannot be loaded in one go.
-
- $file = "$BP_TMP/ucsc_upload.tmp";
- $append = 0;
- $first = 1;
- $i = 0;
-
- $fh_out = Maasha::Common::write_open( $file );
-
- while ( $record = Maasha::Biopieces::get_record( $in ) )
- {
- Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
-
- if ( $record->{ "REC_TYPE" } eq "fixed_step" )
- {
- $format = "WIGGLE";
-
- if ( $entry = Maasha::UCSC::Wiggle::biopiece2fixedstep( $record ) ) {
- Maasha::UCSC::Wiggle::fixedstep_entry_put( $entry, $fh_out );
- }
- }
- elsif ( $record->{ "REC_TYPE" } eq "PSL" )
- {
- $format = "PSL";
-
- Maasha::UCSC::psl_put_header( $fh_out ) if $first;
- Maasha::UCSC::psl_put_entry( $record, $fh_out );
-
- $first = 0;
- }
- elsif ( $record->{ "REC_TYPE" } eq "BED" and $record->{ "SEC_STRUCT" } )
- {
- # chrom chromStart chromEnd name score strand size secStr conf
-
- $format = "BED_SS";
-
- print $fh_out join ( "\t",
- $record->{ "CHR" },
- $record->{ "CHR_BEG" },
- $record->{ "CHR_END" } + 1,
- $record->{ "Q_ID" },
- $record->{ "SCORE" },
- $record->{ "STRAND" },
- $record->{ "SIZE" },
- $record->{ "SEC_STRUCT" },
- $record->{ "CONF" },
- ), "\n";
- }
- elsif ( $record->{ "REC_TYPE" } eq "BED" )
- {
- $format = "BED";
- $columns = $record->{ "BED_COLS" };
-
- if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) {
- Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } );
- }
- }
- elsif ( $record->{ "REC_TYPE" } eq "PATSCAN" and $record->{ "CHR" } )
- {
- $format = "BED";
- $columns = 6;
-
- if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) {
- Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } );
- }
- }
- elsif ( $record->{ "REC_TYPE" } eq "BLAST" and $record->{ "S_ID" } =~ /^chr/ )
- {
- $format = "BED";
- $columns = 6;
-
- $record->{ "SCORE" } = $record->{ "BIT_SCORE" } * 1000;
-
- if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) {
- Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } );
- }
- }
- elsif ( $record->{ "REC_TYPE" } eq "VMATCH" and $record->{ "S_ID" } =~ /^chr/i )
- {
- $format = "BED";
- $columns = 6;
-
- if ( $entry = Maasha::UCSC::BED::biopiece2bed( $record, $columns ) ) {
- Maasha::UCSC::BED::bed_entry_put( $entry, $fh_out, $columns, $options->{ 'check' } );
- }
- }
-
- if ( $i == $options->{ "chunk_size" } )
- {
- close $fh_out;
-
- if ( $format eq "BED" ) {
- Maasha::UCSC::bed_upload_to_ucsc( $BP_TMP, $file, $options, $append );
- } elsif ( $format eq "PSL" ) {
- Maasha::UCSC::psl_upload_to_ucsc( $file, $options, $append );
- }
-
- unlink $file;
-
- $first = 1;
-
- $append = 1;
-
- $fh_out = Maasha::Common::write_open( $file );
- }
-
- $i++;
- }
-
- close $fh_out;
-
- if ( exists $options->{ "database" } and $options->{ "table" } )
- {
- if ( $format eq "BED" )
- {
- $type = "bed $columns";
-
- Maasha::UCSC::bed_upload_to_ucsc( $BP_TMP, $file, $options, $append );
- }
- elsif ( $format eq "BED_SS" )
- {
- $type = "type bed 6 +";
-
- Maasha::UCSC::bed_upload_to_ucsc( $BP_TMP, $file, $options, $append );
- }
- elsif ( $format eq "PSL" )
- {
- $type = "psl";
-
- Maasha::UCSC::psl_upload_to_ucsc( $file, $options, $append );
- }
- elsif ( $format eq "WIGGLE" )
- {
- $options->{ "visibility" } = "full";
-
- $wig_file = "$options->{ 'table' }.wig";
- $wib_file = "$options->{ 'table' }.wib";
-
- $wib_dir = "$ENV{ 'HOME' }/ucsc/wib";
-
- Maasha::Common::dir_create_if_not_exists( $wib_dir );
-
- if ( $options->{ 'verbose' } ) {
- `cd $BP_TMP && wigEncode $file $wig_file $wib_file`;
- } else {
- `cd $BP_TMP && wigEncode $file $wig_file $wib_file > /dev/null 2>&1`;
- }
-
- Maasha::Common::run( "mv", "$BP_TMP/$wib_file $wib_dir" );
-
- unlink $file;
-
- $file = $wig_file;
-
- $type = "wig 0";
-
- Maasha::UCSC::wiggle_upload_to_ucsc( $BP_TMP, $wib_dir, $file, $options );
- }
-
- unlink $file;
-
- Maasha::UCSC::ucsc_update_config( $options, $type );
- }
-}
-
-
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
1;