Created
August 9, 2013 20:40
-
-
Save gregcaporaso/6197007 to your computer and use it in GitHub Desktop.
Quick-and-dirty code to generate a shell script to re-organize the directory structure in the short-read-tax-assignment repo.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41,9 All | |
#!/usr/bin/env python | |
# Author: Greg Caporaso | |
from os.path import join, isdir | |
from glob import glob | |
base_in_dir = "/home/caporaso/analysis/short-read-tax-assignment/data/qiime-mock-community/multiple_assign_taxonomy_output/" | |
base_out_dir = "/home/caporaso/analysis/short-read-tax-assignment/data/eval-pre-computed/" | |
lines = [] | |
lines.append('#!/usr/bin/env bash') | |
lines.append('') | |
lines.append('mkdir %s' % (base_out_dir)) | |
lines.append('') | |
data_sets = [] | |
for e in glob(join(base_in_dir,'*')): | |
id_ = e.split('/')[-1] | |
if '_' not in id_: | |
data_sets.append(id_) | |
for data_set in data_sets: | |
in_data_set_dir = join(base_in_dir,data_set) | |
out_data_set_dir = join(base_out_dir,data_set) | |
lines.append('## %s' % data_set) | |
lines.append('mkdir %s' % (out_data_set_dir)) | |
in_methods = [e.split('/')[-1] for e in glob(join(in_data_set_dir,'*')) if isdir(e)] | |
out_methods = [e.split('_') for e in in_methods] | |
out_ref_tax = 'gg_13_5_otus' | |
for i, o in zip(in_methods,out_methods): | |
in_method_dir = join(in_data_set_dir,i) | |
out_ref_tax_dir = join(out_data_set_dir,o[0]) | |
out_method_dir = join(out_ref_tax_dir,out_ref_tax) | |
try: | |
out_param_dir = join(out_method_dir,o[1]) | |
except IndexError: | |
out_param_dir = out_method_dir | |
lines.append('mkdir %s' % out_ref_tax_dir) | |
lines.append('mkdir %s' % out_method_dir) | |
lines.append('mkdir %s' % out_param_dir) | |
in_biom_fp = join(in_method_dir,'*w_taxa.biom') | |
out_biom_fp = join(out_param_dir,'table.biom') | |
lines.append('cp %s %s' % (in_biom_fp,out_biom_fp)) | |
lines.append('') | |
lines.append('') | |
f = open('reorg.sh','w') | |
f.write('\n'.join(lines)) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment