I am trying to write a Python function extractAlignment(S) that takes in as an i
ID: 3801444 • Letter: I
Question
I am trying to write a Python function extractAlignment(S) that takes in as an input a matrix S, of dynamic length nx by ny (these lengths are determined by strings inputted into an earlier function that I wrote to create S) and returns a vector (list in Python) that represents the optimal path in getting back to S[0][0] from the lower right corner S[nx][ny]. S is filled simply with integers.
The optimal path is determined by looking at the values above and to the left before each move, and choosing the node represented by the smallest number. Only upward and leftward movements can be performed in order to reach S[0][0], and in the case of a tie, the path to the next node MUST be randomly chosen. Any help would be greatly appreciated. Thanks!
Explanation / Answer
>>> from Bio import SeqIO, AlignIO >>> # Read in a file of un-aligned sequences. Turn into list with list() (otherwise remains generator, which is fine, but you can't index) >>> seqs = list( SeqIO.parse("seqs.fasta", "fasta") ) >>> # Read in an alignment file >>> align = AlignIO.read("pb2.phy", "phylip-relaxed") >>> # Biopython parses the file into a list of SeqRecord objects >>> seqs = list( SeqIO.parse("seqs.fasta", "fasta") ) >>> print seqs [SeqRecord(seq=Seq('AGCTAGATCGATGC', SingleLetterAlphabet()), id='1', name='1', description='1', dbxrefs=[]), SeqRecord(seq=Seq('ATCGATACA', SingleLetterAlphabet()), id='2', name='2', description='2', dbxrefs=[]), SeqRecord(seq=Seq('ATACGAATAGCCTATACGTAGCATGCATGGGCTATAATTTTTT', SingleLetterAlphabet()), id='3', name='3', description='3', dbxrefs=[])] >>> # Loop over sequences view important attributes, which can be converted to strings >>> for record in seqs: ... print "Record id:", record.id ... print "Record sequence:", str(record.seq) Record id: 1 The sequence record: AGCTAGATCGATGC Record id: 2 The sequence record: ATCGATACA Record id: 3 The sequence record: ATACGAATAGCCTATACGTAGCATGCATGGGCTATAATTTTTT
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.