Skip to content

Commit

Permalink
make loop more efficient. Fix Martin's crazy grammar requirements.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Hall committed Feb 19, 2018
1 parent 55a32cc commit abeb7e0
Showing 1 changed file with 5 additions and 3 deletions.
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.
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

0 comments on commit abeb7e0

Please sign in to comment.