Batch export for files

Hi! I’ve been using qiime2 (and qiime1) for quite some time now, and it’s working well so far. But I’m curious if there’s a way to export files in batches, say, all *.qzv files for all the emperor plots in a certain directory.

I’ve tried to run the export command in a for-loop, but that just creates the one set of files at the end of the command, presumably for the last input file:
for i in beta/core-metrics-phylo/*emperor.qzv; do qiime tools export $i --output-dir exported/beta-metrics; done

I’m trying to read through the docs to see if there’s an argument that specifies the --output-file as the argument instead of the --output-dir, but I haven’t had much luck! Is there another argument I need to add here? If you could point me in the right direction, that’d be great!

Thanks!

1 Like

Hello Drishti,

This is a great question. You are almost there!

There are a lot of ways to do this, but here is one method I’ve used before that uses only basic linux. It has three steps.

# set variables for input and output folder!
input=/full/file/path/to/beta/core-metrics-phylo
output=newoutputfolder


# Find the part of the name that changes and save it to a file. 
cd $inputpath
ls *emperor.qzv > $output/filenames.txt
head $output/filenames.txt

# Loop through all filenames and export them. 
while read i; do
        echo exporting $i
        qiime tools export ${i} --output-dir $output/${i} 
done < $output/filenames.txt

Note that I use $i twice; first to read in each file, second to write out each file to a new directory.

Let me know if this method works for you!

Colin

3 Likes

Thanks a lot, Colin! This makes sense! I’ll give it a try and let you know.

Thanks,
Drishti

1 Like

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.