CIMA 1.0.1__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.
Files changed (47) hide show
  1. cima-1.0.1/CIMA.egg-info/PKG-INFO +10 -0
  2. cima-1.0.1/CIMA.egg-info/SOURCES.txt +45 -0
  3. cima-1.0.1/CIMA.egg-info/dependency_links.txt +1 -0
  4. cima-1.0.1/CIMA.egg-info/not-zip-safe +1 -0
  5. cima-1.0.1/CIMA.egg-info/top_level.txt +1 -0
  6. cima-1.0.1/LICENCE +28 -0
  7. cima-1.0.1/PKG-INFO +10 -0
  8. cima-1.0.1/README.md +42 -0
  9. cima-1.0.1/setup.cfg +4 -0
  10. cima-1.0.1/setup.py +69 -0
  11. cima-1.0.1/src/CIMA/__init__.py +17 -0
  12. cima-1.0.1/src/CIMA/assessment/Images_Assessment.py +441 -0
  13. cima-1.0.1/src/CIMA/assessment/__init__.py +14 -0
  14. cima-1.0.1/src/CIMA/detection/__init__.py +14 -0
  15. cima-1.0.1/src/CIMA/detection/beads_identification.py +108 -0
  16. cima-1.0.1/src/CIMA/detection/clusters.py +992 -0
  17. cima-1.0.1/src/CIMA/maps/DensityProprieties.py +257 -0
  18. cima-1.0.1/src/CIMA/maps/EMMap.py +2871 -0
  19. cima-1.0.1/src/CIMA/maps/MapFeatures.py +494 -0
  20. cima-1.0.1/src/CIMA/maps/MapParser.py +203 -0
  21. cima-1.0.1/src/CIMA/maps/MapSpatialFeatures.py +122 -0
  22. cima-1.0.1/src/CIMA/maps/ScoringFunctions.py +2366 -0
  23. cima-1.0.1/src/CIMA/maps/StructureBlurrer.py +1014 -0
  24. cima-1.0.1/src/CIMA/maps/VQ.py +185 -0
  25. cima-1.0.1/src/CIMA/maps/__init__.py +13 -0
  26. cima-1.0.1/src/CIMA/maps/maptomap.py +129 -0
  27. cima-1.0.1/src/CIMA/parsers/ParserCSV.py +386 -0
  28. cima-1.0.1/src/CIMA/parsers/Parserh5py.py +156 -0
  29. cima-1.0.1/src/CIMA/parsers/__init__.py +13 -0
  30. cima-1.0.1/src/CIMA/patches/HomologSeparator.py +95 -0
  31. cima-1.0.1/src/CIMA/patches/NuclearMask.py +62 -0
  32. cima-1.0.1/src/CIMA/patches/SegmentReconstruction.py +443 -0
  33. cima-1.0.1/src/CIMA/patches/__init__.py +13 -0
  34. cima-1.0.1/src/CIMA/segments/SegmentConvex.py +117 -0
  35. cima-1.0.1/src/CIMA/segments/SegmentFeatures.py +287 -0
  36. cima-1.0.1/src/CIMA/segments/SegmentGaussian.py +218 -0
  37. cima-1.0.1/src/CIMA/segments/SegmentInfo.py +299 -0
  38. cima-1.0.1/src/CIMA/segments/SegmentInfoH5.py +182 -0
  39. cima-1.0.1/src/CIMA/segments/SegmentInfoXYZ.py +358 -0
  40. cima-1.0.1/src/CIMA/segments/SegmentSpatialFeatures.py +92 -0
  41. cima-1.0.1/src/CIMA/segments/__init__.py +15 -0
  42. cima-1.0.1/src/CIMA/utils/StatsFunction.py +185 -0
  43. cima-1.0.1/src/CIMA/utils/Vector.py +457 -0
  44. cima-1.0.1/src/CIMA/utils/Visualization.py +406 -0
  45. cima-1.0.1/src/CIMA/utils/WalkFeatures.py +454 -0
  46. cima-1.0.1/src/CIMA/utils/WritePDB.py +156 -0
  47. cima-1.0.1/src/CIMA/utils/__init__.py +13 -0
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.1
2
+ Name: CIMA
3
+ Version: 1.0.1
4
+ Home-page: https://github.com/FarabellaLab/CIMA
5
+ Author: Irene Farabella
6
+ Author-email: irene.farabella@iit.it
7
+ Requires: NumPy (>=1.6)
8
+ Requires: Scipy (>= 0.1)
9
+ Requires: Skimage (>= 0.2)
10
+ License-File: LICENCE
@@ -0,0 +1,45 @@
1
+ LICENCE
2
+ README.md
3
+ setup.py
4
+ CIMA.egg-info/PKG-INFO
5
+ CIMA.egg-info/SOURCES.txt
6
+ CIMA.egg-info/dependency_links.txt
7
+ CIMA.egg-info/not-zip-safe
8
+ CIMA.egg-info/top_level.txt
9
+ src/CIMA/__init__.py
10
+ src/CIMA/assessment/Images_Assessment.py
11
+ src/CIMA/assessment/__init__.py
12
+ src/CIMA/detection/__init__.py
13
+ src/CIMA/detection/beads_identification.py
14
+ src/CIMA/detection/clusters.py
15
+ src/CIMA/maps/DensityProprieties.py
16
+ src/CIMA/maps/EMMap.py
17
+ src/CIMA/maps/MapFeatures.py
18
+ src/CIMA/maps/MapParser.py
19
+ src/CIMA/maps/MapSpatialFeatures.py
20
+ src/CIMA/maps/ScoringFunctions.py
21
+ src/CIMA/maps/StructureBlurrer.py
22
+ src/CIMA/maps/VQ.py
23
+ src/CIMA/maps/__init__.py
24
+ src/CIMA/maps/maptomap.py
25
+ src/CIMA/parsers/ParserCSV.py
26
+ src/CIMA/parsers/Parserh5py.py
27
+ src/CIMA/parsers/__init__.py
28
+ src/CIMA/patches/HomologSeparator.py
29
+ src/CIMA/patches/NuclearMask.py
30
+ src/CIMA/patches/SegmentReconstruction.py
31
+ src/CIMA/patches/__init__.py
32
+ src/CIMA/segments/SegmentConvex.py
33
+ src/CIMA/segments/SegmentFeatures.py
34
+ src/CIMA/segments/SegmentGaussian.py
35
+ src/CIMA/segments/SegmentInfo.py
36
+ src/CIMA/segments/SegmentInfoH5.py
37
+ src/CIMA/segments/SegmentInfoXYZ.py
38
+ src/CIMA/segments/SegmentSpatialFeatures.py
39
+ src/CIMA/segments/__init__.py
40
+ src/CIMA/utils/StatsFunction.py
41
+ src/CIMA/utils/Vector.py
42
+ src/CIMA/utils/Visualization.py
43
+ src/CIMA/utils/WalkFeatures.py
44
+ src/CIMA/utils/WritePDB.py
45
+ src/CIMA/utils/__init__.py
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+ CIMA
cima-1.0.1/LICENCE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2023, Irene Farabella
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cima-1.0.1/PKG-INFO ADDED
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 2.1
2
+ Name: CIMA
3
+ Version: 1.0.1
4
+ Home-page: https://github.com/FarabellaLab/CIMA
5
+ Author: Irene Farabella
6
+ Author-email: irene.farabella@iit.it
7
+ Requires: NumPy (>=1.6)
8
+ Requires: Scipy (>= 0.1)
9
+ Requires: Skimage (>= 0.2)
10
+ License-File: LICENCE
cima-1.0.1/README.md ADDED
@@ -0,0 +1,42 @@
1
+
2
+ ![Model](Notebooks/cima-log.png)
3
+
4
+ Chromatin IMaging Analysis tool (CIMA) is a python package that facilitate the automatic detection, assessment, and analysis of complex chromatin tracing experiments (as sequuential OligoSTORM one).
5
+
6
+ Author: Irene Farabella
7
+
8
+ ### Installation on Linux & Mac OSX
9
+ *************
10
+
11
+ [CIMA installation](https://gitlab.iit.it/ina/CIMA/-/blob/main/Notebooks/Installing%20CIMA.ipynb?ref_type=heads)
12
+
13
+
14
+ ### CIMA Notebooks examples
15
+ *************
16
+
17
+ [Notebooks](https://gitlab.iit.it/ina/CIMA/-/tree/main/Notebooks?ref_type=heads)
18
+ - Assessment
19
+ - Guided_identification_of_chromatin_segment
20
+
21
+
22
+
23
+ ### CIMA API Documentation
24
+ *************
25
+
26
+ NOTE: After the publication, CIMA will be public to all the users and the API will have a dedicated page. In the meantime, you can browse it off-line from:
27
+
28
+ [CIMA API](https://gitlab.iit.it/ina/CIMA/-/tree/main/pdocCIMA)
29
+
30
+ ### Citation
31
+ *************
32
+ If you use CIMA, please cite:<br>
33
+
34
+ Nir* G, Farabella* I, Pérez Estrada* C, Ebeling* CG, Beliveau BJ, Sasaki HM, Lee SD, Nguyen SC, McCole RB, Chattoraj S, Erceg J, AlHaj Abed J, Martins NMC, Nguyen HQ, Hannan MA, Russell S, Durand NC, Rao SSP, Kishi JY, Soler-Vila P, Di Pierro M, Onuchic JN, Callahan SP, Schreiner JM, Stuckey JA, Yin P, Aiden EL, Marti-Renom MA, Wu CT. Walking along chromosomes with super-resolution imaging, contact maps, and integrative modeling. PLoS Genet. 2018 Dec 26;14(12):e1007872. doi: 10.1371/journal.pgen.1007872. PMID: 30586358; PMCID: PMC6324821.
35
+
36
+ Other specific references:<br>
37
+ Farabella et al (2015) TEMPy: a Python library for assessment of three-dimensional electron microscopy density fits. J. Appl. Cryst. 48, 1314-1323
38
+
39
+ ### *FAQ*
40
+ --------
41
+ If you have any question remaining, we would be happy to answer informally:
42
+ irene.farabella@iit.it
cima-1.0.1/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
cima-1.0.1/setup.py ADDED
@@ -0,0 +1,69 @@
1
+ import sys, os,shutil
2
+ from distutils.core import setup
3
+
4
+ if os.path.exists('build')==True:
5
+ print("build exists")
6
+ shutil.rmtree('./build')
7
+
8
+ try:
9
+ import numpy
10
+ except ImportError:
11
+ sys.stderr.write('numpy is not installed, you can find it at: '
12
+ 'http://numpy.scipy.org\n')
13
+ sys.exit()
14
+
15
+ #control version
16
+ if [int(dgt) for dgt in numpy.__version__.split('.')[:2]] < [1, 6]:
17
+ sys.stderr.write('CIMA tools requires numpy v1.6 or later, you can find it at: '
18
+ 'http://numpy.scipy.org\n')
19
+ sys.exit()
20
+
21
+
22
+ try:
23
+ import skimage
24
+ except ImportError:
25
+ sys.stderr.write('skimage is not installed, you can find it at: ')
26
+ sys.exit()
27
+
28
+ if [int(dgt) for dgt in skimage.__version__.split('.')[:2]] < [0, 2]:
29
+ sys.stderr.write('CIMA tools requires skimage v0.2 or later, you can find it at: '
30
+ 'http://scikit-image.org\n')
31
+ sys.exit()
32
+
33
+ #Scipy>=???
34
+ try:
35
+ import scipy
36
+ except ImportError:
37
+ sys.stderr.write('Scipy is not installed, you can find it at: '
38
+ 'http://www.scipy.org/\n')
39
+ sys.exit()
40
+
41
+ if [int(dgt) for dgt in scipy.__version__.split('.')[:2]] < [0, 1]:
42
+ sys.stderr.write('CIMA requires Scipy v0.1 or later, you can find it at: '
43
+ 'http://www.scipy.org/\n')
44
+ sys.exit()
45
+
46
+ # Make sure I have the right Python version.
47
+ if sys.version_info[:2] < (3, 1):
48
+ print("CIMA requires Python 3.1 or better. Python %d.%d detected" % \
49
+ sys.version_info[:2])
50
+ print("Please upgrade your version of Python.")
51
+ sys.exit(-1)
52
+
53
+
54
+ setup(
55
+ name='CIMA',
56
+ version='1.0.1',
57
+ author='Irene Farabella',
58
+ author_email='irene.farabella@iit.it',
59
+ zip_safe=False,
60
+ packages=['CIMA','CIMA.parsers','CIMA.segments','CIMA.assessment','CIMA.utils','CIMA.patches','CIMA.maps','CIMA.detection'],
61
+ url='https://github.com/FarabellaLab/CIMA',
62
+ # license='LICENSE.txt',
63
+ description='',
64
+ # long_description=open('README.txt').read(),
65
+ package_dir = {'CIMA':'src/CIMA'},
66
+ package_data = {'CIMA': ['CIMA_data/*']},
67
+ requires=['NumPy (>=1.6)',
68
+ "Scipy (>= 0.1)", " Skimage (>= 0.2)"],
69
+ )
@@ -0,0 +1,17 @@
1
+ #===============================================================================
2
+ # This file is part of CIMA.
3
+ #
4
+ # CIMA is a software designed to help the user in the manipulation
5
+ # and analyses of genomic super resolution localisation data.
6
+ #
7
+ # Copyright 2019-2023
8
+ #
9
+ # Authors: Irene Farabella
10
+ #
11
+ #
12
+ #
13
+ #===============================================================================
14
+
15
+ """
16
+ .. include:: ../../README.md
17
+ """
@@ -0,0 +1,441 @@
1
+ #===============================================================================
2
+ # This file is part of CIMA.
3
+ #
4
+ # CIMA is a software designed to help the user in the manipulation
5
+ # and analyses of genomic super resolution localisation data.
6
+ #
7
+ # Copyright 2019-2023
8
+ #
9
+ # Authors: Irene Farabella
10
+ #
11
+ #
12
+ #
13
+ #===============================================================================
14
+
15
+ __docformat__ = "markdown"
16
+
17
+ from math import pi
18
+ from random import randrange
19
+ import CIMA.utils.Vector as Vector
20
+ import numpy as np
21
+ from numpy import ndarray,array,append,matrix
22
+ import os
23
+ import sys
24
+ import pandas as pd
25
+ from CIMA.parsers import ParserCSV as Parser
26
+ from CIMA.segments import SegmentGaussian as SG
27
+ from CIMA.maps import DensityProprieties as DS
28
+ from CIMA.maps import MapFeatures as MF
29
+ from CIMA.utils import WalkFeatures as WF
30
+ from CIMA.segments import SegmentInfo as SI
31
+
32
+ from CIMA.maps.ScoringFunctions import ScoringFunctions
33
+ from CIMA.segments.SegmentInfo import Segment
34
+
35
+
36
+ scorer = ScoringFunctions()
37
+
38
+ TB=SG.TransformBlurrer()
39
+
40
+ #saturation Plot
41
+ def Saturation_tofinal(endstructure: Segment,prec_mean=0.,mode="unit",maxframes=250,interval=5,ccc_mode=1.,getcom=False, selection_mode='frames', random_groups_num=50):
42
+ """
43
+ Calculates the saturation plot by evaluating the cross-correlation coefficient (CCC) between a reference structure and
44
+ cumulative subsets of its frames or random groups, allowing the assessment of structural saturation over time or random groups.
45
+
46
+ Args:
47
+ * endstructure (Segment): The reference structure used for CCC calculations.
48
+ * prec_mean (float, optional): Precision value used in Gaussian blurring. Defaults to 0.0.
49
+ * mode (str, optional): Mode for Gaussian blurring ('unit' or other available modes). Defaults to "unit".
50
+ * maxframes (int, optional): Maximum number of frames to process. Defaults to 250.
51
+ * interval (int, optional): Number of frames in each chunk for CCC calculation. Defaults to 5.
52
+ * ccc_mode (float, optional): Mode for calculating CCC between reference and partial structures. Defaults to 1.0.
53
+ * getcom (bool, optional): If True, includes the center of mass (COM) of partial structures in the output. Defaults to False.
54
+ * selection_mode (str, optional): Mode of selection for frames ('frames' or 'random'). Defaults to 'frames'.
55
+ * random_groups_num (int, optional): Number of random groups used if `selection_mode` is 'random'. Defaults to 50.
56
+
57
+ Returns:
58
+ * list: A list of scores, where each score is a list containing:
59
+ - Chunk ID (int)
60
+ - CCC value (float)
61
+ - Number of atoms in the partial structure (int)
62
+ - (Optional) COM of the partial structure (if `getcom` is True)
63
+ """
64
+ if(selection_mode == 'frames'):
65
+ maxframes=int(maxframes)
66
+ interval=int(interval)
67
+ frames=list(range(0,int(maxframes)))
68
+ frames_chucks = [frames[x:x+interval] for x in range(0, len(frames),interval)]
69
+ #print (frames_chucks)
70
+ #tmp=[]
71
+ scores=[]
72
+ tmp0=[]
73
+ strcture_list_chucks=[endstructure.getFrames(fr) for C, fr in enumerate(frames_chucks) if endstructure.getFrames(fr)!= None ]
74
+ elif(selection_mode == 'random'):
75
+ labels = np.random.choice(np.arange(0,random_groups_num), len(endstructure), replace=True)
76
+ strcture_list_chucks=[endstructure.copyWithNewContent(subdf) for n, subdf in endstructure.atomList.groupby(labels) if len(subdf)>0 ]
77
+ else:
78
+ raise ValueError('Selection mode not implemented')
79
+ #print (strcture_list_chucks)
80
+ C = 0
81
+ ncc = []
82
+ tmp = []
83
+ scores = []
84
+ #for fr in frames_chucks[0:1]:
85
+ # tmp0_s = endstructure.getFrames(fr)
86
+
87
+ # Run per cicle and add them upon convergence
88
+ for i in range(0,len(strcture_list_chucks)):
89
+ cc = strcture_list_chucks[i]
90
+ if cc:
91
+ if (i==0):
92
+ acc = strcture_list_chucks[0]
93
+ else:
94
+ acc.atomList = pd.concat([acc.atomList,cc.atomList])
95
+ acc.copyWithNewContent(acc.atomList)
96
+ C+=1
97
+ tmp_map = TB.SR_gaussian_blur(acc, prec_mean, sigma_coeff=1.,mode=mode)
98
+ endstructuremap = TB.SR_gaussian_blur(endstructure, prec_mean, sigma_coeff=1.,mode=mode)
99
+ cth = 0.5
100
+ cth2 = 0.5
101
+ map_s1g,map_s2g = MF._match_grid(endstructuremap,tmp_map)
102
+ ccctmp,ovtmp = scorer.CCC_map(map_s1g,map_s2g,map_target_threshold=cth,map_probe_threshold=cth2,mode=ccc_mode)
103
+ # ccctmp = scorer.CCC_simple(map_s1g, map_s2g, map1_thr=cth,map2_thr=cth2,mode=ccc_mode)
104
+ if getcom==True:
105
+ COM2=tmp_map._get_com_threshold(cth2)
106
+ scores.append([C,ccctmp,len(cc.atomList),COM2])
107
+ else:
108
+ scores.append([C,ccctmp,len(cc.atomList)])
109
+ return scores
110
+
111
+
112
+
113
+ def _Saturation_incremental(endstructure: Segment,prec_mean=0.,mode="unit",maxframes=250,interval=5,ccc_mode=1.):
114
+ """
115
+ Arguments:
116
+
117
+ *endstructure*
118
+ an input structure that serves as the reference structure.
119
+ *prec_mean*
120
+ the precision value for the Gaussian blur function used in the function.
121
+ *maxframes*
122
+ the maximum number of frames to use for calculating the saturation.
123
+ *interval*
124
+ the number of locations to use in each chunk for calculating the saturation.
125
+ *ccc_mode*
126
+ the mode for calculating the cross-correlation coefficient (CCC) between the reference structure and the partial structures.
127
+ *getcom*
128
+ a Boolean parameter indicating whether to include the center of mass (COM) of the partial structures in the output.
129
+
130
+
131
+ Return:
132
+
133
+ An array of 3-list (Id, score, number of localisation)
134
+ The function then returns a list of scores, where each score corresponds to a chunk of frames and includes the CCC value and the number of atoms in the partial structure.
135
+ If getcom is True, the output also includes the COM of the partial structure.
136
+ """
137
+ maxframes=int(maxframes)
138
+ interval=int(interval)
139
+ frames=list(range(0,int(maxframes)))
140
+ frames_chucks = [frames[x:x+interval] for x in range(0, len(frames),interval)]
141
+ tmp=[]
142
+ scores=[]
143
+ tmp_ref=[]
144
+ for fr in frames_chucks[0:1]:
145
+ tmp_ref = endstructure.getFrames(fr)
146
+
147
+ if tmp_ref is None:
148
+ tmp_ref=False
149
+ else:
150
+ tmp_ref=tmp_ref
151
+
152
+ for C, fr in enumerate(frames_chucks):
153
+ C+=1
154
+ tmp = endstructure.getFrames(fr)
155
+ if tmp is None:
156
+ scores.append([C,0,0])
157
+ else:
158
+ tmp_str=tmp
159
+ #print(tmp_ref)
160
+ tmp_map=TB.SR_gaussian_blur(tmp_str, prec_mean, sigma_coeff=1.,mode=mode)
161
+ if tmp_ref==False:
162
+ scores.append([C,0,0])
163
+ else:
164
+ endstructuremap=TB.SR_gaussian_blur(tmp_ref, prec_mean, sigma_coeff=1.,mode=mode)
165
+ #cth=DS.calculate_map_threshold_SR(endstructuremap)
166
+ #cth2=DS.calculate_map_threshold_SR(tmp_map)
167
+ cth=0.5
168
+ cth2=0.5
169
+
170
+ map_s1g,map_s2g=MF._match_grid(endstructuremap,tmp_map)
171
+ ccctmp,ovtmp=scorer.CCC_map(map_s1g,map_s2g,map_target_threshold=cth,map_probe_threshold=cth2,mode=ccc_mode)
172
+ scores.append([C,ccctmp,len(tmp_str.atomList)])
173
+ tmp_ref=tmp_str
174
+
175
+
176
+ return scores
177
+
178
+
179
+
180
+ def Assessment_Chrom_Precision(StructureObj,chrin,nuclei="",date="",hom="",pathin="",writeout=True):
181
+
182
+ """
183
+ Assesses chromatin structure precision over time and outputs summary data.
184
+
185
+ This function calculates the mean positional precision of chromatin data across timepoints
186
+ in a given structure. It then compiles this information into a summary table and optionally
187
+ writes the data to a file.
188
+
189
+ Args:
190
+ * StructureObj (Segment): The structure object containing chromatin data.
191
+ * chrin (str): Identifier for the chromatin input structure.
192
+ * nuclei (str, optional): Label for the output file. Defaults to an empty string.
193
+ * date (str, optional): Identifier for the date of the experiment. Defaults to an empty string.
194
+ * hom (str, optional): Identifier for homology data in the experiment. Defaults to an empty string.
195
+ * pathin (str, optional): Directory path for saving the output file. Defaults to an empty string.
196
+ * writeout (bool, optional): If True, writes the assessment data to a file. Defaults to True.
197
+
198
+ Returns:
199
+ * list: A list containing assessment data. Each entry includes:
200
+ - Chromatin ID (`chrin`)
201
+ - Timepoint label
202
+ - Nuclei label
203
+ - Date of experiment
204
+ - Homology identifier
205
+ - Mean precision values (x, y, z)
206
+ - Number of localizations at the timepoint
207
+ - Total number of timepoints
208
+ """
209
+
210
+ table_out=""
211
+ listout=[]
212
+ timechrin=StructureObj.split_into_time()
213
+ prec_mean_ch=StructureObj.GetMeanPrecision()
214
+ nlocchrin=len(StructureObj.atomList)
215
+ timepoint_list=[]
216
+ for t1 in range(len(timechrin)):
217
+ lab1=timechrin[t1].atomList.iloc[0].timepoint
218
+ prec_mean_time=timechrin[t1].GetMeanPrecision()
219
+ nloctime=len(timechrin[t1].atomList)
220
+ listouttmp=[chrin,lab1,nuclei,date,hom,prec_mean_time[0],prec_mean_time[1],prec_mean_time[2],nloctime,0]
221
+ listout.append(listouttmp)
222
+ #timepoint_list.append(lab1)
223
+ table_out+="%s,%s,%s,%s,%s,%s,%s,%s\n"%(date,hom,lab1,prec_mean_time[0],prec_mean_time[1],prec_mean_time[2],nloctime,0)
224
+
225
+ table_out+="%s,%s,%s,%s,%s,%s,%s,%s\n"%(date,hom,0,prec_mean_ch[0],prec_mean_ch[1],prec_mean_ch[2],nlocchrin,len(timechrin))
226
+
227
+ listout.append([chrin,0,nuclei,date,hom,prec_mean_ch[0],prec_mean_ch[1],prec_mean_ch[2],nlocchrin,len(timechrin)])
228
+
229
+ if writeout==True:
230
+ import os
231
+ FOUT=pathin+"Assessment/"+"multi_assessment_precision_chr%s_%s_%s_%s.txt"%(chrin,date,nuclei,hom)
232
+ if not os.path.isdir(pathin+"Assessment/"):
233
+ os.mkdir(pathin+"Assessment/")
234
+ fout=open(FOUT,"w")
235
+ fout.write("Date,hom,Segment,pmeanx,pmeany,pmeanz,nloc,ntime\n")
236
+ fout.write(table_out)
237
+ return listout
238
+
239
+
240
+
241
+ # def _Saturation_tofinal_cycle_incremental_marcius(endstructure,prec_mean=0.,mode="unit",ccc_mode=1.,merge=1):#,getcom=False):
242
+ # """
243
+ # Arguments:
244
+
245
+ # *endstructure*
246
+ # an input structure that serves as the reference structure.
247
+ # *prec_mean*
248
+ # the precision value for the Gaussian blur function used in the function.
249
+ # *mode*
250
+ # a string indicating the mode for the Gaussian blur function used in the function.
251
+ # *ccc_mode*
252
+ # the mode for calculating the cross-correlation coefficient (CCC) between the reference structure and the partial structures.
253
+ # *getcom*
254
+ # a Boolean parameter indicating whether to include the center of mass (COM) of the partial structures in the output.
255
+
256
+
257
+ # Return:
258
+ # An array of 3-list (Id, score, number of localisation)
259
+ # The list includes the cycle number, CCC score, number of atoms in the cycle, and optionally, the center of mass for the cycle.
260
+ # """
261
+ # cicli = endstructure.split_into_cycle()
262
+ # C = 0
263
+ # ncc = []
264
+ # tmp = []
265
+ # scores = []
266
+ # # Run per cicle and add them upon convergence
267
+ # for i in range(0,len(cicli)):
268
+ # cc = cicli[i]
269
+ # if (i==0):
270
+ # acc = cicli[0]
271
+ # else:
272
+ # acc.atomList = pd.concat([acc.atomList,cc.atomList])
273
+ # acc.copyWithNewContent(acc.atomList)
274
+ # C+=1
275
+ # tmp_map = TB.SR_gaussian_blur(acc, prec_mean, sigma_coeff=1.,mode=mode)
276
+ # endstructuremap = TB.SR_gaussian_blur(endstructure, prec_mean, sigma_coeff=1.,mode=mode)
277
+ # #print (acc)
278
+ # #print (tmp_map)
279
+ # #print (endstructuremap)
280
+ # cth = 0.5
281
+ # cth2 = 0.5
282
+ # map_s1g,map_s2g = MF._match_grid(endstructuremap,tmp_map)
283
+ # ccctmp,ovtmp = scorer.CCC_map(map_s1g,map_s2g,map_target_threshold=cth,map_probe_threshold=cth2,mode=ccc_mode)
284
+ # scores.append([C,ccctmp,len(cc.atomList)])
285
+ # return scores
286
+
287
+ def Cycle_assessment(endstructure,prec_mean=0.,mode="unit",ccc_mode=1.,merge=1):#,getcom=False):
288
+ """
289
+ Performs cycle-based assessment of a structure using cross-correlation coefficient (CCC) calculations.
290
+
291
+ This function evaluates the similarity between each cycle in the input structure (`endstructure`)
292
+ and the overall structure by calculating the CCC. Each cycle is processed individually to compute
293
+ the CCC score relative to the full structure, allowing for an assessment of structural changes over cycles.
294
+
295
+ Args:
296
+ * endstructure (Segment): The reference structure used for CCC calculations.
297
+ * prec_mean (float, optional): Precision value used in Gaussian blurring. Defaults to 0.0.
298
+ * mode (str, optional): Mode for Gaussian blurring ('unit' or other available modes). Defaults to "unit".
299
+ * ccc_mode (float, optional): Mode for calculating CCC between reference and cycle structures. Defaults to 1.0.
300
+ * merge (int, optional): Reserved for future extensions to merge cycles, currently unused.
301
+
302
+ Returns:
303
+ * list: A list of lists, where each inner list contains:
304
+ - Cycle number (int)
305
+ - CCC score (float)
306
+ - Number of atoms in the cycle (int)
307
+ """
308
+
309
+
310
+ C=0
311
+ tmp=[]
312
+ scores=[]
313
+ cycles=endstructure.split_into_cycle()
314
+ #print (len(cicli))
315
+ for cc in cycles:
316
+ C+=1
317
+ tmp_map=TB.SR_gaussian_blur(cc, prec_mean, sigma_coeff=1.,mode=mode)
318
+ endstructuremap=TB.SR_gaussian_blur(endstructure, prec_mean, sigma_coeff=1.,mode=mode)
319
+ #cth=DS.calculate_map_threshold_SR(endstructuremap)
320
+ cth=0.5
321
+ cth2=0.5
322
+ #cth2=DS.calculate_map_threshold_SR(tmp_map)
323
+ map_s1g,map_s2g=MF._match_grid(endstructuremap,tmp_map)
324
+ ccctmp,ovtmp=scorer.CCC_map(map_s1g,map_s2g,map_target_threshold=cth,map_probe_threshold=cth2,mode=ccc_mode)
325
+ scores.append([C,ccctmp,len(cc.atomList)])
326
+ return scores
327
+
328
+ def _Halfdataset_ccc(endstructure,prec_mean=45.,mode="unit",ccc_mode=1.):
329
+ """
330
+ Arguments:
331
+
332
+ *endstructure*
333
+ an input structure that serves as the reference structure.
334
+ *prec_mean*
335
+ the precision value for the Gaussian blur function used in the function.
336
+ *maxframes*
337
+ the maximum number of frames to use for calculating the saturation.
338
+ *interval*
339
+ the number of locations to use in each chunk for calculating the saturation.
340
+ *ccc_mode*
341
+ the mode for calculating the cross-correlation coefficient (CCC) between the reference structure and the partial structures.
342
+ *getcom*
343
+ a Boolean parameter indicating whether to include the center of mass (COM) of the partial structures in the output.
344
+
345
+ Return:
346
+
347
+ list of scores, where each score corresponds to a chunk of frames and includes the CCC value and the number of atoms in the partial structure.
348
+ If getcom is True, the output also includes the COM of the partial structure.
349
+
350
+ Id, score, number of localisation
351
+ """
352
+ df=endstructure.atomList
353
+ shuffled_df = df.sample(frac=1)
354
+ splitted_df = np.array_split(shuffled_df, 2)
355
+ #print (len(splitted_df))
356
+ str1=endstructure.copy()
357
+ str2=endstructure.copy()
358
+ #print (str1,str2)
359
+ str1=str1.copyWithNewContent(splitted_df[0])
360
+ str2=str2.copyWithNewContent(splitted_df[1])
361
+ #print (str1,str2)
362
+ tmp_map1=TB.SR_gaussian_blur(str1, prec_mean, sigma_coeff=1.,mode=mode)
363
+ tmp_map2=TB.SR_gaussian_blur(str2, prec_mean, sigma_coeff=1.,mode=mode)
364
+ tmp_map1,tmp_map2=MF._match_grid(tmp_map1,tmp_map2)
365
+ ccctmp,ovtmp=scorer.CCC_map(tmp_map1,tmp_map2,map_target_threshold=0.5,map_probe_threshold=0.5,mode=ccc_mode)
366
+ return [ccctmp,str1.GetMeanPrecision()[2],str2.GetMeanPrecision()[2]]
367
+
368
+
369
+ def Saturation_experimentpseudotime(endstructure: Segment,numberoflocations=100,prec_mean=0.,mode="unit",ccc_mode=1.,getcom=False):
370
+ """
371
+ Calculates saturation over experimental pseudotime by evaluating the cross-correlation coefficient (CCC)
372
+ between the reference structure and cumulative subsets of frames, allowing for an assessment of structural
373
+ stability over pseudotime.
374
+
375
+ Args:
376
+ * endstructure (Segment): The reference structure used for CCC calculations.
377
+ * numberoflocations (int, optional): The number of locations to use in each chunk for CCC calculation. Defaults to 100.
378
+ * prec_mean (float, optional): Precision value used in Gaussian blurring. Defaults to 0.0.
379
+ * mode (str, optional): Mode for Gaussian blurring ('unit' or other available modes). Defaults to "unit".
380
+ * ccc_mode (float, optional): Mode for calculating CCC between reference and partial structures. Defaults to 1.0.
381
+ * getcom (bool, optional): If True, includes the center of mass (COM) of partial structures in the output. Defaults to False.
382
+
383
+ Returns:
384
+ * list: A list of lists, where each inner list contains:
385
+ - Pseudotime step (int)
386
+ - CCC score (float)
387
+ - Number of localizations in the chunk (int)
388
+ - (Optional) COM of the partial structure (if `getcom` is True)
389
+ """
390
+
391
+ StrObjOrdered=endstructure.OrderbyExperimenttime()
392
+ #print (StrObjOrdered)
393
+ maxframes=len(StrObjOrdered.atomList)
394
+ maxframes=int(maxframes)
395
+ interval=int(numberoflocations)
396
+ frames=list(range(0,int(maxframes)))
397
+ frames_chucks = [frames[x:x+interval] for x in range(0, len(frames),interval)]
398
+ #print (frames_chucks)
399
+ C=0
400
+ tmp=[]
401
+ scores=[]
402
+ tmp_ref=[]
403
+ for fr in frames_chucks[0:1]:
404
+ countx=0
405
+ tmp_ref = endstructure.getInRange([f-1 for f in fr])
406
+
407
+ if tmp_ref is None:
408
+ tmp_ref=False
409
+
410
+ for C, fr in enumerate(frames_chucks):
411
+ C+=1
412
+ local_fr_parcial=[]
413
+ countx=0
414
+ tmp = endstructure.getInRange([f-1 for f in fr])
415
+ if tmp is None:
416
+ scores.append([C,0,0])
417
+ else:
418
+ tmp_str=tmp
419
+ print(tmp_ref,tmp_str)
420
+ tmp_map=TB.SR_gaussian_blur(tmp_str, prec_mean, sigma_coeff=1.,mode=mode)
421
+ if tmp_ref==False:
422
+ scores.append([C,0,0])
423
+ else:
424
+ endstructuremap=TB.SR_gaussian_blur(tmp_ref, prec_mean, sigma_coeff=1.,mode=mode)
425
+ #cth=DS.calculate_map_threshold_SR(endstructuremap)
426
+ #cth2=DS.calculate_map_threshold_SR(tmp_map)
427
+ cth=0.5
428
+ cth2=0.5
429
+
430
+ map_s1g,map_s2g=MF._match_grid(endstructuremap,tmp_map)
431
+ ccctmp,ovtmp=scorer.CCC_map(map_s1g,map_s2g,map_target_threshold=cth,map_probe_threshold=cth2,mode=ccc_mode)
432
+ scores.append([C,ccctmp,len(tmp_str.atomList)])
433
+ tmp_ref=tmp_str
434
+
435
+
436
+ return scores
437
+
438
+
439
+ def _split(a, n):
440
+ k, m = divmod(len(a), n)
441
+ return list((a[i*k+min(i, m):(i+1)*k+min(i+1, m)] for i in range(n)))