Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datalink in assay file #43

Open
wants to merge 1 commit into
base: feat/dataFile
Choose a base branch
from
Open
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
30 changes: 27 additions & 3 deletions brapi_to_isa.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
# CASSAVA_BRAPI_V1 = 'https://cassavabase.org/brapi/v1/'


def create_study_sample_and_assay(client, brapi_study_id, isa_study, sample_collection_protocol, phenotyping_protocol, OBSERVATIONUNITLIST):
def create_study_sample_and_assay(client, brapi_study_id, isa_study, sample_collection_protocol, phenotyping_protocol, OBSERVATIONUNITLIST, brapi_study):

spat_dist_mapping_dictionary = {
"X": "X",
Expand All @@ -95,6 +95,28 @@ def create_study_sample_and_assay(client, brapi_study_id, isa_study, sample_col
for k,assay in enumerate(isa_study.assays):
obs_level_to_assay[assay.characteristic_categories[0]] = k

# DATA - link as one line in assay file
# -------------------------------------
if 'dataLinks' in brapi_study and brapi_study['dataLinks']:
for k in range(len(isa_study.assays)):
this_source = isa_study.get_source('study')
this_isa_sample = Sample(
name='study' ,
derives_from=[this_source])
isa_study.assays[k].samples.append(this_isa_sample)
phenotyping_process = Process(executes_protocol=phenotyping_protocol)
phenotyping_process.inputs.append(this_isa_sample)
phenotyping_process.name = brapi_study["studyDbId"]
datalinks = []
for fileName in brapi_study['dataLinks']:
datalinks.append(fileName['url'])
RAW_datafile = DataFile(filename=','.join(datalinks),
label="Derived Data File")
phenotyping_process.outputs.append(RAW_datafile)
isa_study.assays[k].process_sequence.append(phenotyping_process)

# Iterating over the observation units to decorate the assays (each for every observation level)
# ----------------------------------------------------------------------------------------------
treatments = defaultdict(list)
allready_converted_obs_unit = [] # Allow to handle multiyear observation units NOTE (INRA specific)
for obs_unit in OBSERVATIONUNITLIST:
Expand Down Expand Up @@ -319,6 +341,8 @@ def main(arg):
germplasminfo = {}

brapi_study_id = brapi_study['studyDbId']
brapi_study = client.get_study(brapi_study_id)

try:
brapi_study['studyDbId'].encode('ascii')
except:
Expand All @@ -332,7 +356,7 @@ def main(arg):

obs_level, obs_levels = converter.get_obs_levels(brapi_study_id, OBSERVATIONUNITLIST)
# NB: this method always create an ISA Assay Type
isa_study, investigation = converter.create_isa_study(brapi_study_id, investigation, obs_level.keys())
isa_study, investigation = converter.create_isa_study(brapi_study_id, investigation, obs_level.keys(), brapi_study)

investigation.studies.append(isa_study)

Expand Down Expand Up @@ -364,7 +388,7 @@ def main(arg):
isa_study.sources.append(source)

# Now dealing with BRAPI observation units and attempting to create ISA samples
create_study_sample_and_assay(client, brapi_study_id, isa_study, sample_collection_protocol, phenotyping_protocol, OBSERVATIONUNITLIST)
create_study_sample_and_assay(client, brapi_study_id, isa_study, sample_collection_protocol, phenotyping_protocol, OBSERVATIONUNITLIST, brapi_study)


# Writing isa_study to ISA-Tab format:
Expand Down
4 changes: 1 addition & 3 deletions brapi_to_isa_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ def create_germplasm_chars(self, germplasm):

return returned_characteristics

def create_isa_study(self, brapi_study_id, investigation, obs_levels_in_study):
def create_isa_study(self, brapi_study_id, investigation, obs_levels_in_study, brapi_study):
"""Returns an ISA study given a BrAPI endpoints and a BrAPI study identifier."""

brapi_study = self._brapi_client.get_study(brapi_study_id)

# Adding study information on investigation level
###########################################################################
Expand Down