Beispiel #1
0
    def __init__(self, *args, **kwargs):
        """__init__ calls TaxonSetLinked.__init__ for handling of `oid`, `label` and `taxon_set` keyword arguments.

        Can be initialized with:

            - source keyword arguments (see Readable.process_source_kwargs), or
            - a single unnamed CharacterMatrix instance (which will be deep-copied).

        """
        TaxonSetLinked.__init__(
            self, taxon_set=kwargs.get("taxon_set", None), label=kwargs.get("label", None), oid=kwargs.get("oid", None)
        )
        self.taxon_seq_map = CharacterDataMap()
        self.character_types = []
        self.character_subsets = containers.OrderedCaselessDict()
        self.markup_as_sequences = True
        if len(args) > 1:
            raise error.TooManyArgumentsError(func_name=self.__class__.__name__, max_args=1, args=args)
        if len(args) == 1:
            if ("stream" in kwargs and kwargs["stream"] is not None) or (
                "schema" in kwargs and kwargs["schema"] is not None
            ):
                raise error.MultipleInitializationSourceError(class_name=self.__class__.__name__, arg=args[0])
            if isinstance(args[0], self.__class__):
                self.clone_from(args[0])
            else:
                raise error.InvalidArgumentValueError(func_name=self.__class__.__name__, arg=args[0])
        else:
            self.process_source_kwargs(**kwargs)
        if "oid" in kwargs:
            self.oid = kwargs["oid"]
        if "label" in kwargs:
            self.label = kwargs["label"]
Beispiel #2
0
 def __deepcopy__(self, memo):
     o = TaxonSetLinked.__deepcopy__(self, memo)
     o.state_alphabets = self.state_alphabets
     memo[id(self.state_alphabets)] = o.state_alphabets
     o.default_state_alphabet = self.default_state_alphabet
     memo[id(self.default_state_alphabet)] = o.default_state_alphabet
     o._default_symbol_state_map = self._default_symbol_state_map
     memo[id(self._default_symbol_state_map)] = o._default_symbol_state_map
     o.character_types = copy.deepcopy(self.character_types, memo)
     for taxon, cdv in self.taxon_seq_map.items():
         otaxon = memo[id(taxon)]
         ocdv = CharacterDataVector(oid=cdv.oid, label=cdv.label, taxon=otaxon)
         for cell in cdv:
             if cell.character_type is not None:
                 character_type = memo[id(cell.character_type)]
             else:
                 character_type = None
             ocdv.append(CharacterDataCell(value=cell.value, character_type=character_type))
         o.taxon_seq_map[otaxon] = ocdv
         memo[id(self.taxon_seq_map[taxon])] = o.taxon_seq_map[otaxon]
     for k, v in self.__dict__.iteritems():
         if k not in [
             "taxon_set",
             "_oid",
             "state_alphabets",
             "default_state_alphabet",
             "_default_symbol_state_map",
             "taxon_seq_map",
             "character_types",
         ]:
             o.__dict__[k] = copy.deepcopy(v, memo)
     return o
Beispiel #3
0
 def __deepcopy__(self, memo):
     o = TaxonSetLinked.__deepcopy__(self, memo)
     for k, v in self.__dict__.iteritems():
         if k not in ["taxon_set", "_oid", "taxon_seq_map"]:
             o.__dict__[k] = copy.deepcopy(v, memo)
     for taxon, cdv in self.taxon_seq_map.items():
         otaxon = memo[id(taxon)]
         ocdv = CharacterDataVector(oid=cdv.oid, label=cdv.label, taxon=otaxon)
         for cell in cdv:
             if cell.character_type is not None:
                 character_type = memo[id(cell.character_type)]
             else:
                 character_type = None
             ocdv.append(CharacterDataCell(value=cell.value, character_type=character_type))
         o.taxon_seq_map[otaxon] = ocdv
         memo[id(self.taxon_seq_map[taxon])] = o.taxon_seq_map[otaxon]
     return o