X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bp_bin%2FBGB_upload;h=0d5415cc74632cc751b97d138d4359e99234d247;hb=48bea5c28b89dc5586d0bddb338ccd6ba23aa1f9;hp=916ffa803bd540c2847e2506292b89a68c19aadc;hpb=5e668575c47fbb345c6376a3834f682fdaa18a05;p=biopieces.git diff --git a/bp_bin/BGB_upload b/bp_bin/BGB_upload index 916ffa8..0d5415c 100755 --- a/bp_bin/BGB_upload +++ b/bp_bin/BGB_upload @@ -21,7 +21,7 @@ # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -# Write Biopiece records to the KISS Genome browser. +# Write Biopiece records to the Biopieces Genome browser. # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @@ -33,31 +33,36 @@ use Maasha::Common; use Maasha::KISS; use Maasha::Biopieces; use Maasha::Fasta; +use Maasha::BGB::Track; +use Maasha::BGB::Wiggle; use Maasha::Filesys; use constant { SEQ_NAME => 0, SEQ => 1, + + S_ID => 0, }; # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -my ( $data_dir, $user, $options, $path, $in, $out, $tmp_dir, %fh_hash, $fh_out, $record, $entry, $key, @dirs, $dir, $dst_dir, @nums, $num, $contig_dir ); +my ( $data_dir, $user, $options, $path, $in, $out, $tmp_dir, %fh_hash, $fh_out, $record, $entry, $key, $dst_dir, @nums, $num, $contig_dir, $wig ); -$data_dir = Maasha::Biopieces::biopiecesrc( "KISS_DATA_DIR" ); -$user = Maasha::Biopieces::biopiecesrc( "KISS_USER" ); +$data_dir = Maasha::Biopieces::biopiecesrc( "BGB_DATA_DIR" ); +$user = Maasha::Biopieces::biopiecesrc( "BGB_USER" ); $options = Maasha::Biopieces::parse_options( [ - { long => 'user', short => 'u', type => 'string', mandatory => 'no', default => $user, allowed => undef, disallowed => undef }, - { long => 'clade', short => 'c', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, - { long => 'genome', short => 'g', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, - { long => 'assembly', short => 'a', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, - { long => 'track_name', short => 't', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, - { long => 'force', short => 'f', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, - { long => 'no_stream', short => 'x', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'user', short => 'u', type => 'string', mandatory => 'no', default => $user, allowed => undef, disallowed => undef }, + { long => 'clade', short => 'c', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, + { long => 'genome', short => 'g', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, + { long => 'assembly', short => 'a', type => 'string', mandatory => 'yes', default => undef, allowed => undef, disallowed => undef }, + { long => 'track_name', short => 't', type => 'string', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'track_type', short => 'T', type => 'string', mandatory => 'no', default => 'linear', allowed => 'linear,wiggle', disallowed => undef }, + { long => 'force', short => 'f', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, + { long => 'no_stream', short => 'x', type => 'flag', mandatory => 'no', default => undef, allowed => undef, disallowed => undef }, ] ); @@ -68,7 +73,7 @@ if ( $options->{ 'track_name' } ) { $options->{ 'track_name' } =~ tr/ /_/; - $path = join "/", $data_dir, "Users/", $options->{ 'user' }, $options->{ 'clade' }, $options->{ 'genome' }, $options->{ 'assembly' }; + $path = join "/", $data_dir, "Users", $options->{ 'user' }, $options->{ 'clade' }, $options->{ 'genome' }, $options->{ 'assembly' }; Maasha::Common::error( qq(Path not found: "$path") ) if not -d $path; @@ -78,13 +83,13 @@ if ( $options->{ 'track_name' } ) { if ( $entry = Maasha::KISS::biopiece2kiss( $record ) ) { - $entry->{ 'S_ID' } = ( split / /, $entry->{ 'S_ID' } )[ 0 ]; + $entry->[ S_ID ] = ( split / /, $entry->[ S_ID ] )[ 0 ]; - if ( not exists $fh_hash{ $entry->{ 'S_ID' } } ) { - $fh_hash{ $entry->{ 'S_ID' } } = Maasha::Filesys::file_write_open( "$tmp_dir/$entry->{ 'S_ID' }" ); + if ( not exists $fh_hash{ $entry->[ S_ID ] } ) { + $fh_hash{ $entry->[ S_ID ] } = Maasha::Filesys::file_write_open( "$tmp_dir/$entry->[ S_ID ]" ); } - $fh_out = $fh_hash{ $entry->{ 'S_ID' } }; + $fh_out = $fh_hash{ $entry->[ S_ID ] }; Maasha::KISS::kiss_entry_put( $entry, $fh_out ); } @@ -92,6 +97,9 @@ if ( $options->{ 'track_name' } ) Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" }; } + $num = Maasha::BGB::Track::max_track( $options->{ 'user' }, $options->{ 'clade' }, $options->{ 'genome' }, $options->{ 'assembly' } ); + $num = sprintf( "%04d", $num + 10 ); + foreach $key ( keys %fh_hash ) { close $fh_hash{ $key }; @@ -99,31 +107,21 @@ if ( $options->{ 'track_name' } ) $dst_dir = Maasha::Filesys::dir_create_if_not_exists( "$path/$key" ); $dst_dir = Maasha::Filesys::dir_create_if_not_exists( "$dst_dir/Tracks" ); - @dirs = Maasha::Filesys::ls_dirs( $dst_dir ); - - foreach $dir ( @dirs ) - { - $dir = ( split "/", $dir )[ -1 ]; - - if ( $dir =~ /^(\d+)/ ) { - push @nums, $1; - } - } - - @nums = sort { $a <=> $b } @nums; - - $num = $nums[ -1 ] || 0; - - $num += 10; - $dst_dir = "$dst_dir/$num" . "_$options->{ 'track_name' }"; Maasha::Filesys::dir_create( $dst_dir ); - Maasha::Filesys::file_copy( "$tmp_dir/$key", "$dst_dir/track_data.kiss" ); + if ( $options->{ 'track_type' } eq 'linear' ) + { + Maasha::Filesys::file_copy( "$tmp_dir/$key", "$dst_dir/track_data.kiss" ); - Maasha::KISS::kiss_sort( "$dst_dir/track_data.kiss" ); - Maasha::KISS::kiss_index( "$dst_dir/track_data.kiss" ); + Maasha::KISS::kiss_sort( "$dst_dir/track_data.kiss" ); + } + elsif ( $options->{ 'track_type' } eq 'wiggle' ) + { + $wig = Maasha::BGB::Wiggle::wiggle_encode( "$tmp_dir/$key" ); + Maasha::BGB::Wiggle::wiggle_store( "$dst_dir/track_data.wig", $wig ); + } unlink "$tmp_dir/$key"; } @@ -134,7 +132,7 @@ else Maasha::Common::error( qq(Path not found: "$path") ) if not -d $path; - $dst_dir = Maasha::Filesys::dir_create( "$path/$options->{ 'genome' }" ); + $dst_dir = Maasha::Filesys::dir_create_if_not_exists( "$path/$options->{ 'genome' }" ); $dst_dir = Maasha::Filesys::dir_create( "$dst_dir/$options->{ 'assembly' }" ); while ( $record = Maasha::Biopieces::get_record( $in ) )