Esempio n. 1
0
def validate_alphabet_list(alphabet_list, length=None):
    """Checks list of residue names"""
    if hasattr(alphabet_list, '__iter__') or isinstance(alphabet_list, str):
        alphabet_list = [validate_alphabet(alpha) for alpha in alphabet_list]
        if length==None or length==len(alphabet_list):
            return alphabet_list
    raise ParameterError("Bad parameter: '%s' must be a list of residue names."%str(alphabet_list))
Esempio n. 2
0
def validate_resnum_list(resnum_list, length=None):
    """Checks list of residues"""
    if hasattr(resnum_list, '__iter__'):
        resnum_list = [validate_resnum(resi) for resi in resnum_list]
        if length==None or length==len(resnum_list):
            return resnum_list
    raise ParameterError("Bad parameter: '%s' must be a list of residues."%str(resnum_list))
Esempio n. 3
0
def validate_alignment(ali):
    """Checks alignment string or object"""
    if isinstance(ali, RNAAlignment):
        return ali
    elif isinstance(ali, str):
        return read_alignment(ali)
    raise ParameterError("Bad parameter: '%s' must be a pairwise Alignment (object or fasta string)."%str(ali))
Esempio n. 4
0
def validate_seq(seq):
    """Checks sequence format"""
    if isinstance(seq, Sequence):
        return seq
    elif type(seq) == str:
        seq = Sequence(seq)
        return seq
    raise ParameterError("Bad parameter: '%s' must be a RNA sequence."%str(seq))
Esempio n. 5
0
def validate_filename(filename, exist=False):
    """Checks file names"""
    if exist:
        if not os.path.exists(filename):
            raise ParameterError("Bad parameter: '%s' must be a valid file name."%str(filename))
    else:
        path = os.path.dirname(filename)
        validate_path(path)
    return filename
Esempio n. 6
0
def validate_alphabet(alpha):
    """Checks residue names."""
    if alphabet.has_key(str(alpha)):
        return alphabet[str(alpha)].long_abbrev
    else:
        try:
            return alphabet.get_short_original(str(alpha)).long_abbrev
        except AlphabetError:
            pass
    raise ParameterError("Bad parameter: '%s' must be a valid residue name."%str(alpha))
Esempio n. 7
0
def validate_resi(resi):
    """Checks RNAResidue"""
    if isinstance(resi, RNAResidue):
        return resi
    raise ParameterError("Bad parameter: '%s' must be a ModeRNAResidue."%str(resi))
Esempio n. 8
0
def validate_frag_candidate_list(fc_list):
    if isinstance(fc_list, FragmentCandidates):
        return fc_list
    raise ParameterError("Bad parameter: '%s' must be a list of fragment candidates."%str(fc_list))
Esempio n. 9
0
def validate_resnum(resnum):
    """Checks residue number format"""
    resnum = str(resnum)
    if re.search("^\d+\w*$", resnum):
        return resnum
    raise ParameterError("Bad parameter: '%s' must be a residue number."%str(resnum))
Esempio n. 10
0
def validate_secstruc(secstruc):
    """Checks vienna string format"""
    if re.search("^[\(\)\.]*$", secstruc):
        return secstruc
    raise ParameterError("Bad parameter: '%s' must be a RNA secondary structure in dot-bracket format."%str(secstruc))
Esempio n. 11
0
def validate_fragment(frag):
    """Checks RnaModel object"""
    if isinstance(frag, ModernaFragment) or isinstance(frag, LirHit):
        return frag
    raise ParameterError("Bad parameter: '%s' must be a ModernaFragment object."%str(frag))
Esempio n. 12
0
def validate_model(model):
    """Checks RnaModel object"""
    if isinstance(model, RnaModel):
        return model
    raise ParameterError("Bad parameter: '%s' must be a RnaModel object."%str(model))
Esempio n. 13
0
def validate_template(template):
    """Checks Template object"""
    if isinstance(template, Template):
        return template
    raise ParameterError("Bad parameter: '%s' must be a Template object."%str(template))
Esempio n. 14
0
def validate_structure(struc):
    """Checks for ModernaStructure objects."""
    if isinstance(struc, ModernaStructure):
        return struc
    raise ParameterError("Bad parameter: '%s' must be a structure object."%str(struc))
Esempio n. 15
0
def validate_path(path, exist=True):
    """Checks path names."""
    if exist:
        if path != '' and not os.path.exists(path):
            raise ParameterError("Bad parameter: '%s' must be a valid path name."%str(path))
    return path