简体   繁体   中英

How to run a created python program for different samples in a for-loop?

I have a python program which is designed to take an inputfile (containing data for multiple samples) . Data for multiple samples are stored separately so can be accessed by submitting sample name as --s

$python2.7 calc_something.py --i inputfile.txt --s sample01  --p1 parameters --p2  para2 --o output_sample01

I want to run this for each sample in a for-loop by providing the sample name. Something like:

samples = ['sample01', 'sample02', 'sample03'...]
# creates a list of samples I want to input

# then  I want to do:
for x in samples:
    python2.7 calc_something.py --i inputfile.txt --s x  --p1 parameters --p2  para2 --o 'output_'+x

How can I do this in bash vs. python? which one is efficient?

It's simple:

for item in  sample01 sample02 sample03 ... 
do
    python2.7 calc_something.py --i inputfile.txt --s "$item"  --p1 parameters --p2  para2 --o "output_${item}"
done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM