5 use CXGN
::Genomic
::Chromat
;
6 use CXGN
::DB
::Connection
;
7 use CatalystX
::GlobalContext
'$c';
11 # New download script for chromatogram access.
13 our $page = CXGN
::Page
->new( "Trace Download", "Koni");
15 my $dbh = CXGN
::DB
::Connection
->new();
17 #read_id is for a chromat from sgn.seqread
18 #chromat_id is for a chromat from genomic.chromat
19 my ($read_id,$chromat_id) = $page->get_arguments(qw
/read_id chrid/);
21 unless ((defined($read_id) && $read_id =~ m/^[0-9]+$/)
22 || (defined($chromat_id) && $chromat_id =~ m/^[0-9]+$/)) {
23 $page->message_page("Invalid: '$chromat_id', '$read_id'.\n");
24 # invalid_search($page);
27 my ($tablename,$idcol);
30 my $schema = $dbh->qualify_schema('sgn');
31 $tablename = "$schema.seqread";
33 ($path, $name) = $dbh->selectrow_array("SELECT trace_location,trace_name FROM $tablename WHERE $idcol=?",undef,$read_id||$chromat_id);
34 } elsif($chromat_id) {
35 my $chromat = CXGN
::Genomic
::Chromat
->retrieve($chromat_id);
36 $path = $chromat->subpath;
37 $name = $chromat->filename;
39 $page->error_page('Invalid GET parameters');
42 ($path && $name) || not_found
($page, $read_id);
44 my $basename = $c->config->{'trace_path'}."/$path/$name";
45 my $full_pathname = '';
47 # The actual extension used should have been stored in the database, but it
48 # was not. This is because most chromatograms we had at the start did not have
49 # an extension. Overtime, it became clear that preserving the facility's
50 # specified filename is necessary, thus conventions for file extenstions are
51 # not standardized. This nested loop below wastes some time, but is arguably
52 # robust and easily extended to new types.
54 # Add the extenstion used to seqread in the database to solve the problem
55 # cleanly, do NOT standardize the extensions used on the file system.
58 foreach $type_ext ( '',qw
/.ab1 .abi .scf .esd .SCF/) {
59 foreach $comp_ext ( '',qw
/.gz .Z .bz2/) {
60 if ( -f
"$basename$type_ext$comp_ext" ) {
61 $full_pathname = $basename . $type_ext . $comp_ext;
62 $name .= $type_ext . $comp_ext;
68 if (!$full_pathname) {
69 print STDERR
"Can't find chromatogram file at $basename";
70 $page->message_page("This sequence does not seem to have an associated chromatogram.");
73 open F
, "<$full_pathname"
74 or $page->error_page("Failed to open chromatogram file for SGN-T$read_id ($!)");
76 print "Pragma: \"no-cache\"\nContent-Disposition: filename=$name\n";
77 print "Content-type: application/data\n\n";
80 while(read(F
,$_,4096)) {
93 Requested search is invalid.
101 my ($page, $id) = @_;
107 No chromatogram was found for SGN-T$id.