Skip to content

Commit

Permalink
corrections, test passing (new test)
Browse files Browse the repository at this point in the history
  • Loading branch information
proccaserra committed Nov 10, 2023
1 parent c9859d4 commit 195cf71
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions isatools/convert/isatab2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def convert(work_dir, identifier_type=IdentifierType.name,
validate_first=True, config_dir=isatab.default_config_dir,
use_new_parser=False):
i_files = glob.glob(os.path.join(work_dir, 'i_*.txt'))

if validate_first:
log.info("Validating input ISA tab before conversion")
if len(i_files) != 1:
Expand Down Expand Up @@ -120,6 +121,7 @@ def convert(self, work_dir):
log.fatal("No ISA-Tab dataset found")
else:
isa_json = dict([])

if isa_tab.metadata != {}:
isa_json = dict([
("identifier",
Expand Down
5 changes: 2 additions & 3 deletions isatools/isatab/load/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def get_comments_row(cols, row):
file=row['Term Source File'],
version=row['Term Source Version'],
description=row['Term Source Description'])
ontology_source.comments = get_comments(df_dict['ontology_sources'])
ontology_source.comments = get_comments_row(df_dict['ontology_sources'].columns, row)
investigation.ontology_source_references.append(ontology_source)

ontology_source_map = dict(map(lambda x: (x.name, x), investigation.ontology_source_references))
Expand Down Expand Up @@ -317,8 +317,7 @@ def get_comments_row(cols, row):
row['Study Assay Technology Type Term Source REF']
)
assay.technology_platform = row['Study Assay Technology Platform']
assay.comments = get_comments(df_dict['s_assays'][i])

assay.comments = get_comments_row(df_dict['s_assays'][i].columns, row)
if skip_load_tables:
pass
else:
Expand Down
22 changes: 22 additions & 0 deletions tests/isajson/test_isajson.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,28 @@ def test_json_load_and_dump_bii_s_7(self):
self.assertEqual(len(assay_gx['dataFiles']), 29) # 29 data files in a_matteo-assay-Gx.txt
self.assertEqual(len(assay_gx['processSequence']), 116) # 116 processes in in a_matteo-assay-Gx.txt

def test_json_load_and_dump_bii_s_test(self):
# Load into ISA objects
with open(os.path.join(utils.JSON_DATA_DIR, 'ISA-1', 'isa-test1.json')) as isajson_fp:
ISA = isajson.load(isajson_fp)

# Dump into ISA JSON from ISA objects
ISA_J = json.loads(json.dumps(ISA, cls=isajson.ISAJSONEncoder))
study_bii_s_test = [s for s in ISA_J['studies'] if s['filename'] == 's_study.txt'][0]
assay_gx = [a for a in study_bii_s_test['assays'] if a['filename'] == 'a_assay.txt'][0]


def test_json_load_and_dump_isa_le_test(self):
# Load into ISA objects
with open(os.path.join(utils.JSON_DATA_DIR, 'TEST-ISA-LabeledExtract1', 'isa-test-le1.json')) as isajson_fp:
ISA = isajson.load(isajson_fp)

# Dump into ISA JSON from ISA objects
ISA_J = json.loads(json.dumps(ISA, cls=isajson.ISAJSONEncoder))
study_bii_s_test = [s for s in ISA_J['studies'] if s['filename'] == 's_study.txt'][0]
assay_gx = [a for a in study_bii_s_test['assays'] if a['filename'] == 'a_assay.txt'][0]
self.assertEqual(assay_gx['materials']['otherMaterials'][3]["type"], "Labeled Extract Name")

def test_json_load_from_file_and_create_isa_objects(self):
# reading from file
with open(os.path.join(utils.JSON_DATA_DIR, 'ISA-1', 'isa-test1.json')) as isajson_fp:
Expand Down
8 changes: 8 additions & 0 deletions tests/isatab/test_isatab.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,14 @@ def test_isatab_load_sdata201414_isa1(self):
self.assertEqual(len(ISA.studies[0].contacts[1].comments), 5) # 5 comments in contact
self.assertListEqual([a.filename for a in ISA.studies[0].assays], ['a_chambers.txt']) # 1 assays in s_chambers.txt

def test_isatab_load_bii_s_test(self):
with open(os.path.join(self._tab_data_dir, 'BII-S-TEST', 'i_test.txt')) as fp:
ISA = isatab.load(fp)

self.assertEqual(len(ISA.studies[0].assays[0].other_material), 8)
self.assertEqual(ISA.studies[0].assays[0].other_material[1].type, "Labeled Extract Name")


def test_isatab_load_bii_i_1(self):
with open(os.path.join(self._tab_data_dir, 'BII-I-1', 'i_investigation.txt')) as fp:
ISA = isatab.load(fp)
Expand Down

0 comments on commit 195cf71

Please sign in to comment.