annotate snp_wind.py @ 1:ab24883161d3 draft

Uploaded
author greg
date Wed, 22 Nov 2023 20:59:14 +0000
parents e958c5f7c9d1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
1 #!/usr/bin/env python
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
2
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
3 import argparse
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
4 import os
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
5 from os.path import join as j
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
6 from itertools import zip_longest
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
7
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
8
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
9 def setup(base_dir, names=[], fwds=[], revs=[], extension='vcf', pattern="{name}.{orient}.{ext}"):
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
10 if fwds and revs and names and len(fwds) != len(revs) != len(names):
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
11 raise ValueError('number of forward reads must equal number of reverse reads and names')
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
12 elif len(fwds) != len(names) or not fwds or not names:
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
13 raise ValueError('number of forward reads must equal number of names')
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
14 with open(j(base_dir, 'snp-unwind.sh'), 'w') as unwind:
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
15 for i, (name, fwd, rev) in enumerate(zip_longest(names, fwds, revs)):
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
16 dir = j(base_dir, str(i))
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
17 sample_dir = j(dir, name)
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
18 os.makedirs(sample_dir)
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
19 target_f = j(sample_dir, pattern.format(name=name, orient=1, ext=extension))
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
20 if rev:
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
21 target_r = j(sample_dir, pattern.format(name=name, orient=2, ext=extension))
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
22 os.symlink(fwd, target_f)
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
23 if rev:
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
24 os.symlink(rev, target_r)
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
25 print(sample_dir)
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
26 if rev:
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
27 unwind.write('unlink {}\n'.format(target_r))
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
28 unwind.write('unlink {}\n'.format(target_f))
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
29 unwind.write('rmdir {}\n'.format(sample_dir))
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
30 unwind.write('rmdir {}\n'.format(dir))
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
31
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
32
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
33 if __name__ == '__main__':
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
34 parser = argparse.ArgumentParser(description="set up vcf symlink directories for snp-pipeline")
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
35 parser.add_argument('base_dir')
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
36 parser.add_argument('-n', dest='names', type=str, action='append', default=[])
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
37 parser.add_argument('-f', dest='fwds', type=str, action='append', default=[])
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
38 parser.add_argument('-r', dest='revs', type=str, action='append', default=[])
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
39 parser.add_argument('-e', dest='extension', default='vcf')
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
40 parser.add_argument('-p', dest='pattern', default='{name}.{orient}.{ext}')
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
41 params = parser.parse_args()
e958c5f7c9d1 Uploaded
greg
parents:
diff changeset
42 setup(**vars(params))