def __deepcopy__(self, memo): """Return a deep copy of this MSA. Returns ------- TabularMSA Deep copy of this MSA. See Also -------- __copy__ """ seqs = (copy.deepcopy(seq, memo) for seq in self._seqs) # Copying index isn't necessary because pd.Index is immutable. msa_copy = self.__class__(sequences=seqs, index=self.index, metadata=None, positional_metadata=None) msa_copy._metadata = MetadataMixin._deepcopy_(self, memo) msa_copy._positional_metadata = \ PositionalMetadataMixin._deepcopy_(self, memo) return msa_copy
def __copy__(self): """Return a shallow copy of this MSA. Returns ------- TabularMSA Shallow copy of this MSA. Sequence objects will be shallow-copied. See Also -------- __deepcopy__ """ seqs = (copy.copy(seq) for seq in self._seqs) # Copying index isn't necessary because pd.Index is immutable. msa_copy = self.__class__(sequences=seqs, index=self.index, metadata=None, positional_metadata=None) msa_copy._metadata = MetadataMixin._copy_(self) msa_copy._positional_metadata = PositionalMetadataMixin._copy_(self) return msa_copy
def __init__(self, sequences, metadata=None, positional_metadata=None, minter=None, index=None): if isinstance(sequences, TabularMSA): if metadata is None and sequences.has_metadata(): metadata = sequences.metadata if (positional_metadata is None and sequences.has_positional_metadata()): positional_metadata = sequences.positional_metadata if minter is None and index is None: index = sequences.index self._seqs = pd.Series([]) self.extend(sequences, minter=minter, index=index) MetadataMixin._init_(self, metadata=metadata) PositionalMetadataMixin._init_(self, positional_metadata=positional_metadata)
def __init__(self, sequences, metadata=None, positional_metadata=None, minter=None, index=None): # TODO: optimize this to not append Series for each sequence. self._seqs = pd.Series([]) for sequence in sequences: self.append(sequence) if minter is not None and index is not None: raise ValueError( "Cannot use both `minter` and `index` at the same time.") if minter is not None: self.reassign_index(minter=minter) elif index is not None: # Cast to Index to identify tuples as a MultiIndex to match # pandas constructor. Just setting would make an index of tuples. if not isinstance(index, pd.Index): index = pd.Index(index) self.index = index MetadataMixin._init_(self, metadata=metadata) PositionalMetadataMixin._init_( self, positional_metadata=positional_metadata)
def __ne__(self, other): return MetadataMixin._ne_(self, other)
def __eq__(self, other): return MetadataMixin._eq_(self, other)
def __init__(self, metadata=None): MetadataMixin._init_(self, metadata=metadata)
def __deepcopy__(self, memo): copy = self.__class__(metadata=None) copy._metadata = MetadataMixin._deepcopy_(self, memo) return copy
def __copy__(self): copy = self.__class__(metadata=None) copy._metadata = MetadataMixin._copy_(self) return copy
def __eq__(self, other): """Determine if this MSA is equal to another. ``TabularMSA`` objects are equal if their sequences, index, metadata, and positional metadata are equal. Parameters ---------- other : TabularMSA MSA to test for equality against. Returns ------- bool Indicates whether this MSA is equal to `other`. Examples -------- >>> from skbio import DNA, RNA, TabularMSA >>> msa = TabularMSA([DNA('ACG'), DNA('AC-')]) >>> msa == msa True MSAs with different sequence characters are not equal: >>> msa == TabularMSA([DNA('ACG'), DNA('--G')]) False MSAs with different types of sequences (different ``dtype``) are not equal: >>> msa == TabularMSA([RNA('ACG'), RNA('AC-')]) False MSAs with different sequence metadata are not equal: >>> msa == TabularMSA([DNA('ACG', metadata={'id': 'a'}), DNA('AC-')]) False MSAs with different index labels are not equal: >>> msa == TabularMSA([DNA('ACG'), DNA('AC-')], minter=str) False MSAs with different metadata are not equal: >>> msa == TabularMSA([DNA('ACG'), DNA('AC-')], ... metadata={'id': 'msa-id'}) False MSAs with different positional metadata are not equal: >>> msa == TabularMSA([DNA('ACG'), DNA('AC-')], ... positional_metadata={'prob': [3, 2, 1]}) False """ if not isinstance(other, TabularMSA): return False if not MetadataMixin._eq_(self, other): return False if not PositionalMetadataMixin._eq_(self, other): return False return self._seqs.equals(other._seqs)