Mercurial > hg > lib > markup
comparison python/cluster.py @ 7:3ee329b129c6
rename block properties, slightly revise result format
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Wed, 26 May 2021 09:18:49 -0400 |
parents | 672621ab4db4 |
children | e411408d64ec |
comparison
equal
deleted
inserted
replaced
6:a01ff74f9fd7 | 7:3ee329b129c6 |
---|---|
3 import sys | 3 import sys |
4 | 4 |
5 from util import * | 5 from util import * |
6 | 6 |
7 if len(sys.argv)==1 or sys.argv[1]=='-h': | 7 if len(sys.argv)==1 or sys.argv[1]=='-h': |
8 print("""Usage: cluster.py [-h] [-c n] infile.tsv [outfile.tsv] | 8 print("""Usage: cluster.py [-h] [-c n] [-s] infile.tsv [outfile.tsv] |
9 n is cluster diameter, default is 5 | 9 n is cluster diameter, default is 5 |
10 -s for strict circle distance, reduces number of candidates | |
10 default outfile is [infile]_c[n].tsv""") | 11 default outfile is [infile]_c[n].tsv""") |
11 exit(1) | 12 exit(1) |
12 if sys.argv[1]=='-c': | 13 if sys.argv[1]=='-c': |
13 sys.argv.pop(1) | 14 sys.argv.pop(1) |
14 n=float(sys.argv.pop(1)) | 15 n=float(sys.argv.pop(1)) |
15 else: | 16 else: |
16 n=5.0 | 17 n=5.0 |
18 | |
19 if sys.argv[1]=='-s': | |
20 sys.argv.pop(1) | |
21 strict=True | |
22 else: | |
23 strict=False | |
17 | 24 |
18 infile_name=sys.argv.pop(1) | 25 infile_name=sys.argv.pop(1) |
19 if len(sys.argv)>1: | 26 if len(sys.argv)>1: |
20 outfile_name=sys.argv.pop(1) | 27 outfile_name=sys.argv.pop(1) |
21 else: | 28 else: |
38 for l in infile: | 45 for l in infile: |
39 found=False | 46 found=False |
40 (_,td,qd)=l.rstrip().split('\t') | 47 (_,td,qd)=l.rstrip().split('\t') |
41 q=[float(i) for i in qd.split(',')] | 48 q=[float(i) for i in qd.split(',')] |
42 td=float(td) | 49 td=float(td) |
43 if td>orad: | 50 if strict and td>orad: |
44 # Enforce a circular region, not square | 51 # Enforce a circular region, not square |
52 print(td,orad,file=sys.stderr) | |
45 break | 53 break |
46 for c in cc: | 54 for c in cc: |
47 for p in c: | 55 for p in c: |
48 if d(p,q)<=n: | 56 if d(p,q)<=n: |
49 c.append(q) | 57 c.append(q) |