Skip to content

Commit ba6b3c6

Browse files
authored
Merge pull request #281 from polio-nanopore/space_check
Space check
2 parents 8c1aee1 + 193d074 commit ba6b3c6

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

piranha/input_parsing/input_qc.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,40 @@ def parse_barcodes_csv(barcodes_csv,config):
4040
samples = []
4141
with open(config[KEY_BARCODES_CSV],"r") as f:
4242
reader = csv.DictReader(f)
43-
for col in [KEY_BARCODE,KEY_SAMPLE]:
43+
cols_to_check = [KEY_BARCODE,KEY_SAMPLE]
44+
45+
for col in cols_to_check:
4446
if not col in reader.fieldnames:
4547
sys.stderr.write(cyan(f"`{col}` must be a column name in barcode csv file.\n"))
4648
sys.exit(-1)
4749

50+
if KEY_EPID in reader.fieldnames:
51+
cols_to_check.append(KEY_EPID)
52+
4853
for row in reader:
4954
if row[KEY_BARCODE] and not row[KEY_SAMPLE]:
5055
continue
56+
57+
5158
if row[KEY_BARCODE] in barcodes:
5259
barcode = row[KEY_BARCODE]
5360
sys.stderr.write(cyan(f"`{barcode}` duplicated in barcode csv file. Note: barcodes must be unique.\n"))
5461
sys.exit(-1)
5562
if row[KEY_SAMPLE] in samples:
5663
print(cyan(f"Warning: `{row[KEY_SAMPLE]}` sample name provided for multiple barcodes."))
57-
for special_character in ["|",","," ",";"]:
58-
if special_character in row[KEY_BARCODE]:
59-
sys.stderr.write(cyan(f"Special character `{special_character}` cannot be used in barcode or sample name. Please remove this character from barcode `{row[KEY_BARCODE]}` and restart.\n"))
60-
sys.exit(-1)
61-
elif special_character in row[KEY_SAMPLE]:
62-
sys.stderr.write(cyan(f"Special character `{special_character}` cannot be used in barcode or sample name. Please remove this character from sample `{row[KEY_SAMPLE]}` and restart.\n"))
63-
sys.exit(-1)
64+
65+
for col in cols_to_check:
66+
for special_character in ["|",","," ",";"]:
67+
if special_character in row[col]:
68+
sys.stderr.write(cyan(f"Special character `{special_character}` cannot be used in {col} field. Please remove this character from `{row[KEY_BARCODE]}` and restart.\n"))
69+
sys.exit(-1)
6470

6571
if row[KEY_BARCODE] and row[KEY_SAMPLE]:
6672
barcodes.append(row[KEY_BARCODE])
6773
samples.append(row[KEY_SAMPLE])
74+
75+
76+
6877

6978
config[KEY_BARCODES] = barcodes
7079
config[KEY_SAMPLES] = samples

0 commit comments

Comments
 (0)