Last active
July 11, 2018 04:35
-
-
Save mys721tx/6c95b460fd3cb6de8c031293ebbc6bf6 to your computer and use it in GitHub Desktop.
Summing all FASTA headers
This file contains hidden or 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
""" | |
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