11from copy import deepcopy
22from Bio .SeqRecord import SeqRecord
33from ..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+
514from ...biotools import set_record_topology , crop_record_with_saddling_features
615
716
817class 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
0 commit comments