pythonbashiterationfile-iomultipleoutputs

how to output multiple files from a set of different input files for a python script in bash


I already have my python script producing my desired outputfile by passing 5 different inputfiles to it. Every inputfile is in a different folder, and in each folder there are more files which all of them start by "chr" and finish by the extension ".vcf.gz"

So, the command that I execute to produce one output is:

python myscript.py /folder1/chrX.vcf.gz /folder2/chrX.vcf.gz /folder3/chrX.vcf.gz /folder4/chrX.vcf.gz /folder5/chrX.vcf.gz > /myNewFolderForOutputs/chrXoutput.txt

Now what I would like to obtain is a single command to do the same for the other inputfiles contained in the same folders, let's say "chrY.vcf.gz" and "chrZ.vcf.gz", and at the same time, producing one outfile for every set of my inputfiles, named "chrYoutput.txt" and "chrZoutput.txt"

Is that possible? Should I change my strategy maybe?

Thanks a lot for any suggestion or hint!


Solution

  • If your folder structure follows the pattern you described in your sample, then this will work:

    for i in X Y Z; do
        python myscript.py /folder[1-5]/chr$i.vcf.gz > /myNewFolderForOutputs/chr${i}output.txt
    done
    

    Not 100% sure if this is what you asked.