I am using the python script that takes two input files (goodProteins.fasta and list.txt) and save result in gene.fasta output files.
fasta_file = "goodProteins.fasta" # First input
wanted_file = "list.txt" # Second input
result_file = "result.txt" # Output fasta file
wanted = set()
with open(wanted_file) as f:
for line in f:
line = line.strip()
if line != "":
wanted.add(line)
fasta_sequences = SeqIO.parse(open(fasta_file),'fasta')
with open(result_file, "w") as f:
for seq in fasta_sequences:
if seq.id in wanted:
SeqIO.write([seq], f, "fasta")
But now I have several list files (list1.txt, list100.txt etc) that are present in the subdirectory 'outfile' within the current directory. I want to take each list file one at a time, proceed through the script and generates the corresponding output files (gene1.fasta, gene100.fasta) and saved them in a separate sub directory 'result'.
Any help??