Beispiel #1
0
    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
Beispiel #2
0
 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
Beispiel #3
0
    def getAttrsFromExtractionFormat(cls, extractionFormat):
        asOriginal = extractionFormat.lower().startswith(cls.ORIG_FILE_FORMAT_TEXT)
        if asOriginal:
            suffix = TrackExtractor.getFileSuffixFromExtractionFormat(extractionFormat)
            
            from gtrackcore.extract.fileformats.FileFormatComposer import getComposerClsFromFileSuffix
            composerCls = getComposerClsFromFileSuffix(suffix)
            fileFormatName = composerCls.FILE_FORMAT_NAME
            allowOverlaps = True
        else:
            fileFormatName = cls.getFileFormatNameFromExtractionFormat(extractionFormat)
            allowOverlaps = extractionFormat.lower().endswith(cls.ALLOW_OVERLAPS_TRUE_TEXT)

        return fileFormatName, asOriginal, allowOverlaps
Beispiel #4
0
    def getAttrsFromExtractionFormat(cls, extractionFormat):
        asOriginal = extractionFormat.lower().startswith(
            cls.ORIG_FILE_FORMAT_TEXT)
        if asOriginal:
            suffix = TrackExtractor.getFileSuffixFromExtractionFormat(
                extractionFormat)

            from gtrackcore.extract.fileformats.FileFormatComposer import getComposerClsFromFileSuffix
            composerCls = getComposerClsFromFileSuffix(suffix)
            fileFormatName = composerCls.FILE_FORMAT_NAME
            allowOverlaps = True
        else:
            fileFormatName = cls.getFileFormatNameFromExtractionFormat(
                extractionFormat)
            allowOverlaps = extractionFormat.lower().endswith(
                cls.ALLOW_OVERLAPS_TRUE_TEXT)

        return fileFormatName, asOriginal, allowOverlaps
Beispiel #5
0
    def extract(cls, trackName, regionList, fn, fileFormatName=DEFAULT_FILE_FORMAT_NAME, globalCoords=True, \
                addSuffix=False, asOriginal=False, allowOverlaps=False, ignoreEmpty=False):
        from gtrackcore.input.adapters.TrackGenomeElementSource import TrackGenomeElementSource
        from gtrackcore.extract.fileformats.FileFormatComposer import getComposerClsFromFileFormatName, getComposerClsFromFileSuffix

        assert len(regionList) > 0
        for region in regionList:
            genome = region.genome
            break

        #To silently extract correctly if track type is dense
        if allowOverlaps:
            allowOverlaps = os.path.exists(
                createDirPath(trackName, genome, allowOverlaps=True))

        trackGESource = TrackGenomeElementSource(genome, trackName, regionList, globalCoords=globalCoords, \
                                                 allowOverlaps=allowOverlaps, printWarnings=False)

        composerCls = None
        if asOriginal:
            ti = TrackInfo(genome, trackName)
            if ti.fileType != '':
                try:
                    composerCls = getComposerClsFromFileSuffix(ti.fileType)
                except:
                    pass

        if composerCls is None:
            composerCls = getComposerClsFromFileFormatName(fileFormatName)

        if addSuffix:
            fn = os.path.splitext(
                fn)[0] + '.' + composerCls.getDefaultFileNameSuffix()

        composer = composerCls(trackGESource)
        ok = composer.composeToFile(fn, ignoreEmpty=ignoreEmpty)

        if ok:
            return fn
Beispiel #6
0
    def extract(cls, trackName, regionList, fn, fileFormatName=DEFAULT_FILE_FORMAT_NAME, globalCoords=True, \
                addSuffix=False, asOriginal=False, allowOverlaps=False, ignoreEmpty=False):
        from gtrackcore.input.adapters.TrackGenomeElementSource import TrackGenomeElementSource
        from gtrackcore.extract.fileformats.FileFormatComposer import getComposerClsFromFileFormatName, getComposerClsFromFileSuffix
        
        assert len(regionList) > 0
        for region in regionList:
            genome = region.genome
            break
        
        #To silently extract correctly if track type is dense
        if allowOverlaps:
            allowOverlaps = os.path.exists(createDirPath(trackName, genome, allowOverlaps=True))
            
        trackGESource = TrackGenomeElementSource(genome, trackName, regionList, globalCoords=globalCoords, \
                                                 allowOverlaps=allowOverlaps, printWarnings=False)
        
        composerCls = None
        if asOriginal:
            ti = TrackInfo(genome, trackName)
            if ti.fileType != '':
                try:
                    composerCls = getComposerClsFromFileSuffix(ti.fileType)
                except:
                    pass
        
        if composerCls is None:
            composerCls = getComposerClsFromFileFormatName(fileFormatName)

        if addSuffix:
            fn = os.path.splitext(fn)[0] + '.' + composerCls.getDefaultFileNameSuffix()
        
        composer = composerCls(trackGESource)
        ok = composer.composeToFile(fn, ignoreEmpty=ignoreEmpty)
        
        if ok:
            return fn