Mercurial > repos > iuc > stacks2_kmerfilter
annotate check_bcfile.py @ 3:1544278c272e draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit 9a6c14bcb90c0b30c583294a993fac47504f4009"
author | iuc |
---|---|
date | Tue, 27 Apr 2021 09:32:17 +0000 |
parents | 8a55d29c8fcf |
children |
rev | line source |
---|---|
2
8a55d29c8fcf
"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 |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
2 |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
3 import argparse |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
4 import sys |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
5 |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
6 parser = argparse.ArgumentParser() |
8a55d29c8fcf
"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') |
8a55d29c8fcf
"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() |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
9 |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
10 barcodes = [] |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
11 |
8a55d29c8fcf
"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: |
8a55d29c8fcf
"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: |
8a55d29c8fcf
"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: |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
15 continue |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
16 if line.startswith("#"): |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
17 continue |
8a55d29c8fcf
"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()) |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
19 |
8a55d29c8fcf
"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: |
8a55d29c8fcf
"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") |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
22 |
8a55d29c8fcf
"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 |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
24 ncol = None |
8a55d29c8fcf
"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: |
8a55d29c8fcf
"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: |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
27 ncol = len(bc) |
8a55d29c8fcf
"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): |
8a55d29c8fcf
"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") |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
30 |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
31 isname = False |
8a55d29c8fcf
"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: |
8a55d29c8fcf
"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: |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
34 isname = True |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
35 break |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
36 |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
37 names = set() |
8a55d29c8fcf
"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: |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
39 if isname: |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
40 n = bc[-1] |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
41 else: |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
42 n = '-'.join(bc) |
8a55d29c8fcf
"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: |
8a55d29c8fcf
"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) |
8a55d29c8fcf
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/stacks2 commit f55e2407891a3c1f73f14a77b7ddadcd6f5eb1f8"
iuc
parents:
diff
changeset
|
45 names.add(n) |