-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.py
More file actions
executable file
·62 lines (51 loc) · 1.44 KB
/
input.py
File metadata and controls
executable file
·62 lines (51 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
import argparse
import os.path
import glob
import json
def dir_path(path):
if os.path.isdir(path):
return os.path.realpath(path)
else:
raise NotADirectoryError(path)
def main():
# parse argument
parser = argparse.ArgumentParser(
description="Create inputs.json file for preprocessing."
)
parser.add_argument(
"path", type=dir_path, help="sample or library directory"
)
args = parser.parse_args()
path = os.path.realpath(args.path)
library_id = os.path.basename(path)
# list lanes
lanes = glob.glob(path + "/**/*.fastq.gz", recursive=True)
lanes.sort()
# group lanes by sample
sample_ids = []
sample_dict = {}
for lane in lanes:
sample = os.path.basename(os.path.dirname(lane))
if sample in sample_dict:
sample_dict[sample].append(lane)
else:
sample_ids.append(sample)
sample_dict[sample] = [lane]
# write output in JSON format
with open("inputs.json", "w") as output_file:
json.dump(
{
"Main.library_id": library_id,
"Main.sample_ids": sample_ids,
"Main.samples": sample_dict,
},
output_file,
indent=2,
)
# print output
print("samples:")
for i, sample in enumerate(sample_ids, start=1):
print(i, sample)
if __name__ == "__main__":
main()