def getTrackExtractionOptions(genome, trackName): from gtrackcore.track.core.Track import PlainTrack from gtrackcore.input.userbins.UserBinSource import MinimalBinSource from gtrackcore.extract.fileformats.FileFormatComposer import \ findMatchingFileFormatComposers, getComposerClsFromFileSuffix tf = PlainTrack(trackName).getTrackView( MinimalBinSource(genome)[0]).trackFormat extractionOptions = [] matchingComposers = findMatchingFileFormatComposers(tf) for composerInfo in matchingComposers: allOverlapRules = tf.getAllOverlapRules() for allowOverlaps in allOverlapRules: extractionOptions.append( \ (composerInfo.trackFormatName.capitalize() + \ ' ' + TrackExtractor.getFileFormatText(composerInfo.fileFormatName) + \ (', ' + (TrackExtractor.ALLOW_OVERLAPS_TRUE_TEXT if allowOverlaps else \ TrackExtractor.ALLOW_OVERLAPS_FALSE_TEXT) \ if len(allOverlapRules) > 1 else ''), \ composerInfo.fileSuffix) ) ti = TrackInfo(genome, trackName) if ti.fileType != '': try: extractionOptions.append( (TrackExtractor.ORIG_FILE_FORMAT_TEXT.capitalize() + \ ' ' + TrackExtractor.getFileSuffixText(ti.fileType), \ getComposerClsFromFileSuffix(ti.fileType).getDefaultFileNameSuffix())) except Exception, e: print 'Error:', e
def getTrackExtractionOptions(genome, trackName): from gtrackcore.track.core.Track import PlainTrack from gtrackcore.input.userbins.UserBinSource import MinimalBinSource from gtrackcore.extract.fileformats.FileFormatComposer import \ findMatchingFileFormatComposers, getComposerClsFromFileSuffix tf = PlainTrack(trackName).getTrackView(MinimalBinSource(genome)[0]).trackFormat extractionOptions = [] matchingComposers = findMatchingFileFormatComposers(tf) for composerInfo in matchingComposers: allOverlapRules = tf.getAllOverlapRules() for allowOverlaps in allOverlapRules: extractionOptions.append( \ (composerInfo.trackFormatName.capitalize() + \ ' ' + TrackExtractor.getFileFormatText(composerInfo.fileFormatName) + \ (', ' + (TrackExtractor.ALLOW_OVERLAPS_TRUE_TEXT if allowOverlaps else \ TrackExtractor.ALLOW_OVERLAPS_FALSE_TEXT) \ if len(allOverlapRules) > 1 else ''), \ composerInfo.fileSuffix) ) ti = TrackInfo(genome, trackName) if ti.fileType != '': try: extractionOptions.append( (TrackExtractor.ORIG_FILE_FORMAT_TEXT.capitalize() + \ ' ' + TrackExtractor.getFileSuffixText(ti.fileType), \ getComposerClsFromFileSuffix(ti.fileType).getDefaultFileNameSuffix())) except Exception, e: print 'Error:', e
def count_elements_in_all_bounding_regions(track_name, genome='testgenome', allow_overlaps=False): bounding_regions = BoundingRegionShelve(genome, track_name, allow_overlaps).getAllBoundingRegions() track = PlainTrack(track_name) num_elements = 0 for tv in [track.getTrackView(region) for region in bounding_regions]: num_elements += count_elements(tv) return num_elements
def _createRandomizedNumpyArrays(self, binLen, starts, ends, vals, strands, ids, edges, weights, extras, origTrackFormat, region): if self._minimal: return numpy.array([]), None, None, None, None, None, None, OrderedDict() intensityTV = PlainTrack(self._trackNameIntensity).getTrackView(region) if len(intensityTV.valsAsNumpyArray())==0: raise InvalidRunSpecException('Error: No intensity data available for sampling randomized locations in region' + \ str(region) + \ '. Please check that the intensity track was created with the same main track that is being randomized in this analysis.') #intensityTV = PlainTrack(self._trackNameIntensity).getTrackView(self._origRegion) #Dependence on origRegion is not nice, but not a big problem.. if intensityTV.trackFormat.isDense(): assert intensityTV.trackFormat.isValued('number') return self._createRandomizedNumpyArraysFromIntensityFunction(binLen, starts, ends, vals, strands, ids, edges, weights, extras, intensityTV) else: raise NotImplementedError
def _createRandomizedNumpyArrays(self, binLen, starts, ends, vals, strands, ids, edges, weights, extras, origTrackFormat, region): if self._minimal: return numpy.array( []), None, None, None, None, None, None, OrderedDict() intensityTV = PlainTrack(self._trackNameIntensity).getTrackView(region) if len(intensityTV.valsAsNumpyArray()) == 0: raise InvalidRunSpecException('Error: No intensity data available for sampling randomized locations in region' + \ str(region) + \ '. Please check that the intensity track was created with the same main track that is being randomized in this analysis.') #intensityTV = PlainTrack(self._trackNameIntensity).getTrackView(self._origRegion) #Dependence on origRegion is not nice, but not a big problem.. if intensityTV.trackFormat.isDense(): assert intensityTV.trackFormat.isValued('number') return self._createRandomizedNumpyArraysFromIntensityFunction( binLen, starts, ends, vals, strands, ids, edges, weights, extras, intensityTV) else: raise NotImplementedError
def get_track_view(track_name, genome_region): track = PlainTrack(track_name) return track.getTrackView(genome_region)