X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bp_bin%2Fassemble_tag_contigs;h=2a8c04378ac3dd5d7819d69d0ffe586f7507cc84;hb=48bea5c28b89dc5586d0bddb338ccd6ba23aa1f9;hp=9236586f351b7ad6bc999a1ce25fc5de95c5611e;hpb=66938be910a5642b50ddf28991649858b5c36580;p=biopieces.git diff --git a/bp_bin/assemble_tag_contigs b/bp_bin/assemble_tag_contigs index 9236586..2a8c043 100755 --- a/bp_bin/assemble_tag_contigs +++ b/bp_bin/assemble_tag_contigs @@ -1,4 +1,4 @@ -#!/usr/bin/env perl -w +#!/usr/bin/env perl # Copyright (C) 2007-2009 Martin A. Hansen. @@ -26,17 +26,32 @@ # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +use warnings; use strict; use Maasha::Biopieces; use Maasha::Filesys; use Maasha::UCSC::BED; +use constant { + chrom => 0, # BED field names + chromStart => 1, + chromEnd => 2, + name => 3, + score => 4, + strand => 5, + thickStart => 6, + thickEnd => 7, + itemRgb => 8, + blockCount => 9, + blockSizes => 10, + blockStarts => 11, +}; + # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -my ( $options, $in, $out, $tmp_dir, $bed_file, $tag_file, $fh_in, $fh_out, - $cols, $record, $bed_entry, $file_hash, $chr, $strand ); +my ( $options, $in, $out, $tmp_dir, $fh_in, $fh_out, $cols, $record, $bed_entry, %fh_hash, %file_hash, $file, $strand, $id, $tag_file, $bed_file ); $options = Maasha::Biopieces::parse_options( [ @@ -47,42 +62,53 @@ $options = Maasha::Biopieces::parse_options( $in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } ); $out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } ); +`cd "$ENV{ BP_C }/Maasha/src" && make`; # FIXME OMG this is crufty! + $tmp_dir = Maasha::Biopieces::get_tmpdir(); -$bed_file = "$tmp_dir/assemble_tag_contigs.bed"; -$fh_out = Maasha::Filesys::file_write_open( $bed_file ); -$cols = 6; # we only need the first 6 BED columns +$cols = 6; # we only need the first 6 BED columns while ( $record = Maasha::Biopieces::get_record( $in ) ) { if ( $bed_entry = Maasha::UCSC::BED::biopiece2bed( $record, $cols ) ) { - $strand = $record->{ 'STRAND' } || '+'; + if ( not exists $fh_hash{ $bed_entry->[ chrom ] . $bed_entry->[ strand ] } ) + { + $file = "$tmp_dir/$bed_entry->[ chrom ]$bed_entry->[ strand ]"; + + $file_hash{ $bed_entry->[ chrom ] . $bed_entry->[ strand ] } = $file; + $fh_hash{ $bed_entry->[ chrom ] . $bed_entry->[ strand ] } = Maasha::Filesys::file_write_open( $file ); + } + + $fh_out = $fh_hash{ $bed_entry->[ chrom ] . $bed_entry->[ strand ] }; Maasha::UCSC::BED::bed_entry_put( $bed_entry, $fh_out, $cols, $options->{ 'check' } ); } } -close $fh_out; - -$file_hash = Maasha::UCSC::BED::bed_file_split_on_chr( $bed_file, $tmp_dir, $cols ); +$id = 0; -unlink $bed_file; - -foreach $chr ( sort keys %{ $file_hash } ) +foreach $file ( sort keys %file_hash ) { - $bed_file = $file_hash->{ $chr }; + $bed_file = $file_hash{ $file }; $tag_file = "$bed_file.tc"; + $strand = substr $file, -1, 1; + Maasha::Common::run( "bed2tag_contigs", "< $bed_file > $tag_file" ); $fh_in = Maasha::Filesys::file_read_open( $tag_file ); while ( $bed_entry = Maasha::UCSC::BED::bed_entry_get( $fh_in, $cols, $options->{ 'check' } ) ) { + $bed_entry->[ name ] = sprintf( "TC%08d", $id ); + $bed_entry->[ strand ] = $strand; + if ( $record = Maasha::UCSC::BED::bed2biopiece( $bed_entry ) ) { Maasha::Biopieces::put_record( $record, $out ); } + + $id++; } close $fh_in; @@ -91,8 +117,6 @@ foreach $chr ( sort keys %{ $file_hash } ) unlink $tag_file; } -Maasha::Filesys::dir_remove( $tmp_dir ); - Maasha::Biopieces::close_stream( $in ); Maasha::Biopieces::close_stream( $out );