Created
August 11, 2016 17:17
-
-
Save jasonsahl/64d88d2858a915ee730b5f86e305e5d4 to your computer and use it in GitHub Desktop.
Calculates all bases in a multi-FASTA file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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