Ejemplo n.º 1
0
 def __init__(self, value, type, id, residues=('???','???'), max=None, \
         error=0.0):
     from Mara.Library import omniTranslator
     self.value = float(value)
     self.__id__ = int(id)
     if type is str and DCouplings.has_key(type):
         self.__type__ = DCouplings[type]
     elif isinstance(type, DCoupling):
         self.__type__ = type
     else:
         raise TypeError, "Incompatible coupling type '%s'." % repr(type)
     if (isinstance(residues, tuple) or isinstance(residues, list)) \
             and len(residues) == 2 and \
             isinstance(residues[0], str) and isinstance(residues[1], str):
         self.residues = (omniTranslator(residues[0],
                                         '3-letter-aminoacids'),
                          omniTranslator(residues[1],
                                         '3-letter-aminoacids'))
     else:
         raise TypeError, "Incompatible residue names '%s'." % repr(
             residues)
     self.error = float(error)
     self.tag = (self.__id__, str(self.__type__))
     if max:
         self.__max__ = float(max)
     else:
         self.__max__ = None
     self.__name__ = 'Coupling'
Ejemplo n.º 2
0
 def __init__(self, value, type, id, residues=('???','???'), max=None, \
         error=0.0):
     from Mara.Library import omniTranslator
     self.value = float(value)
     self.__id__ = int(id)
     if type is str and DCouplings.has_key(type):
         self.__type__ = DCouplings[type]
     elif isinstance(type, DCoupling):
         self.__type__ = type
     else:
         raise TypeError, "Incompatible coupling type '%s'." % repr(type)
     if (isinstance(residues, tuple) or isinstance(residues, list)) \
             and len(residues) == 2 and \
             isinstance(residues[0], str) and isinstance(residues[1], str):
         self.residues = (
                 omniTranslator(residues[0], '3-letter-aminoacids'),
                 omniTranslator(residues[1], '3-letter-aminoacids'))
     else:
         raise TypeError, "Incompatible residue names '%s'." % repr(residues)
     self.error = float(error)
     self.tag = (self.__id__, str(self.__type__))
     if max:
         self.__max__ = float(max)
     else:
         self.__max__ = None
     self.__name__ = 'Coupling'
Ejemplo n.º 3
0
 def getSequence(self, format='3-letter-aminoacids'):
     if not omniTranslator.recognise_language(format):
         raise ValueError, "Unknown format '%s'." % repr(format)
     sequence = []
     for residue in self:
         name = omniTranslator(str(residue), format)
         sequence.append(name)
     return sequence
Ejemplo n.º 4
0
 def getSequence(self, format='3-letter-aminoacids'):
     if not omniTranslator.recognise_language(format):
         raise ValueError, "Unknown format '%s'." % repr(format)
     sequence = []
     for residue in self:
         name = omniTranslator(str(residue), format)
         sequence.append(name)
     return sequence
Ejemplo n.º 5
0
def write_sequence(seq, output=None, format='long', use_translator=True):
    """
    Write amino acid sequence in the desired format either to a stream
    given or to STDOUT.
    
    TODO: - add some flexibility to the output formats
    """
    if output is None:
        output = sys.stdout
    if format == 'long':
        l = []
        while seq:
            s = seq.pop(0)
            if use_translator:
                s = omniTranslator(s.capitalize(), '3-letter-aminoacids')
            l.append(s.upper())
            if len(l) == 15:
                output.write(' '.join(l) + '\n')
                l = []
        output.write(' '.join(l) + '\n')
    elif format == 'full':
        l = []
        while seq:
            s = seq.pop(0)
            if use_translator:
                s = omniTranslator(s.capitalize(), 'english')
            l.append(s)
        output.write(' '.join(l) + '\n')
    else:
        l = []
        w = ''
        while seq:
            s = seq.pop(0)
            if use_translator:
                s = omniTranslator(s.capitalize(), '1-letter-aminoacids')
            w += s.upper()
            if len(w) == 10:
                l.append(w)
                w = ''
            if len(l) == 6:
                output.write(' '.join(l) + '\n')
                l = []
        if w:
            l.append(w)
        output.write(' '.join(l) + '\n')
Ejemplo n.º 6
0
def write_sequence(seq, output=None, format="long", use_translator=True):
    """
    Write amino acid sequence in the desired format either to a stream
    given or to STDOUT.
    
    TODO: - add some flexibility to the output formats
    """
    if output is None:
        output = sys.stdout
    if format == "long":
        l = []
        while seq:
            s = seq.pop(0)
            if use_translator:
                s = omniTranslator(s.capitalize(), "3-letter-aminoacids")
            l.append(s.upper())
            if len(l) == 15:
                output.write(" ".join(l) + "\n")
                l = []
        output.write(" ".join(l) + "\n")
    elif format == "full":
        l = []
        while seq:
            s = seq.pop(0)
            if use_translator:
                s = omniTranslator(s.capitalize(), "english")
            l.append(s)
        output.write(" ".join(l) + "\n")
    else:
        l = []
        w = ""
        while seq:
            s = seq.pop(0)
            if use_translator:
                s = omniTranslator(s.capitalize(), "1-letter-aminoacids")
            w += s.upper()
            if len(w) == 10:
                l.append(w)
                w = ""
            if len(l) == 6:
                output.write(" ".join(l) + "\n")
                l = []
        if w:
            l.append(w)
        output.write(" ".join(l) + "\n")
Ejemplo n.º 7
0
def parse_sequence(args):
    """
    Parse an amino acid sequence.

    Arguments:
        args     -- a list of sequence items or a name of a file containing
                    them, e.g. 'GLU PRO GLU CYS' or 'EPEC GLK C EEK'
    Returns:
        sequence -- a list of 3-letter amino acid symbols
    """
    loki.debug('parse_sequence < %s' % repr(args))
    if isinstance(args, str) and os.path.isfile(args):
        fname = args
    elif len(args) == 1 and isinstance(args[0], str):
        if os.path.isfile(args[0]):
            fname = args[0]
        else:
            if args[0].count(' '):
                args = args[0].split()
            else:
                args = args[0]
            fname = None
    else:
        fname = None
    if fname:
        f = open(fname)
        seq = f.read()
        f.close()
        loki.info("Read sequence from file '%s'." % fname)
        args = seq.strip().split()
        loki.debug('args=%s' % repr(args))


#        sequence = []
#        for aa in seq.strip().split():
#            try:
#                sequence.append(omniTranslator(aa.capitalize(), \
#                        '3-letter-aminoacids'))
#            except KeyError:
#                loki.warn("Discarding unknown aminoacid '%s'." % repr(aa))
#    else:
# check whether all the sequence items are separated from each other
    args = [x.capitalize() for x in args]
    separated = True
    for a in args:
        if not (a in libLingua.dictionaryAmino1 or \
                a in libLingua.dictionaryAmino3):
            separated = False
    loki.debug('separated=%s' % repr(separated))
    sequence = []
    if separated:
        # append each item after converting it to a 3-letter symbol
        for a in args:
            try:
                sequence.append(omniTranslator(a.capitalize(), \
                        '3-letter-aminoacids'))
            except KeyError:
                loki.warn("Discarding unknown aminoacid '%s'." % repr(a))
    else:
        # jam all symbols together (hope they are all 1-letter symbols)
        aa = ''
        for a in args:
            aa += str(a)
        aa = aa.replace(' ', '')
        loki.debug('aa=%s' % repr(aa))
        # append each item after converting it to a 3-letter symbol
        for a in list(aa):
            try:
                sequence.append(omniTranslator(a, '3-letter-aminoacids'))
            except KeyError:
                loki.warn("Discarding unknown aminoacid '%s'." % repr(a))
    loki.debug('parse_sequence > %s' % repr(sequence))
    return sequence
Ejemplo n.º 8
0
def parse_sequence(args):
    """
    Parse an amino acid sequence.

    Arguments:
        args     -- a list of sequence items or a name of a file containing
                    them, e.g. 'GLU PRO GLU CYS' or 'EPEC GLK C EEK'
    Returns:
        sequence -- a list of 3-letter amino acid symbols
    """
    loki.debug("parse_sequence < %s" % repr(args))
    if isinstance(args, str) and os.path.isfile(args):
        fname = args
    elif len(args) == 1 and isinstance(args[0], str):
        if os.path.isfile(args[0]):
            fname = args[0]
        else:
            if args[0].count(" "):
                args = args[0].split()
            else:
                args = args[0]
            fname = None
    else:
        fname = None
    if fname:
        f = open(fname)
        seq = f.read()
        f.close()
        loki.info("Read sequence from file '%s'." % fname)
        args = seq.strip().split()
        loki.debug("args=%s" % repr(args))
    #        sequence = []
    #        for aa in seq.strip().split():
    #            try:
    #                sequence.append(omniTranslator(aa.capitalize(), \
    #                        '3-letter-aminoacids'))
    #            except KeyError:
    #                loki.warn("Discarding unknown aminoacid '%s'." % repr(aa))
    #    else:
    # check whether all the sequence items are separated from each other
    args = [x.capitalize() for x in args]
    separated = True
    for a in args:
        if not (a in libLingua.dictionaryAmino1 or a in libLingua.dictionaryAmino3):
            separated = False
    loki.debug("separated=%s" % repr(separated))
    sequence = []
    if separated:
        # append each item after converting it to a 3-letter symbol
        for a in args:
            try:
                sequence.append(omniTranslator(a.capitalize(), "3-letter-aminoacids"))
            except KeyError:
                loki.warn("Discarding unknown aminoacid '%s'." % repr(a))
    else:
        # jam all symbols together (hope they are all 1-letter symbols)
        aa = ""
        for a in args:
            aa += str(a)
        aa = aa.replace(" ", "")
        loki.debug("aa=%s" % repr(aa))
        # append each item after converting it to a 3-letter symbol
        for a in list(aa):
            try:
                sequence.append(omniTranslator(a, "3-letter-aminoacids"))
            except KeyError:
                loki.warn("Discarding unknown aminoacid '%s'." % repr(a))
    loki.debug("parse_sequence > %s" % repr(sequence))
    return sequence