diff --git a/api/scripts/mtz2map.sh b/api/scripts/mtz2map.sh index e6f1df143..04fb213c0 100755 --- a/api/scripts/mtz2map.sh +++ b/api/scripts/mtz2map.sh @@ -15,15 +15,35 @@ export CLIBD=$CCP4_MASTER/lib/data export CCP4_SCR=/tmp export root=$CCP4_MASTER/bin +if [ -f $1 ]; then + mtz=$1 +else + if [ -f $1.gz ]; then + mtz=/tmp/$2_$3.mtz + gunzip -c $1.gz > $mtz + else + echo "No mtz file found" + exit + fi +fi + if [ $3 == 'dimple' -o $3 == 'mrbump' ]; then +if [ -f $4 ]; then + pdb=$4 +else + if [ -f $4.gz ]; then + pdb=/tmp/$2_$3.pdb + gunzip -c $4.gz > $pdb + else + echo "No pdb file found" + exit + fi +fi + if [ $3 == 'dimple' ]; then - # fofc2="F1=F SIG1=SIGF PHI=PH2FOFCWT W=FOM" - # fofc="F1=F SIG1=SIGF PHI=PHFOFCWT W=FOM" - # fofc2="F1=F SIG1=SIGF PHI=PHWT W=FOM" - # fofc="F1=F SIG1=SIGF PHI=PHDELWT W=FOM" - if $root/mtzinfo $1 | grep -q PH2FOFCWT; then + if $root/mtzinfo $mtz | grep -q PH2FOFCWT; then fofc2="F1=2FOFCWT SIG1=SIGF PHI=PH2FOFCWT" fofc="F1=F SIG1=SIGF PHI=PHFOFCWT W=FOM" else @@ -37,7 +57,7 @@ fi # F SIGF FC PHIC FC_ALL PHIC_ALL FWT PHWT DELFWT PHDELWT FOM FC_ALL_LS PHIC_ALL_LS -$root/fft HKLIN $1 MAPOUT "/tmp/$2_$3_2fofc.map.tmp" << eof +$root/fft HKLIN $mtz MAPOUT "/tmp/$2_$3_2fofc.map.tmp" << eof title $2 2fofc xyzlim asu scale F1 1.0 @@ -46,11 +66,11 @@ $fofc2 end eof -$root/mapmask MAPIN "/tmp/$2_$3_2fofc.map.tmp" MAPOUT "/tmp/$2_$3_2fofc.map" XYZIN "$4" << eof +$root/mapmask MAPIN "/tmp/$2_$3_2fofc.map.tmp" MAPOUT "/tmp/$2_$3_2fofc.map" XYZIN "$pdb" << eof BORDER 5 eof -$root/fft HKLIN $1 MAPOUT "/tmp/$2_$3_fofc.map.tmp" << eof +$root/fft HKLIN $mtz MAPOUT "/tmp/$2_$3_fofc.map.tmp" << eof title $2 fofc xyzlim asu scale F1 1.0 @@ -60,16 +80,17 @@ end eof -$root/mapmask MAPIN "/tmp/$2_$3_fofc.map.tmp" MAPOUT "/tmp/$2_$3_fofc.map" XYZIN "$4" << eof +$root/mapmask MAPIN "/tmp/$2_$3_fofc.map.tmp" MAPOUT "/tmp/$2_$3_fofc.map" XYZIN "$pdb" << eof BORDER 5 eof gzip "/tmp/$2_$3_2fofc.map" gzip "/tmp/$2_$3_fofc.map" +rm -f /tmp/$2_$3.pdb else -$root/fft HKLIN $1 MAPOUT "/tmp/$2_$3.map" << eof +$root/fft HKLIN $mtz MAPOUT "/tmp/$2_$3.map" << eof title $2 fofc xyzlim asu scale F1 1.0 @@ -78,10 +99,8 @@ F1=F SIG1=SIGF PHI=PHI W=FOM end eof -#$mm MAPIN "/tmp/$2_ep.map.tmp" MAPOUT "/tmp/$2_ep.map" XYZIN "$4" << eof -#BORDER 5 -#eof - gzip "/tmp/$2_$3.map" fi + +rm -f /tmp/$2_$3.mtz diff --git a/api/src/Downstream/BigEPPhasing.php b/api/src/Downstream/BigEPPhasing.php index 8a2068d8a..63458784f 100644 --- a/api/src/Downstream/BigEPPhasing.php +++ b/api/src/Downstream/BigEPPhasing.php @@ -25,13 +25,17 @@ function results() { } $image = $this->_get_image(); - $dat['IMAGE'] = file_exists($image); + $dat['IMAGE'] = file_exists($image) || file_exists($image.'.gz'); $model = $this->_get_attachments('big_ep_model_ispyb.json'); - $dat['HASMODEL'] = $model && file_exists($model['FILE']); + $dat['HASMODEL'] = $model && (file_exists($model['FILE']) || file_exists($model['FILE'].'.gz')); if ($model) { if (file_exists($model['FILE'])) { $json_str = file_get_contents($model['FILE']); + } elseif (file_exists($model['FILE'].'.gz')) { + $json_str = gzdecode(file_get_contents($model['FILE'].'.gz')); + } + if (isset($json_str)) { $json_data = json_decode($json_str, true); foreach ( array( diff --git a/api/src/Downstream/Type/FastEp.php b/api/src/Downstream/Type/FastEp.php index 906a1e0e5..f6a3d54cc 100644 --- a/api/src/Downstream/Type/FastEp.php +++ b/api/src/Downstream/Type/FastEp.php @@ -16,83 +16,95 @@ function results() { $pdb = $this->_get_attachments("sad_fa.pdb"); if ($pdb) { if (file_exists($pdb["FILE"])) { - $pdb = file_get_contents($pdb["FILE"]); - foreach (explode("\n", $pdb) as $l) { - if (strpos($l, 'HETATM') !== false) { - $parts = preg_split('/\s+/', $l); - array_push($ats, array( - $parts[1], - $parts[5], - $parts[6], - $parts[7], - $parts[8], - )); - } - } + $pdb_cont = file_get_contents($pdb["FILE"]); + } elseif (file_exists($pdb['FILE'].'.gz')) { + $pdb_cont = gzdecode(file_get_contents($pdb['FILE'].'.gz')); + } + } - $dat['ATOMS'] = array_slice($ats, 0, 5); + if (isset($pdb_cont)) { + foreach (explode("\n", $pdb_cont) as $l) { + if (strpos($l, 'HETATM') !== false) { + $parts = preg_split('/\s+/', $l); + array_push($ats, array( + $parts[1], + $parts[5], + $parts[6], + $parts[7], + $parts[8], + )); + } } + + $dat['ATOMS'] = array_slice($ats, 0, 5); + } $lst = $this->_get_attachments("sad.lst"); if ($lst) { if (file_exists($lst['FILE'])) { - $p1 = array(); - $p2 = array(); - - $lst = file_get_contents($lst['FILE']); - $graph_vals = 0; - $gvals = array(); - foreach (explode("\n", $lst) as $l) { - if ( - strpos( - $l, - 'Estimated mean FOM and mapCC as a function of resolution' - ) !== false - ) { - $graph_vals = 1; - } - - if ($graph_vals && $graph_vals < 5) { - array_push($gvals, $l); - $graph_vals++; - } - - if ( - preg_match( - '/ Estimated mean FOM = (\d+.\d+)\s+Pseudo-free CC = (\d+.\d+)/', - $l, - $mat - ) - ) { - $dat['FOM'] = floatval($mat[1]); - $dat['CC'] = floatval($mat[2]); - } + $lst_cont = file_get_contents($lst['FILE']); + } elseif (file_exists($lst['FILE'].'.gz')) { + $lst_cont = gzdecode(file_get_contents($lst['FILE'].'.gz')); + } + } + + if (isset($lst_cont)) { + $p1 = array(); + $p2 = array(); + + $graph_vals = 0; + $gvals = array(); + foreach (explode("\n", $lst_cont) as $l) { + if ( + strpos( + $l, + 'Estimated mean FOM and mapCC as a function of resolution' + ) !== false + ) { + $graph_vals = 1; } - if (sizeof($gvals) > 0) { - $x = array_map( - 'floatval', - array_slice(explode(' - ', $gvals[1]), 1) - ); - $y = array_map( - 'floatval', - array_slice(preg_split('/\s+/', $gvals[2]), 2) - ); - $y2 = array_map( - 'floatval', - array_slice(preg_split('/\s+/', $gvals[3]), 2) - ); - - foreach ($x as $i => $v) { - array_push($p1, array(1.0 / pow($v, 2), $y[$i])); - array_push($p2, array(1.0 / pow($v, 2), $y2[$i])); - } + if ($graph_vals && $graph_vals < 5) { + array_push($gvals, $l); + $graph_vals++; } - $dat['PLOTS']['FOM'] = $p1; - $dat['PLOTS']['CC'] = $p2; + if ( + preg_match( + '/ Estimated mean FOM = (\d+.\d+)\s+Pseudo-free CC = (\d+.\d+)/', + $l, + $mat + ) + ) { + $dat['FOM'] = floatval($mat[1]); + $dat['CC'] = floatval($mat[2]); + } } + + if (sizeof($gvals) > 0) { + $x = array_map( + 'floatval', + array_slice(explode(' - ', $gvals[1]), 1) + ); + $y = array_map( + 'floatval', + array_slice(preg_split('/\s+/', $gvals[2]), 2) + ); + $y2 = array_map( + 'floatval', + array_slice(preg_split('/\s+/', $gvals[3]), 2) + ); + + foreach ($x as $i => $v) { + array_push($p1, array(1.0 / pow($v, 2), $y[$i])); + array_push($p2, array(1.0 / pow($v, 2), $y2[$i])); + } + } + + $dat['PLOTS']['FOM'] = $p1; + $dat['PLOTS']['CC'] = $p2; + } $results = new DownstreamResult($this); diff --git a/api/src/Page/DC.php b/api/src/Page/DC.php index 7879d0615..31056572a 100644 --- a/api/src/Page/DC.php +++ b/api/src/Page/DC.php @@ -1605,6 +1605,10 @@ function _rd($aid, $id) $rows = array(); if (file_exists($file)) { $log = file_get_contents($file); + } elseif (file_exists($file.'.gz')) { + $log = gzdecode(file_get_contents($file.'.gz')); + } + if (isset($log)) { $start = 0; foreach (explode("\n", $log) as $l) { diff --git a/api/src/Page/Download.php b/api/src/Page/Download.php index b86188db5..8b24a186b 100644 --- a/api/src/Page/Download.php +++ b/api/src/Page/Download.php @@ -9,6 +9,7 @@ use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\ResponseHeaderBag; use Symfony\Component\HttpFoundation\StreamedResponse; +use Symfony\Component\HttpFoundation\Response; use ZipStream\Option\Archive; use ZipStream\ZipStream; @@ -84,10 +85,7 @@ function _download_visit() if ($filesystem->exists($data)) { $response = new BinaryFileResponse($data); $response->headers->set("Content-Type", "application/octet-stream"); - $response->setContentDisposition( - ResponseHeaderBag::DISPOSITION_ATTACHMENT, - $this->arg('visit') . '_download.zip' - ); + $this->_set_disposition_attachment($response, $this->arg('visit') . '_download.zip'); $response->send(); } else $this->_error('There doesnt seem to be a data archive available for this visit'); @@ -137,6 +135,11 @@ function _auto_processing_plots() $r['PLOTS'] = array(); if (file_exists($json)) { $cont = file_get_contents($json); + } elseif (file_exists($json.'.gz')) { + $cont = gzdecode(file_get_contents($json.'.gz')); + } + + if (isset($cont)) { $plotData = json_decode($cont); $r['PLOTS'] = $plotData; @@ -260,25 +263,25 @@ function _get_file($id, $file) // Do the check first, if no file quit early if ($filesystem->exists($filename)) { - $response = new BinaryFileResponse($filename); - - # Set mime / content type - $this->set_mime_content($response, $file['FILENAME'], $id); - - // All OK - send it - // We were getting out of memory errors - switch off output buffer to fix - if (ob_get_level()) { - ob_end_clean(); - } - // Setting content length means browser can indicate how long is left + $this->set_mime_content($response, $filename, $id); $response->headers->set("Content-Length", filesize($filename)); - - $response->send(); - exit(); + } elseif ($filesystem->exists($filename.'.gz')) { + $filename = $filename.'.gz'; + if ($this->arg('download') == 1) { + // View log file, so unzip and serve + $response = new Response(readgzfile($filename)); + $this->set_mime_content($response, $file['FILENAME'], $id); + } else { + // Download gzipped file + $response = new BinaryFileResponse($filename); + $this->set_mime_content($response, $filename, $id); + $response->headers->set("Content-Length", filesize($filename)); + } } else { $this->_error("No such file, the specified file " . $filename . " doesn't exist"); } + $response->send(); } @@ -306,7 +309,7 @@ function _csv_report() WHERE dcg.sessionid=:1 ORDER BY dc.starttime", array($vis['SESSIONID'])); $this->app->response->headers->set("Content-type", "application/vnd.ms-excel"); - $this->app->response->headers->set("Content-disposition", "attachment; filename=" . $vis['ST'] . "_" . $vis['BEAMLINENAME'] . "_" . $this->arg('visit') . ".csv"); + $this->_set_disposition_attachment($this->app->response, $vis['ST'] . "_" . $vis['BEAMLINENAME'] . "_" . $this->arg('visit') . ".csv"); print "Image prefix,Beamline,Run no,Start Time,Sample Name,Protein Acronym,# images, Wavelength (angstrom), Distance (mm), Exp. Time (sec), Phi start (deg), Phi range (deg), Xbeam (mm), Ybeam (mm), Detector resol. (angstrom), Comments\n"; foreach ($rows as $r) { $r['COMMENTS'] = '"' . $r['COMMENTS'] . '"'; @@ -474,7 +477,11 @@ function _streamZipFile($files, $zipName) $zip = new ZipStream($zipName . '.zip', $options); foreach ($files as $file) { $filename = $file['FILEPATH'] . '/' . $file['FILENAME']; - $zip->addFileFromPath(basename($filename), $filename); + if (file_exists($filename)) { + $zip->addFileFromPath(basename($filename), $filename); + } elseif (file_exists($filename.'.gz')) { + $zip->addFileFromPath(basename($filename).'.gz', $filename.'.gz'); + } } $zip->finish(); @@ -499,28 +506,37 @@ function set_mime_content($response, $filename, $prefix = null) if (in_array($path_ext, array('html', 'htm'))) { $response->headers->set("Content-Type", "text/html"); - $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE); + $this->_set_disposition_inline($response); } elseif ($path_ext == 'pdf') { $response->headers->set("Content-Type", "application/pdf"); - $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $saved_filename); + $this->_set_disposition_attachment($response, $saved_filename); } elseif ($path_ext == 'png') { $response->headers->set("Content-Type", "image/png"); - $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $saved_filename); + $this->_set_disposition_attachment($response, $saved_filename); } elseif (in_array($path_ext, array('jpg', 'jpeg'))) { $response->headers->set("Content-Type", "image/jpeg"); - $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $saved_filename); + $this->_set_disposition_attachment($response, $saved_filename); } elseif (in_array($path_ext, array('log', 'txt', 'error', 'LP', 'json', 'lsa'))) { $response->headers->set("Content-Type", "text/plain"); - $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE); + $this->_set_disposition_inline($response); } else { $response->headers->set("Content-Type", "application/octet-stream"); - $response->setContentDisposition( - ResponseHeaderBag::DISPOSITION_ATTACHMENT, - $saved_filename - ); + $this->_set_disposition_attachment($response, $saved_filename); } } + function _set_disposition_attachment($response, $filename) { + $response->headers->set("Content-Disposition", + ResponseHeaderBag::makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename) + ); + } + + function _set_disposition_inline($response) { + $response->headers->set("Content-Disposition", + ResponseHeaderBag::makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE, '') + ); + } + # ------------------------------------------------------------------------ # Download Data @@ -551,25 +567,11 @@ function _download() if ($filesystem->exists($data)) { $response = new BinaryFileResponse($data); $response->headers->set("Content-Type", "application/octet-stream"); - $response->setContentDisposition( - ResponseHeaderBag::DISPOSITION_ATTACHMENT, - $this->arg('id') . '_download.zip' - ); + $this->_set_disposition_attachment($response, $this->arg('id') . '_download.zip'); $response->send(); } else { error_log("Download file " . $data . " not found"); $this->_error('File not found on filesystem', 404); } } - - - # ------------------------------------------------------------------------ - # Force browser to download file - # Deprecated function now we are using symfony filesystem - function _header($f) - { - header("Content-Type: application/octet-stream"); - header("Content-Transfer-Encoding: Binary"); - header("Content-disposition: attachment; filename=\"$f\""); - } } diff --git a/api/src/Page/Processing.php b/api/src/Page/Processing.php index ab1c792fc..bfe1bd9d2 100644 --- a/api/src/Page/Processing.php +++ b/api/src/Page/Processing.php @@ -424,8 +424,10 @@ function _get_downstreams($dcid = null, $aid = null) { if ($downstream["PARAMETERS"]) { $str_params = explode(',', $downstream["PARAMETERS"]); foreach ($str_params as $str_param) { - list($key, $value) = explode('=', $str_param); - $params[$key] = $value; + if (str_contains($str_param, '=')) { + list($key, $value) = explode('=', $str_param); + $params[$key] = $value; + } } } $downstream['PARAMETERS'] = $params; @@ -518,20 +520,27 @@ function _downstream_images($aid) { $im = $plugin->images($this->has_arg('n') ? $this->arg("n") : 0); if ($im) { if (file_exists($im)) { - $ext = pathinfo($im, PATHINFO_EXTENSION); - if (in_array($ext, array('png', 'jpg', 'jpeg', 'gif'))) { - $head = 'image/' . $ext; - } - + $this->_set_content_type_header($im); $this->_browser_cache(); - $this->app->contentType($head); readfile($im); + } elseif (file_exists($im.'.gz')) { + $this->_set_content_type_header($im); + $this->_browser_cache(); + readgzfile($im.'.gz'); } else { $this->_error("No such image"); } } } + function _set_content_type_header($im) { + $ext = pathinfo($im, PATHINFO_EXTENSION); + if (in_array($ext, array('png', 'jpg', 'jpeg', 'gif'))) { + $head = 'image/' . $ext; + $this->app->contentType($head); + } + } + function _browser_cache() { $expires = 60 * 60 * 24 * 14; $this->app->response->headers->set('Pragma', 'public'); @@ -589,6 +598,8 @@ function _downstream_mapmodel($aid) { filesize($mapmodel) ); readfile($mapmodel); + } elseif (file_exists($mapmodel.'.gz')) { + readgzfile($mapmodel.'.gz'); } else { $this->_error('Could not find map / model'); } diff --git a/client/src/js/modules/dc/views/autoprocattachments.js b/client/src/js/modules/dc/views/autoprocattachments.js index f114cd171..c962098fa 100644 --- a/client/src/js/modules/dc/views/autoprocattachments.js +++ b/client/src/js/modules/dc/views/autoprocattachments.js @@ -18,7 +18,7 @@ define(['marionette', }, render: function() { - this.$el.html(' Download') + this.$el.html(' Download') if (this.model.get('FILETYPE') == 'Log' || this.model.get('FILETYPE') == 'Logfile') { this.$el.append(' View') @@ -115,4 +115,4 @@ define(['marionette', }, }) -}) \ No newline at end of file +}) diff --git a/client/src/js/templates/dc/dc_autoproc.html b/client/src/js/templates/dc/dc_autoproc.html index 0ae0a1f91..6969b9ebd 100644 --- a/client/src/js/templates/dc/dc_autoproc.html +++ b/client/src/js/templates/dc/dc_autoproc.html @@ -8,7 +8,7 @@ Logs & Files

-

This procesing job failed: <%-PROCESSINGMESSAGE%>

+

This processing job failed: <%-PROCESSINGMESSAGE%>

<% } else { %> diff --git a/client/src/js/templates/dc/downstreamerror.html b/client/src/js/templates/dc/downstreamerror.html index 625f8d7c1..784f3b6ef 100644 --- a/client/src/js/templates/dc/downstreamerror.html +++ b/client/src/js/templates/dc/downstreamerror.html @@ -3,4 +3,4 @@ Logs & Files

-

This procesing job failed: <%-PROCESS.PROCESSINGMESSAGE%>

+

This processing job failed: <%-PROCESS.PROCESSINGMESSAGE%>