Skip to content

Commit 686016d

Browse files
committed
RF: reproin - remove binding of fixup data structures in function signatures
Binding in signatured forbided easy rebinding of them to new values at the module level.
1 parent 35e2ef9 commit 686016d

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

heudiconv/heuristics/reproin.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -372,14 +372,14 @@ def get_study_hash(seqinfo):
372372
return md5sum(get_study_description(seqinfo))
373373

374374

375-
def fix_canceled_runs(seqinfo, accession2run=fix_accession2run):
375+
def fix_canceled_runs(seqinfo):
376376
"""Function that adds cancelme_ to known bad runs which were forgotten
377377
"""
378378
accession_number = get_unique(seqinfo, 'accession_number')
379-
if accession_number in accession2run:
379+
if accession_number in fix_accession2run:
380380
lgr.info("Considering some runs possibly marked to be "
381381
"canceled for accession %s", accession_number)
382-
badruns = accession2run[accession_number]
382+
badruns = fix_accession2run[accession_number]
383383
badruns_pattern = '|'.join(badruns)
384384
for i, s in enumerate(seqinfo):
385385
if re.match(badruns_pattern, s.series_id):
@@ -391,13 +391,9 @@ def fix_canceled_runs(seqinfo, accession2run=fix_accession2run):
391391
return seqinfo
392392

393393

394-
def fix_dbic_protocol(seqinfo, keys=None, subsdict=None):
394+
def fix_dbic_protocol(seqinfo):
395395
"""Ad-hoc fixup for existing protocols
396396
"""
397-
if subsdict is None:
398-
subsdict = protocols2fix
399-
if keys is None:
400-
keys = series_spec_fields
401397

402398
study_hash = get_study_hash(seqinfo)
403399

@@ -408,14 +404,14 @@ def fix_dbic_protocol(seqinfo, keys=None, subsdict=None):
408404
('global', ''),
409405
)
410406
for subs_scope, subs_key in candidate_substitutions:
411-
if subs_key not in subsdict:
407+
if subs_key not in protocols2fix:
412408
continue
413-
substitutions = subsdict[subs_key]
409+
substitutions = protocols2fix[subs_key]
414410
lgr.info("Considering %s substitutions", subs_scope)
415411
for i, s in enumerate(seqinfo):
416412
fixed_kwargs = dict()
417413
# need to replace both protocol_name series_description
418-
for key in keys:
414+
for key in series_spec_fields:
419415
value = getattr(s, key)
420416
# replace all I need to replace
421417
for substring, replacement in substitutions:

heudiconv/heuristics/test_reproin.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# Tests for reproin.py
33
#
44
from collections import OrderedDict
5+
from mock import patch
6+
7+
from . import reproin
58
from .reproin import (
69
filter_files,
710
fix_canceled_runs,
@@ -78,7 +81,8 @@ def test_fix_canceled_runs():
7881
'accession1': ['^01-', '^03-']
7982
}
8083

81-
seqinfo_ = fix_canceled_runs(seqinfo, fake_accession2run)
84+
with patch.object(reproin, 'fix_accession2run', fake_accession2run):
85+
seqinfo_ = fix_canceled_runs(seqinfo)
8286

8387
for i, s in enumerate(seqinfo_, 1):
8488
output = runname
@@ -108,14 +112,15 @@ def test_fix_dbic_protocol():
108112

109113

110114
seqinfos = [seq1, seq2]
111-
keys = ['field1']
112-
subsdict = {
115+
protocols2fix = {
113116
md5sum('mystudy'):
114117
[('scout_run\+', 'scout'),
115118
('run-life[0-9]', 'run+_task-life')],
116119
}
117120

118-
seqinfos_ = fix_dbic_protocol(seqinfos, keys=keys, subsdict=subsdict)
121+
with patch.object(reproin, 'protocols2fix', protocols2fix), \
122+
patch.object(reproin, 'series_spec_fields', ['field1']):
123+
seqinfos_ = fix_dbic_protocol(seqinfos)
119124
assert(seqinfos[1] == seqinfos_[1])
120125
# field2 shouldn't have changed since I didn't pass it
121126
assert(seqinfos_[0] == FakeSeqInfo(accession_number,
@@ -124,8 +129,9 @@ def test_fix_dbic_protocol():
124129
seq1.field2))
125130

126131
# change also field2 please
127-
keys = ['field1', 'field2']
128-
seqinfos_ = fix_dbic_protocol(seqinfos, keys=keys, subsdict=subsdict)
132+
with patch.object(reproin, 'protocols2fix', protocols2fix), \
133+
patch.object(reproin, 'series_spec_fields', ['field1', 'field2']):
134+
seqinfos_ = fix_dbic_protocol(seqinfos)
129135
assert(seqinfos[1] == seqinfos_[1])
130136
# now everything should have changed
131137
assert(seqinfos_[0] == FakeSeqInfo(accession_number,

0 commit comments

Comments
 (0)