Beispiel #1
0
    def writeTrackData(choices, genome, tn):
        from gold.util.RandomUtil import random
        from gold.util.CommonFunctions import createCollectedPath
        from quick.util.CommonFunctions import ensurePathExists

        trackFn = createCollectedPath(genome, tn,
                                      'simulatedTracks.category.bed')
        ensurePathExists(trackFn)
        trackFile = open(trackFn, 'w')
        #determinePossibilities
        numPossiblePositions = int(choices[2])
        spacingBetweenPositions = 1e3
        possiblePositions = [
            i * spacingBetweenPositions
            for i in range(1, int(numPossiblePositions))
        ]
        numHighProbPositions = int(choices[3])
        highProbPossiblePositions = possiblePositions[0:numHighProbPositions]
        lowProbPossiblePositions = possiblePositions[numHighProbPositions:]

        largestPossiblePosition = possiblePositions[-1]
        print 'largestPossiblePosition: ', largestPossiblePosition / 1e6, 'M'
        assert largestPossiblePosition < 1.5e8  #just due to hardcoded analysis region below..

        sizePerPosition = 591  #empirical across all VDR binding sites..
        print 'Total BpCoverage: ', len(possiblePositions) * sizePerPosition

        #make samples
        numExperiments = int(choices[0])
        proportionFromHighProbPositions = float(choices[4])
        fixedNumFromHighProbPositions = int(choices[5])
        #numPositionsPerExperiment = [3000]*9
        numPositionsPerExperiment = [
            int(x) for x in choices[1].split(',')
        ]  #[3073, 7118, 5290, 3059, 4051, 1021, 200, 610, 573]
        for experimentIndex in range(numExperiments):
            #sampledPositions = random.sample(possiblePositions, numPositionsPerExperiment[experimentIndex])
            numHighProbSamples = int(numPositionsPerExperiment[experimentIndex]
                                     * proportionFromHighProbPositions
                                     ) + fixedNumFromHighProbPositions
            numLowProbSamples = numPositionsPerExperiment[
                experimentIndex] - numHighProbSamples
            print 'numHighProbSamples: %i, out of numHighProbPossiblePositions: %i' % (
                numHighProbSamples, len(highProbPossiblePositions))
            sampledPositions = random.sample(highProbPossiblePositions, numHighProbSamples ) \
                            + random.sample(lowProbPossiblePositions, numLowProbSamples )
            sampledSegments = [(position, position + sizePerPosition)
                               for position in sampledPositions]
            for seg in sampledSegments:
                trackFile.write('\t'.join([
                    'chr1',
                    '%i' % seg[0],
                    '%i' % seg[1],
                    'T%i' % experimentIndex
                ]) + '\n')

        trackFile.close()
def getRandSegments(size, start, end):
   segments = sorted(random.sample(xrange(start*2, end*2), size*2))
   starts, ends = [], []
   for i in xrange(size):
      starts.append(segments[i*2]/2)
      ends.append((segments[i*2+1]+1)/2)
   return [array(starts), array(ends)]
Beispiel #3
0
def getRandSegments(size, start, end):
    segments = sorted(random.sample(xrange(start * 2, end * 2), size * 2))
    starts, ends = [], []
    for i in xrange(size):
        starts.append(segments[i * 2] / 2)
        ends.append((segments[i * 2 + 1] + 1) / 2)
    return [array(starts), array(ends)]
    def execute(choices, galaxyFn=None, username=''):
        '''Is called when execute-button is pushed by web-user.
        Should print output as HTML to standard out, which will be directed to a results page in Galaxy history.
        If getOutputFormat is anything else than HTML, the output should be written to the file with path galaxyFn.
        If needed, StaticFile can be used to get a path where additional files can be put (e.g. generated image files).
        choices is a list of selections made by web-user in each options box.
        '''
        #print os.getcwd()
        from config.Config import HB_SOURCE_CODE_BASE_DIR
        numRandomPwms = int(choices[2])
        pwms = parseTransfacMatrixFile(HB_SOURCE_CODE_BASE_DIR+'/data/all_PWMs.txt')
        if choices[1]=='All PWMs':
            selectedPwms = pwms
        elif choices[1] == 'Random subset':            
            from gold.util.RandomUtil import random
            selectedPwmKeys = random.sample(pwms.keys(),numRandomPwms)
            selectedPwms = dict([(x,pwms[x]) for x in selectedPwmKeys])

        writeTransfacMatrixFile(selectedPwms, galaxyFn)
    def execute(cls, choices, galaxyFn=None, username=''):
        '''Is called when execute-button is pushed by web-user.
        Should print output as HTML to standard out, which will be directed to a results page in Galaxy history.
        If getOutputFormat is anything else than HTML, the output should be written to the file with path galaxyFn.
        If needed, StaticFile can be used to get a path where additional files can be put (e.g. generated image files).
        choices is a list of selections made by web-user in each options box.
        '''
        #print os.getcwd()
        from config.Config import HB_SOURCE_CODE_BASE_DIR
        
        pwms = parseTransfacMatrixFile(HB_SOURCE_CODE_BASE_DIR+'/data/all_PWMs.txt')
        if choices[1]=='All PWMs':
            selectedPwms = pwms
        elif choices[1] == 'Random subset':
            numRandomPwms = int(choices[2])
            from gold.util.RandomUtil import random            
            selectedPwmKeys = random.sample(pwms.keys(),numRandomPwms)
            selectedPwms = dict([(x,pwms[x]) for x in selectedPwmKeys])

        writeTransfacMatrixFile(selectedPwms, galaxyFn)