Mercurial > repos > jpayne > snp_pipeline
diff snp-wind.py @ 0:eefdd97a6749
planemo upload commit b'7f6183b769772449fbcee903686b8d5ec5b7439f\n'-dirty
author | jpayne |
---|---|
date | Wed, 24 Jan 2018 14:18:21 -0500 |
parents | |
children | 6adaecff5f2b |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snp-wind.py Wed Jan 24 14:18:21 2018 -0500 @@ -0,0 +1,45 @@ +#! /usr/bin/env python3.6 + +import argparse +import uuid +import os, sys +from os.path import join as j +from itertools import zip_longest + +def setup(base_dir, names=[], fwds=[], revs=[], extension='fastq', pattern="{name}.{orient}.{ext}"): + if fwds and revs and names and len(fwds) != len(revs) != len(names): + raise ValueError('number of forward reads must equal number of reverse reads and names') + elif len(fwds) != len(names) or not fwds or not names: + raise ValueError('number of forward reads must equal number of names') + with open(j(base_dir, 'snp-unwind.sh'), 'w') as unwind: + #dir = j(base_dir, str(uuid.uuid4())) + for i, (name, fwd, rev) in enumerate(zip_longest(names, fwds, revs)): + dir = j(base_dir, str(i)) + sample_dir = j(dir, name) + os.makedirs(sample_dir) + target_f = j(sample_dir, pattern.format(name=name, orient=1, ext=extension)) + if rev: + target_r = j(sample_dir, pattern.format(name=name, orient=2, ext=extension)) + os.symlink(fwd, target_f) + if rev: + os.symlink(rev, target_r) + print(sample_dir) + if rev: + unwind.write('unlink {}\n'.format(target_r)) + unwind.write('unlink {}\n'.format(target_f)) + unwind.write('rmdir {}\n'.format(sample_dir)) + unwind.write('rmdir {}\n'.format(dir)) + + + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description="set up fastq symlink directories for snp-pipeline") + parser.add_argument('base_dir') + parser.add_argument('-n', dest='names', type=str, action='append', default=[]) + parser.add_argument('-f', dest='fwds', type=str, action='append', default=[]) + parser.add_argument('-r', dest='revs', type=str, action='append', default=[]) + parser.add_argument('-e', dest='extension', default='fastq') + parser.add_argument('-p', dest='pattern', default='{name}.{orient}.{ext}') + params = parser.parse_args() + setup(**vars(params)) \ No newline at end of file