Mercurial > repos > greg > cfsan_snp_pipeline_snp_matrix
comparison snp_wind.py @ 0:6b0a13deae92 draft
Uploaded
author | greg |
---|---|
date | Fri, 13 Oct 2023 20:26:32 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:6b0a13deae92 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import argparse | |
4 import os | |
5 from os.path import join as j | |
6 from itertools import zip_longest | |
7 | |
8 | |
9 def setup(base_dir, names=[], fwds=[], revs=[], extension='vcf', 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 for i, (name, fwd, rev) in enumerate(zip_longest(names, fwds, revs)): | |
16 dir = j(base_dir, str(i)) | |
17 sample_dir = j(dir, name) | |
18 os.makedirs(sample_dir) | |
19 target_f = j(sample_dir, pattern.format(name=name, orient=1, ext=extension)) | |
20 if rev: | |
21 target_r = j(sample_dir, pattern.format(name=name, orient=2, ext=extension)) | |
22 os.symlink(fwd, target_f) | |
23 if rev: | |
24 os.symlink(rev, target_r) | |
25 print(sample_dir) | |
26 if rev: | |
27 unwind.write('unlink {}\n'.format(target_r)) | |
28 unwind.write('unlink {}\n'.format(target_f)) | |
29 unwind.write('rmdir {}\n'.format(sample_dir)) | |
30 unwind.write('rmdir {}\n'.format(dir)) | |
31 | |
32 | |
33 if __name__ == '__main__': | |
34 parser = argparse.ArgumentParser(description="set up vcf symlink directories for snp-pipeline") | |
35 parser.add_argument('base_dir') | |
36 parser.add_argument('-n', dest='names', type=str, action='append', default=[]) | |
37 parser.add_argument('-f', dest='fwds', type=str, action='append', default=[]) | |
38 parser.add_argument('-r', dest='revs', type=str, action='append', default=[]) | |
39 parser.add_argument('-e', dest='extension', default='vcf') | |
40 parser.add_argument('-p', dest='pattern', default='{name}.{orient}.{ext}') | |
41 params = parser.parse_args() | |
42 setup(**vars(params)) |