Skip to content

Instantly share code, notes, and snippets.

@nturaga
Created February 20, 2015 20:47
Show Gist options
  • Save nturaga/89df64218132d7ecd1f6 to your computer and use it in GitHub Desktop.
Save nturaga/89df64218132d7ecd1f6 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#Write tool to compute GC contect here
# usage : python compute_comething.py <FASTA file> <output file>
import re,sys
import string
inp = sys.argv[1]
out = sys.argv[2]
file = open(inp,"r")
gcCount = 0
totalBaseCount = 0
for line in file:
line = line.strip("\n")
if not line.startswith(">"):
gcCount += len(re.findall("[GC]", line))
totalBaseCount += len(re.findall("[GCTA]", line))
gcFraction = float(gcCount) / totalBaseCount
print( gcFraction * 100 )
out = open(out,"w")
out.write(str(gcFraction*100))
out.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment