Skip to content
Snippets Groups Projects
Commit 203c2e56 authored by cramakri's avatar cramakri
Browse files

SE-341 Improvements to handling the metabolomics data.

SVN: 21597
parent eab56134
No related branches found
No related tags found
No related merge requests found
from datetime import datetime from datetime import datetime
from eu.basynthec.cisd.dss import TimeSeriesDataExcel from eu.basynthec.cisd.dss import TimeSeriesDataExcel
def retrieve_or_create_experiment(tr): def retrieve_or_create_experiment(tr, exp_id):
# Create an experiment """Get the specified experiment form the server, or create a new one if no experiment is specified. Return the experiment."""
now_str = datetime.today().strftime('%Y%m%d-%H%M%S') if exp_id is None:
expid = "/SHARED/SHARED/" + now_str now_str = datetime.today().strftime('%Y%m%d')
exp = tr.getExperiment(expid) exp_id = "/SHARED/SHARED/" + now_str
exp = tr.getExperiment(exp_id)
if None == exp:
exp = tr.createNewExperiment(expid, 'BASYNTHEC')
exp.setPropertyValue("DESCRIPTION", "An experiment created on " + now_str)
else:
exp = tr.getExperiment(exp_id)
return exp
if None == exp: def assign_properties(dataset, metadata):
exp = tr.createNewExperiment(expid, 'BASYNTHEC') """Assign properties to the data set from information in the data."""
exp.setPropertyValue("DESCRIPTION", "An experiment created on " + now_str) propertyNameMap = {
"STRAIN":"STRAIN",
"TIMEPOINT TYPE": "TIMEPOINT_TYPE",
"CELL LOCATION": "CELL_LOCATION",
"VALUE TYPE": "VALUE_TYPE",
"VALUE UNIT": "VALUE_UNIT",
"SCALE": "SCALE"
}
return exp for prop in metadata.keySet():
key = propertyNameMap.get(prop)
if key is not None:
value = metadata.get(prop)
if (key == "STRAIN"):
value = value + " (STRAIN)"
dataset.setPropertyValue(key, value.upper())
def convert_data_to_tsv(tr, dataset, location):
"""Create a tsv file containing the data and add it to the data set."""
tr.createNewDirectory(dataset, location)
tsvFileName = tr.createNewFile(dataset, location, incoming.getName() + ".tsv")
tsv = open(tsvFileName, 'w')
for line in timeSeriesData.getRawDataLines():
for i in range(0, len(line) - 1):
tsv.write(line[i])
tsv.write("\t")
tsv.write(line[len(line) - 1])
tsv.write("\n")
tsv.close()
def store_original_data(tr, dataset, location):
"""Put the original data into the data set."""
tr.createNewDirectory(dataset, location)
tr.moveFile(incoming.getAbsolutePath(), dataset, location + "/" + incoming.getName())
propertyNameMap = {
"STRAIN":"STRAIN",
"TIMEPOINT TYPE": "TIMEPOINT_TYPE",
"CELL LOCATION": "CELL_LOCATION",
"VALUE TYPE": "VALUE_TYPE",
"VALUE UNIT": "VALUE_UNIT",
"SCALE": "SCALE"
}
tr = service.transaction(incoming) tr = service.transaction(incoming)
exp = retrieve_or_create_experiment(tr)
timeSeriesData = TimeSeriesDataExcel.createTimeSeriesDataExcel(incoming.getAbsolutePath()) timeSeriesData = TimeSeriesDataExcel.createTimeSeriesDataExcel(incoming.getAbsolutePath())
# create the data set and assign the metadata from the file # create the data set and assign the metadata from the file
dataSet = tr.createNewDataSet("METABOLITE_INTENSITIES") dataset = tr.createNewDataSet("METABOLITE_INTENSITIES")
metadata = timeSeriesData.getMetadataMap() metadata = timeSeriesData.getMetadataMap()
assign_properties(dataset, metadata)
# Convert the data into a tsv file, and put that and the original data into the data set
convert_data_to_tsv(tr, dataset, "data/tsv")
store_original_data(tr, dataset, "data/xls")
for prop in metadata.keySet(): expCode = metadata.get("EXPERIMENT")
key = propertyNameMap.get(prop) exp = retrieve_or_create_experiment(tr, expCode)
if key is not None: dataset.setExperiment(exp)
value = metadata.get(prop)
if (key == "STRAIN"):
value = value + " (STRAIN)"
dataSet.setPropertyValue(key, value.upper())
dataSet.setExperiment(exp)
tr.moveFile(incoming.getAbsolutePath(), dataSet)
...@@ -133,7 +133,12 @@ public class TimeSeriesDataExcel ...@@ -133,7 +133,12 @@ public class TimeSeriesDataExcel
for (int i = 1; i < metadataLines.size(); ++i) for (int i = 1; i < metadataLines.size(); ++i)
{ {
String[] line = metadataLines.get(i); String[] line = metadataLines.get(i);
metadataMap.put(line[0].toUpperCase(), line[1]); String value = line[1];
if ("BLANK".equals(value))
{
value = null;
}
metadataMap.put(line[0].toUpperCase(), value);
} }
return metadataMap; return metadataMap;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment