No you can't do this with Biopython's pairwise2
. The score_only
parameter will still cause pairwise2.align
to calculate an alignment from two sequences, it will just not return the alignment but only the maximium score (that it has calculated).
I have written a small function which calculates the score of a given alignment (supplied as the two aligned sequences), that may be useful for you:
def evaluate_score(seq1, seq2, match, mismatch, open_gap, extend_gap,
penalize_extend_when_opening=False, force_generic=False,
penalize_end_gaps=True):
openA = False
openB = False
if penalize_extend_when_opening:
open_gap += extend_gap
score = 0
for baseA, baseB in zip(seq1, seq2):
if baseA !='-' and baseB != '-':
openA, openB = False, False
if baseA == baseB:
score += match
else:
score += mismatch
elif baseA == '-':
if not openA:
score += open_gap
openA = True
openB = False
else:
score += extend_gap
elif baseB == '-':
if not openB:
score += open_gap
openB = True
openA = False
else:
score += extend_gap
return score * 1.0
The gap symbol must be -
, match
, mismatch
, open_gap
, extend_gap
are the respective scores; penalties are given as negative scores.