I currently have a python script which takes a file as a command-line argument, does what it needs to do, and then outputs that file with _all_ORF.fsa_aa
appended. I'd like to actually edit the file name rather than appending, but I am getting confused with variables. I'm not sure how I can actually do it when the file is a variable.
Here's an example of the command-line argument:
gL=genomeList.txt #Text file containing a list of genomes to loop through.
for i in $(cat ${gL}); do
#some other stuff ;
python ./find_all_ORF_from_getorf.py ${i}_getorf.fsa_aa ;
done
Here is some of the python script (find_all_ORF_from_getorf.py):
import re, sys
from Bio import SeqIO
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
infile = sys.argv[1]
with open(f'{infile}_all_ORF.fsa_aa'.format(), "a") as file_object:
for sequence in SeqIO.parse(infile, "fasta"):
#do some stuff
print(f'{sequence.description}_ORF_from_position_{h.start()},\n{sequence.seq[h_start:]}',
file=file_object)
Currently, the oupt file is called Genome_file_getorf.fsa_aa_all_ORF.fsa_aa
.I'd like to remove the first fsa_aa
so that the output looks like this: Genome_file_getorf_all_ORF.fsa_aa
. How do I do this? I can't work out how to edit it.
I have had a look at the os.rename module, but that doesn't seem to be able to edit the variable name, just append to it.
Thanks,
J