Skip to content

Commit

Permalink
Final version with multi processing implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Le committed Mar 16, 2017
1 parent f5234a4 commit af1e9a5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
4 changes: 2 additions & 2 deletions ClassDefinitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,13 @@ def findEssentialReactions(self):
print(('There are ' + str(numBasicEssential - 1) + ' essential reactions in a subset with the growth reaction.'))
print('Returning the remaining essential reactions')
return sorted(EssentialFull)
def findSyntheticLethalPairs(self):
def findSyntheticLethalPairs(self,parallel=0):
if self.checkReduced():
Network = self.reducedMatrix
Target = self.findBiomassReactionReduced()
if Target is not None:
Irr = [i for i, subset in enumerate(self.reactionSubsets) if not subset.reversible]
Essential, Lethal = findEssentialLethal(Network, Target, rec = False, I = Irr, verbose = True)
Essential, Lethal = findEssentialLethal(Network, Target, rec = False, I = Irr, verbose = True,parallel=parallel)
allPairs = []
for item in Lethal:
first, second = item[0], item[1]
Expand Down
35 changes: 23 additions & 12 deletions MONGOOSEgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def run(self):
print(getattr(self.model_name, self.function_name)())
print(time.time() - start_time)
elif(self.index_name == self.findSyntheticLethalPairs):
print(getattr(self.model_name, self.function_name)())
print(getattr(self.model_name, self.function_name)(0))
print(time.time() - start_time)
else:
print("Thread could not find work")
Expand Down Expand Up @@ -261,6 +261,7 @@ def setupUi(self, MainWindow):
self.chooseParallel.setObjectName(_fromUtf8("chooseIndex"))
self.chooseParallel.setPlaceholderText('threads')
self.chooseParallel.setVisible(False)
self.chooseParallel.setToolTip(_translate("MainWindow", "<html><head/><body><p>Choose the number of threads</p></body></html>", None))

# intializes third dropdown menu, chooses a function
self.chooseFunction3 = QtGui.QComboBox(self.centralwidget)
Expand Down Expand Up @@ -537,7 +538,7 @@ def hide1(self):
if(index == PRINT_RXN_FORMULA or index==DELETE_RXN or index==DELETE_METAB):
self.chooseIndex.setVisible(True)
self.chooseParallel.setVisible(False)
elif(index == REDUCE_NETWORK or index == FIND_SYNTH_LETH_PAIRS):
elif(index == FIND_SYNTH_LETH_PAIRS):
self.chooseIndex.setVisible(False)
self.chooseParallel.setVisible(True)
elif(index == ADD_RXN or index == ADD_METAB):
Expand Down Expand Up @@ -733,18 +734,28 @@ def chooseFunction(self):
print(">>> model.%s()" % (function1))
if(index1 == REDUCE_NETWORK):
print("Reducing network")
#self.myThread = WorkerThread(model,function1, REDUCE_NETWORK)
self.myThread = WorkerThread(model,function1, REDUCE_NETWORK)
start_time = time.time()
#self.myThread.start()
print(getattr(model, function1)())
print(time.time() - start_time)
self.myThread.start()
#print(getattr(model, function1)())
#print(time.time() - start_time)
elif(index1 == FIND_SYNTH_LETH_PAIRS):
print("Finding synthetic lethal pairs")
#self.myThread = WorkerThread(model,function1, FIND_SYNTH_LETH_PAIRS)
start_time = time.time()
print(getattr(model, function1)())
#self.myThread.start()
print(time.time() - start_time)
numProc = self.chooseParallel.text()
if numProc:
print("Finding synthetic lethal pairs")
numProc = int( numProc )
start_time = time.time()
print(getattr(model, function1)(numProc))
print(time.time() - start_time)
elif(numProc == 0):
print("Finding synthetic lethal pairs")
self.myThread = WorkerThread(model,function1, FIND_SYNTH_LETH_PAIRS)
self.myThread.start()
else:
numProc = 0
print("Finding synthetic lethal pairs")
self.myThread = WorkerThread(model,function1, FIND_SYNTH_LETH_PAIRS)
self.myThread.start()
else:
print(getattr(model, function1)())

Expand Down
10 changes: 2 additions & 8 deletions ModelProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
from math import gcd
from fractions import Fraction
from Utilities import *
#from multiprocessing import Process, Queue
import multiprocessing
#import queue
#from multiprocessing import Pool # threading
#from multiprocessing.dummy import Pool as ThreadPool # threading

zero, one = Fraction(0), Fraction(1)

Expand Down Expand Up @@ -713,7 +709,6 @@ def findDistance(N, special, Irrev, norm = 'inf'):

####parallelization
def parallelizedNegFindFeasible(N, Irrev, pos ,index, option,subList,out_q_neg):
#subOnlyNeg = []
count = len(subList) * index
outdict = {}
for ind, react in enumerate(subList): # changed from subOnlyNeg to subList!
Expand All @@ -723,7 +718,6 @@ def parallelizedNegFindFeasible(N, Irrev, pos ,index, option,subList,out_q_neg)
out_q_neg.put(outdict) #places dictionary into queue asynchronously

def parallelizedPosFindFeasible(N, Irrev, pos ,index, option,subList,out_q_pos):
#subOnlyPos = []
outdict = {}
count = len(subList) * index
for ind, react in enumerate(subList):# changed from subOnlyPos to subList!
Expand All @@ -748,7 +742,7 @@ def findUnidirectional(N, Irrev, option = 'null', verbose = False, parallel = 0)
canBeNegative = findTBlocked(N, allRev, basename = 'canBeNegative.lp', restricted = False, option = option, rev = True, negated = True)
onlyPosCandidates = [i for i in allRev if i not in canBeNegative]
onlyNegCandidates = [i for i in allRev if i not in canBePositive]
parallel = 6 #testing
parallel = 0 #testing

if len(onlyNegCandidates) <= 1:
onlyNeg = onlyNegCandidates
Expand Down Expand Up @@ -1544,7 +1538,7 @@ def findEssentialLethal(Network, Target, Filename = 'lethal.lp', rec = True, I =
CandidatePairs = [[x,y] for x in allCandidates for y in allCandidates if x < y]
if verbose:
print(('There are ' + str(len(CandidatePairs)) + ' pairs to be processed'))
parallel = 6 # testing
#parallel = 6 # testing
if parallel > 0:
CandidatePairs = [pair for pair in CandidatePairs if all([(pair[0] in z or pair[1] in z) for z in Collection])]
splitPairs = [CandidatePairs[i::parallel] for i in range(parallel)]
Expand Down

0 comments on commit af1e9a5

Please sign in to comment.