Commit 4b2eea6a authored by Mathieu Giraud's avatar Mathieu Giraud

fasta.py: Fasta.revcomp()

parent 4e9cba4a
COMPLEMENT_NUCLEOTIDE = {
'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C',
'Y': 'R', 'R': 'Y', # pyrimidine (CT) / purine (AG)
'W': 'S', 'S': 'W', # weak (AT) / strong (GC)
'K': 'M', 'M': 'K', # keto (TG) / amino (AC)
'B': 'V', 'V': 'B', 'D': 'H', 'H': 'D',
'N': 'N'
}
def revcomp(seq):
'''Returns the reverse complement of a sequence
>>> revcomp('ACGNTT')
'AANCGT'
'''
rc = ''
for nucl in seq[::-1]:
rc += COMPLEMENT_NUCLEOTIDE[nucl.upper()]
return rc
def parse(fasta, endline=''):
'''Iterates over sequences in a fasta files, yielding (header, sequence) pairs'''
......@@ -42,6 +62,9 @@ class Fasta():
self.header = header
self.seq = sequence
def revcomp(self):
self.seq = revcomp(self.seq)
@property
def name(self):
return extract_field_if_exists(self.header, '|', 1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment