]> git.donarmstrong.com Git - biopieces.git/commitdiff
fixed KISS
authormartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 24 Nov 2009 17:20:50 +0000 (17:20 +0000)
committermartinahansen <martinahansen@74ccb610-7750-0410-82ae-013aeee3265d>
Tue, 24 Nov 2009 17:20:50 +0000 (17:20 +0000)
git-svn-id: http://biopieces.googlecode.com/svn/trunk@768 74ccb610-7750-0410-82ae-013aeee3265d

bp_bin/upload_to_KISS
code_perl/Maasha/Filesys.pm
code_perl/Maasha/KISS/Draw.pm
code_perl/Maasha/KISS/Track.pm
www/cgi-bin/index.cgi

index 9e9f03904ea1cfce405e9a287df206a16d859992..cbf88fe5b77111f05d0bc0d8bb6710466a9d8390 100755 (executable)
@@ -31,13 +31,19 @@ use strict;
 use Maasha::Common;
 use Maasha::KISS::IO;
 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 );
+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" );
@@ -48,71 +54,97 @@ $options = Maasha::Biopieces::parse_options(
         { 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 => 'yes', default => undef, allowed => undef, disallowed => undef },
+        { long => 'track_name', short => 't', type => 'string', mandatory => 'no',  default => undef, allowed => undef, disallowed => undef },
         { long => 'no_stream',  short => 'x', type => 'flag',   mandatory => 'no',  default => undef, allowed => undef, disallowed => undef },
     ]   
 );
 
-$options->{ 'track_name' } =~ tr/ /_/;
+$in  = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
+$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
 
-$path = join "/", $data_dir, "Users/", $options->{ 'user' }, $options->{ 'clade' }, $options->{ 'genome' }, $options->{ 'assembly' };
+if ( $options->{ 'track_name' } )
+{
+    $options->{ 'track_name' } =~ tr/ /_/;
 
-Maasha::Common::error( qq(Path not found: "$path") ) if not -d $path;
+    $path = join "/", $data_dir, "Users/", $options->{ 'user' }, $options->{ 'clade' }, $options->{ 'genome' }, $options->{ 'assembly' };
 
-$in  = Maasha::Biopieces::read_stream( $options->{ "stream_in" } );
-$out = Maasha::Biopieces::write_stream( $options->{ "stream_out" } );
+    Maasha::Common::error( qq(Path not found: "$path") ) if not -d $path;
 
-$tmp_dir = Maasha::Biopieces::get_tmpdir();
+    $tmp_dir = Maasha::Biopieces::get_tmpdir();
 
-while ( $record = Maasha::Biopieces::get_record( $in ) ) 
-{
-    if ( $entry = Maasha::KISS::IO::biopiece2kiss( $record ) )
+    while ( $record = Maasha::Biopieces::get_record( $in ) ) 
     {
-        if ( not exists $fh_hash{ $entry->{ 'S_ID' } } ) {
-            $fh_hash{ $entry->{ 'S_ID' } } = Maasha::Filesys::file_write_open( "$tmp_dir/$entry->{ 'S_ID' }" );
-        }
+        if ( $entry = Maasha::KISS::IO::biopiece2kiss( $record ) )
+        {
+            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::IO::kiss_entry_put( $entry, $fh_out );
-    }
+            Maasha::KISS::IO::kiss_entry_put( $entry, $fh_out );
+        }
 
-    Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
-}
+        Maasha::Biopieces::put_record( $record, $out ) if not $options->{ "no_stream" };
+    }
 
-foreach $key ( keys %fh_hash )
-{
-    close $fh_hash{ $key };
+    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" );
+        $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 );
+        @dirs = Maasha::Filesys::ls_dirs( $dst_dir );
 
-    foreach $dir ( @dirs )
-    {
-        $dir = ( split "/", $dir )[ -1 ];
+        foreach $dir ( @dirs )
+        {
+            $dir = ( split "/", $dir )[ -1 ];
 
-        if ( $dir =~ /^(\d+)/ ) {
-            push @nums, $1;
+            if ( $dir =~ /^(\d+)/ ) {
+                push @nums, $1;
+            }
         }
-    }
 
-    @nums = sort { $a <=> $b } @nums;
+        @nums = sort { $a <=> $b } @nums;
+
+        $num = $nums[ -1 ] || 0;
+
+        $num += 10;
+
+        $dst_dir = "$dst_dir/$num" . "_$options->{ 'track_name' }";
 
-    $num = $nums[ -1 ] || 0;
+        Maasha::Filesys::dir_create( $dst_dir );
 
-    $num += 10;
+        Maasha::Filesys::file_copy( "$tmp_dir/$key", "$dst_dir/track_data.kiss" );
 
-    $dst_dir = "$dst_dir/$num" . "_$options->{ 'track_name' }";
+        Maasha::KISS::IO::kiss_index( "$dst_dir/track_data.kiss" );
 
-    Maasha::Filesys::dir_create( $dst_dir );
+        unlink "$tmp_dir/$key";
+    }
+}
+else
+{
+    $path = join "/", $data_dir, "Users/", $options->{ 'user' }, $options->{ 'clade' };
 
-    Maasha::Filesys::file_copy( "$tmp_dir/$key", "$dst_dir/track_data.kiss" );
+    Maasha::Common::error( qq(Path not found: "$path") ) if not -d $path;
 
-    Maasha::KISS::IO::kiss_index( "$dst_dir/track_data.kiss" );
+    $dst_dir = Maasha::Filesys::dir_create( "$path/$options->{ 'genome' }" );
+    $dst_dir = Maasha::Filesys::dir_create( "$dst_dir/$options->{ 'assembly' }" );
 
-    unlink "$tmp_dir/$key";
+    while ( $record = Maasha::Biopieces::get_record( $in ) ) 
+    {
+        if ( $entry = Maasha::Fasta::biopiece2fasta( $record ) )
+        {
+            $entry->[ SEQ_NAME ] = ( split " ", $entry->[ SEQ_NAME ] )[ 0 ];
+            $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 );
index ad6259bd988f6999b941c64fd289c267c7c6c606..481cefd55abcf146d02dab17f04a8aba0b202b26 100644 (file)
@@ -321,13 +321,15 @@ sub dir_create
     my ( $path,   # full path to dir
        ) = @_;
 
-    # Returns nothing.
+    # Returns created path.
 
     if ( -d $path ) {
         Maasha::Common::error( qq(Directory already exists "$path") );
     } else {
         mkdir $path or Maasha::Common::error( qq(Could not create directory "$path": $!) );
     }
+
+    return $path;
 }
 
 
@@ -340,11 +342,13 @@ sub dir_create_if_not_exists
     my ( $path,   # full path to dir
        ) = @_;
 
-    # Returns nothing.
+    # Returns path.
 
     if ( not -d $path ) {
         mkdir $path or Maasha::Common::error( qq(Could not create directory "$path": $!) );
     }
+
+    return $path;
 }
 
 
index 6a8bc52d977eb581b1d44b7e9692604176019b19..e9ae40e5f167995e29079d080644aa8a8f799798 100644 (file)
@@ -57,7 +57,7 @@ sub draw_feature
 
     foreach $feature ( @{ $features } )
     {
-        $cr->set_source_rgb( color_name2rgb( $feature->{ 'color' } ) );
+        $cr->set_source_rgb( @{ $feature->{ 'color' } } );
 
         if ( $feature->{ 'type' } eq 'line' )
         {
@@ -88,30 +88,6 @@ sub draw_feature
 }
 
 
-sub color_name2rgb
-{
-    my ( $color_name
-       ) = @_;
-
-    my ( %color_hash, $rgb );
-
-    %color_hash = (
-        'black' => [   0,   0,   0 ],
-        'red'   => [ 255,   0,   0 ],
-        'green' => [   0, 255,   0 ],
-        'blue'  => [   0,   0, 255 ],
-    );
-
-    if ( exists $color_hash{ $color_name } ) {
-        $rgb = $color_hash{ $color_name };
-    } else {
-        $rgb = [ 0, 0, 0 ];
-    }
-
-    return wantarray ? @{ $rgb } : $rgb;
-}
-
-
 sub file_png
 {
     # Martin A. Hansen, October 2009.
index 597244202fe7ebe512f290d946c422c1efa834d4..6e2f9c09025e0397f4422b40a44642ae2fa7bf33 100644 (file)
@@ -211,7 +211,7 @@ sub track_feature_linear
             push @features, {
                 type       => 'rect',
                 line_width => $draw_metrics->{ 'FEAT_WIDTH' },
-                color      => 'green',
+                color      => $draw_metrics->{ 'FEAT_COLOR' },
                 title      => $entry->{ 'Q_ID' },
                 x1         => $x1,
                 y1         => $y1,
@@ -270,7 +270,7 @@ sub feature_align
             push @features, {
                 type       => 'rect',
                 line_width => $feat_height,
-                color      => 'red',
+                color      => [ 1, 0, 0 ],
                 title      => $align,
                 x1         => $x1,
                 y1         => $y_offset,
@@ -283,7 +283,7 @@ sub feature_align
                 push @features, {
                     type       => 'text',
                     font_size  => $feat_height + 2,
-                    color      => 'black',
+                    color      => [ 0, 0, 0 ],
                     txt        => $nt_after,
                     x1         => $x1 + sprintf( "%.0f", ( $w / 2 ) ) - $feat_height / 2,
                     y1         => $y_offset + $feat_height,
@@ -350,7 +350,7 @@ sub track_feature_histogram
                     push @hist, {
                         type       => 'line',
                         line_width => $bucket_width,
-                        color      => 'green',
+                        color      => $draw_metrics->{ 'FEAT_COLOR' },
                         title      => "Features: $buckets[ $i ]",
                         x1         => $x,
                         y1         => $draw_metrics->{ 'TRACK_OFFSET' } + $hist_height,
index e4420e8c9399207b40cb707e7e7cd882e9ccd1b6..3a34fd9fd9bf35ff6af4b01dcb9345e409e31d17 100755 (executable)
@@ -438,7 +438,7 @@ sub sec_browse
 
     # Returns a list.
 
-    my ( $draw_metrics, @tracks, @features, $feat, $elem, $file, $surface, $cr, @html, @img );
+    my ( $draw_metrics, @tracks, $i, @features, $feat, $elem, $file, $surface, $cr, @html, @img );
 
     $draw_metrics = {
         IMG_WIDTH       => 1200,
@@ -446,10 +446,11 @@ sub sec_browse
         TRACK_OFFSET    => 20,
         TRACK_SPACE     => 20,
         RULER_FONT_SIZE => 10,
-        RULER_COLOR     => 'black',
+        RULER_COLOR     => [ 0, 0, 0 ],
         SEQ_FONT_SIZE   => 10,
-        SEQ_COLOR       => 'black',
+        SEQ_COLOR       => [ 0, 0, 0, ],
         FEAT_WIDTH      => 5,
+        FEAT_COLOR      => [ 0, 1, 0 ],
     };
     
     push @features, [ Maasha::KISS::Track::track_ruler( $draw_metrics, $cookie ) ];
@@ -457,7 +458,12 @@ sub sec_browse
 
     @tracks = Maasha::KISS::Track::path_tracks( $cookie );
 
-    map { push @features, [ Maasha::KISS::Track::track_feature( $_, $draw_metrics, $cookie ) ] } @tracks;
+    for ( $i = 0; $i < @tracks; $i++ )
+    {
+        push @features, [ Maasha::KISS::Track::track_feature( $tracks[ $i ], $draw_metrics, $cookie ) ];
+
+        $draw_metrics->{ 'FEAT_COLOR' } = [ 0, 0, 1 ];
+    }
 
     $file = "fisk.png";
 
@@ -485,7 +491,7 @@ sub sec_browse
     {
         foreach $elem ( @{ $feat } )
         {
-            next if not $elem->{ 'type' } eq 'line';
+            next if $elem->{ 'type' } eq 'text';
 
             push @img, Maasha::XHTML::area(
                 href   => "www.dmi.dk",