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 },
use Maasha::KISS;
use Maasha::Biopieces;
use Maasha::Fasta;
+use Maasha::BGB::Common;
use Maasha::Filesys;
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(
[
{
$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;
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 };
$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 );
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;
+}
+
+
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<