Tracing Functions Modules
Miscellaneous tracing functions.
genTracingFuncs
Class of tracing functions.
Source code in topostats\tracing\tracingfuncs.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | |
check_vectors_candidate_points(ordered_points: list | npt.NDArray, candidate_points: list | npt.NDArray) -> list
staticmethod
Find which neighbouring pixels incur the smallest angular change.
This is done with reference to a previous pixel in the ordered trace, and chooses that as the next point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ordered_points
|
list | NDArray
|
Ordered points. |
required |
candidate_points
|
list | NDArray
|
Points to be checked. |
required |
Returns:
| Type | Description |
|---|---|
list
|
Coordinates of the neighbouring pixel with the smallest angular change. |
Source code in topostats\tracing\tracingfuncs.py
count_and_get_neighbours(x: int, y: int, trace_coordinates: list) -> tuple[int, list]
staticmethod
Count the number of neighbouring points for a coordinate and an array containing those points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int
|
X coordinate. |
required |
y
|
int
|
Y coordinate. |
required |
trace_coordinates
|
list
|
Coordinates of the trace. |
required |
Returns:
| Type | Description |
|---|---|
tuple
|
The number of neighbours and the coordinates of the neighbouring points. |
Source code in topostats\tracing\tracingfuncs.py
find_best_next_point(x: int, y: int, ordered_points: list | npt.NDArray, candidate_points: list | npt.NDArray) -> list | None
staticmethod
Find the next best point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int
|
The x coordinate. |
required |
y
|
int
|
They y coordinate. |
required |
ordered_points
|
list | NDArray
|
Ordered points. |
required |
candidate_points
|
list | NDArray
|
Points to be checked. |
required |
Returns:
| Type | Description |
|---|---|
list
|
Coordinates of the neighbouring pixel with the smallest angular change. |
Source code in topostats\tracing\tracingfuncs.py
make_grid(x: int, y: int, size: int) -> list
staticmethod
Make a Grid of coordinates around the points x and y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int
|
The x coordinate. |
required |
y
|
int
|
They y coordinate. |
required |
size
|
int
|
Size of surrounding grid. |
required |
Returns:
| Type | Description |
|---|---|
list
|
List of coordinates that form a grid around x and y of size. |
Source code in topostats\tracing\tracingfuncs.py
return_points_in_array(points_array: list | npt.NDArray, trace_coordinates: list | npt.NDArray) -> list
staticmethod
Return a subset co ordinates for the given set of points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points_array
|
list | NDArray
|
The subset of points for which coordinates are required. |
required |
trace_coordinates
|
list | NDArray
|
Coordinates of all points. |
required |
Returns:
| Type | Description |
|---|---|
list
|
Coordinates for the subset of points. |
Source code in topostats\tracing\tracingfuncs.py
reorderTrace
Class to aid the consecutive ordering of adjacent coordinates of a pixel grid.
Source code in topostats\tracing\tracingfuncs.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
circularTrace(trace_coordinates)
staticmethod
Alternative implementation of the linear tracing algorithm but adapted to work with circular DNA molecules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trace_coordinates
|
list | NDArray
|
Unordered trace coordinates. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
An array of ordered coordinates from one end of a linear trace to the other. |
Source code in topostats\tracing\tracingfuncs.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
linearTrace(trace_coordinates: list | npt.NDArray) -> npt.NDArray
staticmethod
Function to order the points from a linear trace.
This works by checking the local neighbours for a given pixel (starting at one of the ends). If this pixel has only one neighbour in the array of unordered points, this must be the next pixel in the trace -- and it is added to the ordered points trace and removed from the remaining_unordered_coords array.
If there is more than one neighbouring pixel, a fairly simple function (check_vectors_candidate_points) finds which pixel incurs the smallest change in angle compared with the rest of the trace and chooses that as the next point.
This process is repeated until all the points are placed in the ordered trace array or the other end point is reached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trace_coordinates
|
list | NDArray
|
Unordered trace coordinates. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
An array of ordered coordinates from one end of a linear trace to the other. |
Source code in topostats\tracing\tracingfuncs.py
coord_dist(coords: npt.NDArray, pixel_to_nm_scaling: float = 1) -> npt.NDArray
Accumulate a real distance traversing from pixel to pixel from a list of coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
NDArray
|
A Nx2 integer array corresponding to the ordered coordinates of a binary trace. |
required |
pixel_to_nm_scaling
|
float
|
The pixel to nanometer scaling factor. |
1
|
Returns:
| Type | Description |
|---|---|
NDArray
|
An array of length N containing thcumulative sum of the distances. |
Source code in topostats\tracing\tracingfuncs.py
local_area_sum(binary_map: npt.NDArray, point: list | tuple | npt.NDArray) -> npt.NDArray
Evaluate the local area around a point in a binary map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binary_map
|
NDArray
|
A binary array of an image. |
required |
point
|
Union[list, tuple, NDArray]
|
A single object containing 2 integers relating to a point within the binary_map. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
An array values of the local coordinates around the point. |
int
|
A value corresponding to the number of neighbours around the point in the binary_map. |
Source code in topostats\tracing\tracingfuncs.py
order_branch(binary_image: npt.NDArray, anchor: list)
Order a linear branch by identifying an endpoint, and looking at the local area of the point to find the next.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binary_image
|
NDArray
|
A binary image of a skeleton segment to order it's points. |
required |
anchor
|
list
|
A list of 2 integers representing the coordinate to order the branch from the endpoint closest to this. |
required |
Returns:
| Type | Description |
|---|---|
NDArray
|
An array of ordered coordinates. |
Source code in topostats\tracing\tracingfuncs.py
order_branch_from_start(nodeless: npt.NDArray, start: npt.NDArray, max_length: float | np.inf = np.inf) -> npt.NDArray
Order an unbranching skeleton from an end (startpoint) along a specified length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodeless
|
NDArray
|
A 2D array of a binary unbranching skeleton. |
required |
start
|
NDArray
|
2x1 coordinate that must exist in 'nodeless'. |
required |
max_length
|
float | inf
|
Maximum length to traverse along while ordering, by default np.inf. |
inf
|
Returns:
| Type | Description |
|---|---|
NDArray
|
Ordered coordinates. |