From 124f0e8adfe7b829cb160e613c671d51dec2d8ea Mon Sep 17 00:00:00 2001 From: free hacker <freeh4cker@gmail.com> Date: Thu, 18 Feb 2016 08:19:13 +0100 Subject: [PATCH] add gc_percent in Sequence and use it --- source/_static/code/fasta_object.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/_static/code/fasta_object.py b/source/_static/code/fasta_object.py index a1a32c8..abb474a 100644 --- a/source/_static/code/fasta_object.py +++ b/source/_static/code/fasta_object.py @@ -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 -- GitLab