Look up the BioPython file type corresponding with input extension.

    Look up is case insensitive.
10002
def from_extension(extension):
    
    if not extension.startswith('.'):
        raise ValueError("Extensions must begin with a period.")
    try:
        return EXTENSION_TO_TYPE[extension.lower()]
    except KeyError:
        raise UnknownExtensionError(
            "seqmagick does not know how to handle " +
            "files with extensions like this: " + extension)
1332213
def _get_extension(file):
    
    if isinstance(file, str):
        return os.path.splitext(file)[-1]
    elif isinstance(file, bytes):
        kind = imghdr.what(io.BytesIO(file))
        return ('.' + kind) if kind else ''
    elif isinstance(file, io.IOBase) and file.seekable():
        kind = imghdr.what(file)
        return ('.' + kind) if kind is not None else ''
    elif getattr(file, 'name', None):
        # Note: ``file.name`` works for :tl:`InputFile` and some `IOBase`
        return _get_extension(file.name)
    else:
        return ''
689398
def input_file(filename):
    
    if excluded(filename) or not filename_match(filename):
        return {}
    if options.verbose:
        message('checking ' + filename)
    options.counters['files'] = options.counters.get('files', 0) + 1
    errors = Checker(filename).check_all()
    if options.testsuite and not errors:
        message("%s: %s" % (filename, "no errors found"))
    return errors
1299056
def __get_indexer(in_fns, selected_type=None):
  """"""
  indexer = None
  if selected_type is not None:
    indexer = get_indexer_by_filetype(selected_type)
  else:
    if len(in_fns) == 0:
      raise IndexError("reading from stdin, unable to guess input file " +
                       "type, use -t option to set manually.\n")
    else:
      extension = set([os.path.splitext(f)[1] for f in in_fns])
      assert(len(extension) >= 1)
      if len(extension) > 1:
        raise IndexError("more than one file extension present, unable " +
                         "to get input type, use -t option to set manually.\n")
      else:
        indexer = get_indexer_by_file_extension(list(extension)[0])
  assert(indexer is not None)
  return indexer
320316
def get_file_extension(self, filepath):
        
        mtype = magic.from_file(filepath, mime=True)
        if type(mtype) == bytes:
            mtype = mtype.decode("utf-8")

        if mtype == "audio/mpeg":
            ext = ".mp3"
        elif mtype == "audio/x-wav":
            ext = ".wav"
        else:
            ext = "." + self.get("original-format")
        return ext
1295201
def get_type(self):
        

        ext = self.match.group(5)

        if ext == 'pre.py':
            return DeltaType.PRE_PYTHON
        elif ext == 'pre.sql':
            return DeltaType.PRE_SQL
        elif ext == 'py':
            return DeltaType.PYTHON
        elif ext == 'sql':
            return DeltaType.SQL
        elif ext == 'post.py':
            return DeltaType.POST_PYTHON
        elif ext == 'post.sql':
            return DeltaType.POST_SQL
1306799
def _fetch_type_main(cls, cls_in, match):
        

        return cls._str_to_type(
            cls_in,
            match.group(cls._SUBMATCH_INDEX_TYPE_MAIN)
        )
55144
def determine_file_extension_based_on_format(format_specifier):
	
	if format_specifier == FMT_INI:
		return 'ini'
	if format_specifier == FMT_DELIMITED:
		return ''
	if format_specifier == FMT_XML:
		return 'xml'
	if format_specifier == FMT_JSON:
		return 'json'
	if format_specifier == FMT_YAML:
		return 'yml'
	raise ValueError('invalid format specifier: {}'.format(format_specifier))
698385
def find_type(cls, val):
        
        mt = ""
        index = val.rfind(".")
        if index == -1:
            val = "fake.{}".format(val)
        elif index == 0:
            val = "fake{}".format(val)

        mt = mimetypes.guess_type(val)[0]
        if mt is None:
            mt = ""

        return mt
1039943
def parse_file_type(file_type):
    '''
    
    '''
    valid_file_filter = r'^([\w ]+)\((\*(?:\.(?:\w+|\*))*(?:;\*\.\w+)*)\)$'
    match = re.search(valid_file_filter, file_type)

    if match:
        return match.group(1).rstrip(), match.group(2)
    else:
        raise ValueError('{0} is not a valid file filter'.format(file_type))
1057039
def get_input_ext(self, input_file):
        
        if input_file.endswith(".bam"):
            input_ext = ".bam"
        elif input_file.endswith(".fastq.gz") or input_file.endswith(".fq.gz"):
            input_ext = ".fastq.gz"
        elif input_file.endswith(".fastq") or input_file.endswith(".fq"):
            input_ext = ".fastq"
        else:
            errmsg = "'{}'; this pipeline can only deal with .bam, .fastq, " \
                     "or .fastq.gz files".format(input_file)
            raise UnsupportedFiletypeException(errmsg)
        return input_ext
569136
function getFileTypeReg(type) {
    var map = [],
        ext = ""; // fis.config.get('project.fileType.' + type);
    if (type === 'text') {
        map = TEXT_FILE_EXTS;
    } else if (type === 'image') {
        map = IMAGE_FILE_EXTS;
    } else {
        xgulp.log.error('invalid file type [%s]', type);
    }
    if (ext && ext.length) {
        if (typeof ext === 'string') {
            ext = ext.split(/\s*,\s*/);
        }
        map = map.concat(ext);
    }
    map = map.join('|');
    return new RegExp('\\.(?:' + map + ')$', 'i');
}
347238
def search_filename(self, searchterm):
        
        return self.__search(type_attribute=self.__mispfilenametypes(), value=searchterm)
445868
def exttype(suffix):
    """"""
    def inner(s):
        if s == '':
            return s
        first, last = os.path.splitext(s)
        return first + suffix
    return inner
331028
def get_file_type(filename):
    
    txt_extensions = [".txt", ".dat", ".csv"]
    hdf_extensions = [".hdf", ".h5", ".bkup", ".checkpoint"]
    for ext in hdf_extensions:
        if filename.endswith(ext):
            with _h5py.File(filename, 'r') as fp:
                filetype = fp.attrs['filetype']
            return filetypes[filetype]
    for ext in txt_extensions:
        if filename.endswith(ext):
            return InferenceTXTFile
    raise TypeError("Extension is not supported.")
998790
def __get_lookup(in_fn, selected_type=None):
  """"""
  lookup_func = None
  if selected_type is not None:
    lookup_func = get_lookup_by_filetype(selected_type)
  else:
    extension = os.path.splitext(in_fn)[1]
    lookup_func = get_lookup_by_file_extension(extension)
  assert(lookup_func is not None)
  return lookup_func
476178
function getFileTypeReg(type) {
  var map = [], ext = her.config.get('project.fileType.' + type);
  if (type === 'text') {
    map = TEXT_FILE_EXTS;
  } else if (type === 'image') {
    map = IMAGE_FILE_EXTS;
  } else {
    throw new Error('invalid file type [' + type + ']');
  }
  if (ext && ext.length) {
    if (typeof ext === 'string') {
      ext = ext.split(/\s*,\s*/);
    }
    map = map.concat(ext);
  }
  map = map.join('|');
  return new RegExp('\\.(?:' + map + ')$', 'i');
}