Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a function to calculate GC content of a sequence #68

Merged
merged 3 commits into from
Feb 19, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pyfastaq/sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def gc_content(self, as_decimal=True):
This method ignores N when calculating the length of the sequence.
It does not, however ignore other ambiguous bases. It also only
includes the ambiguous base S (G or C). In this sense the method is
conservative with it's calculation.
conservative with its calculation.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


Args:
as_decimal (bool): Return the result as a decimal. Setting to False
Expand All @@ -484,15 +484,17 @@ def gc_content(self, as_decimal=True):
"""
gc_total = 0.0
num_bases = 0.0
n_tuple = tuple('nN')
accepted_bases = tuple('cCgGsS')

# counter sums all unique characters in sequence. Case insensitive.
for base, count in Counter(self.seq).items():

# dont count N in the number of bases
if base not in tuple('nN'):
if base not in n_tuple:
num_bases += count

if base in tuple('cCgGsS'): # S is a G or C
if base in accepted_bases: # S is a G or C
gc_total += count

gc_content = gc_total / num_bases
Expand Down