Data Models
nplinker.strain
¶
Strain
¶
Strain(id: str)
Class to model the mapping between strain id and its aliases.
It's recommended to use NCBI taxonomy strain id or name as the primary id.
Attributes:
-
id
(str
) –The representative id of the strain.
-
names
(set[str]
) –A set of names associated with the strain.
-
aliases
(set[str]
) –A set of aliases associated with the strain.
Parameters:
-
id
(str
) –the representative id of the strain.
Source code in src/nplinker/strain/strain.py
names
property
¶
aliases
property
¶
__hash__
¶
__hash__() -> int
Hash function for Strain.
Note that Strain is a mutable container, so here we hash on only the id
to avoid the hash value changes when self._aliases
is updated.
__contains__
¶
add_alias
¶
add_alias(alias: str) -> None
Add an alias for the strain.
Parameters:
-
alias
(str
) –The alias to add for the strain.
Source code in src/nplinker/strain/strain.py
StrainCollection
¶
A collection of Strain
objects.
Source code in src/nplinker/strain/strain_collection.py
__add__
¶
__add__(other) -> StrainCollection
Source code in src/nplinker/strain/strain_collection.py
__contains__
¶
Check if the strain collection contains the given Strain object.
Source code in src/nplinker/strain/strain_collection.py
__iter__
¶
add
¶
add(strain: Strain) -> None
Add strain to the collection.
If the strain already exists, merge the aliases.
Parameters:
-
strain
(Strain
) –The strain to add.
Source code in src/nplinker/strain/strain_collection.py
remove
¶
remove(strain: Strain) -> None
Remove a strain from the collection.
It removes the given strain object from the collection by strain id.
If the strain id is not found, raise ValueError
.
Parameters:
-
strain
(Strain
) –The strain to remove.
Raises:
-
ValueError
–If the strain is not found in the collection.
Source code in src/nplinker/strain/strain_collection.py
filter
¶
Remove all strains that are not in strain_set
from the strain collection.
Parameters:
Source code in src/nplinker/strain/strain_collection.py
intersection
¶
intersection(other: StrainCollection) -> StrainCollection
Get the intersection of two strain collections.
Parameters:
-
other
(StrainCollection
) –The other strain collection to compare.
Returns:
-
StrainCollection
–StrainCollection object containing the strains that are in both collections.
Source code in src/nplinker/strain/strain_collection.py
has_name
¶
lookup
¶
Lookup a strain by name (id or alias).
Parameters:
-
name
(str
) –Strain name (id or alias) to lookup.
Returns:
Raises:
-
ValueError
–If the strain name is not found.
Source code in src/nplinker/strain/strain_collection.py
read_json
staticmethod
¶
read_json(file: str | PathLike) -> StrainCollection
Read a strain mappings JSON file and return a StrainCollection
object.
Parameters:
Returns:
-
StrainCollection
–StrainCollection
object.
Source code in src/nplinker/strain/strain_collection.py
to_json
¶
Convert the StrainCollection
object to a JSON string.
Parameters:
-
file
(str | PathLike | None
, default:None
) –Path to output JSON file. If None, return the JSON string instead.
Returns:
-
str | None
–If input
file
is None, return the JSON string. Otherwise, write the JSON string to the given -
str | None
–file.