Skip to content

Commit 7816106

Browse files
committed
Require all arguments in IBDinput_rewrite_v3.py and improve input validation
1 parent e3a9ab2 commit 7816106

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

tools/IBDinput_rewrite_v3.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import os
44
import sys
55
import gzip
6-
import multiprocessing as mp
76
import argparse as ap
8-
from functools import partial
97
from bisect import bisect_left
108

119

@@ -33,7 +31,7 @@ def __init__(self, f: str):
3331
self.cM_indx = 7
3432
else:
3533
if f.lower().split(':')[0] in ['other','others']:
36-
indx = in_format.lower().split(':')[1].split(';')
34+
indx = f.lower().split(':')[1].split(';')
3735
self.id1_indx = int(indx[0]) - 1
3836
self.id2_indx = int(indx[1]) - 1
3937
self.chr_indx = int(indx[2]) - 1
@@ -76,6 +74,8 @@ def get_phenotypes(ipf):
7674
for line in pheno_file:
7775
line = line.strip()
7876
line = line.split()
77+
if len(line) < 2:
78+
continue
7979
if line[1] == 'NA':
8080
continue
8181
elif str(line[0]) in uniqID:
@@ -131,7 +131,7 @@ def IBDsumm(args, idx, uniqID, dupID):
131131
start = min(int(line[idx.str_indx]), int(line[idx.end_indx]))
132132
end = max(int(line[idx.str_indx]), int(line[idx.end_indx]))
133133
cM = str(line[idx.cM_indx])
134-
if id1 not in uniqID or id2 not in uniqID or float(cM) < args.min or ( 'unit' in vars() and str(line[unit]) != 'cM'):
134+
if id1 not in uniqID or id2 not in uniqID or float(cM) < args.min or (hasattr(idx, 'unit') and str(line[idx.unit]) != 'cM'):
135135
continue
136136
else:
137137
if uniqID[id1] < uniqID[id2]:
@@ -174,13 +174,13 @@ def IBDsumm(args, idx, uniqID, dupID):
174174
def main():
175175
"""Entrypoint."""
176176
parser = ap.ArgumentParser()
177-
parser.add_argument('-i', '--input', type=str, help='Input IBD segment file.')
178-
parser.add_argument('-p', '--pheno', type=str, help='Input pheotype file.')
179-
parser.add_argument('-o', '--output', type=str, help='Prefix to the output file.')
180-
parser.add_argument('-f', '--format', type=str, help='Which program is the input derived from? May be GERMLINE, iLASH, RaPID, hap-ibd, or other.')
181-
parser.add_argument('-m', '--min', type=float, help='Minimum centimorgan length of segments to be considered.')
182-
parser.add_argument('-c', '--chrom', type=str, help='The current chromosome.')
183-
parser.add_argument('-T', '--temp', type=str, help='Path to the temporary file storage directory.')
177+
parser.add_argument('-i', '--input', type=str, required=True, help='Input IBD segment file.')
178+
parser.add_argument('-p', '--pheno', type=str, required=True, help='Input pheotype file.')
179+
parser.add_argument('-o', '--output', type=str, required=True, help='Prefix to the output file.')
180+
parser.add_argument('-f', '--format', type=str, required=True, help='Which program is the input derived from? May be GERMLINE, iLASH, RaPID, hap-ibd, or other.')
181+
parser.add_argument('-m', '--min', type=float, required=True, help='Minimum centimorgan length of segments to be considered.')
182+
parser.add_argument('-c', '--chrom', type=str, required=True, help='The current chromosome.')
183+
parser.add_argument('-T', '--temp', type=str, required=True, help='Path to the temporary file storage directory.')
184184
args = parser.parse_args()
185185

186186
idx = Indices(args.format)
@@ -192,8 +192,4 @@ def main():
192192

193193
uniqID, dupID = get_phenotypes(args.pheno)
194194

195-
IBDsumm(args, idx, uniqID, dupID)
196-
197-
198-
if __name__ == "__main__":
199-
main()
195+
IBDsumm(args, idx, uniqID, dupID)

0 commit comments

Comments
 (0)