Hi,
So I wrote a simple code that doesn't seem to be working well and I don't know why. I have two files:
seq.txt
AAAATTTTTCCCCCGGGG
AAAAAAAAAAAAAAAAAA
TTTTTTTTTTTTTTTTTTTT
....
Ids_to_add.txt
ID_1
ID_2
ID_3
.....
I want a file fasta like this:
>ID_1
AAAATTTTTCCCCCGGGG
>ID_2
AAAAAAAAAAAAAAAAAA
>ID_3
TTTTTTTTTTTTTTTTTTTT
...
My code is like this so far:
g = open("test.txt",'w')
f = open("Ids_to_add.txt", "r")
a = open("seq.txt", "r")
for line in f:
linef = line.strip()
for line in a:
linea = line.strip()
print(">" + linef.upper()+"\n"+linea.upper(), file=g)
Somehow the code output is:
>ID_3
AAAATTTTTCCCCCGGGG
>ID_3
AAAAAAAAAAAAAAAAAA
>ID_3
TTTTTTTTTTTTTTTTTTTT
...
So in conclusion the sequences are fine, but the IDs are always the last ID in the ID file. Any help is welcome!
Of course it is, your loop that extracts the header lines finishes even before the second one starts, therefore the
print
command uses the last instance off
which is the last header of ID.