def _get_seqtype_from_ext(handle):
    '''Predict the filetype from a handle's name'''
    if isinstance(handle, basestring):
        name = handle
    elif hasattr(handle, 'filename'):
        name = handle.filename
    elif hasattr(handle, 'name'):
        name = handle.name
    else:
        raise ValueError("Unknown datatype for handle!")

    modifier = ''
    dummy, ext = path.splitext(name.lower())
    if ext == ".gz":
        modifier = 'gz-'
        dummy, ext = path.splitext(dummy)

    if not ext:
        ext = "." + dummy

    if ext in (".gbk", ".gb", ".genbank", ".gbff"):
        return modifier + "genbank"
    elif ext in (".embl", ".emb"):
        return modifier + "embl"
    elif ext in (".fa", ".fasta", ".fna", ".faa", ".fas"):
        return modifier + "fasta"
    else:
        raise ValueError("Unknown file format '%s'." % ext)
def _get_seqtype_from_ext ( handle ) : if isinstance ( handle , basestring ) : name = handle elif hasattr ( handle , 'filename' ) : name = handle . filename elif hasattr ( handle , 'name' ) : name = handle . name else : raise ValueError ( "Unknown datatype for handle!" ) modifier = '' dummy , ext = path . splitext ( name . lower ( ) ) if ext == ".gz" : modifier = 'gz-' dummy , ext = path . splitext ( dummy ) if not ext : ext = "." + dummy if ext in ( ".gbk" , ".gb" , ".genbank" , ".gbff" ) : return modifier + "genbank" elif ext in ( ".embl" , ".emb" ) : return modifier + "embl" elif ext in ( ".fa" , ".fasta" , ".fna" , ".faa" , ".fas" ) : return modifier + "fasta" else : raise ValueError ( "Unknown file format '%s'." % ext )
Predict the filetype from a handle's name