Match AA sequence with the Protein fasta file

Viewed 129

I am working with FASTA files of protein. I want to find the protein sequences having similar AA sequences(in a .txt file) using python/biopython. I have tried a lot but could not find the where I am wrong.

#using biopython

records=SeqIO.parse("protein.fasta") #to extract protein sequences from FASTA file
for record in records:
    output=record.sec          
    print(output) #just to show how the output looks like.
    #I used ** to hightlight the desired area
    enter code here
    -->VVSREL**QALEA**IRQKDEEDABCKARFRGIFSH
    -->VVSRPQREEARJKLMIRQKDEED**KARFRG**IFSH
    -->VVSREL**QALEA**RIRDKARFRGIFSH
 f=open('amino_acids.txt', 'r') **#to get the AA sequences from the text file or what is inside the file**
 for i in f: #to show how this file looks like
     print(i)
    -->'QALEA', 'KARFRG', 'QALEAR','KAKAKA', 'PAKAR'
#to match my AA sequences with the protein sequences
 for i in f:
    for j in output:
        if i in j:
            print('found')
        else:
            print('not fount')
 #output
    --> error
    --> error
    -->error
#while writing AA sequence instead of **i**, give correct answers

for j in output:
    if **'QALEA'** in j:
         print('found')
    else:
         print('not fount')
#output
    --> found
    --> not found
    --> found  

here, where I am doing wrong. Any help will be appreciated.##New to coding.

1 Answers

Could you provide a reproducible example?

If I create this example I don't see any problem:

records = [
    'VVSREL**QALEA**IRQKDEEDABCKARFRGIFSH',
    'VVSRPQREEARJKLMIRQKDEED**KARFRG**IFSH',
    'VVSREL**QALEA**RIRDKARFRGIFSH',
]

patterns = ['QALEA', 'KARFRG', 'QALEAR','KAKAKA', 'PAKAR']
    
# or read patterns from file
with open('amino_acids.txt', 'r') as f:
    patterns = f.read().splitlines()

for r in records:
    for p in patterns:
        if p in r:
            print(f'pattern {p} found in {r}')
Related