def testWikiAnswerWithMatchOneAsDict(self): """ Test the example given in Wikipedia http://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm Wikipedia uses a match score of two, here we use a score of one. Get the result as a dict. """ seq1 = Read('seq1', 'ACACACTA') seq2 = Read('seq2', 'AGCACACA') align = LocalAlignment(seq1, seq2, match=1) result = align.createAlignment() self.assertEqual( { 'cigar': '5=1D1=', 'sequence1Start': 2, 'sequence1End': 8, 'sequence2Start': 3, 'sequence2End': 8, 'text': [ 'seq1 2 CACACTA 8', ' ||||| |', 'seq2 3 CACAC-A 8', ] }, result )
def testWikiAnswerAsDict(self): """ Test the example given in Wikipedia: http://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm with the return result being a dict. """ seq1 = Read('seq1', 'ACACACTA') seq2 = Read('seq2', 'AGCACACA') align = LocalAlignment(seq1, seq2, match=2) result = align.createAlignment() self.assertEqual( { 'cigar': '1=1I5=1D1=', 'sequence1Start': 1, 'sequence1End': 8, 'sequence2Start': 1, 'sequence2End': 8, 'text': [ 'seq1 1 A-CACACTA 8', ' | ||||| |', 'seq2 1 AGCACAC-A 8', ] }, result )
def testWikiAnswerAsDict(self): """ Test the example given in Wikipedia: http://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm with the return result being a dict. """ seq1 = Read('seq1', 'ACACACTA') seq2 = Read('seq2', 'AGCACACA') align = LocalAlignment(seq1, seq2, match=2) result = align.createAlignment() self.assertEqual( { 'cigar': '1=1I5=1D1=', 'sequence1Start': 1, 'sequence1End': 8, 'sequence2Start': 1, 'sequence2End': 8, 'text': [ 'seq1 1 A-CACACTA 8', ' | ||||| |', 'seq2 1 AGCACAC-A 8', ] }, result)
def testWikiAnswerWithMatchOneAsDict(self): """ Test the example given in Wikipedia http://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm Wikipedia uses a match score of two, here we use a score of one. Get the result as a dict. """ seq1 = Read('seq1', 'ACACACTA') seq2 = Read('seq2', 'AGCACACA') align = LocalAlignment(seq1, seq2, match=1) result = align.createAlignment() self.assertEqual( { 'cigar': '5=1D1=', 'sequence1Start': 2, 'sequence1End': 8, 'sequence2Start': 3, 'sequence2End': 8, 'text': [ 'seq1 2 CACACTA 8', ' ||||| |', 'seq2 3 CACAC-A 8', ] }, result)
def testTwoCompletelyDifferentSequences(self): """ When two completely different sequences are given, the result should be the two sequences with an empty alignment. """ seq1 = SeqRecord(Seq('aaaaaa'), id='seq1') seq2 = SeqRecord(Seq('gggggg'), id='seq2') align = LocalAlignment(seq1, seq2) result = align.createAlignment() alignment = ("\nNo alignment between seq1 and seq2 \n") self.assertEqual(result, alignment)
def testTwoCompletelyDifferentSequences(self): """ When two completely different sequences are given, the result should be the two sequences with an empty alignment. """ seq1 = Read('seq1', 'aaaaaa') seq2 = Read('seq2', 'gggggg') align = LocalAlignment(seq1, seq2) result = align.createAlignment(resultFormat=str) alignment = ('\nNo alignment between seq1 and seq2\n') self.assertEqual(result, alignment)
def testAlignmentWithGapInMiddle(self): seq1 = Read('seq1', 'agtcagtcagtc') seq2 = Read('seq2', 'cgaatcg') align = LocalAlignment(seq1, seq2) result = align.createAlignment(resultFormat=str) alignment = ('\nCigar string of aligned region: 2=1D1=\n' 'seq1 Match start: 7 Match end: 10\n' 'seq2 Match start: 5 Match end: 7\n' 'seq1 7 TCAG 10\n' ' || |\n' 'seq2 5 TC-G 7') self.assertEqual(result, alignment)
def testGapAtBothEndsOfSeq1(self): seq1 = Read('seq1', 'gaatc') seq2 = Read('seq2', 'cgaatcg') align = LocalAlignment(seq1, seq2) result = align.createAlignment(resultFormat=str) alignment = ('\nCigar string of aligned region: 5=\n' 'seq1 Match start: 1 Match end: 5\n' 'seq2 Match start: 2 Match end: 6\n' 'seq1 1 GAATC 5\n' ' |||||\n' 'seq2 2 GAATC 6') self.assertEqual(result, alignment)
def testGapAtStartOfSeq2(self): seq1 = Read('seq1', 'cgaatcg') seq2 = Read('seq2', 'gaatcg') align = LocalAlignment(seq1, seq2) result = align.createAlignment(resultFormat=str) alignment = ('\nCigar string of aligned region: 6=\n' 'seq1 Match start: 2 Match end: 7\n' 'seq2 Match start: 1 Match end: 6\n' 'seq1 2 GAATCG 7\n' ' ||||||\n' 'seq2 1 GAATCG 6') self.assertEqual(result, alignment)
def testAlignmentWithGapInMiddle(self): seq1 = SeqRecord(Seq('agtcagtcagtc'), id='seq1') seq2 = SeqRecord(Seq('cgaatcg'), id='seq2') align = LocalAlignment(seq1, seq2) result = align.createAlignment() alignment = ("\nCigar string of aligned region: 2=1D1=\n" "seq1 Match start: 7 Match end: 10\n" "seq2 Match start: 5 Match end: 7\n" "seq1 7 TCAG 10\n" " || |\n" "seq2 5 TC-G 7") self.assertEqual(result, alignment)
def testGapAtStartOfSeq2(self): seq1 = SeqRecord(Seq('cgaatcg'), id='seq1') seq2 = SeqRecord(Seq('gaatcg'), id='seq2') align = LocalAlignment(seq1, seq2) result = align.createAlignment() alignment = ("\nCigar string of aligned region: 6=\n" "seq1 Match start: 2 Match end: 7\n" "seq2 Match start: 1 Match end: 6\n" "seq1 2 GAATCG 7\n" " ||||||\n" "seq2 1 GAATCG 6") self.assertEqual(result, alignment)
def testGapAtBothEndsOfSeq1(self): seq1 = SeqRecord(Seq('gaatc'), id='seq1') seq2 = SeqRecord(Seq('cgaatcg'), id='seq2') align = LocalAlignment(seq1, seq2) result = align.createAlignment() alignment = ("\nCigar string of aligned region: 5=\n" "seq1 Match start: 1 Match end: 5\n" "seq2 Match start: 2 Match end: 6\n" "seq1 1 GAATC 5\n" " |||||\n" "seq2 2 GAATC 6") self.assertEqual(result, alignment)
def testTwoEqualSequences(self): """ When two identical sequences are given, the result should show that the sequences completely match. """ seq1 = SeqRecord(Seq('cgaatcg'), id='seq1') seq2 = SeqRecord(Seq('cgaatcg'), id='seq2') align = LocalAlignment(seq1, seq2) result = align.createAlignment() alignment = ("\nCigar string of aligned region: 7=\n" "seq1 Match start: 1 Match end: 7\n" "seq2 Match start: 1 Match end: 7\n" "seq1 1 CGAATCG 7\n" " |||||||\n" "seq2 1 CGAATCG 7") self.assertEqual(result, alignment)
def testWikiAnswer(self): """ Test the example given in Wikipedia: http://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm """ seq1 = SeqRecord(Seq('ACACACTA'), id='seq1') seq2 = SeqRecord(Seq('AGCACACA'), id='seq2') align = LocalAlignment(seq1, seq2, match=2) result = align.createAlignment() alignment = ("\nCigar string of aligned region: 1=1I5=1D1=\n" "seq1 Match start: 1 Match end: 8\n" "seq2 Match start: 1 Match end: 8\n" "seq1 1 A-CACACTA 8\n" " | ||||| |\n" "seq2 1 AGCACAC-A 8") self.assertEqual(result, alignment)
def testTwoEqualSequences(self): """ When two identical sequences are given, the result should show that the sequences completely match. """ seq1 = Read('seq1', 'cgaatcg') seq2 = Read('seq2', 'cgaatcg') align = LocalAlignment(seq1, seq2) result = align.createAlignment(resultFormat=str) alignment = ('\nCigar string of aligned region: 7=\n' 'seq1 Match start: 1 Match end: 7\n' 'seq2 Match start: 1 Match end: 7\n' 'seq1 1 CGAATCG 7\n' ' |||||||\n' 'seq2 1 CGAATCG 7') self.assertEqual(result, alignment)
def testWikiAnswer(self): """ Test the example given in Wikipedia: http://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm """ seq1 = Read('seq1', 'ACACACTA') seq2 = Read('seq2', 'AGCACACA') align = LocalAlignment(seq1, seq2, match=2) result = align.createAlignment(resultFormat=str) alignment = ('\nCigar string of aligned region: 1=1I5=1D1=\n' 'seq1 Match start: 1 Match end: 8\n' 'seq2 Match start: 1 Match end: 8\n' 'seq1 1 A-CACACTA 8\n' ' | ||||| |\n' 'seq2 1 AGCACAC-A 8') self.assertEqual(result, alignment)
def testWikiAnswerWithMatchOne(self): """ Test the example given in Wikipedia http://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm Wikipedia uses a match score of two, here we use a score of one. """ seq1 = Read('seq1', 'ACACACTA') seq2 = Read('seq2', 'AGCACACA') align = LocalAlignment(seq1, seq2, match=1) result = align.createAlignment(resultFormat=str) alignment = ('\nCigar string of aligned region: 5=1D1=\n' 'seq1 Match start: 2 Match end: 8\n' 'seq2 Match start: 3 Match end: 8\n' 'seq1 2 CACACTA 8\n' ' ||||| |\n' 'seq2 3 CACAC-A 8') self.assertEqual(result, alignment)
def testWikiAnswerWithMatchOne(self): """ Test the example given in Wikipedia http://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm Wikipedia uses a match score of two, here we use a score of one. """ seq1 = SeqRecord(Seq('ACACACTA'), id='seq1') seq2 = SeqRecord(Seq('AGCACACA'), id='seq2') align = LocalAlignment(seq1, seq2, match=1) result = align.createAlignment() alignment = ("\nCigar string of aligned region: 5=1D1=\n" "seq1 Match start: 2 Match end: 8\n" "seq2 Match start: 3 Match end: 8\n" "seq1 2 CACACTA 8\n" " ||||| |\n" "seq2 3 CACAC-A 8") self.assertEqual(result, alignment)
help='The mismatch score.') parser.add_argument('--gapOpenScore', type=int, default=-1, help='The gap open score.') parser.add_argument('--gapExtendScore', type=int, default=-1, help='The gap extend score.') parser.add_argument('--gapExtendDecay', type=float, default=0.0, help='The gap extend decay.') args = parser.parse_args() for seq1 in FastaReads(args.fastaFile1): for seq2 in FastaReads(args.fastaFile2): alignment = LocalAlignment(seq1, seq2, match=args.matchScore, mismatch=args.mismatchScore, gap=args.gapOpenScore, gapExtend=args.gapExtendScore, gapExtendDecay=args.gapExtendDecay) print(alignment.createAlignment(resultFormat=str))
'--fastaFile2', required=True, help='The second FASTA file.') parser.add_argument( '--matchScore', type=int, default=1, help='The match score.') parser.add_argument( '--mismatchScore', type=int, default=-1, help='The mismatch score.') parser.add_argument( '--gapOpenScore', type=int, default=-1, help='The gap open score.') parser.add_argument( '--gapExtendScore', type=int, default=-1, help='The gap extend score.') parser.add_argument( '--gapExtendDecay', type=float, default=0.0, help='The gap extend decay.') args = parser.parse_args() for seq1 in FastaReads(args.fastaFile1): for seq2 in FastaReads(args.fastaFile2): alignment = LocalAlignment( seq1, seq2, match=args.matchScore, mismatch=args.mismatchScore, gap=args.gapOpenScore, gapExtend=args.gapExtendScore, gapExtendDecay=args.gapExtendDecay) print(alignment.createAlignment(resultFormat=str))
sys.exit(1) else: fileHandle1 = sys.argv[1] fileHandle2 = sys.argv[2] if len(sys.argv) == 3: matchScore = 1 mismatchScore = -1 gapOpenScore = -1 gapExtendScore = -1 gapExtendDecay = 0.0 else: matchScore = int(sys.argv[3]) mismatchScore = int(sys.argv[4]) gapOpenScore = int(sys.argv[5]) gapExtendScore = int(sys.argv[6]) gapExtendDecay = float(sys.argv[7]) for record in SeqIO.parse(fileHandle1, "fasta"): input1 = record for record in SeqIO.parse(fileHandle2, "fasta"): input2 = record alignment = LocalAlignment( input1, input2, match=matchScore, mismatch=mismatchScore, gap=gapOpenScore, gapExtend=gapExtendScore, gapDecay=gapExtendDecay, ) print(alignment.createAlignment())
'gapExtendDecay)' % sys.argv[0], file=sys.stderr) sys.exit(1) else: fileHandle1 = sys.argv[1] fileHandle2 = sys.argv[2] if len(sys.argv) == 3: matchScore = 1 mismatchScore = -1 gapOpenScore = -1 gapExtendScore = -1 gapExtendDecay = 0.0 else: matchScore = int(sys.argv[3]) mismatchScore = int(sys.argv[4]) gapOpenScore = int(sys.argv[5]) gapExtendScore = int(sys.argv[6]) gapExtendDecay = float(sys.argv[7]) for record in SeqIO.parse(fileHandle1, 'fasta'): input1 = record for record in SeqIO.parse(fileHandle2, 'fasta'): input2 = record alignment = LocalAlignment(input1, input2, match=matchScore, mismatch=mismatchScore, gap=gapOpenScore, gapExtend=gapExtendScore, gapDecay=gapExtendDecay) print(alignment.createAlignment())
print >>sys.stderr, ("Usage: %s filename1, filename2, (matchScore, " "mismatchScore, gapOpenScore, gapExtendScore, " "gapExtendDecay)" % sys.argv[0]) sys.exit(1) else: fileHandle1 = sys.argv[1] fileHandle2 = sys.argv[2] if len(sys.argv) == 3: matchScore = 1 mismatchScore = -1 gapOpenScore = -1 gapExtendScore = -1 gapExtendDecay = 0.0 else: matchScore = int(sys.argv[3]) mismatchScore = int(sys.argv[4]) gapOpenScore = int(sys.argv[5]) gapExtendScore = int(sys.argv[6]) gapExtendDecay = float(sys.argv[7]) for record in SeqIO.parse(fileHandle1, "fasta"): input1 = record for record in SeqIO.parse(fileHandle2, "fasta"): input2 = record alignment = LocalAlignment(input1, input2, match=matchScore, mismatch=mismatchScore, gap=gapOpenScore, gapExtend=gapExtendScore, gapDecay=gapExtendDecay) print alignment.createAlignment()