From 0411353f55e9af778a3e1390a430970fed0ce971 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Tue, 24 Nov 2009 17:20:50 +0000 Subject: [PATCH] fixed KISS git-svn-id: http://biopieces.googlecode.com/svn/trunk@768 74ccb610-7750-0410-82ae-013aeee3265d --- bp_bin/upload_to_KISS | 110 +++++++++++++++++++++------------ code_perl/Maasha/Filesys.pm | 8 ++- code_perl/Maasha/KISS/Draw.pm | 26 +------- code_perl/Maasha/KISS/Track.pm | 8 +-- www/cgi-bin/index.cgi | 16 +++-- 5 files changed, 93 insertions(+), 75 deletions(-) diff --git a/bp_bin/upload_to_KISS b/bp_bin/upload_to_KISS index 9e9f039..cbf88fe 100755 --- a/bp_bin/upload_to_KISS +++ b/bp_bin/upload_to_KISS @@ -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 ); diff --git a/code_perl/Maasha/Filesys.pm b/code_perl/Maasha/Filesys.pm index ad6259b..481cefd 100644 --- a/code_perl/Maasha/Filesys.pm +++ b/code_perl/Maasha/Filesys.pm @@ -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; } diff --git a/code_perl/Maasha/KISS/Draw.pm b/code_perl/Maasha/KISS/Draw.pm index 6a8bc52..e9ae40e 100644 --- a/code_perl/Maasha/KISS/Draw.pm +++ b/code_perl/Maasha/KISS/Draw.pm @@ -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. diff --git a/code_perl/Maasha/KISS/Track.pm b/code_perl/Maasha/KISS/Track.pm index 5972442..6e2f9c0 100644 --- a/code_perl/Maasha/KISS/Track.pm +++ b/code_perl/Maasha/KISS/Track.pm @@ -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, diff --git a/www/cgi-bin/index.cgi b/www/cgi-bin/index.cgi index e4420e8..3a34fd9 100755 --- a/www/cgi-bin/index.cgi +++ b/www/cgi-bin/index.cgi @@ -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", -- 2.39.5