Skip to content

Commit 4f27999

Browse files
committed
Merge branch 'develop'
2 parents f71ddbf + 317dbf6 commit 4f27999

14 files changed

+76
-160
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
sudo: false
12
language: python
3+
cache: pip
24
python:
3-
- '3.6'
5+
- 3.6
46
before_install:
57
- bash -x get_test_data.sh
68
install:

isatools/convert/isatab2w4m.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515

1616
from isatools import isatab as ISATAB
17+
from isatools.utils import utf8_text_file_open
1718

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

336337
def load_investigation(investigation_file):
337-
f = open(investigation_file, 'r')
338+
f = utf8_text_file_open(investigation_file)
338339
investigation = ISATAB.load(f)
339340
return investigation
340341

@@ -364,8 +365,10 @@ def get_sample_names(assay_df, measures_df):
364365

365366
def make_sample_metadata(study_df, assay_df, sample_names, normalize=True):
366367
# Normalize column names
367-
study_df.set_axis(axis=1, labels=make_names(study_df.axes[1].tolist()))
368-
assay_df.set_axis(axis=1, labels=make_names(assay_df.axes[1].tolist()))
368+
study_df.set_axis(
369+
inplace=True, axis=1, labels=make_names(study_df.axes[1].tolist()))
370+
assay_df.set_axis(
371+
inplace=True, axis=1, labels=make_names(assay_df.axes[1].tolist()))
369372

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

380383
return sample_metadata
@@ -395,7 +398,7 @@ def make_variable_metadata(measures_df, sample_names, variable_names,
395398

396399
# Normalize
397400
if normalize:
398-
variable_metadata.set_axis(axis=1, labels=make_names(
401+
variable_metadata.set_axis(inplace=True, axis=1, labels=make_names(
399402
variable_metadata.axes[1].tolist(), uniq=True))
400403

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

427431
return sample_variable_matrix
428432

isatools/isatab.py

Lines changed: 43 additions & 45 deletions
Large diffs are not rendered by default.

isatools/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import uuid
99
from functools import reduce
1010
from zipfile import ZipFile
11+
import sys
1112

1213

1314
from isatools import isatab
@@ -866,3 +867,11 @@ def remove_unused_protocols(self):
866867
investigation, output_path=os.path.dirname(self.path),
867868
i_file_name='{filename}.fix'.format(
868869
filename=os.path.basename(self.path)), skip_dump_tables=True)
870+
871+
872+
def utf8_text_file_open(path):
873+
if sys.version_info[0] < 3:
874+
fp = open(path, 'rb')
875+
else:
876+
fp = open(path, 'r', newline='', encoding='utf8')
877+
return fp

requirements-tests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
numpy
22
jsonschema
3-
pandas==0.20.*
3+
pandas
44
networkx
55
behave
66
httpretty

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
numpy
22
jsonschema
3-
pandas==0.20.*
3+
pandas
44
networkx
55
lxml
66
requests

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setup(
66
name='isatools',
7-
version='0.10.2',
7+
version='0.10.3',
88
packages=['isatools',
99
'isatools.convert',
1010
'isatools.create',
@@ -48,7 +48,7 @@
4848
install_requires=[
4949
'numpy',
5050
'jsonschema',
51-
'pandas==0.20.*',
51+
'pandas',
5252
'networkx',
5353
'lxml',
5454
'requests',

tests/test_create_models_json.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ def test_serialize_ms_assay_topology_modifiers(self):
150150
json.dumps(top_mods, cls=SampleAssayPlanEncoder)
151151
)
152152
)
153-
print(json.dumps(top_mods, cls=SampleAssayPlanEncoder, indent=4))
154153
self.assertTrue(expected == actual)
155154

156155
@unittest.skip(

tests/test_create_models_study_design.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,9 +867,7 @@ def test_study_from_2_level_factorial_plan(self):
867867
study = IsaModelObjectFactory(study_design).create_assays_from_plan()
868868
self.assertEqual(len(study.assays), 6)
869869
self.assertEqual(len(study.protocols), 4)
870-
study.filename = 's_study.txt'
871-
from isatools import isatab
872-
print(isatab.dumps(Investigation(studies=[study])))
870+
873871

874872
def test_study_from_2_by_3_by_2_factorial_plan(self):
875873
factor1 = StudyFactor(name='1')

tests/test_isatab.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from isatools.model import *
1414
from isatools.tests.utils import assert_tab_content_equal
1515
from isatools.tests import utils
16+
from isatools.isatab import IsaTabDataFrame
1617

1718

1819
def setUpModule():
@@ -911,8 +912,7 @@ def test_source_protocol_ref_sample(self):
911912
factory = ProcessSequenceFactory(study_protocols=[Protocol(name="sample collection")])
912913
table_to_load = """Source Name\tProtocol REF\tSample Name
913914
source1\tsample collection\tsample1"""
914-
DF = pd.read_csv(StringIO(table_to_load), sep='\t')
915-
DF.isatab_header = ["Source Name", "Protocol REF", "Sample Name"]
915+
DF = IsaTabDataFrame(pd.read_csv(StringIO(table_to_load), sep='\t'))
916916
so, sa, om, d, pr, _, __ = factory.create_from_df(DF)
917917
self.assertEqual(len(so), 1)
918918
self.assertEqual(len(sa), 1)
@@ -925,8 +925,7 @@ def test_source_protocol_ref_sample_x2(self):
925925
table_to_load = """Source Name\tProtocol REF\tSample Name
926926
source1\tsample collection\tsample1
927927
source2\tsample collection\tsample2"""
928-
DF = pd.read_csv(StringIO(table_to_load), sep='\t')
929-
DF.isatab_header = ["Source Name", "Protocol REF", "Sample Name"]
928+
DF = IsaTabDataFrame(pd.read_csv(StringIO(table_to_load), sep='\t'))
930929
so, sa, om, d, pr, _, __ = factory.create_from_df(DF)
931930
self.assertEqual(len(so), 2)
932931
self.assertEqual(len(sa), 2)
@@ -939,8 +938,7 @@ def test_source_protocol_ref_split_sample(self):
939938
table_to_load = """Source Name\tProtocol REF\tSample Name
940939
source1\tsample collection\tsample1
941940
source1\tsample collection\tsample2"""
942-
DF = pd.read_csv(StringIO(table_to_load), sep='\t')
943-
DF.isatab_header = ["Source Name", "Protocol REF", "Sample Name"]
941+
DF = IsaTabDataFrame(pd.read_csv(StringIO(table_to_load), sep='\t'))
944942
so, sa, om, d, pr, _, __ = factory.create_from_df(DF)
945943
self.assertEqual(len(so), 1)
946944
self.assertEqual(len(sa), 2)
@@ -953,8 +951,7 @@ def test_source_protocol_ref_pool_sample(self):
953951
table_to_load = """Source Name\tProtocol REF\tSample Name
954952
source1\tsample collection\tsample1
955953
source2\tsample collection\tsample1"""
956-
DF = pd.read_csv(StringIO(table_to_load), sep='\t')
957-
DF.isatab_header = ["Source Name", "Protocol REF", "Sample Name"]
954+
DF = IsaTabDataFrame(pd.read_csv(StringIO(table_to_load), sep='\t'))
958955
so, sa, om, d, pr, _, __ = factory.create_from_df(DF)
959956
self.assertEqual(len(so), 2)
960957
self.assertEqual(len(sa), 1)
@@ -969,8 +966,7 @@ def test_sample_protocol_ref_split_extract_protocol_ref_data(self):
969966
table_to_load = """Sample Name\tProtocol REF\tExtract Name\tProtocol REF\tRaw Data File
970967
sample1\textraction\te1\tscanning\td1
971968
sample1\textraction\te2\tscanning\td2"""
972-
DF = pd.read_csv(StringIO(table_to_load), sep='\t')
973-
DF.isatab_header = ["Source Name", "Protocol REF", "Extract Name", "Protocol REF", "Raw Data File"]
969+
DF = IsaTabDataFrame(pd.read_csv(StringIO(table_to_load), sep='\t'))
974970
so, sa, om, d, pr, _, __ = factory.create_from_df(DF)
975971
self.assertEqual(len(so), 0)
976972
self.assertEqual(len(sa), 1)

0 commit comments

Comments
 (0)