Skip to content

Instantly share code, notes, and snippets.

@kallam
Last active August 29, 2015 14:16
Show Gist options
  • Save kallam/6594cd58faef0cdd1f84 to your computer and use it in GitHub Desktop.
Save kallam/6594cd58faef0cdd1f84 to your computer and use it in GitHub Desktop.
Parse fasta file
sequences = []
sequence = {}
text = ""
f = open("in.txt", "r")
for line in f:
if line[0] == '>':
if text != "":
sequence["text"] = text
sequences.append(sequence)
sequence = {}
text = ""
sequence["meta"] = line[1:-1]
elif line == "\n":
if text != "":
sequence["text"] = text
sequences.append(sequence)
sequence = {}
text = ""
else:
text = text + line[:-1]
f.close()
# GBA, strain, name, na, date, host, country = sequence["meta"].split("|")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment