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