organoid_tracker.core.connections module
Connections are used to indicate connections between particles at the same time point, for example because the particles are close by, or they are part of some subsystem. This is different from links, which indicates that two observations made at different time points refer to the same particle.
- class organoid_tracker.core.connections.Connections
Bases:
object
Holds the connections of an experiment.
- add_connection(position1: Position, position2: Position)
Adds a connection between the two positions. They must be in the same time point.
- add_connections(other: Connections)
Merges all connections in the other collection with this collection.
- calculate_distances(sources: List[Position]) Dict[Position, int]
Gets the distances of all positions to the nearest position in [sources]. All sources must be in the same time point, otherwise ValueError is raised. Returns an empty dictionary if sources is empty, or if there are no connections.
- calculate_distances_over_time(sources: Iterable[Position]) Dict[Position, int]
Like calculate_distances, but supports sources for multiple time points. Note: connection distances are still only calculated within a time point. So if you’re 10 connections from a Paneth cell, but in the next time point 1, then for the original time point the distance is still 10.
- contains_connection(position1: Position, position2: Position) bool
Returns True if a connection between the two positions exists.
- contains_time_point(time_point: TimePoint) bool
Returns whether there are connections for the given time point.
- copy() Connections
Returns a copy of this object. Changes made to the copy will not affect this object.
- find_all_connections() Iterable[Tuple[Position, Position]]
Gets all connections of all time points.
- find_connections(position: Position) Iterable[Position]
Finds connections starting from and going to the given position. See find_connections_starting_at for details. This method is slower than find_connections_starting_at, as it has to do more lookups.
Note: if you are looping over all positions in a time point, and then finding their connections, every connection will be found twice if you use this method (the connection from A to B will be returned, but also the connection from B to A). If you use find_connections_starting_at, you won’t have this problem: only the connection from A to B will be returned.
- has_full_neighbors(position: Position) bool
position: The position to check the neighbors for.
True if we think they have full neighbors annotated for that position. This is the case if the neighbor graph is cyclic, or if the neighbor graph contains cycles.
- of_time_point(time_point: TimePoint) Iterable[Tuple[Position, Position]]
Gets all connections of a time point.
- remove_connection(position1: Position, position2: Position) bool
Removes a connection between the given positions. Does nothing if no such connection exists. Returns True if a connection was removed.
- remove_connections_of_position(position: Position)
Removes all connections to or from the position.
- replace_position(position_old: Position, position_new: Position)
Reroutes all connections from position_old to position_new. Does nothing if position_old has no connections. Raises ValueError if the time point is unspecified, or if the time points of both positions are not equal.
- to_networkx_graph(*, time_point: TimePoint) Graph
Gets a non-directional NetworkX graph that represents the connections of the given time point. The graph is a copy, so any changes will not affect the connections in the experiment. This has been done so that we can still switch to another data storage method in the future.