From 938cb1789f95387efc8f3293deba1240e1b2d273 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Tue, 15 Dec 2009 10:43:43 +0000 Subject: [PATCH] fixed upload pipe git-svn-id: http://biopieces.googlecode.com/svn/trunk@814 74ccb610-7750-0410-82ae-013aeee3265d --- bp_bin/BGB_intersect | 4 ++-- bp_bin/BGB_upload | 29 ++++++++------------------ code_perl/Maasha/BGB/Common.pm | 37 ++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 23 deletions(-) diff --git a/bp_bin/BGB_intersect b/bp_bin/BGB_intersect index 54a9822..7561872 100755 --- a/bp_bin/BGB_intersect +++ b/bp_bin/BGB_intersect @@ -39,11 +39,11 @@ use Maasha::KISS; my ( $user, $options, $in, $out, $record, @contigs, $contig, $track, @tracks, %hash, $fh1, $fh2, @records ); -$user = Maasha::Biopieces::biopiecesrc( "BPB_USER" ); +$user = Maasha::Biopieces::biopiecesrc( "BGB_USER" ); $options = Maasha::Biopieces::parse_options( [ - { long => 'user', short => 'u', type => 'string', mandatory => 'yes', default => $user, 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 }, diff --git a/bp_bin/BGB_upload b/bp_bin/BGB_upload index 916ffa8..611f604 100755 --- a/bp_bin/BGB_upload +++ b/bp_bin/BGB_upload @@ -33,6 +33,7 @@ use Maasha::Common; use Maasha::KISS; use Maasha::Biopieces; use Maasha::Fasta; +use Maasha::BGB::Common; use Maasha::Filesys; use constant { @@ -44,10 +45,10 @@ use constant { # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -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 ); -$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( [ @@ -68,7 +69,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; @@ -92,6 +93,9 @@ if ( $options->{ 'track_name' } ) Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" }; } + $num = Maasha::BGB::Common::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,23 +103,6 @@ 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 ); diff --git a/code_perl/Maasha/BGB/Common.pm b/code_perl/Maasha/BGB/Common.pm index aa5842c..018380d 100644 --- a/code_perl/Maasha/BGB/Common.pm +++ b/code_perl/Maasha/BGB/Common.pm @@ -349,6 +349,43 @@ sub list_tracks return wantarray ? @tracks : \@tracks; } + + +sub max_track +{ + # Martin A. Hansen, December 2009. + + # Traverses all contigs for a given user->clade->genome->assembly and + # returns the maximum track's prefix value eg. 20 for 20_Genbank. + + my ( $user, + $clade, + $genome, + $assembly + ) = @_; + + # Returns an integer + + my ( @contigs, $contig, @tracks, $max ); + + @contigs = list_contigs( $user, $clade, $genome, $assembly ); + + foreach $contig ( @contigs ) { + push @tracks, list_tracks( $user, $clade, $genome, $assembly, $contig ); + } + + @tracks = sort @tracks; + + if ( scalar @tracks > 0 and $tracks[ -1 ] =~ /^(\d+)/ ) { + $max = $1; + } else { + $max = 0; + } + + return $max; +} + + # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -- 2.39.5