]> git.donarmstrong.com Git - biopieces.git/blobdiff - www/index.cgi
fixed seq qual length check
[biopieces.git] / www / index.cgi
index 85fed675115605e54c0fb8079670cc938fd8bfaf..64314fa6520ff70122f3b54af9e6c473c8ee0665 100755 (executable)
@@ -29,6 +29,7 @@ use CGI;
 use URI::Escape;
 use Data::Dumper;
 use Digest::MD5;
+use Time::HiRes;
 use Maasha::Common;
 use Maasha::Filesys;
 use Maasha::Calc;
@@ -147,8 +148,8 @@ sub cookie_default
     $cookie->{ 'NAV_START' }     ||= defined $cgi->param( 'nav_start' ) ? $cgi->param( 'nav_start' ) : $session->{ 'NAV_START' };
     $cookie->{ 'NAV_END' }       ||= defined $cgi->param( 'nav_end' )   ? $cgi->param( 'nav_end' )   : $session->{ 'NAV_END' };
     $cookie->{ 'NAV_CENTER' }      = $cgi->param( 'nav_center' );
-    $cookie->{ 'S_BEG' }           = $cgi->param( 's_beg' )       || $session->{ 'S_BEG' };
-    $cookie->{ 'S_END' }           = $cgi->param( 's_end' )       || $session->{ 'S_END' };
+    $cookie->{ 'S_BEG' }           = defined $cgi->param( 's_beg' ) ? $cgi->param( 's_beg' ) : $session->{ 'S_BEG' };
+    $cookie->{ 'S_END' }           = defined $cgi->param( 's_end' ) ? $cgi->param( 's_end' ) : $session->{ 'S_END' };
     $cookie->{ 'STRAND' }          = $cgi->param( 'strand' )      || $session->{ 'STRAND' };
     $cookie->{ 'TRACK' }           = $cgi->param( 'track' );
     $cookie->{ 'ZOOM_IN1' }        = $cgi->param( 'zoom_in1' );
@@ -165,7 +166,7 @@ sub cookie_default
     $cookie->{ 'MOVE_RIGHT3' }     = $cgi->param( 'move_right3' );
 
     $cookie->{ 'IMG_WIDTH' }       = 1200;   # Width of browser image in pixels
-    $cookie->{ 'IMG_HEIGHT' }      = 800;    # Height of browser image in pixels
+    $cookie->{ 'IMG_HEIGHT' }      = 800;    # Height of browser image in pixels  # TODO: Redundant?
     $cookie->{ 'WIGGLE_HEIGHT' }   = 75;     # Height of Wiggle tracks in pixels
     $cookie->{ 'TRACK_OFFSET' }    = 20;
     $cookie->{ 'TRACK_SPACE' }     = 20;
@@ -182,9 +183,21 @@ sub cookie_default
     if ( $cookie->{ 'USER' } and not $cookie->{ 'LOGIN_ERROR' } )
     {
         $cookie->{ 'LIST_CLADE' }      = Maasha::BGB::Track::list_clades(     $cookie->{ 'USER' } );
-        $cookie->{ 'LIST_GENOME' }     = Maasha::BGB::Track::list_genomes(    $cookie->{ 'USER' }, $cookie->{ 'CLADE' } );
-        $cookie->{ 'LIST_ASSEMBLY' }   = Maasha::BGB::Track::list_assemblies( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' } );
-        $cookie->{ 'LIST_CONTIG' }     = Maasha::BGB::Track::list_contigs(    $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' }, $cookie->{ 'ASSEMBLY' } );
+
+        if ( $cookie->{ 'CLADE' } )
+        {
+            $cookie->{ 'LIST_GENOME' }     = Maasha::BGB::Track::list_genomes(    $cookie->{ 'USER' }, $cookie->{ 'CLADE' } );
+
+            if ( $cookie->{ 'GENOME' } )
+            {
+                $cookie->{ 'LIST_ASSEMBLY' }   = Maasha::BGB::Track::list_assemblies( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' } );
+
+                if ( $cookie->{ 'ASSEMBLY' } )
+                {
+                    $cookie->{ 'LIST_CONTIG' }     = Maasha::BGB::Track::list_contigs(    $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' }, $cookie->{ 'ASSEMBLY' } );
+                }
+            }
+        }
 
         if ( $cookie->{ 'CONTIG' } )
         {
@@ -247,7 +260,7 @@ sub session_store
         $new_session->{ 'TIME' }       = Maasha::Common::time_stamp();
         $new_session->{ 'PAGE' }       = $cookie->{ 'PAGE' };
 
-        if ( $cookie->{ 'PAGE' } eq 'browse' )
+        if ( $cookie->{ 'PAGE' } =~ /browse|export_pdf|export_svg/ )
         {
             $new_session->{ 'CLADE' }     = $cookie->{ 'CLADE' };
             $new_session->{ 'GENOME' }    = $cookie->{ 'GENOME' };
@@ -271,7 +284,7 @@ sub session_store
         {
             $new_session->{ 'CLADE' }     = $cookie->{ 'CLADE' };
         }
-        elsif ( $cookie->{ 'PAGE' } eq 'export' )
+        elsif ( $cookie->{ 'PAGE' } =~ /export|dna/ )
         {
             $new_session->{ 'CLADE' }     = $cookie->{ 'CLADE' };
             $new_session->{ 'GENOME' }    = $cookie->{ 'GENOME' };
@@ -586,6 +599,10 @@ sub page
         push @html, page_dna( $cookie );
     } elsif ( $cookie->{ 'PAGE' } eq 'export' ) {
         push @html, page_export( $cookie );
+    } elsif ( $cookie->{ 'PAGE' } eq 'export_pdf' ) {
+        push @html, page_export_pdf( $cookie );
+    } elsif ( $cookie->{ 'PAGE' } eq 'export_svg' ) {
+        push @html, page_export_svg( $cookie );
     } elsif ( $cookie->{ 'PAGE' } eq 'clade' ) {
         push @html, page_clade( $cookie );
     } elsif ( $cookie->{ 'PAGE' } eq 'genome' ) {
@@ -701,6 +718,46 @@ sub page_export
 }
 
 
+sub page_export_pdf
+{
+    # Martin A. Hansen, March 2010.
+
+    # Renders the export PDF page.
+
+    my ( $cookie,
+       ) = @_;
+
+    # Returns a list.
+
+    my ( @html );
+
+    push @html, section_taxonomy_table( $cookie );
+    push @html, section_export_pdf( $cookie );
+
+    return wantarray ? @html : \@html;
+}
+
+
+sub page_export_svg
+{
+    # Martin A. Hansen, March 2010.
+
+    # Renders the export SVG page.
+
+    my ( $cookie,
+       ) = @_;
+
+    # Returns a list.
+
+    my ( @html );
+
+    push @html, section_taxonomy_table( $cookie );
+    push @html, section_export_svg( $cookie );
+
+    return wantarray ? @html : \@html;
+}
+
+
 sub page_clade
 {
     # Martin A. Hansen, March 2010.
@@ -1081,9 +1138,9 @@ sub section_linkout
 
     # Returns a list.
 
-    my ( $link, @html );
+    my ( $link_out, $link_pdf, $link_svg, @html );
 
-    $link = Maasha::XHTML::ln(
+    $link_out = Maasha::XHTML::ln(
         txt  => 'link',
         href => join( "&", "$cookie->{ 'SCRIPT' }?page=browse",
                            "clade=$cookie->{ 'CLADE' }",
@@ -1096,7 +1153,37 @@ sub section_linkout
         title  => "Static link to this view",
     );
 
-    push @html, Maasha::XHTML::p( txt => $link, class => 'center' );
+    $link_pdf = Maasha::XHTML::ln(
+        txt  => 'PDF',
+        href => join( "&", "$cookie->{ 'SCRIPT' }?page=export_pdf",
+                           "session_id=$cookie->{ 'SESSION_ID' }",
+                           "user=$cookie->{ 'USER' }",
+                           "clade=$cookie->{ 'CLADE' }",
+                           "genome=$cookie->{ 'GENOME' }",
+                           "assembly=$cookie->{ 'ASSEMBLY' }",
+                           "contig=$cookie->{ 'CONTIG' }",
+                           "nav_start=$cookie->{ 'NAV_START' }",
+                           "nav_end=$cookie->{ 'NAV_END' }",
+              ),
+        title  => "Export view in PDF",
+    );
+    
+    $link_svg = Maasha::XHTML::ln(
+        txt  => 'SVG',
+        href => join( "&", "$cookie->{ 'SCRIPT' }?page=export_svg",
+                           "session_id=$cookie->{ 'SESSION_ID' }",
+                           "user=$cookie->{ 'USER' }",
+                           "clade=$cookie->{ 'CLADE' }",
+                           "genome=$cookie->{ 'GENOME' }",
+                           "assembly=$cookie->{ 'ASSEMBLY' }",
+                           "contig=$cookie->{ 'CONTIG' }",
+                           "nav_start=$cookie->{ 'NAV_START' }",
+                           "nav_end=$cookie->{ 'NAV_END' }",
+              ),
+        title  => "Export view in SVG",
+    );
+
+    push @html, Maasha::XHTML::p( txt => "$link_out $link_pdf $link_svg", class => 'center' );
 
     return wantarray ? @html : \@html;
 }
@@ -1109,7 +1196,7 @@ sub section_browse
 
     # Returns a list.
 
-    my ( @track_list, $i, @tracks, $track, $elem, $surface, $cr, $png_data, @html, @img, $x1, $y1, $x2, $y2, $factor, $center );
+    my ( @track_list, $i, @tracks, $track, $elem, $png_data, @html, @img, $x1, $y1, $x2, $y2, $factor, $center );
 
     push @tracks, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
     push @tracks, [ Maasha::BGB::Track::track_seq( $cookie ) ];
@@ -1123,18 +1210,9 @@ sub section_browse
         push @tracks, [ Maasha::BGB::Track::track_feature( $track_list[ $i ], $cookie ) ];
     }
 
-    $surface = Cairo::ImageSurface->create( 'argb32', $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
-    $cr      = Cairo::Context->create( $surface );
-
-    $cr->rectangle( 0, 0, $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
-    $cr->set_source_rgb( 1, 1, 1 );
-    $cr->fill;
-
-    foreach $track ( @tracks ) {
-        Maasha::BGB::Draw::draw_feature( $cr, $track ) if $track;
-    }
+    unshift @tracks, [ Maasha::BGB::Track::track_grid( $cookie ) ];
 
-    $png_data = Maasha::BGB::Draw::base64_png( $surface );
+    $png_data = Maasha::BGB::Draw::render_png( $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' }, \@tracks );
 
     push @img, Maasha::XHTML::img(
         src    => "data:image/png;base64,$png_data",
@@ -1180,7 +1258,7 @@ sub section_browse
     {
         foreach $elem ( @{ $track } )
         {
-            next if $elem->{ 'type' } =~ /text|wiggle/;
+            next if $elem->{ 'type' } =~ /grid|text|wiggle/;
 
             if ( $elem->{ 'type' } eq 'track_name' )
             {
@@ -1297,6 +1375,80 @@ sub section_export
 }
 
 
+sub section_export_pdf
+{
+    # Martin A. Hansen, March 2010.
+
+    # Returns a HTML section with export table.
+
+    my ( $cookie,   # cookie hash
+       ) = @_;
+
+    # Returns a list.
+
+    my ( @tracks, @track_list, $i, $file, @html );
+
+    push @tracks, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
+    push @tracks, [ Maasha::BGB::Track::track_seq( $cookie ) ];
+
+    @track_list = Maasha::BGB::Track::list_track_dir( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' }, $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' } );
+
+    for ( $i = 0; $i < @track_list; $i++ )
+    {
+        $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
+
+        push @tracks, [ Maasha::BGB::Track::track_feature( $track_list[ $i ], $cookie ) ];
+    }
+
+    unshift @tracks, [ Maasha::BGB::Track::track_grid( $cookie ) ];
+
+    $file = "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/BGB_export.pdf";
+
+    Maasha::BGB::Draw::render_pdf_file( $file, $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' }, \@tracks );
+
+    push @html, Maasha::XHTML::p( txt => Maasha::XHTML::ln( txt => "BGB_export.pdf", href => $file ), class => 'center' );
+
+    return wantarray ? @html : \@html;
+}
+
+
+sub section_export_svg
+{
+    # Martin A. Hansen, March 2010.
+
+    # Export view in SVG format.
+
+    my ( $cookie,   # cookie hash
+       ) = @_;
+
+    # Returns a list.
+
+    my ( @tracks, @track_list, $i, $file, @html );
+
+    push @tracks, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
+    push @tracks, [ Maasha::BGB::Track::track_seq( $cookie ) ];
+
+    @track_list = Maasha::BGB::Track::list_track_dir( $cookie->{ 'USER' }, $cookie->{ 'CLADE' }, $cookie->{ 'GENOME' }, $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' } );
+
+    for ( $i = 0; $i < @track_list; $i++ )
+    {
+        $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
+
+        push @tracks, [ Maasha::BGB::Track::track_feature( $track_list[ $i ], $cookie ) ];
+    }
+
+    unshift @tracks, [ Maasha::BGB::Track::track_grid( $cookie ) ];
+
+    $file = "$cookie->{ 'SESSION_DIR' }/$cookie->{ 'USER' }/BGB_export.svg";
+
+    Maasha::BGB::Draw::render_svg_file( $file, $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' }, \@tracks );
+
+    push @html, Maasha::XHTML::p( txt => Maasha::XHTML::ln( txt => "BGB_export.svg", href => $file ), class => 'center' );
+
+    return wantarray ? @html : \@html;
+}
+
+
 sub section_search
 {
     # Martin A. Hansen, November 2009.
@@ -1420,3 +1572,7 @@ sub section_dna
 
 
 __END__
+
+
+    # my $t0 = Time::HiRes::gettimeofday();
+    # my $t1 = Time::HiRes::gettimeofday(); print STDERR "Time: " . ( $t1 - $t0 ) . "\n";