def _init(self, **kwArgs):
        if self._parsedUri.params != '':
            raise InvalidFormatError(
                'File suffix parameter is not supported by the '
                '"%s" protocol: %s' % (self.SCHEME, self._parsedUri.params))

        if self._parsedUri.query != '':
            raise InvalidFormatError('Queries in URI ("?%s") ' % self._parsedUri.query +\
                                     'is not supported by the "%s" protocol.' % self.SCHEME)

        super(HbGSuiteTrack, self)._init(**kwArgs)
    def _init(self, **kwArgs):
        if self.fileFormat in (PRIMARY,
                               UNKNOWN) and self._parsedUri.query != '':
            raise InvalidFormatError('Queries in URI ("?%s") ' % self._parsedUri.query +\
                                     'is not allowed for non-binary tracks with "%s" as protocol.' % self.SCHEME)

        super(NoQueryForTextGSuiteTrack, self)._init(**kwArgs)
    def __call__(cls, uri, **kwArgs):

        if cls is GSuiteTrack:
            # This is probably not needed, as the scheme should not be quoted
            #if doUnquote:
            #uri = unquote(uri)
            scheme = urlparse.urlparse(uri).scheme

            if scheme == '':
                raise InvalidFormatError('GSuite track URI does not have a specified ' \
                                         'protocol. URI: ' + uri)

            if scheme not in _GSUITE_TRACK_REGISTRY:
                raise InvalidFormatError('Track protocol "%s" is not supported in ' % scheme +\
                                         'this version of the GSuite format')
            return _GSUITE_TRACK_REGISTRY[scheme](uri, **kwArgs)
        return type.__call__(cls, uri, **kwArgs)
 def trackName(self):
     if self._parsedUri.query:
         if 'track' in self._queryDict:
             if len(self._queryDict['track']) > 1:
                 raise InvalidFormatError(
                     'More than one "track=" clause is not allowed '
                     'in the query of the URI: ' + self.uri)
             return self._queryDict['track'][0].split(':')
    def _init(self, fileFormat=None, **kwArgs):
        self.fileFormat = fileFormat  #To handle deprecated 'binary' value

        if self.fileFormat is not None and self.fileFormat != PREPROCESSED:
            raise InvalidFormatError('Track protocol "%s" requires the file format ' % self.SCHEME +\
                                     'to be "%s", not "%s".' % (PREPROCESSED, fileFormat))

        self.fileFormat = PREPROCESSED

        kwArgs['fileFormat'] = fileFormat
        super(PreprocessedGSuiteTrack, self)._init(**kwArgs)
    def _init(self, **kwArgs):
        oldFileFormat = self.fileFormat

        self.fileFormat = UNKNOWN

        if oldFileFormat != UNKNOWN and oldFileFormat != self.fileFormat:
            raise InvalidFormatError('File format specified as parameter ("%s") does not ' % oldFileFormat +\
                                     'fit with track type as specified by the suffix '
                                     '"%s": "%s"' % (self.suffix, self.fileFormat))

        super(SuffixDependentGSuiteTrack, self)._init(**kwArgs)
    def attributes(self, attributes):
        self._attributes = OrderedDict()

        for key, val in attributes.iteritems():
            if val is not None:
                if val == '':
                    raise InvalidFormatError(
                        'Empty attribute contents not allowed. '
                        'Please use ".", the period character, to '
                        'indicate missing values')

                if self._doUnquote:
                    val = unquote(val)
                self._attributes[key] = val
    def __init__(self,
                 uri,
                 title=None,
                 fileFormat=None,
                 trackType=None,
                 genome=None,
                 attributes=OrderedDict(),
                 comment=None,
                 doUnquote=True):
        self._doUnquote = doUnquote

        self._parsedUri = urlparse.urlparse(uri)
        if self._parsedUri.query:
            self._queryDict = urlparse.parse_qs(self._parsedUri.query,
                                                keep_blank_values=False,
                                                strict_parsing=True)

        if doUnquote:
            self._parsedUri = unquoteParseResults(self._parsedUri)
            if self._parsedUri.query:
                self._queryDict = unquoteQueryDict(self._queryDict)

        assert self._parsedUri.scheme == self.SCHEME, [
            self._parsedUri.scheme, self.SCHEME
        ]
        if self._parsedUri.fragment != '':
            raise InvalidFormatError(
                'Fragment part of URI is not allowed: "#%s"' %
                self._parsedUri.fragment)

        self.title = title
        self.fileFormat = fileFormat if fileFormat is not None else HEADER_VAR_DICT[
            FILE_FORMAT_HEADER].default
        self.trackType = trackType if trackType is not None else HEADER_VAR_DICT[
            TRACK_TYPE_HEADER].default
        self.genome = genome if genome is not None else HEADER_VAR_DICT[
            GENOME_HEADER].default
        self.attributes = attributes
        self.comment = comment

        self._init(uri=uri,
                   title=title,
                   fileFormat=fileFormat,
                   trackType=trackType,
                   genome=genome,
                   attributes=attributes,
                   comment=comment,
                   doUnquote=doUnquote)
Ejemplo n.º 9
0
    def _combineTrackTypeVals(self, curVal, nextVal):
        try:
            return self._combineEqualVals(curVal, nextVal)
        except InvalidFormatError:
            from track.TrackFormat import TrackFormatReq
            curReq = TrackFormatReq(name=curVal)
            nextReq = TrackFormatReq(name=nextVal)

            maxCommonCoreType = TrackFormatReq.maxCommonCoreFormat(
                curReq, nextReq)
            if maxCommonCoreType is not None:
                return maxCommonCoreType.getFormatName().lower()

            raise InvalidFormatError(
                'Track types "%s" and "%s" are not possible to combine. ' %
                (curVal, nextVal))
Ejemplo n.º 10
0
    def addTrack(self, track, allowDuplicateTitles=True):
        if track.title in self._titleToTrackDict:
            if allowDuplicateTitles:
                for i in range(self.numTracks()):
                    candTitle = track.title + ' (%s)' % (i + 2)
                    if candTitle not in self._titleToTrackDict:
                        track.title = candTitle
                        break
            else:
                raise InvalidFormatError(
                    'Multiple tracks with the same title is not allowed: ' +
                    track.title)

        self._updatedHeaders = False
        self._titleToTrackDict[track.title] = track
        self._trackList.append(track)
 def check(self, gSuiteOrTrack):
     for header, allowedVals in self._requirements.iteritems():
         if self._getMemberValue(gSuiteOrTrack, header) not in allowedVals:
             errorString = '\'%s\' is not a supported GSuite %s for this tool. Supported file types are [%s]' % \
                 (self._getMemberValue(gSuiteOrTrack, header), header, ', '.join(self._requirements[header]))
             raise InvalidFormatError(errorString)
    def _init(self, **kwArgs):
        if not self._parsedUri.path.startswith('/'):
            raise InvalidFormatError('Track protocol "%s" requires the ' % self.SCHEME +\
                                     'path to start with the "/" character. Path: "%s"' % self._parsedUri.path)

        super(LocalGSuiteTrack, self)._init(**kwArgs)
    def _init(self, **kwArgs):
        if self.netloc is None:
            raise InvalidFormatError('Track protocol "%s" requires the specification ' % self.SCHEME +\
                                     'of a host server, e.g. "%s://server.org/path/to/file".' % self.SCHEME)

        super(RemoteGSuiteTrack, self)._init(**kwArgs)
 def _checkHeaderValAllowed(self, param, header):
     if param is not None and param not in HEADER_VAR_DICT[header].allowed:
         raise InvalidFormatError('Header "%s" value is not allowed: "%s". ' % (header, param) +\
                                  'Allowed values: ' + ', '.join(HEADER_VAR_DICT[header].allowed))
Ejemplo n.º 15
0
 def _combineEqualVals(self, curVal, nextVal):
     if curVal == nextVal:
         return curVal
     raise InvalidFormatError('%s != %s' % (curVal, nextVal))