Skip to content

Instantly share code, notes, and snippets.

@jasonsahl
Created August 11, 2016 17:17
Show Gist options
  • Save jasonsahl/64d88d2858a915ee730b5f86e305e5d4 to your computer and use it in GitHub Desktop.
Save jasonsahl/64d88d2858a915ee730b5f86e305e5d4 to your computer and use it in GitHub Desktop.
Calculates all bases in a multi-FASTA file
#!/usr/bin/python
#parses sequence lengths from a file and prints them to the screen
#usage python seqlength.py infasta
from __future__ import print_function
from sys import argv
import sys
try:
from Bio import SeqIO
except:
print("script requires BioPython to run..exiting")
sys.exit()
try:
handle = open(argv[1], "U")
except:
print("usage: script input.fasta")
sys.exit()
totals = []
for record in SeqIO.parse(handle, "fasta"):
totals.append(len(record.seq))
print(sum(int(x) for x in totals))
handle.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment