tardis-em-analysis 0.3.20__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tardis_em_analysis-0.3.20/LICENSE +21 -0
- tardis_em_analysis-0.3.20/MANIFEST.in +3 -0
- tardis_em_analysis-0.3.20/PKG-INFO +53 -0
- tardis_em_analysis-0.3.20/README.rst +56 -0
- tardis_em_analysis-0.3.20/pyproject.toml +24 -0
- tardis_em_analysis-0.3.20/requirements.txt +18 -0
- tardis_em_analysis-0.3.20/setup.cfg +34 -0
- tardis_em_analysis-0.3.20/setup.py +12 -0
- tardis_em_analysis-0.3.20/tardis_em_analysis/__init__.py +7 -0
- tardis_em_analysis-0.3.20/tardis_em_analysis/_version.py +11 -0
- tardis_em_analysis-0.3.20/tardis_em_analysis/analysis.py +374 -0
- tardis_em_analysis-0.3.20/tardis_em_analysis/filament_structure.py +94 -0
- tardis_em_analysis-0.3.20/tardis_em_analysis/filament_utils.py +362 -0
- tardis_em_analysis-0.3.20/tardis_em_analysis/geometry_metrics.py +578 -0
- tardis_em_analysis-0.3.20/tardis_em_analysis/mt_classification/__init__.py +0 -0
- tardis_em_analysis-0.3.20/tardis_em_analysis/mt_classification/mt_classes.py +738 -0
- tardis_em_analysis-0.3.20/tardis_em_analysis/mt_classification/utils.py +423 -0
- tardis_em_analysis-0.3.20/tardis_em_analysis/spatial_graph_utils.py +807 -0
- tardis_em_analysis-0.3.20/tardis_em_analysis/stitch_volume/__init__.py +11 -0
- tardis_em_analysis-0.3.20/tardis_em_analysis/stitch_volume/align_tomograms.py +872 -0
- tardis_em_analysis-0.3.20/tardis_em_analysis/stitch_volume/utils.py +71 -0
- tardis_em_analysis-0.3.20/tardis_em_analysis/utils.py +144 -0
- tardis_em_analysis-0.3.20/tardis_em_analysis.egg-info/PKG-INFO +53 -0
- tardis_em_analysis-0.3.20/tardis_em_analysis.egg-info/SOURCES.txt +26 -0
- tardis_em_analysis-0.3.20/tardis_em_analysis.egg-info/dependency_links.txt +1 -0
- tardis_em_analysis-0.3.20/tardis_em_analysis.egg-info/requires.txt +11 -0
- tardis_em_analysis-0.3.20/tardis_em_analysis.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Robert Kiewisz, Tristan Bepler
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tardis_em_analysis
|
|
3
|
+
Version: 0.3.20
|
|
4
|
+
Summary: Collection of analysis libraries used by TARDIS-EM and napari-tardis-em.
|
|
5
|
+
Home-page: https://github.com/SMLC-NYSBC/tardis_em_analysis
|
|
6
|
+
Author: Robert Kiewisz, Tristan Bepler
|
|
7
|
+
Author-email: robert.kiewisz@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: tardis-em,analysis,filaments,membranes
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Education
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Environment :: GPU :: NVIDIA CUDA :: 11
|
|
14
|
+
Classifier: Natural Language :: English
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Requires-Python: !=3.12,>=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: torch>2.0.0
|
|
21
|
+
Requires-Dist: numpy>=2.0.0
|
|
22
|
+
Requires-Dist: pandas>=2.2.0
|
|
23
|
+
Requires-Dist: tifffile
|
|
24
|
+
Requires-Dist: imagecodecs
|
|
25
|
+
Requires-Dist: scikit-learn>1.0.1
|
|
26
|
+
Requires-Dist: scikit-image>0.19.2
|
|
27
|
+
Requires-Dist: scipy>=1.10.0
|
|
28
|
+
Requires-Dist: opencv-python>=4.12.0.0
|
|
29
|
+
Requires-Dist: ipython>8.10.0
|
|
30
|
+
Requires-Dist: setuptools>=67.6.0
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
MIT License
|
|
34
|
+
|
|
35
|
+
Copyright (c) 2022 Robert Kiewisz, Tristan Bepler
|
|
36
|
+
|
|
37
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
38
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
39
|
+
in the Software without restriction, including without limitation the rights
|
|
40
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
41
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
42
|
+
furnished to do so, subject to the following conditions:
|
|
43
|
+
|
|
44
|
+
The above copyright notice and this permission notice shall be included in all
|
|
45
|
+
copies or substantial portions of the Software.
|
|
46
|
+
|
|
47
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
48
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
49
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
50
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
51
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
52
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
53
|
+
SOFTWARE.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
.. image:: resources/Tardis_logo_2.png
|
|
2
|
+
:width: 512
|
|
3
|
+
:align: center
|
|
4
|
+
:target: https://smlc-nysbc.github.io/TARDIS/
|
|
5
|
+
|
|
6
|
+
========
|
|
7
|
+
|
|
8
|
+
.. image:: https://img.shields.io/github/v/release/smlc-nysbc/napari-tardis_em
|
|
9
|
+
:target: https://img.shields.io/github/v/release/smlc-nysbc/tardis
|
|
10
|
+
|
|
11
|
+
.. image:: https://img.shields.io/badge/Join%20Our%20Community-Slack-blue
|
|
12
|
+
:target: https://join.slack.com/t/tardis-em/shared_invite/zt-27jznfn9j-OplbV70KdKjkHsz5FcQQGg
|
|
13
|
+
|
|
14
|
+
.. image:: https://img.shields.io/github/downloads/smlc-nysbc/napari-tardis_em/total
|
|
15
|
+
:target: https://img.shields.io/github/downloads/smlc-nysbc/tardis/total
|
|
16
|
+
|
|
17
|
+
.. image:: https://github.com/SMLC-NYSBC/tardis/actions/workflows/sphinx_documentation.yml/badge.svg
|
|
18
|
+
:target: https://github.com/SMLC-NYSBC/tardis/actions/workflows/sphinx_documentation.yml
|
|
19
|
+
|
|
20
|
+
Napari plugin for TARDIS-analysis
|
|
21
|
+
===========================
|
|
22
|
+
|
|
23
|
+
Collection of analysis libraries used by TARDIS-EM and napari-tardis-em
|
|
24
|
+
|
|
25
|
+
Citation
|
|
26
|
+
========
|
|
27
|
+
|
|
28
|
+
`DOI [BioRxiv] <http://doi.org/10.1101/2024.12.19.629196>`__
|
|
29
|
+
|
|
30
|
+
Kiewisz R. et.al. 2024. Accurate and fast segmentation of filaments and membranes in micrographs and tomograms with TARDIS.
|
|
31
|
+
|
|
32
|
+
`DOI [Microscopy and Microanalysis] <http://dx.doi.org/10.1093/micmic/ozad067.485>`__
|
|
33
|
+
|
|
34
|
+
Kiewisz R., Fabig G., Müller-Reichert T. Bepler T. 2023. Automated Segmentation of 3D Cytoskeletal Filaments from Electron Micrographs with TARDIS. Microscopy and Microanalysis 29(Supplement_1):970-972.
|
|
35
|
+
|
|
36
|
+
`Link: NeurIPS 2022 MLSB Workshop <https://www.mlsb.io/papers_2022/Membrane_and_microtubule_rapid_instance_segmentation_with_dimensionless_instance_segmentation_by_learning_graph_representations_of_point_clouds.pdf>`__
|
|
37
|
+
|
|
38
|
+
Kiewisz R., Bepler T. 2022. Membrane and microtubule rapid instance segmentation with dimensionless instance segmentation by learning graph representations of point clouds. Neurips 2022 - Machine Learning for Structural Biology Workshop.
|
|
39
|
+
|
|
40
|
+
Quick Start
|
|
41
|
+
===========
|
|
42
|
+
|
|
43
|
+
For more examples and advanced usage please find more details in our `Documentation <https://smlc-nysbc.github.io/TARDIS/>`__
|
|
44
|
+
|
|
45
|
+
0) Create new conda enviroment
|
|
46
|
+
|
|
47
|
+
.. code-block::
|
|
48
|
+
|
|
49
|
+
conda create -n tardis python=3.11
|
|
50
|
+
conda activate tardis
|
|
51
|
+
|
|
52
|
+
1) Install TARDIS-analysis:
|
|
53
|
+
|
|
54
|
+
.. code-block:: bash
|
|
55
|
+
|
|
56
|
+
pip install tardis-analysis
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#######################################################################
|
|
2
|
+
# TARDIS - Transformer And Rapid Dimensionless Instance Segmentation #
|
|
3
|
+
# #
|
|
4
|
+
# New York Structural Biology Center #
|
|
5
|
+
# Simons Machine Learning Center #
|
|
6
|
+
# #
|
|
7
|
+
# Robert Kiewisz, Tristan Bepler #
|
|
8
|
+
# MIT License 2025 #
|
|
9
|
+
#######################################################################
|
|
10
|
+
|
|
11
|
+
[build-system]
|
|
12
|
+
requires = ["setuptools>42.0", "wheel"]
|
|
13
|
+
build-backend = "setuptools.build_meta"
|
|
14
|
+
|
|
15
|
+
[tool.isort]
|
|
16
|
+
profile = "black"
|
|
17
|
+
line_length = 100
|
|
18
|
+
lines_between_types = 1
|
|
19
|
+
combine_as_imports = true
|
|
20
|
+
|
|
21
|
+
[tool.pytest.ini_options]
|
|
22
|
+
testpaths = [
|
|
23
|
+
"tests",
|
|
24
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# ML library
|
|
2
|
+
torch>2.0.0
|
|
3
|
+
numpy>=2.0.0
|
|
4
|
+
pandas>=2.2.0
|
|
5
|
+
|
|
6
|
+
# Image loading/export library
|
|
7
|
+
tifffile
|
|
8
|
+
imagecodecs
|
|
9
|
+
|
|
10
|
+
# Image processing library
|
|
11
|
+
scikit-learn>1.0.1
|
|
12
|
+
scikit-image>0.19.2
|
|
13
|
+
scipy>=1.10.0
|
|
14
|
+
opencv-python>=4.12.0.0
|
|
15
|
+
|
|
16
|
+
# Other
|
|
17
|
+
ipython>8.10.0
|
|
18
|
+
setuptools>=67.6.0
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[metadata]
|
|
2
|
+
name = tardis_em_analysis
|
|
3
|
+
version = attr: tardis_em_analysis.__version__
|
|
4
|
+
description = Collection of analysis libraries used by TARDIS-EM and napari-tardis-em.
|
|
5
|
+
long_description = file: README.md, LICENSE
|
|
6
|
+
long_description_content_type = text/markdown
|
|
7
|
+
keywords = tardis-em, analysis, filaments, membranes
|
|
8
|
+
url = https://github.com/SMLC-NYSBC/tardis_em_analysis
|
|
9
|
+
author = Robert Kiewisz, Tristan Bepler
|
|
10
|
+
author_email = robert.kiewisz@gmail.com
|
|
11
|
+
license = MIT
|
|
12
|
+
license_files = LICENSE
|
|
13
|
+
classifiers =
|
|
14
|
+
Development Status :: 5 - Production/Stable
|
|
15
|
+
Intended Audience :: Education
|
|
16
|
+
Environment :: Console
|
|
17
|
+
Environment :: GPU :: NVIDIA CUDA :: 11
|
|
18
|
+
Natural Language :: English
|
|
19
|
+
Programming Language :: Python :: 3.10
|
|
20
|
+
Programming Language :: Python :: 3.11
|
|
21
|
+
|
|
22
|
+
[options]
|
|
23
|
+
packages = find:
|
|
24
|
+
python_requires = >=3.10,!=3.12
|
|
25
|
+
include_package_data = True
|
|
26
|
+
install_requires = file: requirements.txt
|
|
27
|
+
|
|
28
|
+
[flake8]
|
|
29
|
+
max-line-length = 100
|
|
30
|
+
|
|
31
|
+
[egg_info]
|
|
32
|
+
tag_build =
|
|
33
|
+
tag_date = 0
|
|
34
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#######################################################################
|
|
2
|
+
# TARDIS - Transformer And Rapid Dimensionless Instance Segmentation #
|
|
3
|
+
# #
|
|
4
|
+
# New York Structural Biology Center #
|
|
5
|
+
# Simons Machine Learning Center #
|
|
6
|
+
# #
|
|
7
|
+
# Robert Kiewisz, Tristan Bepler #
|
|
8
|
+
# MIT License 2021 - 2025 #
|
|
9
|
+
#######################################################################
|
|
10
|
+
from setuptools import setup
|
|
11
|
+
|
|
12
|
+
setup()
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# #####################################################################
|
|
2
|
+
# TARDIS - Transformer And Rapid Dimensionless Instance Segmentation #
|
|
3
|
+
# #
|
|
4
|
+
# New York Structural Biology Center #
|
|
5
|
+
# Simons Machine Learning Center #
|
|
6
|
+
# #
|
|
7
|
+
# Robert Kiewisz, Tristan Bepler #
|
|
8
|
+
# MIT License 2025 #
|
|
9
|
+
# #####################################################################
|
|
10
|
+
|
|
11
|
+
version = "0.3.20"
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
#######################################################################
|
|
2
|
+
# TARDIS - Transformer And Rapid Dimensionless Instance Segmentation #
|
|
3
|
+
# #
|
|
4
|
+
# New York Structural Biology Center #
|
|
5
|
+
# Simons Machine Learning Center #
|
|
6
|
+
# #
|
|
7
|
+
# Robert Kiewisz, Tristan Bepler #
|
|
8
|
+
# MIT License 2021 - 2025 #
|
|
9
|
+
#######################################################################
|
|
10
|
+
|
|
11
|
+
from datetime import datetime
|
|
12
|
+
from os.path import join
|
|
13
|
+
from typing import Union, List, Tuple
|
|
14
|
+
import numpy as np
|
|
15
|
+
import pandas as pd
|
|
16
|
+
|
|
17
|
+
from tardis_em_analysis.geometry_metrics import (
|
|
18
|
+
length_list,
|
|
19
|
+
curvature_list,
|
|
20
|
+
intensity_list,
|
|
21
|
+
calculate_spline_correlations,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
from tardis_em_analysis.mt_classification.mt_classes import (
|
|
25
|
+
assign_filaments_to_poles,
|
|
26
|
+
pick_pole_to_surfaces,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
from tardis_em_analysis._version import version
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def analyse_filaments(
|
|
33
|
+
data: Union[np.ndarray, List, Tuple],
|
|
34
|
+
image: Union[np.ndarray, List, Tuple] = None,
|
|
35
|
+
thickness=[1, 1],
|
|
36
|
+
px=None,
|
|
37
|
+
normalize_image=False,
|
|
38
|
+
) -> list:
|
|
39
|
+
"""
|
|
40
|
+
Analyzes filament data to compute various attributes including length, curvature,
|
|
41
|
+
tortuosity, and intensity-related metrics. If image data is provided, intensity
|
|
42
|
+
metrics such as average intensity, average length intensity, total intensity,
|
|
43
|
+
and total length intensity are computed. Lengths can be scaled based on pixel size
|
|
44
|
+
(px) if specified.
|
|
45
|
+
|
|
46
|
+
:param data: Filament data used for analysis. Can be a numpy array or a sequence
|
|
47
|
+
containing numpy arrays.
|
|
48
|
+
:type data: Union[np.ndarray, List, Tuple]
|
|
49
|
+
:param image: Optional image data corresponding to the filaments. Used for
|
|
50
|
+
computing intensity metrics. Can be a numpy array or a sequence containing
|
|
51
|
+
numpy arrays.
|
|
52
|
+
:type image: Union[np.ndarray, List, Tuple], optional
|
|
53
|
+
:param thickness: Thickness of filaments used for intensity calculation.
|
|
54
|
+
Defaults to 1.
|
|
55
|
+
:type thickness: int, optional
|
|
56
|
+
:param px: Scaling factors for pixel size to convert lengths into physical
|
|
57
|
+
units. If None, lengths are computed directly without scaling. Defaults to
|
|
58
|
+
None.
|
|
59
|
+
:type px: Sequence, optional
|
|
60
|
+
|
|
61
|
+
:return: A tuple containing:
|
|
62
|
+
|
|
63
|
+
- length (list): Computed lengths of the filaments.
|
|
64
|
+
- curvature (list): Computed mean curvatures of the filaments.
|
|
65
|
+
- tortuosity (list): Computed mean tortuosity of the filaments.
|
|
66
|
+
- avg_intensity (list): Computed average intensity per filament, or None
|
|
67
|
+
if no image data is provided.
|
|
68
|
+
- avg_length_intensity (list): Computed average filament intensity
|
|
69
|
+
normalized by filament length, or None if no image data is provided.
|
|
70
|
+
- sum_intensity (list): Computed total intensity per filament, or None
|
|
71
|
+
if no image data is provided.
|
|
72
|
+
- sum_length_intensity (list): Computed total filament intensity normalized
|
|
73
|
+
by filament length, or None if no image data is provided.
|
|
74
|
+
:rtype: list
|
|
75
|
+
"""
|
|
76
|
+
if isinstance(data, np.ndarray):
|
|
77
|
+
data = [data]
|
|
78
|
+
if image is not None:
|
|
79
|
+
if isinstance(image, np.ndarray):
|
|
80
|
+
image = [image]
|
|
81
|
+
|
|
82
|
+
length, curvature, tortuosity = [], [], []
|
|
83
|
+
avg_intensity, sum_intensity = [], []
|
|
84
|
+
avg_length_intensity, sum_length_intensity = [], []
|
|
85
|
+
|
|
86
|
+
for id_, d_ in enumerate(data):
|
|
87
|
+
if px is None:
|
|
88
|
+
length.append(length_list(d_))
|
|
89
|
+
else:
|
|
90
|
+
length.append([i * px[id_] for i in length_list(d_)]) # length in U
|
|
91
|
+
|
|
92
|
+
curvature_, tortuosity_ = curvature_list(d_, tortuosity_b=True, mean_b=True)
|
|
93
|
+
curvature.append(curvature_)
|
|
94
|
+
tortuosity.append(tortuosity_)
|
|
95
|
+
|
|
96
|
+
if image is not None:
|
|
97
|
+
intensity_mean, intensity_sum = intensity_list(
|
|
98
|
+
d_, image[id_], thickness, normalize_image
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
avg_intensity.append(intensity_mean)
|
|
102
|
+
|
|
103
|
+
avg_length_intensity_ = [i / l for l, i in zip(length[id_], intensity_mean)]
|
|
104
|
+
avg_length_intensity.append(avg_length_intensity_)
|
|
105
|
+
|
|
106
|
+
sum_intensity.append(intensity_sum)
|
|
107
|
+
|
|
108
|
+
sum_length_intensity_ = [
|
|
109
|
+
i / len_ for len_, i in zip(length[id_], intensity_sum)
|
|
110
|
+
]
|
|
111
|
+
sum_length_intensity.append(sum_length_intensity_)
|
|
112
|
+
|
|
113
|
+
analysis = [
|
|
114
|
+
length,
|
|
115
|
+
curvature,
|
|
116
|
+
tortuosity,
|
|
117
|
+
avg_intensity,
|
|
118
|
+
avg_length_intensity,
|
|
119
|
+
sum_intensity,
|
|
120
|
+
sum_length_intensity,
|
|
121
|
+
]
|
|
122
|
+
|
|
123
|
+
return analysis
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def save_analysis(
|
|
127
|
+
names: Union[List, Tuple],
|
|
128
|
+
analysis: Union[List, Tuple],
|
|
129
|
+
anal_list: list,
|
|
130
|
+
px=None,
|
|
131
|
+
save: str = None,
|
|
132
|
+
) -> Union[None, np.ndarray]:
|
|
133
|
+
"""
|
|
134
|
+
Saves or generates a detailed analysis file from the given `analysis` data. The function
|
|
135
|
+
is capable of saving the processed analysis to a CSV file if a save path is provided
|
|
136
|
+
or alternatively returns the processed analysis as a NumPy array. The analysis includes
|
|
137
|
+
details such as filament lengths, curvatures, tortuosities, and intensity-related data. It
|
|
138
|
+
is designed to handle multiple files and their corresponding filament data.
|
|
139
|
+
|
|
140
|
+
:param names: List or tuple containing the names of the files being analyzed.
|
|
141
|
+
:param analysis: Tuple or list containing multiple analysis metrics such as
|
|
142
|
+
length, curvature, tortuosity, intensity, and their derivatives. Each metric
|
|
143
|
+
corresponds to a specific aspect of the filament data.
|
|
144
|
+
:param px: Optional parameter containing pixel size for each file, which is used
|
|
145
|
+
to calculate some metrics. If not specified, a default value is assumed.
|
|
146
|
+
:param save: Optional parameter specifying the path where the CSV file will be
|
|
147
|
+
saved. If not provided, the function will not save the file and returns the
|
|
148
|
+
analysis as a NumPy array.
|
|
149
|
+
|
|
150
|
+
:return: Returns a NumPy array containing the processed analysis, or None if the
|
|
151
|
+
analysis is saved to a CSV file.
|
|
152
|
+
"""
|
|
153
|
+
|
|
154
|
+
length, curvature, tortuosity = analysis[0], analysis[1], analysis[2]
|
|
155
|
+
avg_intensity, avg_length_intensity = analysis[3], analysis[4]
|
|
156
|
+
sum_intensity, sum_length_intensity = analysis[5], analysis[6]
|
|
157
|
+
correlation = analysis[7]
|
|
158
|
+
|
|
159
|
+
correlation_len = len(correlation[0][0])
|
|
160
|
+
rows = np.sum([len(i) for i in length]).item(0)
|
|
161
|
+
|
|
162
|
+
analysis_file = np.zeros((rows, 10 + correlation_len), dtype=object)
|
|
163
|
+
|
|
164
|
+
iter_ = 0
|
|
165
|
+
for i in range(len(length)): # Iterate throw every file
|
|
166
|
+
for j in range(len(length[i])):
|
|
167
|
+
analysis_file[iter_, :10] = [
|
|
168
|
+
names[i], # 0
|
|
169
|
+
str(j), # 1
|
|
170
|
+
str(1.0) if px is None else px[i], # 2
|
|
171
|
+
str(length[i][j]), # 3
|
|
172
|
+
str(curvature[i][j]), # 4
|
|
173
|
+
str(tortuosity[i][j]), # 5
|
|
174
|
+
str(avg_intensity[i][j]), # 6
|
|
175
|
+
str(avg_length_intensity[i][j]), # 7
|
|
176
|
+
str(sum_intensity[i][j]), # 8
|
|
177
|
+
str(sum_length_intensity[i][j]), # 9
|
|
178
|
+
]
|
|
179
|
+
|
|
180
|
+
for k in range(correlation_len):
|
|
181
|
+
analysis_file[iter_, 10 + k] = str(correlation[i][j][k])
|
|
182
|
+
|
|
183
|
+
iter_ += 1
|
|
184
|
+
|
|
185
|
+
if save is not None:
|
|
186
|
+
date = datetime.now()
|
|
187
|
+
|
|
188
|
+
file_name = f"{names[0]}.csv"
|
|
189
|
+
header_pd = [
|
|
190
|
+
"File_Name",
|
|
191
|
+
"No. of Filament",
|
|
192
|
+
"Pixel_Size [nm]",
|
|
193
|
+
"Length [nm]",
|
|
194
|
+
"Curvature [0-inf]",
|
|
195
|
+
"Tortuosity [1-inf]",
|
|
196
|
+
"Avg. Intensity [U]",
|
|
197
|
+
"Avg. Intensity / Length [U/nm]",
|
|
198
|
+
"Sum. Intensity [U]",
|
|
199
|
+
"Sum. Intensity / Length [U/nm]",
|
|
200
|
+
]
|
|
201
|
+
header_pd = header_pd + [
|
|
202
|
+
f"Correlation [Pearson] CH_{i}" for i in range(correlation_len)
|
|
203
|
+
]
|
|
204
|
+
|
|
205
|
+
if anal_list != []:
|
|
206
|
+
df = {
|
|
207
|
+
"length": 3,
|
|
208
|
+
"curvature": 4,
|
|
209
|
+
"tortuosity": 5,
|
|
210
|
+
"avg_intensity": 6,
|
|
211
|
+
"avg_length_intensity": 7,
|
|
212
|
+
"sum_intensity": 8,
|
|
213
|
+
"sum_length_intensity": 9,
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
keep_ = [0, 1, 2] + [df[i] for i in anal_list if i in df]
|
|
217
|
+
if "correlation" in anal_list:
|
|
218
|
+
keep_ = keep_ + [10]
|
|
219
|
+
|
|
220
|
+
remove_ = [
|
|
221
|
+
item
|
|
222
|
+
for item in list(range(analysis_file.shape[1]))
|
|
223
|
+
if item not in keep_
|
|
224
|
+
]
|
|
225
|
+
|
|
226
|
+
if 10 in keep_:
|
|
227
|
+
keep_ = keep_.extend([i for i in remove_ if i > 10])
|
|
228
|
+
remove_ = [i for i in remove_ if i < 10]
|
|
229
|
+
analysis_file = np.delete(analysis_file, remove_, axis=1)
|
|
230
|
+
|
|
231
|
+
header_pd = header_pd + [f"Correlation [Pearson] CH_{i}" for i in range(2)]
|
|
232
|
+
header_pd = [h for id, h in enumerate(header_pd) if id in keep_]
|
|
233
|
+
|
|
234
|
+
segments = pd.DataFrame(analysis_file)
|
|
235
|
+
segments.to_csv(
|
|
236
|
+
join(save, file_name),
|
|
237
|
+
header=header_pd,
|
|
238
|
+
index=False,
|
|
239
|
+
sep=",",
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
return
|
|
243
|
+
return analysis_file
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def analyse_filaments_list(
|
|
247
|
+
data: Union[List, Tuple],
|
|
248
|
+
names_l: Union[List, Tuple],
|
|
249
|
+
path: str,
|
|
250
|
+
images: Union[List, Tuple] = None,
|
|
251
|
+
px: Union[List, Tuple] = None,
|
|
252
|
+
anal_list=None,
|
|
253
|
+
thicknesses=[1, 1],
|
|
254
|
+
image_corr=None,
|
|
255
|
+
frame_id=None,
|
|
256
|
+
normalize_image=False,
|
|
257
|
+
):
|
|
258
|
+
"""
|
|
259
|
+
Analyzes and processes a list of filament data along with optional corresponding images.
|
|
260
|
+
The function validates the input to ensure consistency between the length of the data
|
|
261
|
+
and images before analyzing the filaments. The processed analysis is then saved to the
|
|
262
|
+
specified path.
|
|
263
|
+
|
|
264
|
+
:param data: A collection of data representing filament structures. It must be a list
|
|
265
|
+
or tuple.
|
|
266
|
+
:type data: Union[List, Tuple]
|
|
267
|
+
:param names_l: A collection of filenames or identifiers corresponding to each set of data.
|
|
268
|
+
It must be a list or tuple.
|
|
269
|
+
:type names_l: Union[List, Tuple]
|
|
270
|
+
:param path: A string representing the file path where the analysis results will be saved.
|
|
271
|
+
:type path: str
|
|
272
|
+
:param images: Optional collection of images corresponding to the data, where each
|
|
273
|
+
image represents the visual context of the filament. Default is None.
|
|
274
|
+
:type images: Optional[Union[List, Tuple]]
|
|
275
|
+
:param px: Optional collection indicating pixel calibration or scaling of the images,
|
|
276
|
+
if provided. Default is None.
|
|
277
|
+
:type px: Optional[Union[List, Tuple]]
|
|
278
|
+
:param anal_list: List of analysis to perform, if None that all.
|
|
279
|
+
:type anal_list: None or List[str]
|
|
280
|
+
:param thicknesses: An integer specifying the thickness parameter used during filament
|
|
281
|
+
analysis. Default is 1.
|
|
282
|
+
:type thicknesses: List[int]
|
|
283
|
+
|
|
284
|
+
:return: None
|
|
285
|
+
"""
|
|
286
|
+
|
|
287
|
+
if images is not None:
|
|
288
|
+
assert_i = len(data) == len(images)
|
|
289
|
+
else:
|
|
290
|
+
assert_i = len(data) > 0
|
|
291
|
+
assert not assert_i, "List of analysed files do not match or is 0"
|
|
292
|
+
|
|
293
|
+
if images is None:
|
|
294
|
+
images = [None for _ in range(len(data))]
|
|
295
|
+
|
|
296
|
+
analysis = analyse_filaments(
|
|
297
|
+
data, images, thicknesses, px=px, normalize_image=normalize_image
|
|
298
|
+
)
|
|
299
|
+
correlations, correlations_px = calculate_spline_correlations(
|
|
300
|
+
image_corr, data[0], frame_id=frame_id, thickness=[1, 1]
|
|
301
|
+
)
|
|
302
|
+
analysis.append([correlations])
|
|
303
|
+
if "correlation" in anal_list or anal_list == []:
|
|
304
|
+
# Prepare a dictionary to store our columns
|
|
305
|
+
csv_data = {}
|
|
306
|
+
|
|
307
|
+
# Iterate through the main dictionary
|
|
308
|
+
for main_key in correlations_px:
|
|
309
|
+
# Add reference column
|
|
310
|
+
csv_data[f"{main_key}_reference"] = correlations_px[main_key]["reference"]
|
|
311
|
+
|
|
312
|
+
# Add MT columns
|
|
313
|
+
for mt_key in correlations_px[main_key]["MT"]:
|
|
314
|
+
csv_data[f"{main_key}_MT_{mt_key}"] = correlations_px[main_key]["MT"][
|
|
315
|
+
mt_key
|
|
316
|
+
]
|
|
317
|
+
|
|
318
|
+
# Find the maximum length of all lists to ensure proper DataFrame creation
|
|
319
|
+
max_length = max(len(lst) for col in csv_data.values() for lst in [col])
|
|
320
|
+
|
|
321
|
+
# Pad shorter lists with None to make them equal length
|
|
322
|
+
for col in csv_data:
|
|
323
|
+
current_length = len(csv_data[col])
|
|
324
|
+
if current_length < max_length:
|
|
325
|
+
csv_data[col].extend([None] * (max_length - current_length))
|
|
326
|
+
|
|
327
|
+
# Create DataFrame and save to CSV
|
|
328
|
+
df = pd.DataFrame(csv_data)
|
|
329
|
+
date = datetime.now()
|
|
330
|
+
tardis_version = version
|
|
331
|
+
file_name = f"TARDIS_V{tardis_version}_correlation_{date.day}_{date.month}_{date.year}-{date.hour}_{date.minute}.csv"
|
|
332
|
+
df.to_csv(join(path, file_name), index=False)
|
|
333
|
+
|
|
334
|
+
save_analysis(names_l, analysis, px=px, save=path, anal_list=anal_list)
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
def analyse_mt_classes(
|
|
338
|
+
filaments: np.ndarray, poles: np.ndarray, vertices: list
|
|
339
|
+
) -> tuple:
|
|
340
|
+
"""
|
|
341
|
+
Analyzes microtubule (MT) classes by assigning filaments to poles, then categorizing
|
|
342
|
+
their ends as plus or minus ends. The process involves sorting poles relative to
|
|
343
|
+
defined vertices, assigning filaments to corresponding poles, and subsequently
|
|
344
|
+
determining the extremities of the filaments.
|
|
345
|
+
|
|
346
|
+
:param filaments: A NumPy array of filaments where each filament is defined as a
|
|
347
|
+
collection of points.
|
|
348
|
+
:param poles: A NumPy array containing pole positions.
|
|
349
|
+
:param vertices: A list of vertex points used to determine pole-to-surface assignments.
|
|
350
|
+
|
|
351
|
+
:return: A tuple where the first element contains the mapping of filaments to poles
|
|
352
|
+
and the second element is a tuple with two lists: one for the plus ends and
|
|
353
|
+
another for the minus ends of the filaments.
|
|
354
|
+
"""
|
|
355
|
+
# Sort poles to surfaces
|
|
356
|
+
poles = pick_pole_to_surfaces(poles, vertices)
|
|
357
|
+
# Sort filaments to poles
|
|
358
|
+
filament_poles = assign_filaments_to_poles(filaments, poles)
|
|
359
|
+
|
|
360
|
+
"""
|
|
361
|
+
Get plus and minus ends
|
|
362
|
+
"""
|
|
363
|
+
plus_ends = []
|
|
364
|
+
minus_ends = []
|
|
365
|
+
for f in filament_poles:
|
|
366
|
+
_, first_indices = np.unique(f[:, 0], return_index=True)
|
|
367
|
+
first_points = first_indices
|
|
368
|
+
|
|
369
|
+
last_points = [i + len(f[f[:, 0] == i, :]) - 1 for i in first_points]
|
|
370
|
+
|
|
371
|
+
plus_ends.append(first_points)
|
|
372
|
+
minus_ends.append(last_points)
|
|
373
|
+
|
|
374
|
+
return filament_poles, (plus_ends, minus_ends)
|