annotate check_bcfile.py @ 4:0345dbaaa79b draft

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