From a6a12537af2f448a3de119ab026f974eca09569c Mon Sep 17 00:00:00 2001 From: Maarten van der Sande Date: Mon, 9 Dec 2019 15:50:53 +0100 Subject: [PATCH 1/7] Fasta more dict-like behaviour --- pyfaidx/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyfaidx/__init__.py b/pyfaidx/__init__.py index 2978c88..64cc503 100644 --- a/pyfaidx/__init__.py +++ b/pyfaidx/__init__.py @@ -998,6 +998,8 @@ def __init__(self, rebuild=rebuild, build_index=build_index) self.keys = self.faidx.index.keys + self.values = self.faidx.index.values + self.items = self.faidx.index.items if not self.mutable: self.records = dict( [(rname, FastaRecord(rname, self)) for rname in self.keys()]) From 99a9f69ee62cbe07bbaea21720b31f51052d6ee8 Mon Sep 17 00:00:00 2001 From: Maarten van der Sande Date: Tue, 10 Dec 2019 14:03:42 +0100 Subject: [PATCH 2/7] add keys, values, items to Fasta class --- pyfaidx/__init__.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pyfaidx/__init__.py b/pyfaidx/__init__.py index 64cc503..9307958 100644 --- a/pyfaidx/__init__.py +++ b/pyfaidx/__init__.py @@ -997,9 +997,6 @@ def __init__(self, sequence_always_upper=sequence_always_upper, rebuild=rebuild, build_index=build_index) - self.keys = self.faidx.index.keys - self.values = self.faidx.index.values - self.items = self.faidx.index.items if not self.mutable: self.records = dict( [(rname, FastaRecord(rname, self)) for rname in self.keys()]) @@ -1062,6 +1059,15 @@ def get_spliced_seq(self, name, intervals, rc=False): # len(Sequence.seq) != end - start return Sequence(name=name, seq=seq, start=None, end=None) + def keys(self): + return self.records.keys() + + def values(self): + return self.records.values() + + def items(self): + return self.records.items() + def close(self): self.__exit__() From cede320452bd920ac187d3af173004901ac02746 Mon Sep 17 00:00:00 2001 From: Maarten van der Sande Date: Tue, 10 Dec 2019 14:40:24 +0100 Subject: [PATCH 3/7] minor keys bug fix and list comprehension to dict comprehension --- pyfaidx/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pyfaidx/__init__.py b/pyfaidx/__init__.py index 9307958..9744e7d 100644 --- a/pyfaidx/__init__.py +++ b/pyfaidx/__init__.py @@ -998,11 +998,12 @@ def __init__(self, rebuild=rebuild, build_index=build_index) if not self.mutable: - self.records = dict( - [(rname, FastaRecord(rname, self)) for rname in self.keys()]) + self.records = {rname: FastaRecord(rname, self) + for rname in self.faidx.index.keys()} elif self.mutable: - self.records = dict([(rname, MutableFastaRecord(rname, self)) - for rname in self.keys()]) + self.records = {rname: MutableFastaRecord(rname, self) + for rname in self.faidx.index.keys()} + def __contains__(self, rname): """Return True if genome contains record.""" @@ -1060,6 +1061,7 @@ def get_spliced_seq(self, name, intervals, rc=False): return Sequence(name=name, seq=seq, start=None, end=None) def keys(self): + print('using our keys') return self.records.keys() def values(self): From 2f82d43b01c8b035c3193a4543fb071d412cbb45 Mon Sep 17 00:00:00 2001 From: Maarten van der Sande Date: Tue, 10 Dec 2019 14:42:02 +0100 Subject: [PATCH 4/7] remove debugging print --- pyfaidx/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyfaidx/__init__.py b/pyfaidx/__init__.py index 9744e7d..d1ce64a 100644 --- a/pyfaidx/__init__.py +++ b/pyfaidx/__init__.py @@ -1061,7 +1061,6 @@ def get_spliced_seq(self, name, intervals, rc=False): return Sequence(name=name, seq=seq, start=None, end=None) def keys(self): - print('using our keys') return self.records.keys() def values(self): From 990a22c9719e6bf3a98d9c053d15d3137badcf14 Mon Sep 17 00:00:00 2001 From: Matt Shirley Date: Tue, 10 Dec 2019 09:27:39 -0500 Subject: [PATCH 5/7] Add some debugging for #156 failing test --- tests/test_FastaRecord.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_FastaRecord.py b/tests/test_FastaRecord.py index f8eb9c1..72a525c 100644 --- a/tests/test_FastaRecord.py +++ b/tests/test_FastaRecord.py @@ -46,6 +46,7 @@ def test_long_names(self): long_names = [] for record in fasta: long_names.append(record.long_name) + print(tuple(zip(deflines, long_names))) assert deflines == long_names def test_issue_62(self): From 8995223895eccd82b868375b97f91476c7d46d0b Mon Sep 17 00:00:00 2001 From: Matt Shirley Date: Tue, 10 Dec 2019 09:52:00 -0500 Subject: [PATCH 6/7] Fix for record insertion order in #156 --- pyfaidx/__init__.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pyfaidx/__init__.py b/pyfaidx/__init__.py index d1ce64a..b95fdf5 100644 --- a/pyfaidx/__init__.py +++ b/pyfaidx/__init__.py @@ -997,13 +997,9 @@ def __init__(self, sequence_always_upper=sequence_always_upper, rebuild=rebuild, build_index=build_index) - if not self.mutable: - self.records = {rname: FastaRecord(rname, self) - for rname in self.faidx.index.keys()} - elif self.mutable: - self.records = {rname: MutableFastaRecord(rname, self) - for rname in self.faidx.index.keys()} - + + _record_constructor = MutableFastaRecord if self.mutable else FastaRecord + self.records = OrderedDict([(rname, _record_constructor(rname, self)) for rname in self.faidx.index.keys()]) def __contains__(self, rname): """Return True if genome contains record.""" From 80ad2737faf853a33026fb8f6bc40678008827b6 Mon Sep 17 00:00:00 2001 From: Matt Shirley Date: Tue, 10 Dec 2019 10:06:07 -0500 Subject: [PATCH 7/7] Bump version for release --- pyfaidx/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfaidx/__init__.py b/pyfaidx/__init__.py index b95fdf5..3761535 100644 --- a/pyfaidx/__init__.py +++ b/pyfaidx/__init__.py @@ -25,7 +25,7 @@ dna_bases = re.compile(r'([ACTGNactgnYRWSKMDVHBXyrwskmdvhbx]+)') -__version__ = '0.5.6' +__version__ = '0.5.7' class KeyFunctionError(ValueError):