Beispiel #1
0
def select(rr, dirToExamine, dirNotAnalyze, others):
    
    #to create the directory for models we don't care to study
    BaseFunctions.createDirectoryExit(dirNotAnalyze)
    #to create the directory for others files
    BaseFunctions.createDirectoryExit(others)

    #list of files into directory
    files=os.listdir(dirToExamine)

    #to examine one file at a time
    for file in files:
        if file.endswith('.xml'):
            print(file)
            try:
                #to load the file with roadrunner
                rr.load(dirToExamine+'\\'+file)
            except:
                #if an error occurs we can't examine the file
                shutil.move(dirToExamine+'\\'+file, dirNotAnalyze)
                print('An error occurs during file load: To not analyze')
                continue
            
            #to get the model using libSBML
            model = libsbml.SBMLReader().readSBMLFromString(rr.getSBML()).getModel()
            
            #we don't want to analyze models with rules or events or qualitative models
            #we can't analyze in a correct way models which are bad read from libroadrunner.
            if  model.getNumRules()>0 or model.getNumEvents()>0 or model.getPlugin('qual')!=None or model.getNumSpecies()!=rr.model.getNumFloatingSpecies() or model.getNumReactions()!=rr.model.getNumReactions():
                shutil.move(dirToExamine+'\\'+file, dirNotAnalyze)
                print('To not analyze')            
        else:
            #we don't care other files
            shutil.move(dirToExamine+'\\'+file, others)  
Beispiel #2
0
def selectErrorLoad(rr, dirToExamine, dirNotAnalyze, others):
    
    #to create the directory for models we don't care to study
    BaseFunctions.createDirectoryExit(dirNotAnalyze)
    #to create the directory for others files
    BaseFunctions.createDirectoryExit(others)

    #list of files into directory
    files=os.listdir(dirToExamine)

    #to examine one file at a time
    for file in files:
        if file.endswith('.xml'):
            print(file)
            try:
                #to load the file with roadrunner
                rr.load(dirToExamine+'\\'+file)
            except:
                #if an error occurs we can't examine the file
                shutil.move(dirToExamine+'\\'+file, dirNotAnalyze)
                print('An error occurs during file load: To not analyze')
                continue
               
        else:
            #we don't care other files
            shutil.move(dirToExamine+'\\'+file, others) 
Beispiel #3
0
def selectModifiers(rr, dirToExamine, dirNotAnalyze):
    
    #to create the directory for models we don't care to study
    BaseFunctions.createDirectoryExit(dirNotAnalyze)

    f = open("modifiers_models.txt", "a")

    #list of files into directory
    files=os.listdir(dirToExamine)

    #to examine one file at a time
    for file in files:
        if file.endswith('.xml'):
            print(file)
            try:
                #to load the file with roadrunner
                rr.load(dirToExamine+'\\'+file)
            except:
                #if an error occurs we can't examine the file
                shutil.move(dirToExamine+'\\'+file, dirNotAnalyze)
                print('An error occurs during file load: To not analyze')
                continue
            
            #to get the model using libSBML
            model = libsbml.SBMLReader().readSBMLFromString(rr.getSBML()).getModel()
            
            #we don't want to analyze models with rules or events or qualitative models
            #we can't analyze in a correct way models which are bad read from libroadrunner.
            for i in range(model.getNumReactions()):
                if  model.getReaction(i).getNumModifiers() > 0:
                    f.write(file + "\n")
                    #shutil.move(dirToExamine+'\\'+file, dirNotAnalyze)
                    print('Modifiers!')    
                    break        
         
    f.close()
Beispiel #4
0
def analysisTheorems(rr, dirToExamine, dirNotAnalyze, dirToSimulation,
                     dirTheorems):

    BaseFunctions.createDirectoryExit(dirToSimulation)
    BaseFunctions.createDirectoryExit(dirTheorems)
    BaseFunctions.createDirectoryExit(dirTheorems + "\\not_known")
    BaseFunctions.createDirectoryExit(dirTheorems + "\\SteadyState")

    #analyze each file into the directory
    files = os.listdir(dirToExamine)

    for file in files:
        if file.endswith('.xml'):
            print(file)
            rr.clearModel()

            try:
                rr.load(dirToExamine + '\\' + file)
            except:
                shutil.move(dirToExamine + '\\' + file, dirNotAnalyze)
                print('Not_Analyze')
                continue

            #check of use of mass action
            if Simulation.toSimulate(rr) == 1:
                #theorems are not applicable
                shutil.move(dirToExamine + '\\' + file, dirToSimulation)
                continue

            #study of model with Feinberg's theorems
            results = Deficiency_Calculation.deficiency_calculation(rr)
            if results[1] == 1:
                print("Cannot use Feinberg's theorems")
                shutil.move(dirToExamine + '\\' + file, dirToSimulation)
            elif results[0] == 0 or results[0] == 1:
                print("Model reaches steady state")
                shutil.move(dirToExamine + '\\' + file,
                            dirTheorems + "\\SteadyState")
            else:
                print("Unknown behavior")
                shutil.move(dirToExamine + '\\' + file,
                            dirTheorems + "\\not_known")
Beispiel #5
0
def main(interval=-1, maxInterval=20, dirToExamine="models", func=0):
    #for use the library libRoadRunner
    rr=roadrunner.RoadRunner()

    simulationTime=20000
    mintime=0

    nTest=10
    increase=5

    dirNotAnalyze="Not_Analyze"
    dirOtherFiles="Other_Files"
    dirPetriNets=os.getcwd()+'\\PetriNets'
    dirTheorems=os.getcwd()+'\\Theorems_Models'
    dirResultsTheorems=os.getcwd()+'\\Results_Theorems'
    dirToSimulation=os.getcwd()+'\\Simulate_Models'
    dirResultsSimulation=os.getcwd()+'\\Results_Simulations'
    

    if func==1:
        SelectFiles.select(rr, dirToExamine, dirNotAnalyze, dirOtherFiles)
    elif func==2:
        analysisTheorems(rr, dirToExamine, dirNotAnalyze, dirToSimulation, dirTheorems)    
    elif func==4:
        PetriNets.createPetriNets(rr, dirToExamine, dirPetriNets, nTest, increase)
    elif func in [0, 3]:
        
        if interval<=0:
            interval=BaseFunctions.numericalInput('Range of initial perturbation (X %) : ',[])
        
        if interval<=0 or maxInterval<=0 or interval>maxInterval:
            exit("Error: invalid interval parameters")

        #contains the percentages to modify the quantities of species
        percent=[]
        i=interval
        while i<=maxInterval:
            percent.append(i)
            i=i+interval
        
        if func==3:
            Simulation.simulateAllModels(rr, dirToExamine, dirResultsSimulation, dirNotAnalyze, simulationTime, mintime, percent)
        else:

            #select models with certain characteristics
            SelectFiles.select(rr, dirToExamine, dirNotAnalyze, dirOtherFiles)
            
            analysisTheorems(rr, dirToExamine, dirNotAnalyze, dirToSimulation, dirTheorems)
                    
            BaseFunctions.createDirectoryExit(dirResultsTheorems)

            #model's simulations
            files=os.listdir(dirTheorems+"\\SteadyState")
            for file in files:     
                Simulation.simulationWithSteadyState(rr, percent, dirResultsTheorems+"\\SteadyState", dirTheorems+"\\SteadyState", file)
            Simulation.simulateAllModels(rr, dirTheorems+"\\not_known", dirResultsTheorems+"\\not_known", dirNotAnalyze, simulationTime, mintime, percent)
            Simulation.simulateAllModels(rr, dirToSimulation, dirResultsSimulation, dirNotAnalyze, simulationTime, mintime, percent)
            
            #creation of Petri nets
            print("Petri Nets")
            PetriNets.createPetriNets(rr, dirToSimulation, dirPetriNets, nTest, increase)
            PetriNets.createPetriNets(rr, dirTheorems+"\\not_known", dirPetriNets, nTest, increase)
            PetriNets.createPetriNets(rr, dirTheorems+"\\SteadyState", dirPetriNets, nTest, increase)
            
    else:
        print("Invalid parameter")
Beispiel #6
0
def simulationWithSteadyState(rr, percent, dirResults, dirToExamine, file, points=_points):
    
    nameDir=file[0:(len(file)-4)]

    if BaseFunctions.createDirectory(dirResults)==1 or BaseFunctions.createDirectory(dirResults+"\\"+nameDir)==1:
        #an error has occured
        return

    path=dirResults+"\\"+nameDir+"\\"

    try:
        rr.load(dirToExamine+'\\'+file)
    except:
        print('Error')
        return

    originalQuantities=rr.model.getFloatingSpeciesAmounts()
    
    withValues=True
    values=[]

    try:
        rr.conservedMoietyAnalysis = True
    except:
        withValues=False
        print('Error during studying of steady state')

    if withValues:
        try:
            #to calculate values at steady state. It can be return values
            #also for models that show oscillations
            values=rr.getSteadyStateValues()
            rr.resetAll()
        except:
            #an error has occured 
            print('Error during studying of steady state')
            withValues=False
            rr.conservedMoietyAnalysis = False
    
    simulationSteps(rr, path, "Results_Original"+_extension, points, values)
    
    for i in range(rr.model.getNumFloatingSpecies()):

            for j in range(len(percent)):

                rr.resetAll()   
                values=[]

                if withValues:
                    try:
                        rr.conservedMoietyAnalysis = True
                        rr.model.setFloatingSpeciesAmounts([i],[originalQuantities[i]+originalQuantities[i]*percent[j]/100])
                        values=rr.getSteadyStateValues()
                        rr.resetAll()   
                    except:
                        print('Error during studying of steady state')

                rr.model.setFloatingSpeciesAmounts([i],[originalQuantities[i]+originalQuantities[i]*percent[j]/100])
                simulationSteps(rr, path, "Results_species_"+str(i+1)+"_plus_"+str(percent[j])+"_p"+_extension, points, values)

                rr.resetAll()    
                values=[]
                    
                if withValues:
                    try:
                        rr.conservedMoietyAnalysis = True
                        rr.model.setFloatingSpeciesAmounts([i], [originalQuantities[i]-originalQuantities[i]*percent[j]/100])        
                        values=rr.getSteadyStateValues()
                        rr.resetAll()   
                    except:
                        print('Error during studying of steady state')
                
                rr.model.setFloatingSpeciesAmounts([i], [originalQuantities[i]-originalQuantities[i]*percent[j]/100])        
                simulationSteps(rr, path, "Results_species_"+str(i+1)+"_minus_"+str(percent[j])+"_p"+_extension, points, values)
    
    rr.conservedMoietyAnalysis = False
Beispiel #7
0
def simulateModel(rr, path, file, toPath, dirReject, simulationTime, time, percent, points=_points):


    #creation of directories used
    if BaseFunctions.createDirectory(dirReject)==1 or BaseFunctions.createDirectory(toPath)==1 or \
        BaseFunctions.createDirectory(toPath+"\\Oscillation")==1 or \
        BaseFunctions.createDirectory(toPath+"\\Steady_State")==1 or \
            BaseFunctions.createDirectory(toPath+"\\Others")==1:
        return 1


    rr.conservedMoietyAnalysis = False
    rr.clearModel()

    step=_step
    max=simulationTime/step
    
    #name of file
    nameDir=file[0:(len(file)-4)]
    rr.clearModel()

    try:
        rr.load(path+'\\'+file)
    except:
        shutil.move(path+'\\'+file, dirReject)
        print('To not analyze')
        return 1

    
    #original quantities of species
    originalQuantities=rr.model.getFloatingSpeciesAmounts()
    
    originalPath=toPath
    #files to memorize the results
    allResults=open(originalPath+"\\Results_Original"+_extension, "w")
    smallResults=open(originalPath+"\\Small_Results_Original"+_extension, "w")
        
    oldSimulations=np.array(np.zeros(rr.model.getNumFloatingSpecies()), dtype=int)
    stop=False
    steadyState=False

    start=-(step/points)
    i=0
    while(i<max and not stop):
        try:
            sim=rr.simulate(start+(step/points),start+step,points)
        except:
            #an error has occured during the simulation
            break

        if i==0:
            np.savetxt(allResults, sim, fmt='%.8f',header=str(rr.timeCourseSelections))

            np.savetxt(smallResults, [sim[0,:]], fmt='%.5f',header=str(rr.timeCourseSelections))
            j=_interval
            while j<len(sim):
                np.savetxt(smallResults, [sim[j,:]], fmt='%.5f')
                j=j+_interval
        else:
            np.savetxt(allResults, sim, fmt='%.8f')

            j=0
            while j<len(sim):
                np.savetxt(smallResults, [sim[j,:]], fmt='%.5f')
                j=j+_interval*2
            

        #the behaviour of models is studying
        if start>time:
            first=sim[0,1:].round(decimals=5)
            last=sim[points-1,1:].round(decimals=5)

            j=0
            while j<len(last) and last[j]>=0:
                j=j+1
            if j<len(last):
                break
                
            if not (first==last).all():
                for j in range(np.shape(oldSimulations)[0]):
                    if (not (np.array(first, dtype=int)==np.array(last, dtype=int)).all()) and (np.array(last, dtype=int)==oldSimulations[j]).all():
                        toPath=toPath+"\\Oscillation"
                        stop=True
                        print("Oscillation")
                        break
            else:
                for j in range(points-1):
                    if not (sim[j,1:].round(decimals=5)==last).all():
                        stop=True
                        toPath=toPath+"\\Oscillation"
                        print("Oscillation")
                        break
                if not stop:
                    stop=True
                    steadyState=True
                    toPath=toPath+"\\Steady_State"
                    print("Steady state")

        oldSimulations = np.vstack((oldSimulations, np.array(sim[:,1:], dtype=int)))
        start=start+step
        i=i+1

    #if the behaviour of model is not identified
    if stop==False:
        print("Behaviour not known")
        toPath=toPath+"\\Others"

    allResults.close()
    smallResults.close()

    #creation of directory for store the results
    if BaseFunctions.createDirectory(toPath+'\\'+nameDir)==1 or \
        BaseFunctions.removeFile(toPath+"\\"+nameDir+'\\'+"Results_Original"+_extension)==1 or\
        BaseFunctions.removeFile(toPath+"\\"+nameDir+'\\'+"Small_Results_Original"+_extension)==1:
        #if an error has occured
        return 1 
            
    shutil.move(originalPath+"\\Results_Original"+_extension, toPath+"\\"+nameDir)
    shutil.move(originalPath+"\\Small_Results_Original"+_extension, toPath+"\\"+nameDir)

    toPath=toPath+"\\"+nameDir+'\\'


    #simulations with different quantities of species
    for i in range(rr.model.getNumFloatingSpecies()):
        for j in range(len(percent)):

            rr.resetAll()   
            #new quantity is setting
            rr.model.setFloatingSpeciesAmounts([i],[originalQuantities[i]+originalQuantities[i]*percent[j]/100])
                
            if not steadyState:
                #files to store the results
                allResults=open(toPath+"Results_species_"+str(i+1)+"_plus_"+str(percent[j])+"_p"+_extension, "w")
                smallResults=open(toPath+"Small_Results_species_"+str(i+1)+"_plus_"+str(percent[j])+"_p"+_extension, "w")
                try:
                    sim=rr.simulate(0, simulationTime, simulationTime*int(points/step))
        
                    np.savetxt(allResults, sim, fmt='%.8f',header=str(rr.timeCourseSelections))

                    np.savetxt(smallResults, [sim[0,:]], fmt='%.5f',header=str(rr.timeCourseSelections))
                    k=_interval
                    while k<len(sim):
                        np.savetxt(smallResults, [sim[k,:]], fmt='%.5f')
                        k=k+_interval
                except:
                    print("Error")

                #files are closed
                allResults.close()   
                smallResults.close() 
            else:
                #simulation for models with steady state
                simulationSteps(rr, toPath, "Results_species_"+str(i+1)+"_plus_"+str(percent[j])+"_p"+_extension, points)

            rr.resetAll()    
            #new quantity is setting
            rr.model.setFloatingSpeciesAmounts([i],[originalQuantities[i]-originalQuantities[i]*percent[j]/100])        

            if not steadyState:
                #files to store the results
                allResults=open(toPath+"Results_species_"+str(i+1)+"_minus_"+str(percent[j])+"_p"+_extension, "w")
                smallResults=open(toPath+"Small_Results_species_"+str(i+1)+"_minus_"+str(percent[j])+"_p"+_extension, "w")
                try:
                    sim=rr.simulate(0, simulationTime, simulationTime*int(points/step))
                    np.savetxt(allResults, sim, fmt='%.8f',header=str(rr.timeCourseSelections))
                    
                    np.savetxt(smallResults, [sim[0,:]], fmt='%.5f',header=str(rr.timeCourseSelections))
                    k=_interval
                    while k<len(sim):
                        np.savetxt(smallResults, [sim[k,:]], fmt='%.5f')
                        k=k+_interval
                except:
                    print("Error")

                allResults.close()
                smallResults.close()
            else:
                simulationSteps(rr, toPath, "Results_species_"+str(i+1)+"_minus_"+str(percent[j])+"_p"+_extension, points)
Beispiel #8
0
def simulateWithTime(rr, nameDir, simulationTime, toPath, percent, points):

    if BaseFunctions.createDirectory(toPath+"\\"+nameDir)==1:
        #an error has occured
        return
    
    path=toPath+"\\"+nameDir+"\\"

    originalQuantities=rr.model.getFloatingSpeciesAmounts()

    allResults=open(path+"Results_Original"+_extension, "w")
    smallResults=open(path+"Small_Results_Original"+_extension, "w")
        
    try:
        sim=rr.simulate(0,simulationTime, points)
        np.savetxt(allResults, sim, fmt='%.8f',header=str(rr.timeCourseSelections))

        np.savetxt(smallResults, [sim[0,:]], fmt='%.5f', header=str(rr.timeCourseSelections))
        i=_interval
        while i<len(sim):
            np.savetxt(smallResults, [sim[i,:]], fmt='%.5f')
            i=i+_interval
    except:
        print("Error")

    allResults.close()
    smallResults.close()

    for i in range(rr.model.getNumFloatingSpecies()):
      
        for j in range(len(percent)):

            rr.resetAll()    
            
            rr.model.setFloatingSpeciesAmounts([i], [originalQuantities[i]+originalQuantities[i]*percent[j]/100])

            allResults=open(path+"Results_species_"+str(i+1)+"_plus_"+str(percent[j])+"_p"+_extension, "w")
            smallResults=open(path+"Small_Results_species_"+str(i+1)+"_plus_"+str(percent[j])+"_p"+_extension, "w")

            try:
                sim=rr.simulate(0,simulationTime, points)
                np.savetxt(allResults, sim, fmt='%.8f',header=str(rr.timeCourseSelections))

                np.savetxt(smallResults, [sim[0,:]], fmt='%.5f',header=str(rr.timeCourseSelections))
                k=_interval
                while k<len(sim):
                    np.savetxt(smallResults, [sim[k,:]], fmt='%.5f')
                    k=k+_interval
            except:
                print("Error")

            allResults.close()
            smallResults.close()

            rr.resetAll()    
            
            rr.model.setFloatingSpeciesAmounts([i], [originalQuantities[i]-originalQuantities[i]*percent[j]/100])        

            allResults=open(path+"Results_species_"+str(i+1)+"_minus_"+str(percent[j])+"_p"+_extension, "w")
            smallResults=open(path+"Small_Results_species_"+str(i+1)+"_minus_"+str(percent[j])+"_p"+_extension, "w")

            try:
                sim=rr.simulate(0,simulationTime, points)
                np.savetxt(allResults, sim, fmt='%.8f',\
                    header=str(rr.timeCourseSelections))

                np.savetxt(smallResults, [sim[0,:]], fmt='%.5f',\
                    header=str(rr.timeCourseSelections))
                k=_interval
                while k<len(sim):
                    np.savetxt(smallResults, [sim[k,:]], fmt='%.5f')
                    k=k+_interval
            except:
                print("Error")

            allResults.close()
            smallResults.close()
Beispiel #9
0
def createOnePetriNet(rr, path, file, pathResult, nTest, valueIncrease):
    
    if BaseFunctions.createDirectory(pathResult)==1:
        return 1
    
    #it clears the currently loaded model and all associated memory
    rr.clearModel()

    path=path+"\\"

    try:
        #to load the file with roadrunner
        rr.load(path+file)
    except:
        print("An error occurs during file load")
        return 1

    #to get the model using libSBML
    model = libsbml.SBMLReader().readSBMLFromString(rr.getSBML()).getModel()

    nameFile=file[0:(len(file)-4)]
    try:
        f=open(pathResult+"\\"+nameFile+".gv", "w")
    except IOError:
        print("An error occurs during opening file")
        return 1

    #string that will contains petri net of model
    graph='digraph "'+str(file)+'"{\n'

    #to create a node for each specie
    for i in range(model.getNumSpecies()):
        graph=graph+str(model.getSpecies(i).getId())+" [shape=circle];\n"
    
    #to examine one reaction at a time
    for i in range(model.getNumReactions()):

        #to create a box (node) for each reaction
        graph=graph+str(model.getListOfReactions().get(i).getId())+" [shape=box];\n"

        #to get reaction's reactants
        for reactant in model.getReaction(i).getListOfReactants():
            graph=graph+str(reactant.getSpecies())+" -> "+str(model.getReaction(i).getId())+" [arrowhead=vee, label="+str(reactant.getStoichiometry())+"];\n"
        
        #to get reaction's products
        for product in model.getListOfReactions().get(i).getListOfProducts():
            graph=graph+str(model.getReaction(i).getId())+" -> "+str(product.getSpecies())+" [arrowhead=vee, label="+str(product.getStoichiometry())+"];\n"

        #to get reaction's modifiers and establish if they are promoter or inhibitor
        for j in range(model.getReaction(i).getNumModifiers()):
            response=functionality(rr, model, j, i, nTest, valueIncrease)
            #if it's a promoter
            if response==1:
                graph=graph+str(model.getReaction(i).getModifier(j).getSpecies())+" -> "+str(model.getReaction(i).getId())+" [arrowhead=dot];\n"
            #if it's a inhibitor
            elif response==0:
                graph=graph+str(model.getReaction(i).getModifier(j).getSpecies())+" -> "+str(model.getReaction(i).getId())+" [arrowhead=tee];\n"    

        #if there is the inverse reaction
        if model.getReaction(i).getReversible():
            #to create a box (node) for the inverse reaction
            graph=graph+str(model.getReaction(i).getId())+"_Reverse [shape=box];\n"

            #to get inverse reaction's reactants
            for reactant in model.getListOfReactions().get(i).getListOfReactants():
                graph=graph+str(model.getListOfReactions().get(i).getId())+"_Reverse -> "+str(reactant.getSpecies())+" [arrowhead=vee, label="+str(reactant.getStoichiometry())+"];\n"

            #to get inverse reaction's products
            for product in model.getListOfReactions().get(i).getListOfProducts():
                graph=graph+str(product.getSpecies())+" -> "+str(model.getListOfReactions().get(i).getId())+"_Reverse [arrowhead=vee, label="+str(product.getStoichiometry())+"];\n"

    graph=graph+"}"
    
    try:
        f.write(graph)
    finally:
        try:
            f.close()
        except IOError:
            return 1
    

    return 0
Beispiel #10
0
def createOnePetriNet(rr, path, file, pathResult, nTest, valueIncrease):

    filefile = open("modifiers_discovered.txt", "a")
    filefilelist = []

    if BaseFunctions.createDirectory(pathResult) == 1:
        return 1

    #it clears the currently loaded model and all associated memory
    rr.clearModel()

    path = path + "\\"

    try:
        #to load the file with roadrunner
        rr.load(path + file)
    except:
        print("An error occurs during file load")
        return 1

    #to get the model using libSBML
    model = libsbml.SBMLReader().readSBMLFromString(rr.getSBML()).getModel()

    nameFile = file[0:(len(file) - 4)]
    try:
        f = open(pathResult + "\\" + nameFile + ".gv", "w")
    except IOError:
        print("An error occurs during opening file")
        return 1

    #string that will contains petri net of model
    graph = 'digraph "' + str(file) + '"{\n'

    #to create a node for each specie
    for i in range(model.getNumSpecies()):
        graph = graph + str(model.getSpecies(i).getId()) + " [shape=circle];\n"

    #to examine one reaction at a time
    for i in range(model.getNumReactions()):

        #to create a box (node) for each reaction
        graph = graph + str(
            model.getListOfReactions().get(i).getId()) + " [shape=box];\n"

        #to get reaction's reactants
        for reactant in model.getReaction(i).getListOfReactants():
            graph = graph + str(reactant.getSpecies()) + " -> " + str(
                model.getReaction(
                    i).getId()) + " [arrowhead=vee, label=" + str(
                        reactant.getStoichiometry()) + "];\n"

        #to get reaction's products
        for product in model.getListOfReactions().get(i).getListOfProducts():
            graph = graph + str(model.getReaction(i).getId()) + " -> " + str(
                product.getSpecies()) + " [arrowhead=vee, label=" + str(
                    product.getStoichiometry()) + "];\n"

        #lista di tutti i modificatori
        listModifiers = [
            modifier.getSpecies()
            for modifier in model.getReaction(i).getListOfModifiers()
        ]

        #to get reaction's modifiers and establish if they are promoter or inhibitor
        for j in range(model.getReaction(i).getNumModifiers()):

            #se il modificatore è anche un reagente non lo considero
            if model.getReaction(i).getModifier(j).getSpecies() in [
                    reactant.getSpecies()
                    for reactant in model.getReaction(i).getListOfReactants()
            ]:
                continue

            #se il modificatore compare più volte lo considero solo l'ultima volta
            if model.getReaction(i).getModifier(
                    j).getSpecies() in listModifiers[j + 1:]:
                continue

            response = findRole(
                rr, model,
                model.getReaction(i).getModifier(j).getSpecies(), i, nTest,
                valueIncrease)

            #if it's a promoter
            if response == 1:
                graph = graph + str(
                    model.getReaction(i).
                    getModifier(j).getSpecies()) + " -> " + str(
                        model.getReaction(i).getId()) + " [arrowhead=dot];\n"
            #if it's a inhibitor
            elif response == 0:
                graph = graph + str(
                    model.getReaction(i).
                    getModifier(j).getSpecies()) + " -> " + str(
                        model.getReaction(i).getId()) + " [arrowhead=tee];\n"

        listReactants = [
            reactant.getSpecies()
            for reactant in model.getReaction(i).getListOfReactants()
        ]
        listProducts = [
            product.getSpecies()
            for product in model.getReaction(i).getListOfProducts()
        ]

        alreadySeen = []

        #vedo se ci sono specie nè reagenti nè modificatori nella legge cinetica
        for k in range(
                model.getReaction(
                    i).getKineticLaw().getMath().getListOfNodes().getSize()):
            #se il nodo è una specie
            nameOfNode = model.getReaction(
                i).getKineticLaw().getMath().getListOfNodes().get(k).getName()
            if nameOfNode in [
                    specie.getId() for specie in model.getListOfSpecies()
            ]:
                #se non è nè nella lista dei reagenti nè dei modificatore trattalo come un modificatore
                if nameOfNode in alreadySeen or nameOfNode in listReactants or  nameOfNode in listModifiers or \
                    (nameOfNode in listProducts and model.getReaction(i).getReversible()):
                    continue

                alreadySeen.append(nameOfNode)

                response = findRole(rr, model, nameOfNode, i, nTest,
                                    valueIncrease)
                #if it's a promoter
                if response == 1:
                    graph = graph + str(
                        model.getReaction(i).getKineticLaw().getMath().
                        getListOfNodes().get(k).getName()) + " -> " + str(
                            model.getReaction(
                                i).getId()) + " [arrowhead=dot];\n"
                #if it's a inhibitor
                elif response == 0:
                    graph = graph + str(
                        model.getReaction(i).getKineticLaw().getMath().
                        getListOfNodes().get(k).getName()) + " -> " + str(
                            model.getReaction(
                                i).getId()) + " [arrowhead=tee];\n"
                if file not in filefilelist:
                    filefilelist.append(file)

        #if there is the inverse reaction
        if model.getReaction(i).getReversible():
            #to create a box (node) for the inverse reaction
            graph = graph + str(
                model.getReaction(i).getId()) + "_Reverse [shape=box];\n"

            #to get inverse reaction's reactants
            for reactant in model.getListOfReactions().get(
                    i).getListOfReactants():
                graph = graph + str(model.getListOfReactions().get(i).getId(
                )) + "_Reverse -> " + str(
                    reactant.getSpecies()) + " [arrowhead=vee, label=" + str(
                        reactant.getStoichiometry()) + "];\n"

            #to get inverse reaction's products
            for product in model.getListOfReactions().get(
                    i).getListOfProducts():
                graph = graph + str(product.getSpecies()) + " -> " + str(
                    model.getListOfReactions().get(
                        i).getId()) + "_Reverse [arrowhead=vee, label=" + str(
                            product.getStoichiometry()) + "];\n"

    graph = graph + "}"

    try:
        f.write(graph)
    finally:
        try:
            f.close()
        except IOError:
            return 1

    for elem in filefilelist:
        filefile.write(elem + "\n")

    filefile.close()

    return 0