This file is indexed.

/usr/lib/python2.7/dist-packages/metastudentPkg/runMethods.py is in metastudent 1.0.11-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
'''
Created on Mar 17, 2012

@author: hampt
'''

import os
import commands
from Logger import Logger
from BlastWrapper import blastallParameters, createBlastPGPCommand
import sys

silent=False
whiteSpaceCode = "~"


def setSilent(val):
	global silent
	silent=val

def isSilent():
	global silent
	return silent

def p(string):
	if not silent:
		print string

def getPkgPath():
	myPath=""
	if hasattr(sys, "frozen"):
		myPath = os.path.dirname(unicode(sys.executable, sys.getfilesystemencoding( )))
	else:
		myPath = os.path.dirname(os.path.abspath(__file__))
	return myPath

def encodeFastaHeaders(fastaFilePath):
	fastaFile = open(fastaFilePath)
	fileContent = fastaFile.read().rstrip("\n")
	fastaFile.close()
	if fileContent == "":
		Logger.log("Error: empty fasta file")
		raise
	
	lines = fileContent.split("\n")
	newLines = []
	i=0

	for line in lines:
		if line.startswith(">"):
			newLines.append(line.replace(" ", whiteSpaceCode).replace("\t", whiteSpaceCode))
		else:
			newLines.append(line)
	
	fastaFile = open(fastaFilePath,'w')
	fastaFile.write("\n".join(newLines))
	fastaFile.close()
	
def decodeFastaHeader(fastaHeader):
	return fastaHeader.replace(whiteSpaceCode, " ")

#preserves order of sequences
def splitBigFastaFile(fastaFilePath, tmpDir, splitSize): 
	
	fastaSplitFolder = os.path.join(tmpDir, "fasta_splits")
	if not os.path.exists(fastaSplitFolder):
		os.mkdir(fastaSplitFolder)
	
	fastaFile = open(fastaFilePath)
	fileContent = fastaFile.read().rstrip("\n")
	fastaFile.close()
	if fileContent == "":
		Logger.log("Error: empty fasta file")
		raise
	
	fastaFilePaths=[]
	lines = fileContent.split("\n")
	i=0
	numEntries=0
	fileCount=0
	currFileLines=[]
	
	while True:
		currHeader=""
		while(currHeader=="") and i<len(lines):
			if lines[i].startswith(">"):
				currHeader=lines[i]
			i+=1	

		currSequence = ""
		while i<len(lines) and not lines[i].startswith(">"):
			if lines[i][0].isalpha():
				currSequence += lines[i].replace(" ","").replace("\t","")
			i+=1
		currSequence.replace("\n","")
		
		currFileLines.append(currHeader+"\n")
		currFileLines.append(currSequence + "\n")
	
		numEntries += 1
		if numEntries % splitSize == 0 or i == len(lines):
			newFastaFilePath = os.path.join(fastaSplitFolder,"split_%d.fasta" % (fileCount))
			fastaFilePaths.append(newFastaFilePath)
			currFile = open(newFastaFilePath, 'w')
			currFile.write("".join(currFileLines))
			currFileLines = []
			currFile.close()
			fileCount += 1
			
		if i == len(lines):
			break
	
	return fastaFilePaths


def runBlast(inputFilePath, blastDatabasePath, outputFilePath, tmpDir, eValue, iters, configMap):
	
	fastaSplits = splitBigFastaFile(inputFilePath, tmpDir, configMap["FASTA_SPLIT_SIZE"])

	for fastaSplit in fastaSplits:
		blastParas = blastallParameters()
		blastParas.setBlastExePath(configMap["BLASTPGP_EXE_PATH"])
		blastParas.setBlastDatabasePath(blastDatabasePath)
		blastParas.setEValue(eValue)
		blastParas.setJ(iters)
		blastParas.setInputFilePath(fastaSplit)
		blastParas.setOutputFilePath(fastaSplit+".blast")
		
		blastCommand = createBlastPGPCommand(blastParas)
		
		s, o = commands.getstatusoutput(blastCommand)
		if s != 0:
			Logger.log("!!!Error!!! " + blastCommand)
			Logger.log(s)
			Logger.log(o)
			raise Exception
		
	p("Merging Blast Output")
#	allRoundSplits = ["" for bla in range(int(NUMBER_OF_ITERATIONS))]
	bigOutputFile = open(outputFilePath,'w')
	for fastaSplit in fastaSplits:
		blastFile = open(fastaSplit+".blast")
		blastOutput = "\n" + blastFile.read()
		blastFile.close()
		bigOutputFile.write(blastOutput)
	bigOutputFile.close()


def runMethodA(blastOutputFilePath, fastaFilePath, tmpDir, GROUP_A_THRESHOLD, GROUP_A_K, iters, onto, configMap):#
	p("Running Method A")
	
	currCwd = os.getcwd()
	
	tmpDirPath = os.path.join(tmpDir, "methodA")
	jarPath = os.path.join(configMap["JAR_INSTALL_FOLDER_PATH"], "gossip.jar")
	outputFilePath = os.path.join(tmpDirPath, "output.%s.cafa.txt" % (onto))
	commandsi = ["mkdir -p " + tmpDirPath, 
	   			"cd " + configMap["GROUP_A_PATH"],
				"java -cp %s GOSSIPSTarter %s %s %s %s %s %s" % (jarPath, fastaFilePath, blastOutputFilePath, outputFilePath, GROUP_A_THRESHOLD, GROUP_A_K, iters)]
	commandString = ";".join(commandsi)

	os.chdir(currCwd)

	logFile=None
	logPath=os.path.join(tmpDir, "logA.txt")
	if not os.path.exists(logPath):
		logFile = open(logPath, 'w')
	else:
		logFile = open(logPath, 'a')

	s, o = commands.getstatusoutput(commandString)
	if True:#s != 0:
		logFile.write("Command: " + commandString + "\n")
		logFile.write(str(s)+"\n")
		logFile.write(o+"\n")
	if s != 0:
		print >> sys.stderr,"!!!Error!!! " + commandString
		print >> sys.stderr,str(s)
		print >> sys.stderr,o
		#raise
	logFile.close()
	
	outputFilePath = outputFilePath+".cafa"
	outputFile = open(outputFilePath)
	preds =  set([])
	predFilesContent=[]
	for line in outputFile:
		if line.startswith("AUTHOR") or line.startswith("MODEL") or line.startswith("ACCURACY") or line.startswith("KEYWORDS") or line.startswith("END"):
			None
		else:
			targetId, goTerm, rel = line.rstrip().split("\t")
			targetId = targetId[1:].split("(")[0][:63]
		
			relFloat = max(min(float(rel), 1.00), 0.00)
			rel = "%.2f" % (relFloat)

			line = targetId + "\t" + goTerm + "\t" + rel

			if targetId + "\t" + goTerm not in preds and goTerm.strip() != "":
				predFilesContent.append(line)
				preds.add(targetId + "\t" + goTerm)

	return predFilesContent

def runMethodB(blastOutputFilePath, fastaFilePath, tmpDir, GROUP_B_K, onto, configMap):#
	p("Running Method B")
	
	currCwd = os.getcwd()
	
	tmpDirPath = os.path.join(tmpDir, "methodB")
	if not os.path.exists(tmpDirPath):
		os.mkdir(tmpDirPath)
	jarPath = configMap["JAR_INSTALL_FOLDER_PATH"].rstrip("/")
	outputFilePath = os.path.join(tmpDirPath, onto)
	os.mkdir(outputFilePath)
	commandsi = ["mkdir -p " + tmpDirPath, 
	   			"cd " + configMap["GROUP_B_PATH"],
				"./knn_weighted -m weighted_knn -j %s -d %s -i %s -o %s -k %s -l %s" % (blastOutputFilePath, blastOutputFilePath, fastaFilePath, outputFilePath, GROUP_B_K, jarPath)]
	commandString = ";".join(commandsi)
	#print commandString
	os.chdir(currCwd)

	logFile=None
	logPath=os.path.join(tmpDir, "logB.txt")
	if not os.path.exists(logPath):
		logFile = open(logPath, 'w')
	else:
		logFile = open(logPath, 'a')
	
	s, o = commands.getstatusoutput(commandString)
	if True:#s != 0:
		logFile.write("Command: " + commandString + "\n")
		logFile.write(str(s) + "\n")
		logFile.write(o+ "\n")
	if s != 0:
		print >> sys.stderr,"!!!Error!!! " + commandString
		print >> sys.stderr,str(s)
		print >> sys.stderr,o
		#raise
	logFile.close()
	
	outputFilePath = os.path.join(outputFilePath, os.path.basename(fastaFilePath)+".weighted_knn.predicted_leaves")

	idToGoTermCount = {}
	predFilesContent=[]
	with open(outputFilePath) as f: 
		for line in f.readlines():
			line = line.rstrip()
			if line.startswith("AUTHOR") or line.startswith("MODEL") or line.startswith("ACCURACY") or line.startswith("KEYWORDS") or line.startswith("END"):
				None
			else:
				currId = line.split("\t")[0][:63]
				restOfLine = "\t".join(line.split("\t")[1:])
				if idToGoTermCount.get(currId, 0) < 1000: 
					if float(restOfLine.split("\t")[1]) > 1.0:
						restOfLine = restOfLine.rstrip("\n").replace("1.01", "1.00")
					idToGoTermCount[currId] = idToGoTermCount.get(currId, 0) + 1
					line = currId + "\t" +  restOfLine
					predFilesContent.append(line)
	return predFilesContent

def runMethodC(blastOutputFilePath, fastaFilePath, tmpDir, scoring, onto, configMap, debug):#
	p("Running Method C")
	
	currCwd = os.getcwd()
	
	tmpDirPath = os.path.join(tmpDir, "methodC")
	outputFilePath = os.path.join(tmpDirPath, "output.%s.txt" % (onto))
	commandsi = ["mkdir -p " + tmpDirPath, 
	   			"cd " + configMap["GROUP_C_PATH"],
				"./CafaWrapper3.pl %s %s %s %s" % (blastOutputFilePath, outputFilePath, scoring, tmpDirPath)]
	commandString = ";".join(commandsi)
	if debug:
		print >> sys.stderr, commandString
	os.chdir(currCwd)

	logFile=None
	logPath=os.path.join(tmpDir, "logC.txt")
	if not os.path.exists(logPath):
		logFile = open(logPath, 'w')
	else:
		logFile = open(logPath, 'a')
	
	s, o = commands.getstatusoutput(commandString)
	if True:#s != 0:
		logFile.write("Command: " + commandString)
		logFile.write(str(s))
		logFile.write(o)
	if s != 0:
		print >> sys.stderr, "!!!Error!!! " + commandString
		print >> sys.stderr,str(s)
		print >> sys.stderr,o
		#raise
	logFile.close()

	predFilesContent = []
	with open(outputFilePath) as f: 						
		preds =  set([])
		for line in f.readlines():
			line=line.rstrip()
			if line.rstrip() == "" or line.startswith("AUTHOR") or line.startswith("MODEL") or line.startswith("ACCURACY") or line.startswith("KEYWORDS") or line.startswith("END"):
				None
			else:
				targetId, goTerm, rel = line.rstrip().split(" ")
				relFloat = max(min(float(rel), 1.00), 0.00)
				rel = "%.2f" % (relFloat)					
				line = targetId[:63] + "\t" + goTerm + "\t" + rel				
				if targetId[:63] + "\t" + goTerm not in preds and goTerm.strip() != "" and float(rel) > 0.0:
					predFilesContent.append(line)
					preds.add(targetId[:63] + "\t" + goTerm)

	return predFilesContent