comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:eefdd97a6749
1 #! /usr/bin/env python3.6
2
3 import argparse
4 import uuid
5 import os, sys
6 from os.path import join as j
7 from itertools import zip_longest
8
9 def setup(base_dir, names=[], fwds=[], revs=[], extension='fastq', pattern="{name}.{orient}.{ext}"):
10 if fwds and revs and names and len(fwds) != len(revs) != len(names):
11 raise ValueError('number of forward reads must equal number of reverse reads and names')
12 elif len(fwds) != len(names) or not fwds or not names:
13 raise ValueError('number of forward reads must equal number of names')
14 with open(j(base_dir, 'snp-unwind.sh'), 'w') as unwind:
15 #dir = j(base_dir, str(uuid.uuid4()))
16 for i, (name, fwd, rev) in enumerate(zip_longest(names, fwds, revs)):
17 dir = j(base_dir, str(i))
18 sample_dir = j(dir, name)
19 os.makedirs(sample_dir)
20 target_f = j(sample_dir, pattern.format(name=name, orient=1, ext=extension))
21 if rev:
22 target_r = j(sample_dir, pattern.format(name=name, orient=2, ext=extension))
23 os.symlink(fwd, target_f)
24 if rev:
25 os.symlink(rev, target_r)
26 print(sample_dir)
27 if rev:
28 unwind.write('unlink {}\n'.format(target_r))
29 unwind.write('unlink {}\n'.format(target_f))
30 unwind.write('rmdir {}\n'.format(sample_dir))
31 unwind.write('rmdir {}\n'.format(dir))
32
33
34
35
36 if __name__ == '__main__':
37 parser = argparse.ArgumentParser(description="set up fastq symlink directories for snp-pipeline")
38 parser.add_argument('base_dir')
39 parser.add_argument('-n', dest='names', type=str, action='append', default=[])
40 parser.add_argument('-f', dest='fwds', type=str, action='append', default=[])
41 parser.add_argument('-r', dest='revs', type=str, action='append', default=[])
42 parser.add_argument('-e', dest='extension', default='fastq')
43 parser.add_argument('-p', dest='pattern', default='{name}.{orient}.{ext}')
44 params = parser.parse_args()
45 setup(**vars(params))