def __init__(self, *args, **kwargs): """ __init__ takes a new `DataSet` object from another DataSet object or by parsing an input stream. Can be invoked with: - a single unnamed argument that is an instance of a DataSet (which will result in a deep copy of all taxa, trees and characters), - 1 or more unnamed TaxonSet, TreeList or CharacterMatrix (which is like calling DataSet.add with each argument) - keyword arguments that supply a file-like object (`stream`) to be parsed and a string (`schema`) specifying the schema of the data in the file-like object. """ AnnotatedDataObject.__init__(self, label=kwargs.get('label'), oid=kwargs.get('oid')) iosys.Writeable.__init__(self) iosys.Readable.__init__(self) self.taxon_sets = containers.OrderedSet() self.tree_lists = containers.OrderedSet() self.char_matrices = containers.OrderedSet() self.attached_taxon_set = None taxon_set, attach_taxon_set = self.process_taxon_set_directives( **kwargs) stream = kwargs.get("stream") if len(args) > 0: if (stream is not None) or (kwargs.get("schema") is not None): raise error.MultipleInitializationSourceError( self.__class__.__name__, args[0]) if len(args) == 1 and isinstance(args[0], DataSet): if attach_taxon_set or (taxon_set is not None): raise error.MultipleInitializationSourceError( "Cannot initialize DataSet from another DataSet object when taxon_set or attach_taxon_set are specified" ) self.clone_from(args[0]) else: for arg in args: if isinstance(arg, DataSet): raise error.MultipleInitializationSourceError( "Cannot initialize DataSet from another DataSet object when multiple other initialization objects are given" ) else: self.add(arg) elif stream is not None: # if self.attached_taxon_set is not None: # kwargs["taxon_set"] = self.attached_taxon_set self.process_source_kwargs(**kwargs)
def __init__(self, *args, **kwargs): """ __init__ takes a new `DataSet` object from another DataSet object or by parsing an input stream. Can be invoked with: - a single unnamed argument that is an instance of a DataSet (which will result in a deep copy of all taxa, trees and characters), - 1 or more unnamed TaxonSet, TreeList or CharacterMatrix (which is like calling DataSet.add with each argument) - keyword arguments that supply a file-like object (`stream`) to be parsed and a string (`schema`) specifying the schema of the data in the file-like object. """ AnnotatedDataObject.__init__(self, label=kwargs.get('label'), oid=kwargs.get('oid')) iosys.Writeable.__init__(self) iosys.Readable.__init__(self) self.taxon_sets = containers.OrderedSet() self.tree_lists = containers.OrderedSet() self.char_matrices = containers.OrderedSet() self.attached_taxon_set = None taxon_set, attach_taxon_set = self.process_taxon_set_directives(**kwargs) stream = kwargs.get("stream") if len(args) > 0: if (stream is not None) or (kwargs.get("schema") is not None): raise error.MultipleInitializationSourceError(self.__class__.__name__, args[0]) if len(args) == 1 and isinstance(args[0], DataSet): if attach_taxon_set or (taxon_set is not None): raise error.MultipleInitializationSourceError("Cannot initialize DataSet from another DataSet object when taxon_set or attach_taxon_set are specified") self.clone_from(args[0]) else: for arg in args: if isinstance(arg, DataSet): raise error.MultipleInitializationSourceError("Cannot initialize DataSet from another DataSet object when multiple other initialization objects are given") else: self.add(arg) elif stream is not None: # if self.attached_taxon_set is not None: # kwargs["taxon_set"] = self.attached_taxon_set self.process_source_kwargs(**kwargs)
def __deepcopy__(self, memo): taxon_sets = [] for ts0 in self.taxon_sets: ts1 = TaxonSet(label=ts0.label) memo[id(ts0)] = ts1 taxon_sets.append(ts1) for t in ts0: taxon = ts1.new_taxon(label=t.label) memo[id(t)] = taxon memo[id(self.taxon_sets)] = taxon_sets o = AnnotatedDataObject.__deepcopy__(self, memo) memo[id(self)] = o o.taxon_sets = taxon_sets assert o.annotations.target is o return o
def __deepcopy__(self, memo): taxon_sets = [] for ts0 in self.taxon_sets: ts1 = TaxonSet(label=ts0.label) memo[id(ts0)] = ts1 taxon_sets.append(ts1) for t in ts0: taxon = ts1.new_taxon(label=t.label) memo[id(t)] = taxon memo[id(self.taxon_sets)] = taxon_sets o = AnnotatedDataObject.__deepcopy__(self, memo) memo[id(self)] = o o.taxon_sets = taxon_sets assert o.annotations.target is o return o