use Storable qw( dclone );
use Maasha::Config;
use Maasha::Common;
+use Maasha::Filesys;
use Maasha::Fasta;
use Maasha::Align;
use Maasha::Matrix;
use Maasha::Plot;
use Maasha::Calc;
use Maasha::UCSC;
+use Maasha::UCSC::BED;
+use Maasha::UCSC::Wiggle;
use Maasha::NCBI;
use Maasha::GFF;
use Maasha::TwoBit;
my ( $script, $BP_TMP );
-$script = Maasha::Common::get_scriptname();
-$BP_TMP = Maasha::Common::get_tmpdir();
+$script = Maasha::Common::get_scriptname();
+$BP_TMP = Maasha::Common::get_tmpdir();
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> LOG <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
elsif ( $script eq "remove_keys" ) { script_remove_keys( $in, $out, $options ) }
elsif ( $script eq "remove_adaptor" ) { script_remove_adaptor( $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 "rename_keys" ) { script_rename_keys( $in, $out, $options ) }
elsif ( $script eq "uniq_vals" ) { script_uniq_vals( $in, $out, $options ) }
elsif ( $script eq "merge_vals" ) { script_merge_vals( $in, $out, $options ) }
{
@options = qw(
data_in|i=s
+ cols|c=s
num|n=s
+ check|C
);
}
elsif ( $script eq "read_fixedstep" )
num|n=s
);
}
+ elsif ( $script eq "assemble_tag_contigs" )
+ {
+ @options = qw(
+ check|C
+ );
+ }
+ elsif ( $script eq "calc_fixedstep" )
+ {
+ @options = qw(
+ check|C
+ );
+ }
elsif ( $script eq "format_genome" )
{
@options = qw(
percent|p
);
}
- elsif ( $script eq "calc_fixedstep" )
- {
- @options = qw(
- score|S
- log10|L
- );
- }
elsif ( $script eq "transliterate_seq" )
{
@options = qw(
elsif ( $script eq "write_bed" )
{
@options = qw(
+ cols|c=s
+ check|C
no_stream|x
data_out|o=s
compress|Z
{
@options = qw(
database|d=s
+ tables|t=s
keys|k=s
- query|q=s
+ user|u=s
+ password|p=s
+ no_stream|x
+ );
+ }
+ elsif ( $script eq "remove_ucsc_tracks" )
+ {
+ @options = qw(
+ database|d=s
+ tracks|t=s
+ keys|k=s
+ config_file|c=s
user|u=s
password|p=s
no_stream|x
use_score|u
visibility|V=s
color|c=s
- chunk_size|C=s
+ check|C
);
}
$options{ "frames" } = [ split ",", $options{ "frames" } ] if defined $options{ "frames" };
$options{ "formats" } = [ split ",", $options{ "formats" } ] if defined $options{ "formats" };
$options{ "samples" } = [ split ",", $options{ "samples" } ] if defined $options{ "samples" };
+ $options{ "tables" } = [ split ",", $options{ "tables" } ] if defined $options{ "tables" };
+ $options{ "tracks" } = [ split ",", $options{ "tracks" } ] if defined $options{ "tracks" };
# ---- check arguments ----
# print STDERR Dumper( \%options );
- $real = "beg|end|word_size|wrap|chunk_size|tile_size|len|prefix_length|mismatches|offset|num|skip|cpus|window_size|step_size";
+ $real = "beg|end|word_size|wrap|tile_size|len|prefix_length|mismatches|offset|num|skip|cpus|window_size|step_size";
foreach $opt ( keys %options )
{
# Returns nothing.
- my ( $file, $record, $entry, $data_in, $num );
+ my ( $cols, $file, $record, $bed_entry, $data_in, $num );
+
+ $cols = $options->{ 'cols' }->[ 0 ];
while ( $record = get_record( $in ) ) {
put_record( $record, $out );
{
$data_in = Maasha::Common::read_open( $file );
- while ( $entry = Maasha::UCSC::bed_get_entry( $data_in ) )
+ while ( $bed_entry = Maasha::UCSC::BED::bed_entry_get( $data_in, $cols, $options->{ 'check' } ) )
{
- put_record( $entry, $out );
+ $record = Maasha::UCSC::BED::bed2biopiece( $bed_entry );
+
+ put_record( $record, $out );
goto NUM if $options->{ "num" } and $num == $options->{ "num" };
# Returns nothing.
- my ( $file, $record, $entry, $head, $chr, $chr_beg, $step, $data_in, $num );
+ my ( $file, $record, $entry, $data_in, $num );
while ( $record = get_record( $in ) ) {
put_record( $record, $out );
{
$data_in = Maasha::Common::read_open( $file );
- while ( $entry = Maasha::UCSC::fixedstep_get_entry( $data_in ) )
+ while ( $entry = Maasha::UCSC::Wiggle::fixedstep_entry_get( $data_in ) )
{
- $head = shift @{ $entry };
-
- if ( $head =~ /^chrom=([^ ]+) start=(\d+) step=(\d+)$/ )
- {
- $record->{ "REC_TYPE" } = "fixed_step";
- $record->{ "CHR" } = $1;
- $record->{ "CHR_BEG" } = $2;
- $record->{ "STEP" } = $3;
- $record->{ "VALS" } = join ";", @{ $entry };
- }
+ $record = Maasha::UCSC::Wiggle::fixedstep2biopiece( $entry );
put_record( $record, $out );
{
$data_in = Maasha::Common::read_open( $file );
- while ( $record = Maasha::UCSC::ucsc_config_get_entry( $data_in ) )
+ while ( $record = Maasha::UCSC::ucsc_config_entry_get( $data_in ) )
{
$record->{ 'REC_TYPE' } = "UCSC Config";
# Assemble tags from the stream into
# tag contigs.
+ # The current implementation is quite
+ # slow because of heavy use of temporary
+ # files.
+
my ( $in, # handle to in stream
$out, # handle to out stream
$options, # options hash
# Returns nothing.
- my ( $record, $new_record, %fh_hash, $fh_out, $chr, $array, $pos, $beg, $end, $score, $file, $id );
+ my ( $bed_file, $tag_file, $fh_in, $fh_out, $cols, $record, $bed_entry, $file_hash, $chr, $strand );
+
+ $bed_file = "$BP_TMP/assemble_tag_contigs.bed";
+ $fh_out = Maasha::Filesys::file_write_open( $bed_file );
+ $cols = 6; # we only need the first 6 BED columns
while ( $record = get_record( $in ) )
{
- $record->{ "CHR" } = $record->{ "S_ID" } if not defined $record->{ "CHR" };
- $record->{ "CHR_BEG" } = $record->{ "S_BEG" } if not defined $record->{ "CHR_BEG" };
- $record->{ "CHR_END" } = $record->{ "S_END" } if not defined $record->{ "CHR_END" };
-
- if ( $record->{ "CHR" } and defined $record->{ "CHR_BEG" } and $record->{ "CHR_END" } )
+ if ( $bed_entry = Maasha::UCSC::BED::biopiece2bed( $record, $cols ) )
{
- $fh_hash{ $record->{ "CHR" } } = Maasha::Common::write_open( "$BP_TMP/$record->{ 'CHR' }" ) if not exists $fh_hash{ $record->{ "CHR" } };
+ $strand = $record->{ 'STRAND' } || '+';
- $fh_out = $fh_hash{ $record->{ "CHR" } };
-
- Maasha::UCSC::bed_put_entry( $record, $fh_out, 5 );
+ Maasha::UCSC::BED::bed_entry_put( $bed_entry, $fh_out, $cols, $options->{ 'check' } );
}
}
- map { close $_ } keys %fh_hash;
-
- foreach $chr ( sort keys %fh_hash )
- {
- $array = tag_contigs_assemble( "$BP_TMP/$chr" );
-
- $pos = 0;
- $id = 0;
-
- while ( ( $beg, $end, $score ) = tag_contigs_scan( $array, $pos ) and $beg )
- {
- $new_record = {
- CHR => $chr,
- CHR_BEG => $beg,
- CHR_END => $end - 1,
- Q_ID => sprintf( "TC%06d", $id ),
- SCORE => $score,
- STRAND => $record->{ 'STRAND' } || '+',
- };
-
- put_record( $new_record, $out );
-
- $pos = $end;
- $id++;
- }
-
- unlink "$BP_TMP/$chr";
- }
-}
-
-
-sub tag_contigs_assemble
-{
- # Martin A. Hansen, November 2008.
-
- # Given a BED file with entries from only one
- # chromosome assembles tag contigs from these
- # ignoring strand information. Only tags with
- # a score higher than the clone count over
- # genomic loci (the SCORE field) is included
- # in the tag contigs.
-
- # ----------- tags
- # -------------
- # ----------
- # ----------
- # ======================== tag contig
+ close $fh_out;
+ $file_hash = Maasha::UCSC::BED::bed_file_split_on_chr( $bed_file, $BP_TMP, $cols );
- my ( $path, # full path to BED file
- ) = @_;
+ unlink $bed_file;
- # Returns an arrayref.
+ foreach $chr ( sort keys %{ $file_hash } )
+ {
+ $bed_file = $file_hash->{ $chr };
+ $tag_file = "$bed_file.tc";
- my ( $fh, $entry, $clones, $score, @array );
+ Maasha::Common::run( "bed2tag_contigs", "< $bed_file > $tag_file" );
- $fh = Maasha::Common::read_open( $path );
+ $fh_in = Maasha::Filesys::file_read_open( $tag_file );
- while ( $entry = Maasha::UCSC::bed_get_entry( $fh ) )
- {
- if ( $entry->{ 'Q_ID' } =~ /(\d+)$/ )
+ while ( $bed_entry = Maasha::UCSC::BED::bed_entry_get( $fh_in, $cols, $options->{ 'check' } ) )
{
- $clones = $1;
-
- $score = int( $clones / $entry->{ 'SCORE' } );
-
- map { $array[ $_ ] += $score } $entry->{ 'CHR_BEG' } .. $entry->{ 'CHR_END' } if $score >= 1;
+ if ( $record = Maasha::UCSC::BED::bed2biopiece( $bed_entry ) ) {
+ put_record( $record, $out );
+ }
}
- }
- close $fh;
-
- return wantarray ? @array : \@array;
-}
-
-
-sub tag_contigs_scan
-{
- # Martin A. Hansen, November 2008.
-
- # Scans an array with tag contigs and locates
- # the next contig from a given position. The
- # score of the tag contig is determined as the
- # maximum value of the tag contig. If a tag contig
- # is found a triple is returned with beg, end and score
- # otherwise an empty triple is returned.
-
- my ( $array, # array to scan
- $beg, # position to start scanning from
- ) = @_;
-
- # Returns an arrayref.
-
- my ( $end, $score );
-
- $score = 0;
-
- while ( $beg < scalar @{ $array } and not $array->[ $beg ] ) { $beg++ }
-
- $end = $beg;
-
- while ( $array->[ $end ] )
- {
- $score = Maasha::Calc::max( $score, $array->[ $end ] );
-
- $end++
- }
+ close $fh_in;
- if ( $score > 0 ) {
- return wantarray ? ( $beg, $end, $score ) : [ $beg, $end, $score ];
- } else {
- return wantarray ? () : [];
+ unlink $bed_file;
+ unlink $tag_file;
}
}
while ( $record = get_record( $in ) )
{
- if ( $fh_out and $entry = record2fasta( $record ) )
+ if ( $fh_out and $entry = Maasha::Fasta::biopiece2fasta( $record ) )
{
Maasha::Fasta::put_entry( $entry, $fh_out, $options->{ "wrap" } );
}
# Returns nothing.
- my ( $record, %fh_hash, $fh_in, $fh_out, $chr, $chr, $beg, $end, $q_id, $block, $entry, $clones, $beg_block, $max, $i );
+ my ( $bed_file, $fh_in, $fh_out, $cols, $record, $file_hash, $chr, $bed_entry, $fixedstep_file, $fixedstep_entry );
+
+ $bed_file = "$BP_TMP/calc_fixedstep.bed";
+ $fh_out = Maasha::Filesys::file_write_open( $bed_file );
+ $cols = 5; # we only need the first 5 BED columns
while ( $record = get_record( $in ) )
{
- $record->{ "CHR" } = $record->{ "S_ID" } if not defined $record->{ "CHR" };
- $record->{ "CHR_BEG" } = $record->{ "S_BEG" } if not defined $record->{ "CHR_BEG" };
- $record->{ "CHR_END" } = $record->{ "S_END" } if not defined $record->{ "CHR_END" };
-
- if ( $record->{ "CHR" } and defined $record->{ "CHR_BEG" } and $record->{ "CHR_END" } )
- {
- $fh_hash{ $record->{ "CHR" } } = Maasha::Common::write_open( "$BP_TMP/$record->{ 'CHR' }" ) if not exists $fh_hash{ $record->{ "CHR" } };
-
- $fh_out = $fh_hash{ $record->{ "CHR" } };
-
- Maasha::UCSC::bed_put_entry( $record, $fh_out, 5 );
+ if ( $bed_entry = Maasha::UCSC::BED::biopiece2bed( $record, $cols ) ) {
+ Maasha::UCSC::BED::bed_entry_put( $bed_entry, $fh_out, $cols, $options->{ 'check' } );
}
}
- map { close $_ } keys %fh_hash;
+ close $fh_out;
- foreach $chr ( sort keys %fh_hash )
- {
- #Maasha::Common::run( "bedSort", "$BP_TMP/$chr $BP_TMP/$chr" );
- Maasha::Common::run( "bed_sort", "--sort 3 --cols 5 $BP_TMP/$chr > $BP_TMP/$chr.sort" );
+ $file_hash = Maasha::UCSC::BED::bed_file_split_on_chr( $bed_file, $BP_TMP, $cols );
- rename "$BP_TMP/$chr.sort", "$BP_TMP/$chr";
+ unlink $bed_file;
- $fh_in = Maasha::Common::read_open( "$BP_TMP/$chr" );
+ foreach $chr ( sort keys %{ $file_hash } )
+ {
+ $bed_file = $file_hash->{ $chr };
+ $fixedstep_file = "$bed_file.fixedstep";
+
+ Maasha::Common::run( "bed2fixedstep", "< $bed_file > $fixedstep_file" );
- undef $block;
+ $fh_in = Maasha::Filesys::file_read_open( $fixedstep_file );
- while ( $entry = Maasha::UCSC::bed_get_entry( $fh_in, 5 ) )
+ while ( $fixedstep_entry = Maasha::UCSC::Wiggle::fixedstep_entry_get( $fh_in ) )
{
- $chr = $entry->{ 'CHR' };
- $beg = $entry->{ 'CHR_BEG' };
- $end = $entry->{ 'CHR_END' };
- $q_id = $entry->{ 'Q_ID' };
-
- if ( $options->{ "score" } ) {
- $clones = $entry->{ 'SCORE' };
- } elsif ( $q_id =~ /_(\d+)$/ ) {
- $clones = $1;
- } else {
- $clones = 1;
- }
-
- if ( $block )
- {
- if ( $beg > $max )
- {
- map { $_ = sprintf( "%.4f", Maasha::Calc::log10( $_ ) ) } @{ $block } if $options->{ "log10" };
-
- $record->{ "CHR" } = $chr;
- $record->{ "CHR_BEG" } = $beg_block;
- $record->{ "STEP" } = 1;
- $record->{ "VALS" } = join ";", @{ $block };
- $record->{ "REC_TYPE" } = "fixed_step";
-
- put_record( $record, $out );
-
- undef $block;
- }
- else
- {
- for ( $i = $beg - $beg_block; $i < ( $beg - $beg_block ) + ( $end - $beg ); $i++ ) {
- $block->[ $i ] += $clones;
- }
-
- $max = Maasha::Calc::max( $max, $end );
- }
- }
-
- if ( not $block )
- {
- $beg_block = $beg;
- $max = $end;
-
- for ( $i = 0; $i < ( $end - $beg ); $i++ ) {
- $block->[ $i ] += $clones;
- }
+ if ( $record = Maasha::UCSC::Wiggle::fixedstep2biopiece( $fixedstep_entry ) ) {
+ put_record( $record, $out );
}
}
close $fh_in;
- map { $_ = sprintf( "%.4f", Maasha::Calc::log10( $_ ) ) } @{ $block } if $options->{ "log10" };
-
- $record->{ "CHR" } = $chr;
- $record->{ "CHR_BEG" } = $beg_block;
- $record->{ "STEP" } = 1;
- $record->{ "VALS" } = join ";", @{ $block };
- $record->{ "REC_TYPE" } = "fixed_step";
-
- put_record( $record, $out );
-
- unlink "$BP_TMP/$chr";
+ unlink $bed_file;
+ unlink $fixedstep_file;
}
}
{
$align = Maasha::UCSC::maf_extract( $BP_TMP, $options->{ "genome" }, $maf_track, $record->{ "CHR" }, $record->{ "CHR_BEG" }, $record->{ "CHR_END" }, $record->{ "STRAND" } );
}
+ elsif ( $record->{ "REC_TYPE" } eq "VMATCH" )
+ {
+ $align = Maasha::UCSC::maf_extract( $BP_TMP, $options->{ "genome" }, $maf_track, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" } + 1, $record->{ "STRAND" } );
+ }
elsif ( $record->{ "REC_TYPE" } eq "PSL" )
{
$align = Maasha::UCSC::maf_extract( $BP_TMP, $options->{ "genome" }, $maf_track, $record->{ "S_ID" }, $record->{ "S_BEG" }, $record->{ "S_END" }, $record->{ "STRAND" } );
{
put_record( $record, $out ) if not $options->{ "no_stream" };
- if ( $entry = record2fasta( $record ) )
+ if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) )
{
$seq_type = Maasha::Seq::seq_guess_type( $entry->[ SEQ ] ) if not $seq_type;
$tmp_in = "$BP_TMP/blast_query.seq";
$tmp_out = "$BP_TMP/blast.result";
- $fh_out = Maasha::Common::write_open( $tmp_in );
+ $fh_out = Maasha::Filesys::file_write_open( $tmp_in );
while ( $record = get_record( $in ) )
{
- if ( $entry = record2fasta( $record ) )
+ if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) )
{
$q_type = Maasha::Seq::seq_guess_type( $entry->[ SEQ ] ) if not $q_type;
unlink $tmp_in;
- $fh_out = Maasha::Common::read_open( $tmp_out );
+ $fh_out = Maasha::Filesys::file_read_open( $tmp_out );
undef $record;
while ( $record = get_record( $in ) )
{
- if ( $entry = record2fasta( $record ) )
+ if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) )
{
$type = Maasha::Seq::seq_guess_type( $entry->[ SEQ ] ) if not $type;
Maasha::Fasta::put_entry( $entry, $fh_out, 80 );
while ( $record = get_record( $in ) )
{
- if ( $entry = record2fasta( $record ) )
+ if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) )
{
Maasha::Fasta::put_entry( $entry, $fh_out );
while ( $record = get_record( $in ) )
{
- if ( $options->{ "index_name" } and $entry = record2fasta( $record ) )
+ if ( $options->{ "index_name" } and $entry = Maasha::Fasta::biopiece2fasta( $record ) )
{
Maasha::Fasta::put_entry( $entry, $fh_tmp );
while ( $record = get_record( $in ) )
{
- if ( $entry = record2fasta( $record ) ) {
+ if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) ) {
Maasha::Fasta::put_entry( $entry, $fh, $options->{ "wrap" } );
}
# Returns nothing.
- my ( $fh, $record, $new_record );
+ my ( $cols, $fh, $record, $bed_entry, $new_record );
- $fh = write_stream( $options->{ "data_out" }, $options->{ "compress" } );
+ $cols = $options->{ 'cols' }->[ 0 ];
+
+ $fh = write_stream( $options->{ 'data_out' }, $options->{ 'compress' } );
while ( $record = get_record( $in ) )
{
- if ( $record->{ "REC_TYPE" } eq "BED" ) # ---- Hits from BED ----
- {
- Maasha::UCSC::bed_put_entry( $record, $fh, $record->{ "BED_COLS" } );
- }
- elsif ( $record->{ "REC_TYPE" } eq "PSL" and $record->{ "S_ID" } =~ /^chr/i ) # ---- Hits from BLAT (PSL) ----
- {
- $new_record->{ "CHR" } = $record->{ "S_ID" };
- $new_record->{ "CHR_BEG" } = $record->{ "S_BEG" };
- $new_record->{ "CHR_END" } = $record->{ "S_END" };
- $new_record->{ "Q_ID" } = $record->{ "Q_ID" };
- $new_record->{ "SCORE" } = $record->{ "SCORE" } || 999;
- $new_record->{ "STRAND" } = $record->{ "STRAND" };
+ $record = Maasha::UCSC::psl2record( $record ) if $record->{ 'tBaseInsert' }; # Dirty addition to allow Affy data from MySQL to be dumped
- Maasha::UCSC::bed_put_entry( $new_record, $fh, 6 );
+ if ( $bed_entry = Maasha::UCSC::BED::biopiece2bed( $record, $cols ) ) {
+ Maasha::UCSC::BED::bed_entry_put( $bed_entry, $fh, $cols, $options->{ 'check' } );
}
- elsif ( $record->{ "REC_TYPE" } eq "PATSCAN" and $record->{ "CHR" } ) # ---- Hits from patscan_seq ----
- {
- Maasha::UCSC::bed_put_entry( $record, $fh, 6 );
- }
- elsif ( $record->{ "REC_TYPE" } eq "BLAST" and $record->{ "S_ID" } =~ /^chr/i ) # ---- Hits from BLAST ----
- {
- $new_record->{ "CHR" } = $record->{ "S_ID" };
- $new_record->{ "CHR_BEG" } = $record->{ "S_BEG" };
- $new_record->{ "CHR_END" } = $record->{ "S_END" };
- $new_record->{ "Q_ID" } = $record->{ "Q_ID" };
- $new_record->{ "SCORE" } = $record->{ "SCORE" } || 999; # or use E_VAL somehow
- $new_record->{ "STRAND" } = $record->{ "STRAND" };
- Maasha::UCSC::bed_put_entry( $new_record, $fh, 6 );
- }
- elsif ( $record->{ "REC_TYPE" } eq "VMATCH" and $record->{ "S_ID" } =~ /^chr/i ) # ---- Hits from Vmatch ----
- {
- $new_record->{ "CHR" } = $record->{ "S_ID" };
- $new_record->{ "CHR_BEG" } = $record->{ "S_BEG" };
- $new_record->{ "CHR_END" } = $record->{ "S_END" };
- $new_record->{ "Q_ID" } = $record->{ "Q_ID" };
- $new_record->{ "SCORE" } = $record->{ "SCORE" } || 999; # or use E_VAL somehow
- $new_record->{ "STRAND" } = $record->{ "STRAND" };
-
- Maasha::UCSC::bed_put_entry( $new_record, $fh, 6 );
- }
- elsif ( $record->{ "REC_TYPE" } eq "SOAP" and $record->{ "S_ID" } =~ /^chr/i ) # ---- Hits from Vmatch ----
- {
- $new_record->{ "CHR" } = $record->{ "S_ID" };
- $new_record->{ "CHR_BEG" } = $record->{ "S_BEG" };
- $new_record->{ "CHR_END" } = $record->{ "S_END" };
- $new_record->{ "Q_ID" } = $record->{ "Q_ID" };
- $new_record->{ "SCORE" } = $record->{ "SCORE" } || 999;
- $new_record->{ "STRAND" } = $record->{ "STRAND" };
-
- Maasha::UCSC::bed_put_entry( $new_record, $fh, 6 );
- }
- elsif ( $record->{ "CHR" } and defined $record->{ "CHR_BEG" } and $record->{ "CHR_END" } ) # ---- Generic data from tables ----
- {
- Maasha::UCSC::bed_put_entry( $record, $fh );
- }
-
- put_record( $record, $out ) if not $options->{ "no_stream" };
+ put_record( $record, $out ) if not $options->{ 'no_stream' };
}
close $fh;
# Returns nothing.
- my ( $fh, $record, $vals );
+ my ( $fh, $record, $entry );
$fh = write_stream( $options->{ "data_out" }, $options->{ "compress" } );
while ( $record = get_record( $in ) )
{
- if ( $record->{ "CHR" } and $record->{ "CHR_BEG" } and $record->{ "STEP" } and $record->{ "VALS" } )
- {
- print $fh "fixedStep chrom=$record->{ 'CHR' } start=$record->{ 'CHR_BEG' } step=$record->{ 'STEP' }\n";
-
- $vals = $record->{ 'VALS' };
-
- $vals =~ tr/;/\n/;
-
- print $fh "$vals\n";
+ if ( $entry = Maasha::UCSC::Wiggle::biopiece2fixedstep( $record ) ) {
+ Maasha::UCSC::Wiggle::fixedstep_entry_put( $entry, $fh );
}
put_record( $record, $out ) if not $options->{ "no_stream" };
while ( $record = get_record( $in ) )
{
- if ( $entry = record2fasta( $record ) ) {
+ if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) ) {
Maasha::Fasta::put_entry( $entry, $fh_tmp );
}
while ( $record = get_record( $in ) )
{
- if ( $entry = record2fasta( $record ) )
+ if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) )
{
$entry->[ SEQ ] = Maasha::Solid::seq2color_space( uc $entry->[ SEQ ] );
while ( $record = get_record( $in ) )
{
- Maasha::UCSC::ucsc_config_put_entry( $record, $fh ) if $record->{ "REC_TYPE" } eq "UCSC Config";
+ Maasha::UCSC::ucsc_config_entry_put( $record, $fh ) if $record->{ "REC_TYPE" } eq "UCSC Config";
put_record( $record, $out ) if not $options->{ "no_stream" };
}
$options->{ "user" } ||= Maasha::UCSC::ucsc_get_user();
$options->{ "password" } ||= Maasha::UCSC::ucsc_get_password();
+ map { $table_hash{ $_ } = 1 } @{ $options->{ 'tables' } };
+
while ( $record = get_record( $in ) )
{
map { $table_hash{ $record->{ $_ } } = 1 } @{ $options->{ 'keys' } };
}
+sub script_remove_ucsc_tracks
+{
+ # Martin A. Hansen, November 2008.
+
+ # Remove track from MySQL tables and config file.
+
+ my ( $in, # handle to in stream
+ $out, # handle to out stream
+ $options, # options hash
+ ) = @_;
+
+ # Returns nothing.
+
+ my ( $record, %track_hash, $fh_in, $fh_out, $track, @tracks, @new_tracks, $dbh );
+
+ $options->{ 'user' } ||= Maasha::UCSC::ucsc_get_user();
+ $options->{ 'password' } ||= Maasha::UCSC::ucsc_get_password();
+ $options->{ 'config_file' } ||= "$ENV{ 'HOME' }/ucsc/my_tracks.ra";
+
+ map { $track_hash{ $_ } = 1 } @{ $options->{ 'tracks' } };
+
+ while ( $record = get_record( $in ) )
+ {
+ map { $track_hash{ $record->{ $_ } } = 1 } @{ $options->{ 'keys' } };
+
+ put_record( $record, $out ) if not $options->{ 'no_stream' };
+ }
+
+ # ---- locate track in config file ----
+
+ $fh_in = Maasha::Common::read_open( $options->{ 'config_file' } );
+
+ while ( $track = Maasha::UCSC::ucsc_config_entry_get( $fh_in ) ) {
+ push @tracks, $track;
+ }
+
+ close $fh_in;
+
+ map { push @new_tracks, $_ if not exists $track_hash{ $_->{ 'track' } } } @tracks;
+
+ print STDERR qq(WARNING: track not found in config file: "$options->{ 'config_file' }"\n) if scalar @tracks == scalar @new_tracks;
+
+ rename "$options->{ 'config_file' }", "$options->{ 'config_file' }~";
+
+ $fh_out = Maasha::Common::write_open( $options->{ 'config_file' } );
+
+ map { Maasha::UCSC::ucsc_config_entry_put( $_, $fh_out ) } @new_tracks;
+
+ close $fh_out;
+
+ # ---- locate track in database ----
+
+ $dbh = Maasha::SQL::connect( $options->{ "database" }, $options->{ "user" }, $options->{ "password" } );
+
+ foreach $track ( sort keys %track_hash )
+ {
+ if ( Maasha::SQL::table_exists( $dbh, $track ) )
+ {
+ print STDERR qq(Removing table "$track" from database "$options->{ 'database' }" ... ) if $options->{ 'verbose' };
+ Maasha::SQL::delete_table( $dbh, $track );
+ print STDERR "done.\n" if $options->{ 'verbose' };
+ }
+ else
+ {
+ print STDERR qq(WARNING: table "$track" not found in database "$options->{ 'database' }\n");
+ }
+ }
+
+ Maasha::SQL::disconnect( $dbh );
+
+ Maasha::Common::run( "ucscMakeTracks.pl", "-b > /dev/null 2>&1" );
+}
+
+
sub script_rename_keys
{
# Martin A. Hansen, August 2007.
{
if ( $options->{ "eval" } )
{
- if ( $options->{ "eval" } =~ /^(.+)\s*=\s*(.+)$/ )
+ if ( $options->{ "eval" } =~ /^(\S+)\s*=\s*(.+)$/ )
{
$eval_key = $1;
$eval_val = $2;
map { $eval_val =~ s/\Q$_\E/$record->{ $_ }/g } @keys;
- $record->{ $eval_key } = eval "$eval_val" or Maasha::Common::error( "eval failed -> $@" );
+ $record->{ $eval_key } = eval "$eval_val";
+ Maasha::Common::error( qq(eval "$eval_key = $eval_val" failed -> $@) ) if $@;
}
else
{
- warn qq(WARNING: Bad compute expression: "$options->{ 'eval' }"\n);
+ Maasha::Common::error( qq(Bad compute expression: "$options->{ 'eval' }"\n) );
}
}
# Returns nothing.
- my ( $record, $file, $wib_file, $wig_file, $wib_dir, $fh_out, $i, $first, $format, $type, $columns, $append, $vals );
+ 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->{ "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";
-
+ $file = "$BP_TMP/ucsc_upload.tmp";
$append = 0;
-
- $first = 1;
-
- $i = 0;
+ $first = 1;
+ $i = 0;
$fh_out = Maasha::Common::write_open( $file );
if ( $record->{ "REC_TYPE" } eq "fixed_step" )
{
- $vals = $record->{ "VALS" };
- $vals =~ tr/;/\n/;
-
- print $fh_out "fixedStep chrom=$record->{ 'CHR' } start=$record->{ 'CHR_BEG' } step=$record->{ 'STEP' }\n";
- print $fh_out "$vals\n";
+ $format = "WIGGLE";
- $format = "WIGGLE" if not $format;
+ 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;
-
- $format = "PSL" if not $format;
}
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->{ "SEC_STRUCT" },
$record->{ "CONF" },
), "\n";
-
- $format = "BED_SS" if not $format;
}
elsif ( $record->{ "REC_TYPE" } eq "BED" )
{
- Maasha::UCSC::bed_put_entry( $record, $fh_out, $record->{ "BED_COLS" } );
+ $format = "BED";
+ $columns = $record->{ "BED_COLS" };
- $format = "BED" if not $format;
- $columns = $record->{ "BED_COLS" } if not $columns;
+ 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" } )
{
- Maasha::UCSC::bed_put_entry( $record, $fh_out, 6 );
+ $format = "BED";
+ $columns = 6;
- $format = "BED" if not $format;
- $columns = 6 if not $columns;
+ 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/ )
{
- $record->{ "CHR" } = $record->{ "S_ID" };
- $record->{ "CHR_BEG" } = $record->{ "S_BEG" };
- $record->{ "CHR_END" } = $record->{ "S_END" };
- $record->{ "SCORE" } = $record->{ "BIT_SCORE" } * 1000;
+ $format = "BED";
+ $columns = 6;
- $format = "BED" if not $format;
- $columns = 6 if not $columns;
+ $record->{ "SCORE" } = $record->{ "BIT_SCORE" } * 1000;
- Maasha::UCSC::bed_put_entry( $record, $fh_out );
+ 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 )
{
- $record->{ "CHR" } = $record->{ "S_ID" };
- $record->{ "CHR_BEG" } = $record->{ "S_BEG" };
- $record->{ "CHR_END" } = $record->{ "S_END" };
- $record->{ "SCORE" } = $record->{ "SCORE" } || 999;
- $record->{ "SCORE" } = int( $record->{ "SCORE" } );
+ $format = "BED";
+ $columns = 6;
- $format = "BED" if not $format;
- $columns = 6 if not $columns;
-
- Maasha::UCSC::bed_put_entry( $record, $fh_out, 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" } )
}
elsif ( $format eq "BED_SS" )
{
- $options->{ "sec_struct" } = 1;
-
- $type = "sec_struct";
+ $type = "type bed 6 +";
Maasha::UCSC::bed_upload_to_ucsc( $BP_TMP, $file, $options, $append );
}
unlink $file;
- Maasha::UCSC::update_my_tracks( $options, $type );
+ Maasha::UCSC::ucsc_update_config( $options, $type );
}
}
}
-sub record2fasta
-{
- # Martin A. Hansen, July 2008.
-
- # Given a biopiece record converts it to a FASTA record.
- # If no generic SEQ or SEQ_NAME is found, the Q_* and S_* are
- # tried in that order.
-
- my ( $record, # record
- ) = @_;
-
- # Returns a tuple.
-
- my ( $seq_name, $seq );
-
- $seq_name = $record->{ "SEQ_NAME" } || $record->{ "Q_ID" } || $record->{ "S_ID" };
- $seq = $record->{ "SEQ" } || $record->{ "Q_SEQ" } || $record->{ "S_SEQ" };
-
- if ( defined $seq_name and defined $seq ) {
- return wantarray ? ( $seq_name, $seq ) : [ $seq_name, $seq ];
- } else {
- return;
- }
-}
-
-
sub read_stream
{
# Martin A. Hansen, July 2007.