Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/config_sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
$mode = 'dev';

# Database credentials, db = hostname/database
$isb = array('user' => 'user', 'pass' => 'pass', 'db' => 'localhost/ispyb');
$isb = array('user' => 'user', 'pass' => 'pass', 'db' => 'localhost/ispyb');
$dbtype = 'mysql';

# Encoded JWT key, used to sign and check validaty of jwt tokens
Expand Down
3 changes: 2 additions & 1 deletion api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function setupApplication($mode): Slim
});

$app->get('/options', function () use ($app) {
global $motd, $authentication_type, $cas_url, $cas_sso, $sso_url, $package_description,
global $mode, $motd, $authentication_type, $cas_url, $cas_sso, $sso_url, $package_description,
$facility_courier_countries, $facility_courier_countries_nde, $facility_courier_countries_link, $icat_base_url,
$visit_persist_storage_dir_segment, $dhl_enable, $scale_grid, $scale_grid_end_date, $preset_proposal, $timezone,
$valid_components, $enabled_container_types, $synchweb_version, $redirects,
Expand All @@ -78,6 +78,7 @@ function setupApplication($mode): Slim
$app->contentType('application/json');
$options = $app->container['options'];
$app->response()->body(json_encode(array(
'mode' => $mode == 'production' ? 'production' : 'development',
'motd' => $options->get('motd', $motd),
'authentication_type' => $authentication_type,
'cas_url' => $cas_url,
Expand Down
9 changes: 9 additions & 0 deletions api/src/Downstream/Type/LigandFit.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ function results() {
$dat['MODEL_APPAID'] = $appaid;
$dat['SOLUTIONS'] = json_decode($json_data);
$dat['PARENTAUTOPROCPROGRAM'] = $this->process['PROCESSINGCOMMENTS'];

$integrator = $this->_lookup_autoproc(
null,
$this->process['PARAMETERS']['scaling_id']
);
if ($integrator) {
$dat['PARENTAUTOPROCPROGRAM'] .= ' (' . $integrator['PROCESSINGPROGRAMS'] . ')';
$dat['PARENTAUTOPROCPROGRAMID'] = $integrator['AUTOPROCPROGRAMID'];
}

$results = new DownstreamResult($this);
$results->data = $dat;
Expand Down
71 changes: 64 additions & 7 deletions api/src/Page/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Download extends Page

'ppl' => '\w+',
'aid' => '\w+',
'cid' => '\d+',

'filetype' => '\w+',
'blsampleid' => '\d+',
Expand All @@ -49,6 +50,7 @@ class Download extends Page
public static $dispatch = array(
array('/plots', 'get', '_auto_processing_plots'),
array('/csv/visit/:visit', 'get', '_csv_report'),
array('/csv/container/:cid', 'get', '_dispensing_csv'),
array('/sign', 'post', '_sign_url'),
array('/data/visit/:visit', 'get', '_download_visit'),
array('/attachments', 'get', '_get_attachments'),
Expand Down Expand Up @@ -247,16 +249,16 @@ function _get_autoproc_attachments()
/**
* Download a file to the browser
* This function is used to download autoproc and phasing run attachments.
* It sets a maximum amount of memory for the download.
* The $id is used as a prefix to the filename.
*
* @param integer $id One of AutoProcProgramId or PhasingProgramRunId
* @param array $file Array that must include FILENAME (including extension) and FILEPATH
*/
function _get_file($id, $file)
{
// We don't want to allow unlimited file sizes
ini_set('memory_limit', '512M');
// Remove all buffers
while (ob_get_level() > 0) ob_end_clean();

$filesystem = new Filesystem();

$filename = $file['FILEPATH'] . '/' . $file['FILENAME'];
Expand All @@ -265,18 +267,27 @@ function _get_file($id, $file)
if ($filesystem->exists($filename)) {
$response = new BinaryFileResponse($filename);
$this->set_mime_content($response, $filename, $id);
$response->headers->set("Content-Length", filesize($filename));
} elseif ($filesystem->exists($filename.'.gz')) {
$filename = $filename.'.gz';
if ($this->has_arg('download') && $this->arg('download') < 3) {
// View/open file, so unzip and serve
$response = new Response(readgzfile($filename));
// View log file, so unzip and serve
$response = new StreamedResponse(function() use ($filename) {
$fileHandle = gzopen($filename, 'rb');
if ($fileHandle === false) {
$this->_error("The file " . $filename . " couldn't be opened");
}
// Read the file in 8KB chunks and send them
while (!gzeof($fileHandle)) {
echo gzread($fileHandle, 8192);
flush();
}
gzclose($fileHandle);
});
$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");
Expand Down Expand Up @@ -317,6 +328,52 @@ function _csv_report()
}
}

# ------------------------------------------------------------------------
# CSV Report of dispensing positions for a plate
function _dispensing_csv()
{
if (!$this->has_arg('cid'))
$this->_error('No container id specified');
$rows = $this->db->pq("SELECT c.code, s.location, ct.name, ct.capacity, ct.wellperrow,
bsp.posx, bsp.posy, si.imagefullpath, si.micronsperpixelx, si.micronsperpixely
FROM blsample s
INNER JOIN container c ON c.containerid = s.containerid
INNER JOIN blsampleimage si ON si.blsampleid = s.blsampleid
LEFT OUTER JOIN containertype ct ON (c.containertypeid IS NOT NULL AND c.containertypeid = ct.containertypeid) OR (c.containertypeid IS NULL AND c.containertype = ct.name)
LEFT OUTER JOIN
(SELECT * FROM blsampleposition bsp1 WHERE bsp1.blsamplepositionid =
(SELECT MAX(blsamplepositionid) FROM blsampleposition bsp2 WHERE bsp2.blsampleid = bsp1.blsampleid AND bsp2.positiontype='dispensing')
) bsp ON bsp.blsampleid = s.blsampleid
WHERE c.containerid=:1
ORDER BY s.location+0",
array($this->arg('cid')));
$plate = $rows[0];
$rowNames = range("A", "H");
$dropNames = range("a", "z");
// SWISSCI 3 Drop have drops a/c/d
if ($plate["NAME"] == "SWISSCI 3 Drop") {
$dropNames = array_merge(array("a"), range("c","z"));
}
$dropsPerWell = $plate["CAPACITY"] / (count($rowNames) * $plate["WELLPERROW"]);
$this->app->response->headers->set("Content-type", "text/csv");
$this->_set_disposition_attachment($this->app->response, $plate["CODE"] . "_targets.csv");
list($width, $height, $type, $attr) = getimagesize($plate['IMAGEFULLPATH']);
foreach ($rows as $r) {
if (!isset($r["POSX"]) || !isset($r["POSY"])) {
continue; # skip empty rows
}
$wellNumber = intval(($r["LOCATION"] - 1) / $dropsPerWell); # 0 indexed
$rowNumber = intval($wellNumber / $plate["WELLPERROW"]); # 0 indexed
$row = $rowNames[$rowNumber];
$column = str_pad($wellNumber - ($rowNumber * $plate["WELLPERROW"]) + 1, 2, 0, STR_PAD_LEFT); # pad with a zero if needed
$dropNumber = intval($r["LOCATION"] - ($dropsPerWell * $wellNumber)); # 1 indexed
$drop = $dropNames[$dropNumber-1];
$xval = round(($r["POSX"] - $width/2) * $r["MICRONSPERPIXELX"]); # integers
$yval = round(($height/2 - $r["POSY"]) * $r["MICRONSPERPIXELY"]); # integers
print $row . $column . $drop . "," . $xval . "," . $yval . "\n";
}
}


# ------------------------------------------------------------------------
# Get dc attachmmnts
Expand Down
Loading
Loading