Commit 124f0e8a authored by Bertrand Néron's avatar Bertrand Néron
Browse files

add gc_percent in Sequence and use it

parent e1e73d4c
......@@ -5,6 +5,9 @@ class Sequence(object):
self.comment = comment
self.sequence = sequence
def gc_percent(self):
seq = self.sequence.upper()
return float(seq.count('G') + seq.count('C')) / float(len(seq))
class FastaParser(object):
......@@ -73,4 +76,5 @@ if __name__ == '__main__':
fasta_parser = FastaParser(fasta_path)
for sequence in fasta_parser:
print "----------------"
print sequence.id
\ No newline at end of file
print "{seqid} = {gc:.3%}".format(gc=sequence.gc_percent(),
seqid = sequence.id)
\ No newline at end of file
Supports Markdown
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