Skip to content

Commit e78e1aa

Browse files
committed
updated to biopython latest alignment functions
1 parent 40d6372 commit e78e1aa

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

moleculekit/tools/modelling.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ def model_gaps(
105105
>>> res = model_gaps(mol, sequence, "0", "./promod.img") # doctest: +SKIP
106106
"""
107107
try:
108-
from Bio import pairwise2
109-
from Bio.Align import substitution_matrices
108+
from Bio.Align import PairwiseAligner, substitution_matrices
110109
except ImportError:
111110
raise ImportError(
112111
"You need to install the biopython package to use this function. Install it with `conda install biopython`."
@@ -131,18 +130,21 @@ def model_gaps(
131130

132131
molseq = mol.getSequence(dict_key="segid")[segid]
133132

133+
aligner = PairwiseAligner()
134+
aligner.mode = "global"
134135
# -11 is gap creation penalty. -1 is gap extension penalty. Taken from https://www.arabidopsis.org/Blast/BLASToptions.jsp BLASTP options
135-
alignments = pairwise2.align.globalds(sequence, molseq, blosum62, -11.0, -1.0)
136-
# elif segment_type == "nucleic":
137-
# alignments = pairwise2.align.globalxx(sequence, molseq)
136+
aligner.substitution_matrix = blosum62
137+
aligner.open_gap_score = -11.0
138+
aligner.extend_gap_score = -1.0
139+
alignments = aligner.align(sequence, molseq)
138140

139141
print(alignments[0])
140142

141143
fastafile = os.path.join(tmpdir, "input.fasta")
142144
with open(fastafile, "w") as f:
143145
# Need to add gaps to sequence
144146
f.write(f">REFERENCE\n{sequence}\n")
145-
f.write(f">{segid}\n{alignments[0].seqB}")
147+
f.write(f">{segid}\n{alignments[0][1]}")
146148

147149
runpy = os.path.join(tmpdir, "run.py")
148150
with open(runpy, "w") as f:

moleculekit/tools/sequencestructuralalignment.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,11 @@ def sequenceStructureAlignment(
163163
refsel = f"segid {refseg}"
164164

165165
try:
166-
from Bio import pairwise2
166+
from Bio.Align import PairwiseAligner, substitution_matrices
167167
except ImportError:
168168
raise ImportError(
169169
"You need to install the biopython package to use this function. Try using `conda install biopython`."
170170
)
171-
from Bio.Align import substitution_matrices
172171

173172
blosum62 = substitution_matrices.load("BLOSUM62")
174173

@@ -189,11 +188,20 @@ def sequenceStructureAlignment(
189188
)
190189
segment_type = segment_type_mol
191190

191+
aligner = PairwiseAligner()
192+
aligner.mode = "global"
192193
if segment_type == "protein":
193194
# -11 is gap creation penalty. -1 is gap extension penalty. Taken from https://www.arabidopsis.org/Blast/BLASToptions.jsp BLASTP options
194-
alignments = pairwise2.align.globalds(seqref, seqmol, blosum62, -11.0, -1.0)
195+
aligner.substitution_matrix = blosum62
196+
aligner.open_gap_score = -11.0
197+
aligner.extend_gap_score = -1.0
195198
elif segment_type == "nucleic":
196-
alignments = pairwise2.align.globalxx(seqref, seqmol)
199+
# Equivalent to the old pairwise2.align.globalxx: score matches only
200+
aligner.match_score = 1.0
201+
aligner.mismatch_score = 0.0
202+
aligner.open_gap_score = 0.0
203+
aligner.extend_gap_score = 0.0
204+
alignments = aligner.align(seqref, seqmol)
197205

198206
alignedstructs, masks = _align_by_sequence_alignment(
199207
mol,

0 commit comments

Comments
 (0)