Skip to content

Commit 962822c

Browse files
authored
Merge pull request #4 from Edinburgh-Genome-Foundry/dev
Biopython v1.78 compatibility
2 parents 0892ace + b61b7e7 commit 962822c

File tree

12 files changed

+258
-190
lines changed

12 files changed

+258
-190
lines changed

LICENCE.txt

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
2-
The MIT License (MIT)
3-
[OSI Approved License]
4-
5-
The MIT License (MIT)
1+
MIT License
62

73
Copyright (c) 2020 Edinburgh Genome Foundry
84

@@ -13,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
139
copies of the Software, and to permit persons to whom the Software is
1410
furnished to do so, subject to the following conditions:
1511

16-
The above copyright notice and this permission notice shall be included in
17-
all copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
1814

1915
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2016
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2117
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2218
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2319
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25-
THE SOFTWARE.
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

dnacauldron/Fragment/Fragment.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def from_biopython_record(biopython_record):
1919

2020
def plot(self, ax=None):
2121
"""Plot the fragment and its features on a Matplotlib ax.
22-
22+
2323
This creates a new ax if no ax is provided. The ax is returned at the
2424
end.
2525
"""
@@ -37,9 +37,9 @@ def reverse_complement(self):
3737

3838
def to_standard_string(self):
3939
"""Return a standard string to represent and identify the fragment.
40-
40+
4141
This method is used to standardize and recognize similar FragmentChain
42-
instances.
42+
instances.
4343
"""
4444

4545
return str(self.seq)
@@ -53,13 +53,11 @@ def create_homology_annotation(
5353
"ApEinfo_fwdcolor": color,
5454
}
5555
return SeqFeature(
56-
FeatureLocation(start, end),
57-
type=annotation_type,
58-
qualifiers=qualifiers,
56+
FeatureLocation(start, end), type=annotation_type, qualifiers=qualifiers,
5957
)
60-
58+
6159
def text_representation_in_plots(self):
6260
return r"$\bf{%s}$" % self.original_part.id
63-
64-
def as_bioptyhon_record(self):
61+
62+
def as_biopython_record(self):
6563
return self

dnacauldron/Fragment/HomologousFragment/HomologousFragment.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
from copy import deepcopy
22
from Bio.SeqRecord import SeqRecord
33
from ..Fragment import Fragment
4-
from Bio.Alphabet import DNAAlphabet
4+
5+
try:
6+
# Biopython <1.78
7+
from Bio.Alphabet import DNAAlphabet
8+
9+
has_dna_alphabet = True
10+
except ImportError:
11+
# Biopython >=1.78
12+
has_dna_alphabet = False
13+
514
from ...biotools import set_record_topology, crop_record_with_saddling_features
615

716

817
class HomologousFragment(Fragment):
918
@staticmethod
1019
def from_biopython_record(biopython_record):
11-
"""Convert a biopython record into a HomologousFragment (class change).
20+
"""Convert a Biopython record into a HomologousFragment (class change).
1221
"""
1322
new_record = deepcopy(biopython_record)
1423
new_record.original_part = biopython_record
1524
new_record.__class__ = HomologousFragment
1625
return new_record
1726

1827
def circularized(
19-
self,
20-
homology_checker,
21-
annotate_homology=False,
22-
annotation_type="homology",
28+
self, homology_checker, annotate_homology=False, annotation_type="homology",
2329
):
24-
"""Return the biopython record obtained by cirularizing the result.
30+
"""Return the Biopython record obtained by cirularizing the result.
2531
2632
Only works if the left and right sticky ends are compatible. The
2733
return is a simple Biopython record where the sticky end has been
@@ -33,8 +39,10 @@ def circularized(
3339
annotate_homology=True,
3440
annotation_type="homology",
3541
)
42+
3643
def only_parts_indicators(feature):
3744
return feature.qualifiers.get("indicates_part", False)
45+
3846
result = crop_record_with_saddling_features(
3947
record=double_self,
4048
start=len(self),
@@ -64,13 +72,11 @@ def _push_source_features(self, homology_size, side="left"):
6472
def will_clip_in_this_order_with(self, other_fragment, homology_checker):
6573
"""Return whether the fragment will assemble with anoter via homology
6674
recombination.
67-
75+
6876
homology_checker should be an HomologyChecker instance definining the
6977
homology conditions.
7078
"""
71-
homology_size = homology_checker.find_end_homologies(
72-
self, other_fragment
73-
)
79+
homology_size = homology_checker.find_end_homologies(self, other_fragment)
7480
return homology_size > 0
7581

7682
def assemble_with(
@@ -82,16 +88,16 @@ def assemble_with(
8288
):
8389
"""Return the fragment resulting from the assembly of this fragment
8490
with another, in that order.
85-
91+
8692
Parameters
8793
----------
88-
94+
8995
fragment
90-
The other parameter to assemble with
91-
96+
The other parameter to assemble with.
97+
9298
homology_checker
9399
An HomologyChecker instance definining the homology conditions.
94-
100+
95101
annotate_homology
96102
If true, homologies will have an annotation in the final, predicted
97103
construct records.
@@ -130,30 +136,25 @@ def only_parts_indicators(feature):
130136

131137
@staticmethod
132138
def assemble(
133-
fragments,
134-
homology_checker,
135-
circularize=False,
136-
annotate_homologies=False,
139+
fragments, homology_checker, circularize=False, annotate_homologies=False,
137140
):
138141
"""Return the record obtained by assembling the fragments.
139142
140143
Parameters
141144
----------
142145
143146
fragments
144-
List of HomologousFragments to assemble
147+
List of HomologousFragments to assemble.
145148
146149
homology_checker
147150
An HomologyChecker instance definining the homology conditions.
148-
151+
149152
circularize
150153
True to also assemble the end flanks of the final construct.
151154
152155
annotate_homologies
153156
If true, homologies will have an annotation in the final, predicted
154157
construct records.
155-
156-
157158
"""
158159
result = fragments[0]
159160
for fragment in fragments[1:]:
@@ -167,5 +168,9 @@ def assemble(
167168
annotate_homology=annotate_homologies,
168169
homology_checker=homology_checker,
169170
)
170-
result.seq.alphabet = DNAAlphabet()
171+
172+
if has_dna_alphabet: # Biopython <1.78
173+
result.seq.alphabet = DNAAlphabet()
174+
result.annotations["molecule_type"] = "DNA"
175+
171176
return result

dnacauldron/Fragment/StickyEndFragment/StickyEnd.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
from Bio.Seq import Seq
2+
3+
try:
4+
# Biopython <1.78
5+
from Bio.Alphabet import DNAAlphabet
6+
7+
has_dna_alphabet = True
8+
except ImportError:
9+
# Biopython >=1.78
10+
has_dna_alphabet = False
211
from ...biotools import sequence_to_biopython_record, annotate_record
312

13+
414
class StickyEnd(Seq):
515
"""A class to represent the sticky end of a sequence.
616
@@ -10,10 +20,10 @@ class StickyEnd(Seq):
1020
----------
1121
1222
data
13-
A DNA sequence in ATGC format
23+
A DNA sequence in ATGC format.
1424
1525
strand
16-
The strand (+1 or -1) on which the protusion is
26+
The strand (+1 or -1) on which the protusion is.
1727
1828
**k
1929
Optional keyword arguments for the sequence, such as ``alphabet`` etc.
@@ -24,11 +34,15 @@ def __init__(self, data, strand, **k):
2434
self.strand = strand
2535

2636
def reverse_complement(self):
27-
return StickyEnd(
28-
str(Seq.reverse_complement(self)),
29-
strand=-self.strand,
30-
alphabet=self.alphabet,
31-
)
37+
38+
if has_dna_alphabet: # Biopython <1.78
39+
return StickyEnd(
40+
str(Seq.reverse_complement(self)),
41+
strand=-self.strand,
42+
alphabet=self.alphabet,
43+
)
44+
else:
45+
return StickyEnd(str(Seq.reverse_complement(self)), strand=-self.strand,)
3246

3347
def __repr__(self):
3448
return "%s(%s)" % (Seq.__str__(self), {1: "+", -1: "-"}[self.strand])
@@ -40,10 +54,9 @@ def will_clip_directly_with(self, other):
4054
and (self.strand == -other.strand)
4155
and (str(self) == str(other))
4256
)
43-
57+
4458
def as_biopython_record(self):
4559
record = sequence_to_biopython_record(str(self))
4660
sign = "+" if self.strand == 1 else "-"
4761
annotate_record(record, label="(%s) strand" % sign)
4862
return record
49-

0 commit comments

Comments
 (0)