Skip to content

Instantly share code, notes, and snippets.

@skaae
Created October 7, 2015 16:01
Show Gist options
  • Save skaae/b923722698ce13b0cc9f to your computer and use it in GitHub Desktop.
Save skaae/b923722698ce13b0cc9f to your computer and use it in GitHub Desktop.
def find_prot2(fasta_dict, re_str):
'''Search through a dictionary of fasta entries using a regular expression'''
# Import re module
import re # typically imported at top of module file
# Create pattern object
pattern = re.compile(re_str)
# Create empty list to store results
result_list = []
# Iterate over all keys in dictionary
for key in fasta_dict.keys():
# If the pattern matches, append to result_list
if pattern.match(key):
result_list.append(key)
return result_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment