Skip to content

Instantly share code, notes, and snippets.

@mys721tx
Last active July 11, 2018 04:35
Show Gist options
  • Save mys721tx/6c95b460fd3cb6de8c031293ebbc6bf6 to your computer and use it in GitHub Desktop.
Save mys721tx/6c95b460fd3cb6de8c031293ebbc6bf6 to your computer and use it in GitHub Desktop.
Summing all FASTA headers
"""
sum.py
"""
import sys
size = 0
def parse(line):
if line[0] == ">":
line = line[1:]
result = {}
for cell in line.split(";"):
try:
key, value = cell.split("=")
result[key] = value
except ValueError:
result[cell] = None
return result
for row in sys.stdin:
result = parse(row)
try:
size += int(result["size"])
except KeyError:
pass
print(size)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment