def targetDiseaseCircos(directory, empty, empty2): print("\n ---------targetDiseaseCircos Protocol ------------ \n") """ Create edgelist for network clustered by tissue-miRNA. """ if not os.path.exists(directory): os.makedirs(directory) allMirnaTargetInteractions = ml.readMirTarBase() targetMatrix = ml.Matrix(allMirnaTargetInteractions) tarClustnum = targetMatrix.createClusters() allMirnaDiseaseInteractions = ml.readMiriadData() diseaseMatrix = ml.Matrix(allMirnaDiseaseInteractions) diseaseClustnum = diseaseMatrix.createClusters() interactionDict = {} num = 0 mirnaSet = set() diseaseSet = set() targetSet = set() for i in range(tarClustnum): mirnaTargetInteractions = targetMatrix.getClusterInteractions(i) for j in range(diseaseClustnum): mirnaDiseaseInteractions = diseaseMatrix.getClusterInteractions(j) for disItems, tarItems in [(disItems, tarItems) for disItems in mirnaDiseaseInteractions for tarItems in mirnaTargetInteractions ]: if disItems[0] == ml.simplifyMirnaNames([tarItems[0]])[0][0]: key = ("targetCluster" + str(i + 1), "diseaseCluster" + str(j + 1), len(targetMatrix.getClusterRows(i)) + len(targetMatrix.getClusterColumns(i)), len(diseaseMatrix.getClusterRows(j)) + len(diseaseMatrix.getClusterColumns(j))) if key not in interactionDict: interactionDict[key] = 1 else: interactionDict[key] += 1 num += 1 for mirna in targetMatrix.getClusterRows(i): mirnaSet.add(mirna) for mirna in diseaseMatrix.getClusterRows(i): mirnaSet.add(mirna) for target in targetMatrix.getClusterColumns(i): targetSet.add(target) for disease in diseaseMatrix.getClusterColumns(i): diseaseSet.add(disease) print("targetDisease mirna total: ", len(mirnaSet)) print("targetDisease target total: ", len(targetSet)) print("targetDisease disease total: ", len(diseaseSet), "\n") interactions = [] for key, value in list(interactionDict.items()): interactions.append(key + (value, )) #print(key, "\t", value) edgeList = ml.EdgeList([]) edgeList.addInteractions(interactions) edgeList.circos(directory + "/targetDisease")
def clusterProtocol(directory, tsi, empty): print("Cluster lists Protocol") clusterDirectory = directory + "/clusters" if not os.path.exists(clusterDirectory): os.makedirs(clusterDirectory) allMirnaTargetInteractions = ml.readMirTarBase() #print(allMirnaTargetInteractions) targetMatrix = ml.Matrix(allMirnaTargetInteractions) #print(targetMatrix.getColumns()) tarClustnum = targetMatrix.createClusters() #print(targetMatrix.getClusterColumns()) allMirnaDiseaseInteractions = ml.readMiriadData() diseaseMatrix = ml.Matrix(allMirnaDiseaseInteractions) disClustnum = diseaseMatrix.createClusters() allMirnaTissueInteractions = ml.readTissueMatrix(ml.readMirnaTSI(tsi)) tissueMatrix = ml.Matrix(allMirnaTissueInteractions) tisClustnum = tissueMatrix.createClusters() targetDirectory = clusterDirectory + "/target" if not os.path.exists(targetDirectory): os.makedirs(targetDirectory) allInteractions = [] clusterTxtList = open(clusterDirectory + "/targetClusterList.txt", "w") for i in range(tarClustnum): edgeList = ml.EdgeList([]) edgeList.addInteractions(targetMatrix.getClusterInteractions(i)) edgeList.writeEdgeList(targetDirectory + "/targetCluster" + str(i + 1) + ".txt") #print(targetMatrix.getClusterInteractions(i)) allInteractions.extend(targetMatrix.getClusterInteractions(i)) clusterTxtList.write("Target Cluster " + str(i + 1) + "\n\n") targetList = [] for target in targetMatrix.getClusterColumns(i): targetList.append(target) #print(target) targetList.sort() for target in targetList: clusterTxtList.write(target + "\n") clusterTxtList.write("\n") mirnaList = [] for mirna in targetMatrix.getClusterRows(i): mirnaList.append(mirna) mirnaList.sort() for mirna in mirnaList: clusterTxtList.write(mirna + "\n") clusterTxtList.write("\n\n") clusterTxtList.close() targetList = ml.EdgeList([]) targetList.addInteractions(allInteractions) targetList.writeLists(targetDirectory + "/targetList", False) tissueDirectory = clusterDirectory + "/tissue" allInteractions = [] clusterTxtList = open(clusterDirectory + "/tissueClusterList.txt", "w") if not os.path.exists(tissueDirectory): os.makedirs(tissueDirectory) for i in range(tisClustnum): edgeList = ml.EdgeList([]) edgeList.addInteractions(tissueMatrix.getClusterInteractions(i)) edgeList.writeEdgeList(tissueDirectory + "/tissueCluster" + str(i + 1) + ".txt") allInteractions.extend(tissueMatrix.getClusterInteractions(i)) clusterTxtList.write("Tissue Cluster " + str(i + 1) + "\n\n") tissueList = [] for tissue in tissueMatrix.getClusterColumns(i): tissueList.append(tissue) tissueList.sort() for tissue in tissueList: clusterTxtList.write(tissue + "\n") clusterTxtList.write("\n") mirnaList = [] for mirna in tissueMatrix.getClusterRows(i): mirnaList.append(mirna) mirnaList.sort() for mirna in mirnaList: clusterTxtList.write(mirna + "\n") clusterTxtList.write("\n\n") clusterTxtList.close() #print(allInteractions) tissueList = ml.EdgeList([]) tissueList.addInteractions(allInteractions) tissueList.writeLists(tissueDirectory + "/tissueList", False) diseaseDirectory = clusterDirectory + "/disease" allInteractions = [] clusterTxtList = open(clusterDirectory + "/diseaseClusterList.txt", "w") if not os.path.exists(diseaseDirectory): os.makedirs(diseaseDirectory) for i in range(disClustnum): edgeList = ml.EdgeList([]) edgeList.addInteractions(diseaseMatrix.getClusterInteractions(i)) edgeList.writeEdgeList(diseaseDirectory + "/diseaseCluster" + str(i + 1) + ".txt") allInteractions.extend(diseaseMatrix.getClusterInteractions(i)) clusterTxtList.write("Disease Cluster " + str(i + 1) + "\n\n") diseaseList = [] for disease in diseaseMatrix.getClusterColumns(i): diseaseList.append(disease) diseaseList.sort() for disease in diseaseList: clusterTxtList.write(disease + "\n") clusterTxtList.write("\n") mirnaList = [] for mirna in diseaseMatrix.getClusterRows(i): mirnaList.append(mirna) mirnaList.sort() for mirna in mirnaList: clusterTxtList.write(mirna + "\n") clusterTxtList.write("\n\n") clusterTxtList.close() diseaseList = ml.EdgeList([]) diseaseList.addInteractions(allInteractions) diseaseList.writeLists(diseaseDirectory + "/diseaseList", False) pathwayDirectory = clusterDirectory + "/pathway" if not os.path.exists(pathwayDirectory): os.makedirs(pathwayDirectory) allInteractions = [] clusterTxtList = open(clusterDirectory + "/pathwayClusterList.txt", "w") for i in range(tarClustnum): targetMirnaInteractions = targetMatrix.getClusterInteractions(i) entrezDict = ml.geneNameEntrezDict() newTargetMirnaInteractions = [] for interaction in targetMirnaInteractions: newTargetMirnaInteractions.append([ interaction[0], ml.Gene(interaction[1], entrezDict[interaction[1]]) ]) mirnaPathwayInterations = ml.reactomePA(newTargetMirnaInteractions, 0.05) edgeList = ml.EdgeList([]) edgeList.addInteractions(mirnaPathwayInterations) edgeList.writeEdgeList(targetDirectory + "/pathwayCluster" + str(i + 1) + ".txt") allInteractions.extend(targetMatrix.getClusterInteractions(i)) clusterTxtList.write("Pathway Cluster " + str(i + 1) + "\n\n") pathwaySet = set() mirnaSet = set() for interaction in mirnaPathwayInterations: pathwaySet.add(interaction[1]) mirnaSet.add(interaction[0]) pathwayList = sorted(list(pathwaySet)) mirnaList = sorted(list(mirnaSet)) for pathway in pathwayList: clusterTxtList.write(pathway + "\n") clusterTxtList.write("\n") for mirna in mirnaList: clusterTxtList.write(mirna + "\n") clusterTxtList.write("\n\n") clusterTxtList.close() """
def tissueTargetCircos(directory, tsi, empty): print("\n --------- tissueTargetCircos Protocol ------------ \n") """ Create edgelist for network clustered by tissue-miRNA. """ if not os.path.exists(directory): os.makedirs(directory) allMirnaTissueInteractions = ml.readTissueMatrix(ml.readMirnaTSI(tsi)) tissueMatrix = ml.Matrix(allMirnaTissueInteractions) tisClustnum = tissueMatrix.createClusters() allMirnaTargetInteractions = ml.readMirTarBase() targetMatrix = ml.Matrix(allMirnaTargetInteractions) tarClustnum = targetMatrix.createClusters() num = 0 interactionDict = {} mirnaSet = set() tissueSet = set() targetSet = set() for i in range(tisClustnum): mirnaTissueInteractions = tissueMatrix.getClusterInteractions(i) tissueClusterName = "" for name in tissueMatrix.getClusterColumns(i): tissueClusterName += name for j in range(tarClustnum): mirnaTargetInteractions = targetMatrix.getClusterInteractions(j) #print(mirnaTargetInteractions) targetClusterName = "" for name in targetMatrix.getClusterColumns(j): targetClusterName += name print("\n") for tarItems, tisItems in [(tarItems, tisItems) for tarItems in mirnaTargetInteractions for tisItems in mirnaTissueInteractions ]: #print(tisItems) if tarItems[0] == tisItems[0]: print(tarItems[0]) #print("+") #print("\n\nCluster: ", i + 1) #print("miRNAs: ", + len(tissueMatrix.getClusterRows(i))) #print("tissues: ", + len(tissueMatrix.getClusterColumns(i))) tissueClusterSize = ( len(tissueMatrix.getClusterRows(i)) + len(tissueMatrix.getClusterColumns(i))) targetClusterSize = ( len(targetMatrix.getClusterRows(j)) + len(targetMatrix.getClusterColumns(j))) key = ("tissueCluster" + str(i + 1), "targetCluster" + str(j + 1), tissueClusterSize, targetClusterSize) #print("\n\nCluster: ", i + 1, " Size: ", tissueClusterSize) if key not in interactionDict: interactionDict[key] = 1 else: interactionDict[key] += 1 num += 1 for mirna in targetMatrix.getClusterRows(i): mirnaSet.add(mirna) for mirna in tissueMatrix.getClusterRows(i): mirnaSet.add(mirna) for target in targetMatrix.getClusterColumns(i): targetSet.add(target) for tissue in tissueMatrix.getClusterColumns(i): tissueSet.add(tissue) print("tissueTarget mirna total: ", len(mirnaSet)) print("tissueTarget target total: ", len(targetSet)) print("tissueTarget tissue total: ", len(tissueSet), "\n") interactions = [] for key, value in list(interactionDict.items()): interactions.append(key + (value, )) print(key, "\t", value) edgeList = ml.EdgeList([]) edgeList.addInteractions(interactions) edgeList.circos(directory + "/tissueTarget")
def diseaseClusterNetwork(directory, tsi, pValue): """ A protocol for an individual network by disease clusters """ print("\n --------- diseaseclusterNetwork Protocol ------------ \n") if not os.path.exists(directory): os.makedirs(directory) newDir = directory + ("/diseaseClusterNetwork") if not os.path.exists(newDir): os.makedirs(newDir) allDiseaseMirnaInteractions = ml.readMiriadData() matrix = ml.Matrix(allDiseaseMirnaInteractions) numberOfClusters = matrix.createClusters() mirnaTissueInteractions = ml.readTissueMatrix(ml.readMirnaTSI(tsi)) #network for all clusters print("\n All Clusters \n") diseaseMirnaInteractions = matrix.getClusterInteractions() mirnaInteractions = ml.mirnaFullNames(matrix.getClusterRows()) mirnaNames = [interaction[1] for interaction in mirnaInteractions] mirnaTargetInterations = ml.readMirTarBase(mirnaNames) #create edgeList edgeList = ml.EdgeList(mirnaInteractions) edgeList.addInteractions(diseaseMirnaInteractions) edgeList.addInteractions(mirnaTargetInterations) edgeList.addInteractions(mirnaTissueInteractions) # Lists for node selection in cytoscape edgeList.writeLists(newDir + "/list") # reduce network to only through interactions edgeList.removeIncompleteLinks() ################################## #edgeList.simplifyMirnaNames() #All groups edgeList.writeEdgeList(newDir + "/EdgeListAll.txt") # No Tissues tissues = edgeList.popInteractions() # No Pathways pathways = edgeList.popInteractions() edgeList.addInteractions(tissues) edgeList.writeEdgeList(newDir + "/EdgeListAllNoTargets.txt") # No Diseases edgeList.popInteractions() edgeList.popInteractions() edgeList.addInteractions(tissues) edgeList.addInteractions(pathways) edgeList.writeEdgeList(newDir + "/EdgeListAllNoDiseases.txt") # network for each cluster allClusterEdgeList = open(newDir + "/allClusterEdgeList.txt", "w") allClusterEdgeList.write("Source\tTarget\n") for i in range(numberOfClusters): print("\n Cluster " + str(i + 1) + "\n") diseaseMirnaInteractions = matrix.getClusterInteractions(i) mirnaInteractions = ml.mirnaFullNames(matrix.getClusterRows(i)) mirnaNames = [interaction[1] for interaction in mirnaInteractions] mirnaTargetInterations = ml.readMirTarBase(mirnaNames) #create edgeList edgeList = ml.EdgeList(mirnaInteractions) edgeList.addInteractions(mirnaTargetInterations) edgeList.addInteractions(mirnaTissueInteractions) edgeList.addInteractions(diseaseMirnaInteractions) # reduce network to only through interactions edgeList.removeIncompleteLinks() ################################ #edgeList.simplifyMirnaNames() #All groups allClusterEdgeList.write( edgeList.writeEdgeList(newDir + "/EdgeList" + str(i + 1) + ".txt")) # No Tissues tissues = edgeList.popInteractions() edgeList.writeEdgeList(newDir + "/EdgeListNoTissues" + str(i + 1) + ".txt") # No Pathways pathways = edgeList.popInteractions() edgeList.addInteractions(tissues) edgeList.writeEdgeList(newDir + "/EdgeListNoTargets" + str(i + 1) + ".txt") # No Diseases edgeList.popInteractions() edgeList.popInteractions() edgeList.addInteractions(tissues) edgeList.addInteractions(pathways) edgeList.writeEdgeList(newDir + "/EdgeListDiseaseNoDiseases" + str(i + 1) + ".txt") allClusterEdgeList.close()
def targetClusterNetworkPA(directory, tsi, pValue): """ A protocol for an individual network by disease clusters using reacotme pathways """ print("\n --------- targetClusterNetworkPA Protocol ------------ \n") if not os.path.exists(directory): os.makedirs(directory) newDir = directory + ("/targetClusterNetworkPA") if not os.path.exists(newDir): os.makedirs(newDir) allMirnaTargetInteractions = ml.readMirTarBase() matrix = ml.Matrix(allMirnaTargetInteractions) numberOfClusters = matrix.createClusters() mirnaTissueInteractions = ml.readTissueMatrix(ml.readMirnaTSI(tsi)) mirnaDiseaseInteractions = ml.readMiriadData() #network for all clusters print("\n All Clusters \n") targetMirnaInteractions = matrix.getClusterInteractions() entrezDict = ml.geneNameEntrezDict() newTargetMirnaInteractions = [] for interaction in targetMirnaInteractions: newTargetMirnaInteractions.append([ interaction[0], ml.Gene(interaction[1], entrezDict[interaction[1]]) ]) mirnaPathwayInterations = ml.reactomePA(newTargetMirnaInteractions, pValue) mirnaInteractions = ml.simplifyMirnaNames(matrix.getClusterRows()) #create edgeList edgeList = ml.EdgeList(mirnaInteractions) edgeList.addInteractions(mirnaPathwayInterations) edgeList.addInteractions(mirnaDiseaseInteractions) edgeList.addInteractions(mirnaTissueInteractions) # Lists for node selection in cytoscape edgeList.writeLists(newDir + "/list") # reduce network to only through interactions edgeList.removeIncompleteLinks() #edgeList.simplifyMirnaNames() #All groups edgeList.writeEdgeList(newDir + "/EdgeListAll.txt") # No Tissues tissues = edgeList.popInteractions() edgeList.writeEdgeList(newDir + "/EdgeListAllNoTissues.txt") # No Pathways pathways = edgeList.popInteractions() edgeList.addInteractions(tissues) edgeList.writeEdgeList(newDir + "/EdgeAllNoTargets.txt") # No Diseases edgeList.popInteractions() edgeList.popInteractions() edgeList.addInteractions(tissues) edgeList.addInteractions(pathways) edgeList.writeEdgeList(newDir + "/EdgeListAllNoDiseases.txt") # network for each cluster for i in range(numberOfClusters): print("\n Cluster " + str(i + 1) + "\n") targetMirnaInteractions = matrix.getClusterInteractions(i) entrezDict = ml.geneNameEntrezDict() newTargetMirnaInteractions = [] for interaction in targetMirnaInteractions: newTargetMirnaInteractions.append([ interaction[0], ml.Gene(interaction[1], entrezDict[interaction[1]]) ]) mirnaPathwayInterations = ml.reactomePA(newTargetMirnaInteractions, pValue) mirnaInteractions = ml.simplifyMirnaNames(matrix.getClusterRows(i)) #create edgeList edgeList = ml.EdgeList(mirnaInteractions) edgeList.addInteractions(mirnaDiseaseInteractions) edgeList.addInteractions(mirnaTissueInteractions) edgeList.addInteractions(mirnaPathwayInterations) # reduce network to only through interactions edgeList.removeIncompleteLinks() #edgeList.simplifyMirnaNames() #All groups edgeList.writeEdgeList(newDir + "/EdgeList" + str(i + 1) + ".txt") # No Tissues tissues = edgeList.popInteractions() edgeList.writeEdgeList(newDir + "/EdgeListNoTissues" + str(i + 1) + ".txt") # No Pathways pathways = edgeList.popInteractions() edgeList.addInteractions(tissues) edgeList.writeEdgeList(newDir + "/EdgeListNoTargets" + str(i + 1) + ".txt") # No Diseases edgeList.popInteractions() edgeList.popInteractions() edgeList.addInteractions(tissues) edgeList.addInteractions(pathways) edgeList.writeEdgeList(newDir + "/EdgeListNoDiseases" + str(i + 1) + ".txt")