4.5 years ago by
from Bio import SeqIO
fout = open("output.fasta", "w")
handle = open("input.fasta", "r")
for seq_record in SeqIO.parse(handle, "fasta"):
seq_record.id = new_id
new_id =+ 1
seq_record.description = ""
It looks like you're currently trying to read the numbers from a file. When you take your file (in your case lines_file) and ask it for subscript 0 (i.e. ) you're really asking for the 0th character, not the first row. Python doesn't handle this (at least in a way I'm familiar with but then again I'm a C++ guy primarily).
The code above solves the problem by starting a variable at 0 and incrementing by 1 for each sequence record and then assigning it to the seq_record.id within the loop you already constructed. This doesn't solve the case if you wanted to extract out IDs from a file and transfer them in, which might be what you're really after.
If you're trying to do that, then you'll need to open the file (like you're currently doing) and instead of trying to access  in the file, you probably want to use the
readline() method. You can try code like this:
Alternatively you can use:
which will also remove the newline (I'm not sure if you want it to or not in this case). You would substitute one of these two lines for the line where you're currently saying:
seq_record.id = lines_file
in your code.
I believe that should solve your issue, but I'm happy to help further if it doesn't quite get you there.