Mercurial > repos > jpayne > snp_pipeline
view snp-wind.py @ 9:41bd2a5793ee
planemo upload commit 7f6183b769772449fbcee903686b8d5ec5b7439f-dirty
author | jpayne |
---|---|
date | Tue, 30 Jan 2018 15:55:32 -0500 |
parents | eefdd97a6749 |
children | 6adaecff5f2b |
line wrap: on
line source
#! /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))