Skip to content

Commit

Permalink
LIMS-1074: Allow accessing zipped files (#684)
Browse files Browse the repository at this point in the history
* LIMS-1074: Allow access to compressed processing logs etc

* LIMS-1074: Remove debug message

* LIMS-1074: Fix map/model viewer

* LIMS-1074: Fix downstream processing

* LIMS-1074: Remove debug message

* LIMS-1074: Remove debug message

* LIMS-1074: Use readgzfile instead of gzopen/gzread/gzclose

* LIMS-1074: Download file zipped if already zipped

* LIMS-1074: Fix download filenames

* LIMS-1074: Use readgzfile to replace readfile, and gzdecode the contents of files to manipulate

* LIMS-1074: Use readgzfile to replace readfile, and gzdecode the contents of files to manipulate

* LIMS-1074: Tidy up setting content disposition

* LIMS-1074: Deploy suggestions from code review

---------

Co-authored-by: Mark Williams <[email protected]>
  • Loading branch information
ndg63276 and Mark Williams authored Nov 2, 2023
1 parent 6f36e9f commit 9a0ad6f
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 137 deletions.
47 changes: 33 additions & 14 deletions api/scripts/mtz2map.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
8 changes: 6 additions & 2 deletions api/src/Downstream/BigEPPhasing.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
142 changes: 77 additions & 65 deletions api/src/Downstream/Type/FastEp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions api/src/Page/DC.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 9a0ad6f

Please sign in to comment.