Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
djcomlab committed Aug 8, 2018
2 parents f71ddbf + 317dbf6 commit 4f27999
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 160 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
sudo: false
language: python
cache: pip
python:
- '3.6'
- 3.6
before_install:
- bash -x get_test_data.sh
install:
Expand Down
16 changes: 10 additions & 6 deletions isatools/convert/isatab2w4m.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


from isatools import isatab as ISATAB
from isatools.utils import utf8_text_file_open

# original from https://github.com/workflow4metabolomics/mtbls-dwnld/blob/develop/isatab2w4m.py
__author__ = 'pkrog (Pierrick Roger)'
Expand Down Expand Up @@ -334,7 +335,7 @@ def get_investigation_file(input_dir):
################################################################

def load_investigation(investigation_file):
f = open(investigation_file, 'r')
f = utf8_text_file_open(investigation_file)
investigation = ISATAB.load(f)
return investigation

Expand Down Expand Up @@ -364,8 +365,10 @@ def get_sample_names(assay_df, measures_df):

def make_sample_metadata(study_df, assay_df, sample_names, normalize=True):
# Normalize column names
study_df.set_axis(axis=1, labels=make_names(study_df.axes[1].tolist()))
assay_df.set_axis(axis=1, labels=make_names(assay_df.axes[1].tolist()))
study_df.set_axis(
inplace=True, axis=1, labels=make_names(study_df.axes[1].tolist()))
assay_df.set_axis(
inplace=True, axis=1, labels=make_names(assay_df.axes[1].tolist()))

# Merge data frames
sample_metadata = assay_df.merge(study_df, on='Sample.Name', sort=False)
Expand All @@ -374,7 +377,7 @@ def make_sample_metadata(study_df, assay_df, sample_names, normalize=True):
if normalize:
norm_sample_names = make_names(sample_names, uniq=True)
sample_metadata.insert(0, 'sample.name', norm_sample_names)
sample_metadata.set_axis(axis=1, labels=make_names(
sample_metadata.set_axis(inplace=True, axis=1, labels=make_names(
sample_metadata.axes[1].tolist(), uniq=True))

return sample_metadata
Expand All @@ -395,7 +398,7 @@ def make_variable_metadata(measures_df, sample_names, variable_names,

# Normalize
if normalize:
variable_metadata.set_axis(axis=1, labels=make_names(
variable_metadata.set_axis(inplace=True, axis=1, labels=make_names(
variable_metadata.axes[1].tolist(), uniq=True))

return variable_metadata
Expand All @@ -422,7 +425,8 @@ def make_matrix(measures_df, sample_names, variable_names, normalize=True):
if normalize:
norm_sample_names = make_names(sample_names, uniq=True)
norm_sample_names.insert(0, 'variable.name')
sample_variable_matrix.set_axis(axis=1, labels=norm_sample_names)
sample_variable_matrix.set_axis(
inplace=True, axis=1, labels=norm_sample_names)

return sample_variable_matrix

Expand Down
88 changes: 43 additions & 45 deletions isatools/isatab.py

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions isatools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import uuid
from functools import reduce
from zipfile import ZipFile
import sys


from isatools import isatab
Expand Down Expand Up @@ -866,3 +867,11 @@ def remove_unused_protocols(self):
investigation, output_path=os.path.dirname(self.path),
i_file_name='{filename}.fix'.format(
filename=os.path.basename(self.path)), skip_dump_tables=True)


def utf8_text_file_open(path):
if sys.version_info[0] < 3:
fp = open(path, 'rb')
else:
fp = open(path, 'r', newline='', encoding='utf8')
return fp
2 changes: 1 addition & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
numpy
jsonschema
pandas==0.20.*
pandas
networkx
behave
httpretty
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
numpy
jsonschema
pandas==0.20.*
pandas
networkx
lxml
requests
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='isatools',
version='0.10.2',
version='0.10.3',
packages=['isatools',
'isatools.convert',
'isatools.create',
Expand Down Expand Up @@ -48,7 +48,7 @@
install_requires=[
'numpy',
'jsonschema',
'pandas==0.20.*',
'pandas',
'networkx',
'lxml',
'requests',
Expand Down
1 change: 0 additions & 1 deletion tests/test_create_models_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ def test_serialize_ms_assay_topology_modifiers(self):
json.dumps(top_mods, cls=SampleAssayPlanEncoder)
)
)
print(json.dumps(top_mods, cls=SampleAssayPlanEncoder, indent=4))
self.assertTrue(expected == actual)

@unittest.skip(
Expand Down
4 changes: 1 addition & 3 deletions tests/test_create_models_study_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,9 +867,7 @@ def test_study_from_2_level_factorial_plan(self):
study = IsaModelObjectFactory(study_design).create_assays_from_plan()
self.assertEqual(len(study.assays), 6)
self.assertEqual(len(study.protocols), 4)
study.filename = 's_study.txt'
from isatools import isatab
print(isatab.dumps(Investigation(studies=[study])))


def test_study_from_2_by_3_by_2_factorial_plan(self):
factor1 = StudyFactor(name='1')
Expand Down
16 changes: 6 additions & 10 deletions tests/test_isatab.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from isatools.model import *
from isatools.tests.utils import assert_tab_content_equal
from isatools.tests import utils
from isatools.isatab import IsaTabDataFrame


def setUpModule():
Expand Down Expand Up @@ -911,8 +912,7 @@ def test_source_protocol_ref_sample(self):
factory = ProcessSequenceFactory(study_protocols=[Protocol(name="sample collection")])
table_to_load = """Source Name\tProtocol REF\tSample Name
source1\tsample collection\tsample1"""
DF = pd.read_csv(StringIO(table_to_load), sep='\t')
DF.isatab_header = ["Source Name", "Protocol REF", "Sample Name"]
DF = IsaTabDataFrame(pd.read_csv(StringIO(table_to_load), sep='\t'))
so, sa, om, d, pr, _, __ = factory.create_from_df(DF)
self.assertEqual(len(so), 1)
self.assertEqual(len(sa), 1)
Expand All @@ -925,8 +925,7 @@ def test_source_protocol_ref_sample_x2(self):
table_to_load = """Source Name\tProtocol REF\tSample Name
source1\tsample collection\tsample1
source2\tsample collection\tsample2"""
DF = pd.read_csv(StringIO(table_to_load), sep='\t')
DF.isatab_header = ["Source Name", "Protocol REF", "Sample Name"]
DF = IsaTabDataFrame(pd.read_csv(StringIO(table_to_load), sep='\t'))
so, sa, om, d, pr, _, __ = factory.create_from_df(DF)
self.assertEqual(len(so), 2)
self.assertEqual(len(sa), 2)
Expand All @@ -939,8 +938,7 @@ def test_source_protocol_ref_split_sample(self):
table_to_load = """Source Name\tProtocol REF\tSample Name
source1\tsample collection\tsample1
source1\tsample collection\tsample2"""
DF = pd.read_csv(StringIO(table_to_load), sep='\t')
DF.isatab_header = ["Source Name", "Protocol REF", "Sample Name"]
DF = IsaTabDataFrame(pd.read_csv(StringIO(table_to_load), sep='\t'))
so, sa, om, d, pr, _, __ = factory.create_from_df(DF)
self.assertEqual(len(so), 1)
self.assertEqual(len(sa), 2)
Expand All @@ -953,8 +951,7 @@ def test_source_protocol_ref_pool_sample(self):
table_to_load = """Source Name\tProtocol REF\tSample Name
source1\tsample collection\tsample1
source2\tsample collection\tsample1"""
DF = pd.read_csv(StringIO(table_to_load), sep='\t')
DF.isatab_header = ["Source Name", "Protocol REF", "Sample Name"]
DF = IsaTabDataFrame(pd.read_csv(StringIO(table_to_load), sep='\t'))
so, sa, om, d, pr, _, __ = factory.create_from_df(DF)
self.assertEqual(len(so), 2)
self.assertEqual(len(sa), 1)
Expand All @@ -969,8 +966,7 @@ def test_sample_protocol_ref_split_extract_protocol_ref_data(self):
table_to_load = """Sample Name\tProtocol REF\tExtract Name\tProtocol REF\tRaw Data File
sample1\textraction\te1\tscanning\td1
sample1\textraction\te2\tscanning\td2"""
DF = pd.read_csv(StringIO(table_to_load), sep='\t')
DF.isatab_header = ["Source Name", "Protocol REF", "Extract Name", "Protocol REF", "Raw Data File"]
DF = IsaTabDataFrame(pd.read_csv(StringIO(table_to_load), sep='\t'))
so, sa, om, d, pr, _, __ = factory.create_from_df(DF)
self.assertEqual(len(so), 0)
self.assertEqual(len(sa), 1)
Expand Down
1 change: 0 additions & 1 deletion tests/test_isatab2json.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ def test_isatab2json_convert_repeated_measure(self):
actual_json = isatab2json.convert(
os.path.join(self._tab_data_dir, test_case), validate_first=False,
use_new_parser=True)
print(json.dumps(actual_json, indent=4))
with open(os.path.join(self._tmp_dir, 'isa.json'), 'w') as out_fp:
json.dump(actual_json, out_fp)
with open(os.path.join(self._tmp_dir, 'isa.json')) as actual_json:
Expand Down
83 changes: 0 additions & 83 deletions tests/test_json2isatab2json_convert.py

This file was deleted.

2 changes: 0 additions & 2 deletions tests/test_mw2isa.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ def test_conversion(self):
if success and validate:
log.info("conversion successful, invoking the validator for " + study_id)
with open(os.path.join(self._tmp_dir, study_id, 'i_investigation.txt')) as fp:
# print(isatab.dumps(isatab.load(fp)))
# fp.seek(0)
report = isatab.validate(fp)
print(report)
if len(report['errors']) > 0:
Expand Down
4 changes: 0 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,3 @@ envlist = py34,py35,py36
[testenv]
deps=-r{toxinidir}/requirements-tests.txt
commands=nosetests

[travis]
python =
3.6: py36

0 comments on commit 4f27999

Please sign in to comment.