using JSON object in ontology browser server side script
[sgn.git] / cgi-bin / tools / trace_view.pl
blobc8f01bffdf6a22045b4f63ad66f08fd08023bf12
1 use strict;
2 use warnings;
4 use CXGN::Page;
5 use CXGN::Chromatogram;
6 use URI::Escape;
7 use CatalystX::GlobalContext '$c';
9 my $page = CXGN::Page->new( "Chromatogram viewer", "john" );
10 my ( $file, $temp ) = $page->get_encoded_arguments( 'file', 'temp' );
11 if ($file) {
13 #do not accept files specified with /. because that might be an attempt to view some other file that they
14 #are not allowed to view
15 if ( $file =~ /\/\./ ) {
16 $page->message_page( 'Invalid file location.',
17 '', '', "Invalid file location: $file" );
20 #if it's a tempfile, look in the tempfile location
21 if ($temp) {
22 $file =~ /^[\w\-]+\.mct$/
23 or $page->message_page( 'Invalid file location.',
24 '', '', "Invalid file location: $file" )
25 ; #i made up the extension 'mct' for 'mystery chromatogram type' since we have various kinds of chromatograms and nothing recorded about their file types. --john
26 $file =
27 $c->config->{'basepath'}
28 . $c->config->{'tempfiles_subdir'}
29 . '/traceimages/'
30 . $file;
33 #otherwise it will be in data shared
34 else {
35 my $data_shared_url = $c->config->{'static_datasets_url'};
36 my $data_shared_website_path =
37 $c->config->{'static_datasets_path'};
39 #find cosii chromatogram
40 if ( $file =~ /^$data_shared_url\/cosii2?\/[\w\-\/]+\.ab1$/ ) {
41 $file =~ s/$data_shared_url/$data_shared_website_path/;
44 #or find pgn chromatogram
45 elsif ( $file =~ /trace_files/ ) {
46 $file =~
47 s/trace_files/data\/prod\/public\/pgn_data_processing\/processed_traces\//;
50 #or give up
51 else {
52 $page->message_page( 'Invalid file location.',
53 '', '', "Invalid file location: $file" );
57 my $temp_image_filename;
58 if ( $file =~ /([\w\-\.]+)\.\w+$/ ) {
59 $temp_image_filename = $1;
61 else {
62 $page->message_page( 'Invalid file location.',
63 '', '', "Invalid file location: $file" );
64 print STDERR
65 "/cgi-bin/tools/trace_view.pl: invalid file location: $file\n";
68 my $display_pngfile;
69 if ( -f ($file) ) {
70 if ( CXGN::Chromatogram::is_abi_file($file) ) {
71 $display_pngfile = CXGN::Chromatogram::create_image_file( $file,
72 "$temp_image_filename.png" );
74 else {
75 my $uncompressed_file =
76 $c->config->{'basepath'}
77 . $c->config->{'tempfiles_subdir'}
78 . "/traceimages/$temp_image_filename"
79 . "_uncompressed";
80 CXGN::Chromatogram::uncompress_if_necessary( $file,
81 $uncompressed_file );
82 if ( CXGN::Chromatogram::is_abi_file($uncompressed_file) ) {
83 $display_pngfile =
84 CXGN::Chromatogram::create_image_file( $uncompressed_file,
85 "$temp_image_filename.png" );
87 else {
88 $page->message_page(
89 'Sorry, but the viewer does not support this type of chromatogram file.'
94 else {
95 $page->message_page( 'Invalid file location.',
96 '', '', "Chromatogram file not found at $file" );
97 print STDERR
98 "/cgi-bin/tools/trace_view.pl: invalid file location: $file\n";
101 #create the page
102 $page->header("Chromatogram viewer: $temp_image_filename");
103 print
104 "<center><h4>$temp_image_filename</h4></center><img src=\"$display_pngfile\" border=\"0\">";
105 $page->footer();
107 else {
108 $page->message_page('Invalid arguments.');