Created
October 7, 2015 14:04
-
-
Save skaae/3851fe0eac0104eb50bc to your computer and use it in GitHub Desktop.
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
def read_fasta(fasta_filename): | |
'''Function to parse a fasta sequence file''' | |
# Initialize dictionary | |
fasta_dict = {} | |
# Open file and iterate over lines | |
for line in open(fasta_filename): | |
# Remove newline and other whitespace from end of line | |
line = line.rstrip() | |
# Test if line starts with '>' | |
if line[0] == '>': | |
# If so, save name in variable | |
name = line[1:] | |
# Register name in dictionary - with empty sequence | |
fasta_dict[name] = "" | |
else: | |
# Add partial sequence to the entry in the dictionary | |
fasta_dict[name] += line | |
# Return result | |
return fasta_dict | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment