comparison spring_minz.py @ 25:5d1ae615e4ec draft

"planemo upload commit ff7d7e512b79436c3538078552983762330a920d-dirty"
author guerler
date Sat, 31 Oct 2020 22:01:29 +0000
parents 5469e19f1f96
children e34da554d415
comparison
equal deleted inserted replaced
24:802daf2993b0 25:5d1ae615e4ec
39 targetName=targetName, 39 targetName=targetName,
40 inputs=inputs, 40 inputs=inputs,
41 inputPath=inputPath, 41 inputPath=inputPath,
42 crossReference=crossReference, 42 crossReference=crossReference,
43 minScore=args.minscore, 43 minScore=args.minscore,
44 idLength=args.idx,
45 logFile=logFile, 44 logFile=logFile,
46 interactions=interactions) 45 interactions=interactions)
47 if args.inputlist: 46 if args.inputlist:
48 for inputName in inputs: 47 for inputName in inputs:
49 inputDirectory = inputPath 48 inputDirectory = inputPath
52 targetName=inputName, 51 targetName=inputName,
53 inputs=targets, 52 inputs=targets,
54 inputPath=targetPath, 53 inputPath=targetPath,
55 crossReference=crossReference, 54 crossReference=crossReference,
56 minScore=args.minscore, 55 minScore=args.minscore,
57 idLength=args.idx,
58 logFile=logFile, 56 logFile=logFile,
59 interactions=interactions) 57 interactions=interactions)
60 interactions = sorted(interactions.values(), key=lambda item: item["minZ"], reverse=True) 58 interactions = sorted(interactions.values(), key=lambda item: item["minZ"], reverse=True)
61 with open(args.output, 'w') as output_file: 59 with open(args.output, 'w') as output_file:
62 for entry in interactions: 60 for entry in interactions:
63 output_file.write("%s\t%s\t%s\t%s\n" % (entry["targetName"], entry["inputName"], entry["minZ"], entry["minInfo"])) 61 output_file.write("%s\t%s\t%s\t%s\n" % (entry["targetName"], entry["inputName"], entry["minZ"], entry["minInfo"]))
64 logFile.close() 62 logFile.close()
65 63
66 def matchScores(targetFile, targetName, inputs, inputPath, crossReference, minScore, idLength, logFile, interactions): 64 def matchScores(targetFile, targetName, inputs, inputPath, crossReference, minScore, logFile, interactions):
67 targetTop, targetHits = getTemplateScores(targetFile, minScore, idLength) 65 targetTop, targetHits = getTemplateScores(targetFile, minScore)
68 if not targetHits: 66 if not targetHits:
69 print("No targets found `%s`" % targetFile) 67 print("No targets found `%s`" % targetFile)
70 else: 68 else:
71 print ("Loaded target scores from `%s`." % targetFile) 69 print ("Loaded target scores from `%s`." % targetFile)
72 for inputName in inputs: 70 for inputName in inputs:
73 inputFile = "%s/%s" % (inputPath, inputName) 71 inputFile = "%s/%s" % (inputPath, inputName)
74 inputTop, inputHits = getTemplateScores(inputFile, minScore, idLength) 72 inputTop, inputHits = getTemplateScores(inputFile, minScore)
75 minZ = 0 73 minZ = 0
76 minInfo = "" 74 minInfo = ""
77 for t in targetHits: 75 for t in targetHits:
78 if t in crossReference: 76 if t in crossReference:
79 partners = crossReference[t] 77 partners = crossReference[t]
92 if interactions[interactionKey]["minZ"] >= minZ: 90 if interactions[interactionKey]["minZ"] >= minZ:
93 continue 91 continue
94 interactions[interactionKey] = dict(targetName=targetName, inputName=inputName, minZ=minZ, minInfo=minInfo) 92 interactions[interactionKey] = dict(targetName=targetName, inputName=inputName, minZ=minZ, minInfo=minInfo)
95 logFile.write("Interaction between %s and %s [min-Z: %s].\n" % (targetName, inputName, minZ)) 93 logFile.write("Interaction between %s and %s [min-Z: %s].\n" % (targetName, inputName, minZ))
96 94
97 def getTemplateScores(hhrFile, minScore, identifierLength): 95 def getTemplateScores(hhrFile, minScore):
98 result = dict() 96 result = dict()
99 topTemplate = None 97 topTemplate = None
100 identifierLength = identifierLength + 4
101 if os.path.isfile(hhrFile): 98 if os.path.isfile(hhrFile):
102 with open(hhrFile) as file: 99 with open(hhrFile) as file:
103 for index, line in enumerate(file): 100 for index, line in enumerate(file):
104 if index > 8: 101 if index > 8:
105 if not line.strip(): 102 if not line.strip():
106 break 103 break
107 templateId = line[4:identifierLength] 104 templateId = line[4:10]
108 templateScore = float(line[57:63]) 105 templateScore = float(line[57:63])
109 if templateScore > minScore: 106 if templateScore > minScore:
110 if topTemplate is None: 107 if topTemplate is None:
111 topTemplate = templateId 108 topTemplate = templateId
112 result[templateId] = templateScore 109 result[templateId] = templateScore
117 parser.add_argument('-tl', '--targetlist', help='Text file containing identifiers.', required=True) 114 parser.add_argument('-tl', '--targetlist', help='Text file containing identifiers.', required=True)
118 parser.add_argument('-tp', '--targetpath', help='Directory containing `hhr` files', required=True) 115 parser.add_argument('-tp', '--targetpath', help='Directory containing `hhr` files', required=True)
119 parser.add_argument('-il', '--inputlist', help='Text file containing identifiers.', required=False) 116 parser.add_argument('-il', '--inputlist', help='Text file containing identifiers.', required=False)
120 parser.add_argument('-ip', '--inputpath', help='Directory containing `hhr` files', required=False) 117 parser.add_argument('-ip', '--inputpath', help='Directory containing `hhr` files', required=False)
121 parser.add_argument('-c', '--crossreference', help='Cross Reference index file', required=True) 118 parser.add_argument('-c', '--crossreference', help='Cross Reference index file', required=True)
122 parser.add_argument('-x', '--idx', help='Length of identifier', type=int, default=6)
123 parser.add_argument('-o', '--output', help='Output file containing min-Z scores', required=True) 119 parser.add_argument('-o', '--output', help='Output file containing min-Z scores', required=True)
124 parser.add_argument('-l', '--log', help='Log file', required=True) 120 parser.add_argument('-l', '--log', help='Log file', required=True)
125 parser.add_argument('-m', '--minscore', help='min-Z score threshold', type=int, default=10) 121 parser.add_argument('-m', '--minscore', help='min-Z score threshold', type=int, default=10)
126 args = parser.parse_args() 122 args = parser.parse_args()
127 main(args) 123 main(args)