From 23d3afca728a5e12d20327853751061cffcd4b22 Mon Sep 17 00:00:00 2001 From: kohleman <kohleman> Date: Thu, 31 Mar 2016 12:23:19 +0000 Subject: [PATCH] drop box for error rate of phix, error rate and density based on illuminate SVN: 36052 --- .../drop-boxes/read-json/plugin.properties | 6 ++ .../2/dss/drop-boxes/read-json/read-json.py | 76 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/2/dss/drop-boxes/read-json/plugin.properties create mode 100644 deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/2/dss/drop-boxes/read-json/read-json.py diff --git a/deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/2/dss/drop-boxes/read-json/plugin.properties b/deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/2/dss/drop-boxes/read-json/plugin.properties new file mode 100644 index 00000000000..98a7c8ff001 --- /dev/null +++ b/deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/2/dss/drop-boxes/read-json/plugin.properties @@ -0,0 +1,6 @@ +incoming-dir = ${incoming-root-dir}/read-json +incoming-data-completeness-condition = marker-file +top-level-data-set-handler = ch.systemsx.cisd.etlserver.registrator.api.v2.JythonTopLevelDataSetHandlerV2 +script-path = read-json.py +storage-processor = ch.systemsx.cisd.etlserver.DefaultStorageProcessor +jython-version=2.7 diff --git a/deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/2/dss/drop-boxes/read-json/read-json.py b/deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/2/dss/drop-boxes/read-json/read-json.py new file mode 100644 index 00000000000..d4873308a4d --- /dev/null +++ b/deep_sequencing_unit/sourceTest/core-plugins/illumina-qgf/2/dss/drop-boxes/read-json/read-json.py @@ -0,0 +1,76 @@ +''' +@copyright: +2016 ETH Zuerich, SIS + +@license: +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +@author: +Manuel Kohler +''' + +import re +import glob +import os +from itertools import islice +from ch.systemsx.cisd.openbis.generic.shared.api.v1.dto import SearchCriteria + +# The following module is located in the path defined in the datastore_server.conf +# Look for: -Dpython.path} +from gfb_utils import * + +import json + + +def get_json_from_file(file): + with open(file, 'r') as f: + read_json = f.read() + return json.loads(read_json)[0] + +def get_lane_count(json_string): + return int(json_string['lanecount']) + + +def get_flowcell_id(json_string): + return json_string['name'] + + +def register_in_openbis(transaction, json_string): + lane_count = get_lane_count(json_string) + flowcell_id = get_flowcell_id(json_string) + found_flow_cell = search_unique_sample(transaction, flowcell_id) + search_service = transaction.getSearchService() + get_flowcell_with_contained_samples = search_service.getSample(found_flow_cell[0].getSampleIdentifier()) + flowlanes = get_flowcell_with_contained_samples.getContainedSamples() + for lane in flowlanes: + mutable_lane = transaction.getSampleForUpdate(lane.getSampleIdentifier()) + lane_number = lane.getCode().split(":")[-1] + aligned_mean = json_string['cluster_lane_dict'][str(lane_number)]['aligned'][0]['mean'] + cluster_density_mean = json_string['cluster_lane_dict'][str(lane_number)]['clusterDensity'][0]['mean'] + error_rate_mean = json_string['error_metrics'][str(lane_number)]['mean'] + mutable_lane.setPropertyValue("PERC_PHIX_ALIGNED", str(aligned_mean)) + mutable_lane.setPropertyValue("CLUSTER_DENSITY", str(cluster_density_mean)) + mutable_lane.setPropertyValue("ERROR_RATE", str(error_rate_mean)) + + +def process(transaction): + incoming = transaction.getIncoming() + incoming_path = incoming.getAbsolutePath() + + json_file = glob.glob(os.path.join(incoming_path, "*.json")) + + if json_file: + json_string = get_json_from_file(json_file[0]) + register_in_openbis(transaction, json_string) + else: + print("No json file found!") \ No newline at end of file -- GitLab