how to change script for multiple input and output files

This is the place for queries that don't fit in any of the other categories.

how to change script for multiple input and output files

Postby utpalmtbi » Mon Jun 17, 2013 7:40 am

Hi all,

I am using the python script that takes two input files (goodProteins.fasta and list.txt) and save result in gene.fasta output files.

Code: Select all
fasta_file = "goodProteins.fasta" # First input
wanted_file = "list.txt" # Second input
result_file = "gene.fasta" # Output

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). 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).

Any help??
utpalmtbi
 
Posts: 1
Joined: Fri Jun 14, 2013 2:17 pm

Re: how to change script for multiple input and output files

Postby setrofim » Mon Jun 17, 2013 4:53 pm

Code: Select all
files =  ['list1.txt', 'list100.txt']

for wanted_file in files:
    # Do the stuff you're currently doing...
setrofim
 
Posts: 288
Joined: Mon Mar 04, 2013 7:52 pm


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot] and 6 guests