I want to write a for loop that uses a function that takes two variables, both of which are files. I have a set of FASTA files and a set of text files that correspond to each FASTA file, and I want the for loop to itereate over both lists in parallel. This is what the function would look like for one pair of files:
anvi-gen-contigs-database --contigs-fasta fastafile.fna --project-name ProjectName --output-db-path /path/to/file/fastafile.fna.db --external-gene-calls /path/to/file/textfile.txt --ignore-internal-stop-codons
I know how to set up a for loop that takes only one variable, and previously I have used a for loop that looks like this:
for f in *.fna; do
anvi-gen-contigs-database --contigs-fasta $f --project-name ProjectName --output-db-path /path/to/file/${f}_out.db;
done
I've been looking around this and other sites for a way to modify the preceding for loop so that it will take two files as variables and iterate over them in pairs, and I've found two ways that might work, but none of the examples I have found involve using files as variables, so I wanted to check and make sure the for loop will do what I want it to do before I try running it. Here is the first way:
for f in *.fna and for e in *.txt; do
anvi-gen-contigs-database --contigs-fasta $f --project-name ProjectName --output-db-path /path/to/file/${f}_out.db --external-gene-calls /path/to/file/$e --ignore-internal-stop-codons;
done
And here is the second way:
for f, e in zip(*.fna, *.txt); do
anvi-gen-contigs-database --contigs-fasta $f --project-name ProjectName --output-db-path /path/to/file/${f}_out.db --external-gene-calls /path/to/file/$e --ignore-internal-stop-codons;
done
Can someone please confirm that at least one of those ways is syntactically correct and will iterate over the two lists of files in parallel as I want it to do, or else suggest a correct or better way? Thanks!
zip()is a Python function, notbash.