Last active
August 29, 2015 14:08
-
-
Save cplaisier/73f2262a4cf7d84c10fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Read in clusters of biclusters | |
| clusters = {} | |
| inFile = open('clustersOfBiclusters_VALL.csv','r') | |
| inFile.readline() # Get rid of header | |
| while 1: | |
| line = inFile.readline() | |
| if not line: | |
| break | |
| splitUp = line.strip().split(',') | |
| if not splitUp[1] in clusters: | |
| clusters[splitUp[1]] = [] | |
| clusters[splitUp[1]].append(splitUp[0].strip('"').lower()) | |
| inFile.close() | |
| # Read in post processed files | |
| #Bicluster - 0 Genes - 1 Conditions - 2 Norm. Residual - 3 Norm. Residual Perm. P-Value - 4 Var. Exp. First PC - 5 Var. Exp. First PC Perm. P-Value - 6 MEME Motif1 E-Value - 7 Up.MEME Motif1 Consensus - 8 Up.MEME Motif1 Matches - 9 Up.MEME Motif1 Expanded Matches - 10 Up.MEME Motif1 Correlated Matches - 11 Up.MEME Motif1 Original/Expanded - 12 Up.MEME Motif1 Minimum Correlated - 13 Up.MEME Motif2 E-Value - 14 Up.MEME Motif2 Consensus - 15 Up.MEME Motif2 Matches - 16 Up.MEME Motif2 Expanded Matches - 17 Up.MEME Motif2 Correlated Matches - 18 Up.MEME Motif2 Original/Expanded - 19 Up.MEME Motif2 Minimum Correlated - 20 Up.WEEDER Motif1 Score - 21 Up.WEEDER Motif1 Consensus - 22 Up.WEEDER Motif1 Matches - 23 Up.WEEDER Motif1 Expanded Matches - 24 Up.WEEDER Motif1 Correlated Matches - 25 Up.WEEDER Motif1 Original/Expanded - 26 Up.WEEDER Motif1 Minimum Correlated - 27 Up.WEEDER Motif2 Score - 28 Up.WEEDER Motif2 Consensus - 29 Up.WEEDER Motif2 Matches - 30 Up.WEEDR Motif2 Expanded Matches - 31 Up.WEEDER Motif2 Correlated Matches - 32 Up.WEEDER Motif2 Original/Expanded - 33 Up.WEEDER Motif2 Minimum Correlated - 34 TFBS_DB.TFs - 35 TFBS_DB.percTargets - 36 TFBS_DB.pValue - 37 TFBS_DB.Exapnded Matches - 38 TFBS_DB.Correlated Matches - 39 TFBS_DB.Original/Expanded - 40 TFBS_DB.Minimum Correlated - 41 3pUTR.WEEDER Motif1 E-Value - 42 3pUTR.WEEDER Motif1 Consensus - 43 3pUTR.WEEDER Motif1 Matches - 44 3pUTR.WEEDER Motif1 Model - 45 3pUTR.WEEDER Motif2 E-Value - 46 3pUTR.WEEDER Motif2 Consensus - 47 3pUTR.WEEDER Motif2 Matches - 48 3pUTR.WEEDER Motif2 Model - 49 3pUTR_pita.miRNAs - 50 3pUTR_pita.percTargets - 51 3pUTR_pita.pValue - 52 3pUTR_targetScan.miRNAs - 53 3pUTR_targetScan.percTargets - 54 3pUTR_targetScan.pValue - 55 GO_Term_BP - 56 | |
| biclusters = {} | |
| biclusterHeader = '' | |
| for i in ['pita','targetscan','tfbs_db']: | |
| inFile = open('postProcessed_urdahlTCell_'+i+'.csv','r') | |
| biclusterHeader = inFile.readline() # Get rid of header | |
| while 1: | |
| line = inFile.readline() | |
| if not line: | |
| break | |
| splitUp = line.split(',') | |
| biclusters[i+'_'+splitUp[0]] = line.strip() | |
| inFile.close() | |
| inFile = open('genesInBiclusters/cluster.members.genes_'+i+'.txt','r') | |
| while 1: | |
| line = inFile.readline() | |
| if not line: | |
| break | |
| splitUp = line.strip().split(' ') | |
| j = splitUp.pop(0) | |
| biclusters[i+'_'+j] = biclusters[i+'_'+j] + ',' + ';'.join(splitUp) | |
| inFile.close() | |
| inFile = open('genesInBiclusters/cluster.members.conditions_'+i+'.txt','r') | |
| while 1: | |
| line = inFile.readline() | |
| if not line: | |
| break | |
| splitUp = line.strip().split(' ') | |
| j = splitUp.pop(0) | |
| biclusters[i+'_'+j] = biclusters[i+'_'+j] + ',' + ';'.join(splitUp) | |
| inFile.close() | |
| # Dump combined postProcessed file with clusters IDs | |
| #Bicluster - 0 Genes - 1 Conditions - 2 Norm. Residual - 3 Norm. Residual Perm. P-Value - 4 Var. Exp. First PC - 5 Var. Exp. First PC Perm. P-Value - 6 MEME Motif1 E-Value - 7 Up.MEME Motif1 Consensus - 8 Up.MEME Motif1 Matches - 9 Up.MEME Motif1 Expanded Matches - 10 Up.MEME Motif1 Correlated Matches - 11 Up.MEME Motif1 Original/Expanded - 12 Up.MEME Motif1 Minimum Correlated - 13 Up.MEME Motif2 E-Value - 14 Up.MEME Motif2 Consensus - 15 Up.MEME Motif2 Matches - 16 Up.MEME Motif2 Expanded Matches - 17 Up.MEME Motif2 Correlated Matches - 18 Up.MEME Motif2 Original/Expanded - 19 Up.MEME Motif2 Minimum Correlated - 20 Up.WEEDER Motif1 Score - 21 Up.WEEDER Motif1 Consensus - 22 Up.WEEDER Motif1 Matches - 23 Up.WEEDER Motif1 Expanded Matches - 24 Up.WEEDER Motif1 Correlated Matches - 25 Up.WEEDER Motif1 Original/Expanded - 26 Up.WEEDER Motif1 Minimum Correlated - 27 Up.WEEDER Motif2 Score - 28 Up.WEEDER Motif2 Consensus - 29 Up.WEEDER Motif2 Matches - 30 Up.WEEDR Motif2 Expanded Matches - 31 Up.WEEDER Motif2 Correlated Matches - 32 Up.WEEDER Motif2 Original/Expanded - 33 Up.WEEDER Motif2 Minimum Correlated - 34 TFBS_DB.TFs - 35 TFBS_DB.percTargets - 36 TFBS_DB.pValue - 37 TFBS_DB.Exapnded Matches - 38 TFBS_DB.Correlated Matches - 39 TFBS_DB.Original/Expanded - 40 TFBS_DB.Minimum Correlated - 41 3pUTR.WEEDER Motif1 E-Value - 42 3pUTR.WEEDER Motif1 Consensus - 43 3pUTR.WEEDER Motif1 Matches - 44 3pUTR.WEEDER Motif1 Model - 45 3pUTR.WEEDER Motif2 E-Value - 46 3pUTR.WEEDER Motif2 Consensus - 47 3pUTR.WEEDER Motif2 Matches - 48 3pUTR.WEEDER Motif2 Model - 49 3pUTR_pita.miRNAs - 50 3pUTR_pita.percTargets - 51 3pUTR_pita.pValue - 52 3pUTR_targetScan.miRNAs - 53 3pUTR_targetScan.percTargets - 54 3pUTR_targetScan.pValue - 55 GO_Term_BP - 56 | |
| tfs = {} | |
| correlatedTfs = {} | |
| bestTfs = {} | |
| miRNAs = {} | |
| goBP = {} | |
| writeMe = ['Meta-Cluster,bicluster,'+biclusterHeader.strip()+',Gene Names,Condition Names'] | |
| for i in clusters: | |
| tfs[i] = {'MEME':[], 'WEEDER':[], 'TFBS_DB':[]} | |
| correlatedTfs[i] = {'MEME':[], 'WEEDER':[], 'TFBS_DB':[]} | |
| bestTfs[i] = {'MEME':[], 'WEEDER':[], 'TFBS_DB':[]} | |
| miRNAs[i] = [] | |
| goBP[i] = [] | |
| for j in clusters[i]: | |
| writeMe.append(i+','+j+','+biclusters[j]) | |
| # Process out tfs and miRNAs | |
| splitUp = dict(zip(biclusterHeader.strip().split(','),biclusters[j].split(','))) | |
| # MEME1 | |
| if (not splitUp['MEME Motif1 E-Value']=='NA') and float(splitUp['MEME Motif1 E-Value'])<=0.05 and (not splitUp['Up.MEME Motif1 Matches']=='NA'): # and len(splitUp[10].split(' '))<10: | |
| tfs[i]['MEME'] += splitUp['Up.MEME Motif1 Matches'].split(' ') | |
| if not splitUp['Up.MEME Motif1 Correlated Matches']=='NA': | |
| correlatedTfs[i]['MEME'] += [k.split(':')[0] for k in splitUp['Up.MEME Motif1 Correlated Matches'].split(' ')] | |
| bestTfs[i]['MEME'] += [splitUp['Up.MEME Motif1 Minimum Correlated'].split(':')[0]] | |
| # MEME2 | |
| if (not splitUp['Up.MEME Motif2 E-Value']=='NA') and float(splitUp['Up.MEME Motif2 E-Value'])<=0.05 and (not splitUp['Up.MEME Motif2 Matches']=='NA'): # and len(splitUp[14].split(' '))<10: | |
| tfs[i]['MEME'] += splitUp['Up.MEME Motif2 Matches'].split(' ') | |
| if not splitUp['Up.MEME Motif2 Correlated Matches']=='NA': | |
| correlatedTfs[i]['MEME'] += [k.split(':')[0] for k in splitUp['Up.MEME Motif2 Correlated Matches'].split(' ')] | |
| bestTfs[i]['MEME'] += [splitUp['Up.MEME Motif2 Minimum Correlated'].split(':')[0]] | |
| # Weeder | |
| if (not splitUp['Up.WEEDER Motif1 Matches']=='NA'): # and len(splitUp[17].split(' '))<10: | |
| tfs[i]['WEEDER'] += splitUp['Up.WEEDER Motif1 Matches'].split(' ') | |
| if not splitUp['Up.WEEDER Motif1 Correlated Matches']=='NA': | |
| correlatedTfs[i]['WEEDER'] += [k.split(':')[0] for k in splitUp['Up.WEEDER Motif1 Correlated Matches'].split(' ')] | |
| bestTfs[i]['WEEDER'] += [splitUp['Up.WEEDER Motif1 Minimum Correlated'].split(':')[0]] | |
| # Weeder | |
| if (not splitUp['Up.WEEDER Motif2 Matches']=='NA'): # and len(splitUp[20].split(' '))<10: | |
| tfs[i]['WEEDER'] += splitUp['Up.WEEDER Motif2 Matches'].split(' ') | |
| if not splitUp['Up.WEEDER Motif2 Correlated Matches']=='NA': | |
| correlatedTfs[i]['WEEDER'] += [k.split(':')[0] for k in splitUp['Up.WEEDER Motif2 Correlated Matches'].split(' ')] | |
| bestTfs[i]['WEEDER'] += [splitUp['Up.WEEDER Motif2 Minimum Correlated'].split(':')[0]] | |
| # TFBS_DB | |
| if (not splitUp['TFBS_DB.percTargets']=='NA') and float((splitUp['TFBS_DB.percTargets'].split(' '))[0])>=0.1 and float((splitUp['TFBS_DB.pValue'].split(' '))[0])<=0.05: | |
| tfs[i]['TFBS_DB'] += splitUp['TFBS_DB.TFs'].split(' ') | |
| if not splitUp['TFBS_DB.Correlated Matches']=='NA': | |
| correlatedTfs[i]['TFBS_DB'] += [k.split(':')[0] for k in splitUp['TFBS_DB.Correlated Matches'].split(' ')] | |
| bestTfs[i]['TFBS_DB'] += [splitUp['TFBS_DB.Minimum Correlated'].split(':')[0]] | |
| # WEEDER:miRvestigator miRNA? | |
| if splitUp['3pUTR.WEEDER Motif1 Model']=='8mer': | |
| miRNAs[i] += [splitUp['3pUTR.WEEDER Motif1 Matches']] | |
| if splitUp['3pUTR.WEEDER Motif2 Model']=='8mer': | |
| miRNAs[i] += [splitUp['3pUTR.WEEDER Motif2 Matches']] | |
| # PITA miRNA? | |
| if (not splitUp['3pUTR_pita.percTargets']=='NA') and float((splitUp['3pUTR_pita.percTargets'].split(' '))[0])>=0.1 and float((splitUp['3pUTR_pita.pValue'].split(' '))[0])<=0.05: # and len(splitUp[36].split(' '))<10: | |
| miRNAs[i] += splitUp['3pUTR_pita.miRNAs'].split(' ') | |
| # TargetScan miRNA? | |
| if (not splitUp['3pUTR_targetScan.percTargets']=='NA') and float((splitUp['3pUTR_targetScan.percTargets'].split(' '))[0])>=0.1 and float((splitUp['3pUTR_targetScan.pValue'].split(' '))[0])<=0.05: # and len(splitUp[39].split(' '))<10: | |
| miRNAs[i] += splitUp['3pUTR_targetScan.miRNAs'].split(' ') | |
| # GO Biological Processes | |
| if not splitUp['GO_Term_BP']=='NA': | |
| goBP[i] += splitUp['GO_Term_BP'].split(';') | |
| outFile = open('postProcessed_clustersOfBiclusters.csv','w') | |
| outFile.write('\n'.join(writeMe)) | |
| outFile.close() | |
| # Dump out TFs to test | |
| outFile = open('tf_regulators.csv','w') | |
| outFile.write('cluster,MEME,WEEDER,TFBS_DB,Number Predicted\n') | |
| outFile.write('\n'.join([i+','+';'.join(list(set(tfs[i]['MEME'])))+','+';'.join(list(set(tfs[i]['WEEDER'])))+','+';'.join(list(set(tfs[i]['TFBS_DB'])))+','+str(len(list(set(list(set(tfs[i]['MEME']))+list(set(tfs[i]['WEEDER']))+list(set(tfs[i]['TFBS_DB'])))))) for i in tfs])) | |
| outFile.close() | |
| # Dump out TFs to test | |
| outFile = open('correlated_tf_regulators.csv','w') | |
| outFile.write('cluster,MEME,WEEDER,TFBS_DB,Number Predicted\n') | |
| outFile.write('\n'.join([i+','+';'.join(list(set(correlatedTfs[i]['MEME'])))+','+';'.join(list(set(correlatedTfs[i]['WEEDER'])))+','+';'.join(list(set(correlatedTfs[i]['TFBS_DB'])))+','+str(len(list(set(list(set(correlatedTfs[i]['MEME']))+list(set(correlatedTfs[i]['WEEDER']))+list(set(correlatedTfs[i]['TFBS_DB'])))))) for i in correlatedTfs])) | |
| outFile.close() | |
| # Dump out TFs to test | |
| outFile = open('best_tf_regulators.csv','w') | |
| outFile.write('cluster,MEME,WEEDER,TFBS_DB,Number Predicted\n') | |
| outFile.write('\n'.join([i+','+';'.join(list(set(bestTfs[i]['MEME'])))+','+';'.join(list(set(bestTfs[i]['WEEDER'])))+','+';'.join(list(set(bestTfs[i]['TFBS_DB'])))+','+str(len(list(set(list(set(bestTfs[i]['MEME']))+list(set(bestTfs[i]['WEEDER']))+list(set(bestTfs[i]['TFBS_DB'])))))) for i in bestTfs])) | |
| outFile.close() | |
| # Dump out miRNAs to test | |
| outFile = open('miRNA_regulators.csv','w') | |
| outFile.write('\n'.join([i+','+';'.join(list(set(miRNAs[i])))+','+str(len(list(set(miRNAs[i])))) for i in miRNAs])) | |
| outFile.close() | |
| # Dump out GO BPs to test | |
| outFile = open('GO_BPs_metaClusters.csv','w') | |
| outFile.write('\n'.join([i+','+';'.join(list(set(goBP[i])))+','+str(len(list(set(goBP[i])))) for i in goBP])) | |
| outFile.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment