def getGenesForGenome(self, genome): tnExon = ['Genes and gene subsets','Exons'] tnGenes =['Genes and gene subsets','Genes'] multiCountDef = 'dummy -> PointCountInsideSegsStat' try: genesList = [ v[0] for v in GalaxyInterface.getSubTrackNames(genome, tnGenes, deep=False)[0]] exonList = [ v[0] for v in GalaxyInterface.getSubTrackNames(genome, tnExon, deep=False)[0]] for tn in genesList: self.analysisDict['Genes_CountPointStat_'+tn] = [tnGenes+[tn], multiCountDef, 'Result'] for tn in exonList: self.analysisDict['Exons_CountPointStat_'+tn] = [tnExon+[tn], multiCountDef, 'Result'] except: pass
def countSubTracks(genome, parentTrack, recursioncount): if recursioncount < 10: thissubs = GalaxyInterface.getSubTrackNames(genome, parentTrack, False)[0] tname = genome + ":" + ":".join(parentTrack) #ti = TrackInfo. if thissubs: # has subtrakcs, ie is a folder thisndirs = 0 thisntracks = 0 for a in thissubs: nextparenttrack = parentTrack nextparenttrack.append(a[0]) ndirs, ntracks = countSubTracks(genome, nextparenttrack, recursioncount + 1) thisndirs = thisndirs + ndirs thisntracks = thisntracks + ntracks nextparenttrack = nextparenttrack.remove(a[0]) print('plan to update trackinfo', tname, ' set number of folders to ', thisndirs, ' and number of tracks to ', thisntracks) return (thisndirs + 1, thisntracks) else: # is a track. return (0, 1) else: print "to many recursions"
def analyseTrackData(genome, baseTn, username, galaxyFn): from quick.application.GalaxyInterface import GalaxyInterface print GalaxyInterface.getSubTrackNames(genome, baseTn, deep=False, username=username) allTns = [ baseTn + [leafTn[0]] for leafTn in GalaxyInterface.getSubTrackNames( genome, baseTn, deep=False, username=username)[0] if leafTn != None ] mainTns = allTns[:2] extraTracks = '&'.join(['^'.join(tn) for tn in allTns[2:]]) analysisDef = '[extraTracks=%s] -> ThreeWayCoverageDepthStat' % extraTracks print allTns, mainTns GalaxyInterface.runManual(mainTns, analysisDef, 'chr1:1-150m', '*', genome, galaxyFn=galaxyFn, username=username, \ printResults=True, printProgress=True, printHtmlWarningMsgs=True, applyBoundaryFilter=False, printRunDescription=True)
def getOptionsBox3(prevChoices): '''Returns a list of options to be displayed in the second options box, which will be displayed after a selection is made in the first box. prevChoices is a list of selections made by the web-user in the previous input boxes (that is, list containing only one element for this case) ''' from quick.application.GalaxyInterface import GalaxyInterface try: subTrackList = [v[0] for v in GalaxyInterface.getSubTrackNames(prevChoices[0], prevChoices[1].split(':'), deep=False)[0]] #return (repr(subTrackList), 4, True) return ('\n'.join(subTrackList), len(subTrackList), True) except: pass
def getOptionsBox3(prevChoices): '''Returns a list of options to be displayed in the second options box, which will be displayed after a selection is made in the first box. prevChoices is a list of selections made by the web-user in the previous input boxes (that is, list containing only one element for this case) ''' from quick.application.GalaxyInterface import GalaxyInterface from collections import OrderedDict try: subTrackList = [ v[0] for v in GalaxyInterface.getSubTrackNames( prevChoices[0], prevChoices[1].split(':'), deep=False)[0] ] if len(subTrackList) > 0: subSubTrackList = GalaxyInterface.getSubTrackNames( prevChoices[0], prevChoices[1].split(':') + [subTrackList[0]], deep=False)[0] if len(subSubTrackList) == 0: return OrderedDict([(v, False) for v in subTrackList]) #return ('\n'.join(subTrackList), len(subTrackList), True) except: pass
def getSubTrackLeafTerms(genome, parentTrack, excludeSelfIfValid=True, username=''): from quick.application.GalaxyInterface import GalaxyInterface subTrackTriples = GalaxyInterface.getSubTrackNames(genome, parentTrack, deep=False, username=username)[0] filteredSubTrackLeaves = [ x[0] for x in subTrackTriples if x not in [[], None] and not (excludeSelfIfValid and x[0] == '-- All subtypes --') ] return filteredSubTrackLeaves
def countSubTracks(genome, parentTrack, recursioncount): if recursioncount < 10: thissubs=GalaxyInterface.getSubTrackNames(genome, parentTrack, False)[0] tname=genome+":"+":".join( parentTrack) #ti = TrackInfo. if thissubs: # has subtrakcs, ie is a folder thisndirs=0 thisntracks=0 for a in thissubs: nextparenttrack=parentTrack nextparenttrack.append(a[0]) ndirs, ntracks =countSubTracks(genome, nextparenttrack, recursioncount+1) thisndirs=thisndirs+ndirs thisntracks=thisntracks+ntracks nextparenttrack=nextparenttrack.remove(a[0]) print('plan to update trackinfo', tname,' set number of folders to ', thisndirs, ' and number of tracks to ', thisntracks) return(thisndirs+1, thisntracks) else:# is a track. return (0,1) else: print "to many recursions"
def execute(choices, galaxyFn=None, username=''): #setupDebugModeAndLogging() from time import time startTime = time() print HtmlCore().begin() print '<pre>' genome = choices[0] #assert genome=='hg19' flankSize = choices[3] if choices[1] == 'Prepared catalogues': if choices[2] == 'GiulioNewGwas': gwasTnBase = 'Private:GK:NewGwasBase'.split(':') elif choices[2] == 'GiulioAllGwas': gwasTnBase = 'Private:GK:AllGiulioGwasSnpsAsOf9feb13'.split( ':') elif choices[2] == 'GiulioMay13Gwas': gwasTnBase = 'Private:GK:Gwas:GiulioMay13'.split(':') elif choices[2] == 'SmallTest': gwasTnBase = 'Private:GK:Gwas'.split(':') else: raise gwasTnBase += [flankSize] elif choices[1] == 'Custom track': gwasTnBase = choices[2].split(':') assert flankSize == 'SNPs' else: assert False, choices[1] referenceTrackSource = choices[4] normalization = choices[5] assert normalization == 'CoverageDepth' analysisType = choices[6] if analysisType == 'Enrichment': ResultClass = EnrichmentGwasResults elif analysisType == 'Testing': ResultClass = HypothesisTestingGwasResults nullmodelMapping = dict( zip([ 'Sample disease regions uniformly', 'Sample disease regions with preserved inter-region spacings', 'Sample disease regions with preserved distance to nearest exon' ], [ 'PermutedSegsAndSampledIntersegsTrack_', 'PermutedSegsAndIntersegsTrack_', 'SegsSampledByDistanceToReferenceTrack_,trackNameIntensity=Genes and gene subsets^Exons^Ensembl exons' ])) nullmodel = nullmodelMapping[choices[9]] assert nullmodel in [ 'PermutedSegsAndSampledIntersegsTrack_', 'PermutedSegsAndIntersegsTrack_', 'SegsSampledByDistanceToReferenceTrack_,trackNameIntensity=Genes and gene subsets^Exons^Ensembl exons' ] else: raise kernelType = choices[7] kernelParam = choices[8] if choices[10] == 'Include links to full underlying results': includeDetailedResults = True elif choices[10] == 'Only produce main result values': includeDetailedResults = False else: raise InvalidRunSpecException('Did not understand option: %s' % choices[12]) mcDepth = choices[11] if choices[12] == 'yes': includeLocalResults = True elif choices[12] == 'no': includeLocalResults = False else: raise InvalidRunSpecException('Did not understand option: %s' % choices[12]) if choices[15] == 'yes': useCache = True elif choices[15] == 'no': useCache = False else: raise InvalidRunSpecException('Did not understand option: %s' % choices[15]) if choices[16] == 'yes': printProgress = True elif choices[16] == 'no': printProgress = False else: raise InvalidRunSpecException('Did not understand option: %s' % choices[16]) from quick.application.GalaxyInterface import GalaxyInterface #print GalaxyInterface.getHtmlForToggles() #print GalaxyInterface.getHtmlBeginForRuns() #from quick.webtools.GwasAPI import getEnrichmentValues print 'Progress: ' #print 'base: ',gwasTnBase #print 'leaves: ',GalaxyInterface.getSubTrackNames(genome, gwasTnBase,deep=False, username=username) disRes = MultiGwasResults() from gold.application.HyperBrowserCLI import getSubTrackLeafTerms from quick.application.ProcTrackOptions import ProcTrackOptions #for gwasTrackLeaf in GalaxyInterface.getSubTrackNames(genome, gwasTnBase,deep=False, username=username): allDiseases = getSubTrackLeafTerms(genome, gwasTnBase, username=username) if len(allDiseases) == 0: assert ProcTrackOptions.isValidTrack( genome, gwasTnBase, GalaxyInterface.userHasFullAccess( username)), 'Genome: %s, TN: %s, Access: %s' % ( genome, gwasTnBase, GalaxyInterface.userHasFullAccess(username)) allDiseases = gwasTnBase[-1:] gwasTnBase = gwasTnBase[:-1] for disease in allDiseases: #print 'Leaf:',gwasTrackLeaf[0] #if not gwasTrackLeaf[0] in ['11 - Height.txt']: #if not disease in ['1 - Alzheimer.txt','10 - Graves.txt']:#['Malaria','UC']: # print 'IGNORING: ', gwasTrackLeaf[0] # continue #if gwasTrackLeaf in [[],None] or gwasTrackLeaf[0]=='-- All subtypes --': #continue #gwasTn = ':'.join(gwasTnBase + [gwasTrackLeaf[0]]) gwasTn = ':'.join(gwasTnBase + [disease]) #print 'Running API: ', "$getEnrichmentValues(%s, '%s', '%s')" % ([gwasTn], referenceTrackSource, normalization) #enrichmentsDict = getEnrichmentValues([gwasTn], referenceTrackSource, normalization)#, ['114 - Brain_Mid_Frontal_Lobe.txt','134 - Rectal_Smooth_Muscle.txt']) #assert len(enrichmentsDict.values())==1 #enrichments = enrichmentsDict.values()[0] #if gwasTrackLeaf[0] in ['Malaria','UC']: #print 'HERE IS WHAT I GOT: ',enrichmentsDict #print 'ENR: ',enrichments #print 'One: ', (enrichments.values()[0])['enrichment']['13 - CD4'].getGlobalResult() #assert 'enrichment' in (enrichments.values()[0]), (enrichments.values()[0]) #disRes[gwasTrackLeaf[0]] = (enrichments.values()[0])['enrichment'] #disRes[gwasTrackLeaf[0]] = (enrichments.values()[0]) #disease = gwasTrackLeaf[0] #disRes[disease] = [x.getGlobalResult() for x in enrichments] #print 'DISres: ', disRes[gwasTrackLeaf[0]] #from quick.util.CommonFunctions import extractIdFromGalaxyFn res = ResultClass(gwasId=disease, verbose=True, galaxyFn=galaxyFn) #referenceSubTypes = enrichments.keys() #referenceSubTypes = [x[0] for x in GalaxyInterface.getSubTrackNames(genome, 'Private:GK:Psych:DHSs'.split(':'), deep=False, username=username) if not x[0] == '-- All subtypes --'] if referenceTrackSource == 'H3K4me3': refTrackBase = 'Private:GK:Psych:H3K4me3' refTrackCoverageFunction = 'Private^GK^Psych^H3K4me3CoverageTrack' elif referenceTrackSource == 'DHS': refTrackBase = 'Private:GK:Psych:DHSs' refTrackCoverageFunction = 'Private^GK^Psych^DHSCoverageTrack' elif referenceTrackSource == 'Chromatin state 1-AP': refTrackBase = 'Private:Anders:Chromatin State Segmentation:1_Active_Promoter' refTrackCoverageFunction = 'Private^GWAS^Chromatin^CoverageFunctionTracks^1_Active_PromoterV2' elif referenceTrackSource == 'Chromatin state 4-SE': refTrackBase = 'Private:Anders:Chromatin State Segmentation:4_Strong_Enhancer' refTrackCoverageFunction = 'Private^GWAS^Chromatin^CoverageFunctionTracks^4_Strong_Enhancer' elif referenceTrackSource == 'Chromatin state 5-SE': refTrackBase = 'Private:Anders:Chromatin State Segmentation:5_Strong_Enhancer' refTrackCoverageFunction = 'Private^GWAS^Chromatin^CoverageFunctionTracks^5_Strong_Enhancer' else: raise refTrackSelectType = choices[13] allReferenceTracks = [ x[0] for x in GalaxyInterface.getSubTrackNames( genome, refTrackBase.split(':'), deep=False, username=username) if not x[0] == '-- All subtypes --' ] if refTrackSelectType == 'Use all reference tracks': referenceSubTypes = allReferenceTracks elif refTrackSelectType == 'Select single reference track': referenceSubTypes = [choices[14]] assert referenceSubTypes[0] in allReferenceTracks elif refTrackSelectType == 'Select a range among all reference tracks': try: firstRefTrack, lastRefTrack = choices[14].split('-') referenceSubTypes = allReferenceTracks[ int(firstRefTrack):int(lastRefTrack) + 1] print 'Analyzing %s among a total of %s reference tracks' % ( choices[14], len(allReferenceTracks)) except Exception: print 'Range format should be e.g. "15-18".' raise else: raise for referenceSubType in referenceSubTypes: #if not referenceSubType in ['107 - Adult_Kidney.txt','106 - Adipose_Nuclei.txt']: # #print 'IGNORING: ',referenceSubType # continue # if analysisType == 'Enrichment': res[referenceSubType] = directGetEnrichment( gwasTn, referenceSubType, refTrackBase, kernelType, kernelParam, useCache, printProgress) elif analysisType == 'Testing': res[referenceSubType] = directGetTestResults( gwasTn, referenceSubType, refTrackBase, kernelType, kernelParam, refTrackCoverageFunction, nullmodel, mcDepth, useCache, printProgress) else: raise #print disease, referenceSubType, res[referenceSubType] #print "ENR: ",enrichments #res[referenceSubType] = enrichments[referenceSubType] disRes[disease] = res #for disease in disRes: # print 'D FULL %s:' %disease, disRes[disease] # print 'D DICTS %s:'%disease, disRes[disease].getAllGlobalResultDicts() # print 'DISEASE %s:'%disease, disRes[disease].getAllGlobalResults() print 'Total run time (excluding figure generation): %i seconds.' % ( time() - startTime) print '</pre>' #print GalaxyInterface.getHtmlBeginForRuns() print '<h1>Results</h1>' if len(allDiseases) > 1: try: heatMapLink = disRes.getLinkToClusteredHeatmap( 'Heatmap', galaxyFn) print '<h3>Heatmap</h3>', heatMapLink #, '<br>' except: print '<p>Creation of heatmap failed</p>' tableOutput = disRes.getHtmlResultsTable(includeDetailedResults) print '<h3>Results table</h3>', tableOutput if choices[-1]: print '<h3>Prior coloring table</h3>' colorFn = ExternalTrackManager.extractFnFromGalaxyTN( choices[-1].split(':')) print disRes.getColoredSortedReferencesTable(colorFn) if includeLocalResults: print '<h3>Local results</h3>' print disRes.getLinksToAllLocalHtmlResultsTables(galaxyFn)