Skip to content

Commit

Permalink
fixes #569
Browse files Browse the repository at this point in the history
  • Loading branch information
proccaserra committed Sep 9, 2024
1 parent 339db38 commit 95a788c
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 16 deletions.
3 changes: 3 additions & 0 deletions isatools/isatab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
write_study_table_files,
write_assay_table_files,
write_value_columns,
flatten,

dump_tables_to_dataframes
)
from isatools.isatab.load import (
Expand All @@ -18,3 +20,4 @@
from isatools.isatab.defaults import default_config_dir
from isatools.isatab.utils import IsaTabDataFrame, TransposedTabParser
from isatools.isatab.validate import validate, batch_validate

2 changes: 1 addition & 1 deletion isatools/isatab/dump/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from isatools.isatab.dump.core import dump, dumps, dump_tables_to_dataframes
from isatools.isatab.dump.write import write_study_table_files, write_assay_table_files, write_value_columns
from isatools.isatab.dump.write import write_study_table_files, write_assay_table_files, write_value_columns, flatten
28 changes: 20 additions & 8 deletions isatools/isatab/dump/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@
)


def flatten(current_list) -> list:
"""
:rtype: object
:param current_list: List
:return: flattened_listL: List
"""
flattened_list = []
if current_list is not None:

for sublist in current_list:
if sublist is not None:
for item in sublist:
flattened_list.append(item)
else:
raise ValueError
else:
raise ValueError
return flattened_list


def write_study_table_files(inv_obj, output_dir):
"""Writes out study table files according to pattern defined by
Expand All @@ -49,10 +69,6 @@ def write_study_table_files(inv_obj, output_dir):
break
protrefcount = 0
protnames = dict()

def flatten(current_list):
return [item for sublist in current_list for item in sublist]

columns = []

# start_nodes, end_nodes = _get_start_end_nodes(s_graph)
Expand Down Expand Up @@ -255,10 +271,6 @@ def write_assay_table_files(inv_obj, output_dir, write_factor_values=False):
break
protrefcount = 0
protnames = dict()

def flatten(current_list):
return [item for sublist in current_list for item in sublist]

columns = []

paths, indexes = _build_paths_and_indexes(assay_obj.process_sequence)
Expand Down
9 changes: 7 additions & 2 deletions isatools/isatab/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,15 @@ def get_pv_columns(label, pv):
"""
columns = None
try:
columns = ["{0}.Parameter Value[{1}]".format(label, pv.category.parameter_name.term)]
if pv.category is not None:
columns = ["{0}.Parameter Value[{1}]".format(label, pv.category.parameter_name.term)]
print(columns)
else:
raise ValueError
except AttributeError:
log.fatal(label, pv)
columns.extend(get_value_columns(columns[0], pv))
if columns is not None:
columns.extend(get_value_columns(columns[0], pv))
return columns


Expand Down
2 changes: 1 addition & 1 deletion isatools/model/parameter_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, category=None, value=None, unit=None, comments=None):

# Shouldn't this be in the setter to avoid manually setting a non-numerical value when a unit is supplied ?
if not isinstance(value, Number) and unit:
raise ValueError("ParameterValue value mus be quantitative (i.e. numeric) if a unit is supplied")
raise ValueError("ParameterValue value must be quantitative (i.e. numeric) if a unit is supplied")
self.value = value
self.unit = unit

Expand Down
2 changes: 1 addition & 1 deletion isatools/net/mw2isa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def getblock(container, start_marker, end_marker):


def get_archived_file(mw_study_id):
"""A method of download Metabolomics Workbench archived data from their anonymous FTP site input: a valid Metabolomics
""" A method of download Metabolomics Workbench archived data from their anonymous FTP site input: a valid Metabolomics
Workbench study accession number that should follow this pattern ^ST\d+[6]
:param mw_study_id -> str
:return: success -> boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"id": "https://raw.githubusercontent.com/ISA-tools/isa-api/master/isatools/resources/schemas/isa_model_version_1_0_schemas/core/comment_schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "ISA Comment schema - it corresponds to ISA Comment[] construct",
Expand Down
22 changes: 21 additions & 1 deletion tests/isatab/test_isatab.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
)
from isatools.tests.utils import assert_tab_content_equal
from isatools.tests import utils
from isatools.isatab import IsaTabDataFrame
from isatools.isatab import IsaTabDataFrame, flatten

from isatools.isatab.utils import (
get_comment_column,
get_pv_columns
)

def setUpModule():
if not os.path.exists(utils.DATA_DIR):
Expand Down Expand Up @@ -94,6 +98,22 @@ def setUp(self):
def tearDown(self):
shutil.rmtree(self._tmp_dir)

def test_isatab_flatten(self):
test_list = None
with self.assertRaises(ValueError):
flatten(test_list)

def test_isatab_get_pv_columns(self):
columns = []
pp = ProtocolParameter(parameter_name="test_parameter_name")
with self.assertRaises(AttributeError):
pv = ParameterValue(category="test_parameter_name", value=3)
get_pv_columns("Protocol REF", pv)

with self.assertRaises(AttributeError):
pv = ParameterValue(category=pp.parameter_name, value=3)
get_pv_columns("Protocol REF", pv)

def test_isatab_bad_i_file_name(self):
with self.assertRaises(NameError):
isatab.dump(Investigation(), self._tmp_dir, i_file_name='investigation.txt')
Expand Down
2 changes: 1 addition & 1 deletion tests/model/test_parameter_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_init(self):
with self.assertRaises(ValueError) as context:
ParameterValue(unit=OntologyAnnotation())
self.assertEqual(str(context.exception),
"ParameterValue value mus be quantitative (i.e. numeric) if a unit is supplied")
"ParameterValue value must be quantitative (i.e. numeric) if a unit is supplied")

def test_category(self):
self.assertIsNone(self.parameter.category)
Expand Down

0 comments on commit 95a788c

Please sign in to comment.