Mercurial > repos > guerler > springsuite
comparison spring_minz.py @ 9:4ac5d5a9b21c draft
"planemo upload commit f465445ebca0307953f59938494a2244ca8ea23c"
author | guerler |
---|---|
date | Sat, 01 Aug 2020 02:13:31 -0400 |
parents | f2f38991c36f |
children | 21a7dd67b483 |
comparison
equal
deleted
inserted
replaced
8:f2f38991c36f | 9:4ac5d5a9b21c |
---|---|
16 partner = columns[2] | 16 partner = columns[2] |
17 if core not in crossreference: | 17 if core not in crossreference: |
18 crossreference[core] = [] | 18 crossreference[core] = [] |
19 crossreference[core].append(partner) | 19 crossreference[core].append(partner) |
20 print ("Loaded cross reference from `%s`." % args.crossreference) | 20 print ("Loaded cross reference from `%s`." % args.crossreference) |
21 targets = get_template_scores(args.target, args.minscore) | 21 targets = get_template_scores(args.target, args.minscore, args.idx) |
22 interactions = [] | 22 interactions = [] |
23 if not targets: | 23 if not targets: |
24 print("No targets found `%s`" % args.target) | 24 print("No targets found `%s`" % args.target) |
25 else: | 25 else: |
26 print ("Loaded target scores from `%s`." % args.target) | 26 print ("Loaded target scores from `%s`." % args.target) |
27 for name in names: | 27 for name in names: |
28 input_directory = args.inputs.rstrip("/") | 28 input_directory = args.inputs.rstrip("/") |
29 input_file = "%s/%s" % (input_directory, name) | 29 input_file = "%s/%s" % (input_directory, name) |
30 templates = get_template_scores(input_file, args.minscore) | 30 templates = get_template_scores(input_file, args.minscore, args.idx) |
31 minz = 0 | 31 minz = 0 |
32 for t in targets: | 32 for t in targets: |
33 if t in crossreference: | 33 if t in crossreference: |
34 partners = crossreference[t] | 34 partners = crossreference[t] |
35 for p in partners: | 35 for p in partners: |
43 interactions.sort(key=lambda tup: tup[1], reverse=True) | 43 interactions.sort(key=lambda tup: tup[1], reverse=True) |
44 with open(args.output, 'w') as output_file: | 44 with open(args.output, 'w') as output_file: |
45 for i in interactions: | 45 for i in interactions: |
46 output_file.write("%s %s\n" % (i[0], i[1])) | 46 output_file.write("%s %s\n" % (i[0], i[1])) |
47 | 47 |
48 def get_template_scores(hhr_file, min_score): | 48 def get_template_scores(hhr_file, min_score, identifier_length): |
49 result = {} | 49 result = {} |
50 identifier_length = identifier_length + 4 | |
50 if os.path.isfile(hhr_file): | 51 if os.path.isfile(hhr_file): |
51 with open(hhr_file) as file: | 52 with open(hhr_file) as file: |
52 for index, line in enumerate(file): | 53 for index, line in enumerate(file): |
53 if index > 8: | 54 if index > 8: |
54 if not line.strip(): | 55 if not line.strip(): |
55 break | 56 break |
56 template_id = line[4:10] | 57 template_id = line[4:identifier_length] |
57 template_score = float(line[57:63]) | 58 template_score = float(line[57:63]) |
58 if template_score > min_score: | 59 if template_score > min_score: |
59 result[template_id] = template_score | 60 result[template_id] = template_score |
60 return result | 61 return result |
61 | 62 |
62 if __name__ == "__main__": | 63 if __name__ == "__main__": |
63 parser = argparse.ArgumentParser(description='This script identifies interactions by detecting matching HH-search results.') | 64 parser = argparse.ArgumentParser(description='This script identifies interactions by detecting matching HH-search results.') |
64 parser.add_argument('-t', '--target', help='HHR target file result', required=True) | 65 parser.add_argument('-t', '--target', help='HHR target file result', required=True) |
65 parser.add_argument('-c', '--crossreference', help='Cross Reference index file', required=True) | 66 parser.add_argument('-c', '--crossreference', help='Cross Reference index file', required=True) |
67 parser.add_argument('-x', '--idx', help='Length of identifier', type=int, default=6) | |
66 parser.add_argument('-l', '--list', help='Text file containing identifiers.', required=True) | 68 parser.add_argument('-l', '--list', help='Text file containing identifiers.', required=True) |
67 parser.add_argument('-i', '--inputs', help='Directory containing `hhr/X/Y.hhr` files', required=True) | 69 parser.add_argument('-i', '--inputs', help='Directory containing `hhr` files', required=True) |
68 parser.add_argument('-o', '--output', help='Output file containing minZ-scores`', required=True) | 70 parser.add_argument('-o', '--output', help='Output file containing minZ-scores`', required=True) |
69 parser.add_argument('-m', '--minscore', help='min-Z score threshold', type=int, default=10) | 71 parser.add_argument('-m', '--minscore', help='min-Z score threshold', type=int, default=10) |
70 args = parser.parse_args() | 72 args = parser.parse_args() |
71 main(args) | 73 main(args) |