comparison check_bcfile.py @ 2:421c33b8bf17 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
author iuc
date Wed, 15 Jul 2020 17:25:36 -0400
parents
children
comparison
equal deleted inserted replaced
1:afdbc7fcce70 2:421c33b8bf17
1 #!/usr/bin/env python
2
3 import argparse
4 import sys
5
6 parser = argparse.ArgumentParser()
7 parser.add_argument('bcfile', help='barcode file')
8 args = parser.parse_args()
9
10 barcodes = []
11
12 with open(args.bcfile, "r") as fh:
13 for line in fh:
14 if len(line) == 0:
15 continue
16 if line.startswith("#"):
17 continue
18 barcodes.append(line.split())
19
20 if len(barcodes) <= 1:
21 sys.exit("barcode file is empty")
22
23 # check that all lines have the same number of columns
24 ncol = None
25 for bc in barcodes:
26 if ncol is None:
27 ncol = len(bc)
28 elif ncol != len(bc):
29 sys.exit("barcode file has inconsistent number of columns")
30
31 isname = False
32 for bc in barcodes:
33 if len(bc[-1].strip("ATCGatcg")) > 0:
34 isname = True
35 break
36
37 names = set()
38 for bc in barcodes:
39 if isname:
40 n = bc[-1]
41 else:
42 n = '-'.join(bc)
43 if n in names:
44 sys.exit("duplicate sample %s in barcode file" % n)
45 names.add(n)