I'm trying to learn Python to perform some tasks in the lab.
I was trying to find a pattern in a FASTA file, interpolating pattern and fasta as string variables. This way the program doesn't find anything. On the other hand, when I try to do the same, but writing the pattern string instead of using the variable interpolation, it works and finds the pattern. Could you please help me to figure out what the problem is?
Here is my code:
firstname = "header1"
for record in SeqIO.parse("prueba_fasta.fasta", "fasta"):
print ">" + record.id + "\n" + record.seq
fa = strrecord.id)
print fa
fir = str(firstname)
print fir
matches = re.search (fir, fa)
if matches:
print ">" + record.id + "\n" + record.seq
Thanks in advance
Uxue
Unrelated advice, you should/could use
print(seq_record.format("fasta").strip())
to properly write (to stdout) instead of using the awkwardprint ">" + record.id + "\n" + record.seq
In addition, you miss something here:
fa = strrecord.id)
, I guess you mean:fa = str( record.id)
I'm sorry for the mistake, this is the right version of the code:
Thank you!
Oh right, there is some weird auto formatting going on with str( record.id).
Which pattern exactly are you trying to match? So if something occurs in the fasta identifier you want to keep it?