Created
November 23, 2022 10:21
-
-
Save altanner/a8ae7d11f49ab95e879032f105135f98 to your computer and use it in GitHub Desktop.
How to search through a fasta file and print out the sequence associated with a record name.
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
from Bio import SeqIO | |
def fasta_search(fastas, target): | |
""" | |
Search for a sequence motif in multiple FASTA records. | |
Args: fastas - SeqIO iterable | |
target - the sequence name to find (string) | |
Returns: Nothing. | |
""" | |
for record in fasta_batch: | |
if target == record.name: | |
print(record.seq) | |
# assign name of file to variable | |
filename = "five_seqs.fas" | |
# parse in my fasta file | |
fasta_batch = list(SeqIO.parse(filename, "fasta")) | |
# declare what I am looking for, as a string | |
seq_name = "seq3" | |
# call the function! | |
fasta_search(fasta_batch, seq_name) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
an example input file would be