From: martinahansen Date: Mon, 14 Dec 2009 14:09:23 +0000 (+0000) Subject: renamed upload_to_bbrowser to BGB_upload X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=5e668575c47fbb345c6376a3834f682fdaa18a05;p=biopieces.git renamed upload_to_bbrowser to BGB_upload git-svn-id: http://biopieces.googlecode.com/svn/trunk@808 74ccb610-7750-0410-82ae-013aeee3265d --- diff --git a/bp_bin/BGB_upload b/bp_bin/BGB_upload new file mode 100755 index 0000000..916ffa8 --- /dev/null +++ b/bp_bin/BGB_upload @@ -0,0 +1,182 @@ +#!/usr/bin/env perl + +# Copyright (C) 2007-2009 Martin A. Hansen. + +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# http://www.gnu.org/copyleft/gpl.html + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +# Write Biopiece records to the KISS Genome browser. + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +use warnings; +use strict; +use Data::Dumper; +use Maasha::Common; +use Maasha::KISS; +use Maasha::Biopieces; +use Maasha::Fasta; +use Maasha::Filesys; + +use constant { + SEQ_NAME => 0, + SEQ => 1, +}; + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +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 ); + +$data_dir = Maasha::Biopieces::biopiecesrc( "KISS_DATA_DIR" ); +$user = Maasha::Biopieces::biopiecesrc( "KISS_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 }, + ] +); + +$in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } ); +$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } ); + +if ( $options->{ 'track_name' } ) +{ + $options->{ 'track_name' } =~ tr/ /_/; + + $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; + + $tmp_dir = Maasha::Biopieces::get_tmpdir(); + + while ( $record = Maasha::Biopieces::get_record( $in ) ) + { + if ( $entry = Maasha::KISS::biopiece2kiss( $record ) ) + { + $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' }" ); + } + + $fh_out = $fh_hash{ $entry->{ 'S_ID' } }; + + Maasha::KISS::kiss_entry_put( $entry, $fh_out ); + } + + Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" }; + } + + foreach $key ( keys %fh_hash ) + { + close $fh_hash{ $key }; + + $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" ); + + Maasha::KISS::kiss_sort( "$dst_dir/track_data.kiss" ); + Maasha::KISS::kiss_index( "$dst_dir/track_data.kiss" ); + + unlink "$tmp_dir/$key"; + } +} +else +{ + $path = join "/", $data_dir, "Users/", $options->{ 'user' }, $options->{ 'clade' }; + + 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( "$dst_dir/$options->{ 'assembly' }" ); + + while ( $record = Maasha::Biopieces::get_record( $in ) ) + { + if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) ) + { + $entry->[ SEQ_NAME ] = ( split " ", $entry->[ SEQ_NAME ] )[ 0 ]; + + if ( $options->{ 'force' } ) { + Maasha::Filesys::dir_remove( "$dst_dir/$entry->[ SEQ_NAME ]" ); + } + + $contig_dir = Maasha::Filesys::dir_create( "$dst_dir/$entry->[ SEQ_NAME ]" ); + $contig_dir = Maasha::Filesys::dir_create( "$contig_dir/Sequence" ); + + $fh_out = Maasha::Filesys::file_write_open( "$contig_dir/sequence.txt" ); + print $fh_out $entry->[ SEQ ]; + close $fh_out; + } + } +} + +Maasha::Biopieces::close_stream( $in ); +Maasha::Biopieces::close_stream( $out ); + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +BEGIN +{ + Maasha::Biopieces::status_set(); +} + + +END +{ + Maasha::Biopieces::status_log(); +} + + +# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +__END__ diff --git a/bp_bin/upload_to_bbrowser b/bp_bin/upload_to_bbrowser deleted file mode 100755 index 916ffa8..0000000 --- a/bp_bin/upload_to_bbrowser +++ /dev/null @@ -1,182 +0,0 @@ -#!/usr/bin/env perl - -# Copyright (C) 2007-2009 Martin A. Hansen. - -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -# http://www.gnu.org/copyleft/gpl.html - - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DESCRIPTION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - -# Write Biopiece records to the KISS Genome browser. - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - -use warnings; -use strict; -use Data::Dumper; -use Maasha::Common; -use Maasha::KISS; -use Maasha::Biopieces; -use Maasha::Fasta; -use Maasha::Filesys; - -use constant { - SEQ_NAME => 0, - SEQ => 1, -}; - - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - -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 ); - -$data_dir = Maasha::Biopieces::biopiecesrc( "KISS_DATA_DIR" ); -$user = Maasha::Biopieces::biopiecesrc( "KISS_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 }, - ] -); - -$in = Maasha::Biopieces::read_stream( $options->{ "stream_in" } ); -$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } ); - -if ( $options->{ 'track_name' } ) -{ - $options->{ 'track_name' } =~ tr/ /_/; - - $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; - - $tmp_dir = Maasha::Biopieces::get_tmpdir(); - - while ( $record = Maasha::Biopieces::get_record( $in ) ) - { - if ( $entry = Maasha::KISS::biopiece2kiss( $record ) ) - { - $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' }" ); - } - - $fh_out = $fh_hash{ $entry->{ 'S_ID' } }; - - Maasha::KISS::kiss_entry_put( $entry, $fh_out ); - } - - Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" }; - } - - foreach $key ( keys %fh_hash ) - { - close $fh_hash{ $key }; - - $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" ); - - Maasha::KISS::kiss_sort( "$dst_dir/track_data.kiss" ); - Maasha::KISS::kiss_index( "$dst_dir/track_data.kiss" ); - - unlink "$tmp_dir/$key"; - } -} -else -{ - $path = join "/", $data_dir, "Users/", $options->{ 'user' }, $options->{ 'clade' }; - - 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( "$dst_dir/$options->{ 'assembly' }" ); - - while ( $record = Maasha::Biopieces::get_record( $in ) ) - { - if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) ) - { - $entry->[ SEQ_NAME ] = ( split " ", $entry->[ SEQ_NAME ] )[ 0 ]; - - if ( $options->{ 'force' } ) { - Maasha::Filesys::dir_remove( "$dst_dir/$entry->[ SEQ_NAME ]" ); - } - - $contig_dir = Maasha::Filesys::dir_create( "$dst_dir/$entry->[ SEQ_NAME ]" ); - $contig_dir = Maasha::Filesys::dir_create( "$contig_dir/Sequence" ); - - $fh_out = Maasha::Filesys::file_write_open( "$contig_dir/sequence.txt" ); - print $fh_out $entry->[ SEQ ]; - close $fh_out; - } - } -} - -Maasha::Biopieces::close_stream( $in ); -Maasha::Biopieces::close_stream( $out ); - - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - -BEGIN -{ - Maasha::Biopieces::status_set(); -} - - -END -{ - Maasha::Biopieces::status_log(); -} - - -# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< - - -__END__