def __init__(self, msa, title='Unknown', labels=None, **kwargs): """*msa* must be a 2D Numpy character array. *labels* is a list of sequence labels (or titles). *mapping* should map label or part of label to sequence index in *msa* array. If *mapping* is not given, one will be build from *labels*.""" self._aligned = aligned = kwargs.get('aligned', True) msa = toChararray(msa, aligned) numseq = msa.shape[0] if labels and len(labels) != numseq: raise ValueError('len(labels) must be equal to number of ' 'sequences') if labels is None: labels = [str(i+1) for i in range(numseq)] if PY3K: for i, label in enumerate(labels): if not isinstance(label, str): labels[i] = label.decode() self._labels = labels mapping = kwargs.get('mapping') self._map(mapping) self._msa = msa self._title = str(title) or 'Unknown' self._split = bool(kwargs.get('split', True))
def extend(self, other): """Adds *other* to this MSA.""" A = self.getArray() if isinstance(other, MSA): B = other.getArray() otherlabels = other._labels elif isinstance(other, Sequence): B = other.getArray() B = reshape(B, (1, B.shape[0])) otherlabels = other.getLabel(full=True) else: try: B = toChararray(other, aligned=False) numA, numB = A.shape[0], B.shape[0] otherlabels = [str(i + 1) for i in range(numA, numA + numB)] except: raise ValueError('failed to add {1} to {0}'.format( repr(self), repr(other))) try: AB = vstack((A, B)) except: raise ValueError( 'failed to add {1} to {0}: shapes do not match'.format( repr(self), repr(other))) labels = list(self._labels) labels.extend(otherlabels) self._msa = AB self._labels = labels self._map()
def extend(self, other): """Adds *other* to this MSA.""" A = self.getArray() if isinstance(other, MSA): B = other.getArray() otherlabels = other._labels elif isinstance(other, Sequence): B = other.getArray() B = reshape(B, (1, B.shape[0])) otherlabels = other.getLabel(full=True) else: try: B = toChararray(other, aligned=False) numA, numB = A.shape[0], B.shape[0] otherlabels = [str(i+1) for i in range(numA, numA+numB)] except: raise ValueError('failed to add {1} to {0}' .format(repr(self), repr(other))) try: AB = vstack((A, B)) except: raise ValueError('failed to add {1} to {0}: shapes do not match' .format(repr(self), repr(other))) labels = list(self._labels) labels.extend(otherlabels) self._msa = AB self._labels = labels self._map()