dcatoolkit 0.1.3__tar.gz → 0.1.5__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.
- {dcatoolkit-0.1.3 → dcatoolkit-0.1.5}/LICENSE +21 -21
- {dcatoolkit-0.1.3/src/dcatoolkit.egg-info → dcatoolkit-0.1.5}/PKG-INFO +57 -57
- {dcatoolkit-0.1.3 → dcatoolkit-0.1.5}/README.md +2 -2
- {dcatoolkit-0.1.3 → dcatoolkit-0.1.5}/pyproject.toml +53 -53
- {dcatoolkit-0.1.3 → dcatoolkit-0.1.5}/setup.cfg +4 -4
- {dcatoolkit-0.1.3 → dcatoolkit-0.1.5}/src/dcatoolkit/__init__.py +3 -3
- {dcatoolkit-0.1.3 → dcatoolkit-0.1.5}/src/dcatoolkit/analytics.py +144 -144
- {dcatoolkit-0.1.3 → dcatoolkit-0.1.5}/src/dcatoolkit/representation.py +928 -877
- {dcatoolkit-0.1.3 → dcatoolkit-0.1.5/src/dcatoolkit.egg-info}/PKG-INFO +57 -57
- {dcatoolkit-0.1.3 → dcatoolkit-0.1.5}/src/dcatoolkit.egg-info/SOURCES.txt +0 -0
- {dcatoolkit-0.1.3 → dcatoolkit-0.1.5}/src/dcatoolkit.egg-info/dependency_links.txt +0 -0
- {dcatoolkit-0.1.3 → dcatoolkit-0.1.5}/src/dcatoolkit.egg-info/requires.txt +0 -0
- {dcatoolkit-0.1.3 → dcatoolkit-0.1.5}/src/dcatoolkit.egg-info/top_level.txt +0 -0
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Raheel Syed Ahmed
|
|
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.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Raheel Syed Ahmed
|
|
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.
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: dcatoolkit
|
|
3
|
-
Version: 0.1.
|
|
4
|
-
Summary: Collection of useful modules and representations for managing DCA output data.
|
|
5
|
-
Author-email: Raheel Syed Ahmed <raheelsyedahmed@gmail.com>
|
|
6
|
-
Maintainer-email: Raheel Syed Ahmed <raheelsyedahmed@gmail.com>
|
|
7
|
-
License: MIT License
|
|
8
|
-
|
|
9
|
-
Copyright (c) 2024 Raheel Syed Ahmed
|
|
10
|
-
|
|
11
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
-
in the Software without restriction, including without limitation the rights
|
|
14
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
-
furnished to do so, subject to the following conditions:
|
|
17
|
-
|
|
18
|
-
The above copyright notice and this permission notice shall be included in all
|
|
19
|
-
copies or substantial portions of the Software.
|
|
20
|
-
|
|
21
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
-
SOFTWARE.
|
|
28
|
-
|
|
29
|
-
Keywords: dca,toolkit,DI,coevolution
|
|
30
|
-
Classifier: Development Status :: 4 - Beta
|
|
31
|
-
Classifier: Intended Audience :: Science/Research
|
|
32
|
-
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
33
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
-
Classifier: Programming Language :: Python :: 3
|
|
35
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
36
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
37
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
38
|
-
Requires-Python: >=3.10
|
|
39
|
-
Description-Content-Type: text/markdown
|
|
40
|
-
License-File: LICENSE
|
|
41
|
-
Requires-Dist: biotite
|
|
42
|
-
Requires-Dist: matplotlib>=3.8.0
|
|
43
|
-
Requires-Dist: numpy>=1.26.0
|
|
44
|
-
Requires-Dist: pandas>=2.1.0
|
|
45
|
-
Requires-Dist: scikit-learn>=1.3
|
|
46
|
-
Requires-Dist: scipy>=1.11.0
|
|
47
|
-
Provides-Extra: tests
|
|
48
|
-
Requires-Dist: pytest; extra == "tests"
|
|
49
|
-
Provides-Extra: docs
|
|
50
|
-
Requires-Dist: sphinx; extra == "docs"
|
|
51
|
-
Requires-Dist: pdoc; extra == "docs"
|
|
52
|
-
Requires-Dist: numpydoc; extra == "docs"
|
|
53
|
-
Provides-Extra: lint
|
|
54
|
-
Requires-Dist: ruffle; extra == "lint"
|
|
55
|
-
|
|
56
|
-
# dcatoolkit
|
|
57
|
-
Collection of useful modules and representations for managing DCA output data.
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: dcatoolkit
|
|
3
|
+
Version: 0.1.5
|
|
4
|
+
Summary: Collection of useful modules and representations for managing DCA output data.
|
|
5
|
+
Author-email: Raheel Syed Ahmed <raheelsyedahmed@gmail.com>
|
|
6
|
+
Maintainer-email: Raheel Syed Ahmed <raheelsyedahmed@gmail.com>
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2024 Raheel Syed Ahmed
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
|
|
29
|
+
Keywords: dca,toolkit,DI,coevolution
|
|
30
|
+
Classifier: Development Status :: 4 - Beta
|
|
31
|
+
Classifier: Intended Audience :: Science/Research
|
|
32
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Programming Language :: Python :: 3
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
38
|
+
Requires-Python: >=3.10
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
License-File: LICENSE
|
|
41
|
+
Requires-Dist: biotite
|
|
42
|
+
Requires-Dist: matplotlib>=3.8.0
|
|
43
|
+
Requires-Dist: numpy>=1.26.0
|
|
44
|
+
Requires-Dist: pandas>=2.1.0
|
|
45
|
+
Requires-Dist: scikit-learn>=1.3
|
|
46
|
+
Requires-Dist: scipy>=1.11.0
|
|
47
|
+
Provides-Extra: tests
|
|
48
|
+
Requires-Dist: pytest; extra == "tests"
|
|
49
|
+
Provides-Extra: docs
|
|
50
|
+
Requires-Dist: sphinx; extra == "docs"
|
|
51
|
+
Requires-Dist: pdoc; extra == "docs"
|
|
52
|
+
Requires-Dist: numpydoc; extra == "docs"
|
|
53
|
+
Provides-Extra: lint
|
|
54
|
+
Requires-Dist: ruffle; extra == "lint"
|
|
55
|
+
|
|
56
|
+
# dcatoolkit
|
|
57
|
+
Collection of useful modules and representations for managing DCA output data.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
# dcatoolkit
|
|
2
|
-
Collection of useful modules and representations for managing DCA output data.
|
|
1
|
+
# dcatoolkit
|
|
2
|
+
Collection of useful modules and representations for managing DCA output data.
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
[build-system]
|
|
2
|
-
requires = ["setuptools >= 61.0"]
|
|
3
|
-
build-backend = "setuptools.build_meta"
|
|
4
|
-
|
|
5
|
-
[project]
|
|
6
|
-
name = "dcatoolkit"
|
|
7
|
-
version = "0.1.
|
|
8
|
-
description = "Collection of useful modules and representations for managing DCA output data."
|
|
9
|
-
keywords = ["dca", "toolkit", "DI", "coevolution"]
|
|
10
|
-
|
|
11
|
-
readme = "README.md"
|
|
12
|
-
license = {file = "LICENSE"}
|
|
13
|
-
|
|
14
|
-
requires-python = ">=3.10"
|
|
15
|
-
|
|
16
|
-
authors = [
|
|
17
|
-
{name = "Raheel Syed Ahmed", email = "raheelsyedahmed@gmail.com"}
|
|
18
|
-
]
|
|
19
|
-
maintainers = [
|
|
20
|
-
{name = "Raheel Syed Ahmed", email = "raheelsyedahmed@gmail.com"}
|
|
21
|
-
]
|
|
22
|
-
|
|
23
|
-
dependencies = [
|
|
24
|
-
"biotite",
|
|
25
|
-
"matplotlib>=3.8.0",
|
|
26
|
-
"numpy>=1.26.0",
|
|
27
|
-
"pandas>=2.1.0",
|
|
28
|
-
"scikit-learn>=1.3",
|
|
29
|
-
"scipy>=1.11.0",
|
|
30
|
-
]
|
|
31
|
-
|
|
32
|
-
classifiers = [
|
|
33
|
-
"Development Status :: 4 - Beta",
|
|
34
|
-
"Intended Audience :: Science/Research",
|
|
35
|
-
"Topic :: Scientific/Engineering :: Bio-Informatics",
|
|
36
|
-
"License :: OSI Approved :: MIT License",
|
|
37
|
-
"Programming Language :: Python :: 3",
|
|
38
|
-
"Programming Language :: Python :: 3.10",
|
|
39
|
-
"Programming Language :: Python :: 3.11",
|
|
40
|
-
"Programming Language :: Python :: 3.12",
|
|
41
|
-
]
|
|
42
|
-
|
|
43
|
-
[project.optional-dependencies]
|
|
44
|
-
tests = [
|
|
45
|
-
"pytest",
|
|
46
|
-
]
|
|
47
|
-
docs = [
|
|
48
|
-
"sphinx",
|
|
49
|
-
"pdoc",
|
|
50
|
-
"numpydoc"
|
|
51
|
-
]
|
|
52
|
-
lint = [
|
|
53
|
-
"ruffle",
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools >= 61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dcatoolkit"
|
|
7
|
+
version = "0.1.5"
|
|
8
|
+
description = "Collection of useful modules and representations for managing DCA output data."
|
|
9
|
+
keywords = ["dca", "toolkit", "DI", "coevolution"]
|
|
10
|
+
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
license = {file = "LICENSE"}
|
|
13
|
+
|
|
14
|
+
requires-python = ">=3.10"
|
|
15
|
+
|
|
16
|
+
authors = [
|
|
17
|
+
{name = "Raheel Syed Ahmed", email = "raheelsyedahmed@gmail.com"}
|
|
18
|
+
]
|
|
19
|
+
maintainers = [
|
|
20
|
+
{name = "Raheel Syed Ahmed", email = "raheelsyedahmed@gmail.com"}
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
dependencies = [
|
|
24
|
+
"biotite",
|
|
25
|
+
"matplotlib>=3.8.0",
|
|
26
|
+
"numpy>=1.26.0",
|
|
27
|
+
"pandas>=2.1.0",
|
|
28
|
+
"scikit-learn>=1.3",
|
|
29
|
+
"scipy>=1.11.0",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
classifiers = [
|
|
33
|
+
"Development Status :: 4 - Beta",
|
|
34
|
+
"Intended Audience :: Science/Research",
|
|
35
|
+
"Topic :: Scientific/Engineering :: Bio-Informatics",
|
|
36
|
+
"License :: OSI Approved :: MIT License",
|
|
37
|
+
"Programming Language :: Python :: 3",
|
|
38
|
+
"Programming Language :: Python :: 3.10",
|
|
39
|
+
"Programming Language :: Python :: 3.11",
|
|
40
|
+
"Programming Language :: Python :: 3.12",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[project.optional-dependencies]
|
|
44
|
+
tests = [
|
|
45
|
+
"pytest",
|
|
46
|
+
]
|
|
47
|
+
docs = [
|
|
48
|
+
"sphinx",
|
|
49
|
+
"pdoc",
|
|
50
|
+
"numpydoc"
|
|
51
|
+
]
|
|
52
|
+
lint = [
|
|
53
|
+
"ruffle",
|
|
54
54
|
]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
[egg_info]
|
|
2
|
-
tag_build =
|
|
3
|
-
tag_date = 0
|
|
4
|
-
|
|
1
|
+
[egg_info]
|
|
2
|
+
tag_build =
|
|
3
|
+
tag_date = 0
|
|
4
|
+
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
__version__ = "0.1.
|
|
3
|
-
from .representation import Pairs, DirectInformationData, StructureInformation, ResidueAlignment
|
|
1
|
+
|
|
2
|
+
__version__ = "0.1.5"
|
|
3
|
+
from .representation import Pairs, DirectInformationData, StructureInformation, ResidueAlignment
|
|
4
4
|
from .analytics import MSATools
|
|
@@ -1,145 +1,145 @@
|
|
|
1
|
-
import re
|
|
2
|
-
from collections import Counter
|
|
3
|
-
from typing import Optional
|
|
4
|
-
import string
|
|
5
|
-
|
|
6
|
-
class MSATools:
|
|
7
|
-
"""
|
|
8
|
-
Tools and interface for encapsulating MSA data and providing functionality for filtering and analysis.
|
|
9
|
-
|
|
10
|
-
Parameters
|
|
11
|
-
----------
|
|
12
|
-
MSA : list of tuple of str, str
|
|
13
|
-
Loaded MSA that is a list of tuples where the first element is the header and the second element is its corresponding sequence.
|
|
14
|
-
"""
|
|
15
|
-
def __init__(self, MSA: list[tuple[str, str]]):
|
|
16
|
-
self.MSA = MSA
|
|
17
|
-
|
|
18
|
-
@staticmethod
|
|
19
|
-
def load_from_file(msa_filepath: str) -> 'MSATools':
|
|
20
|
-
"""
|
|
21
|
-
Generates MSATools object from an MSA file in ".afa" format.
|
|
22
|
-
|
|
23
|
-
Parameters
|
|
24
|
-
----------
|
|
25
|
-
msa_filepath : str
|
|
26
|
-
Filepath of the MSA in ".afa" format that is provided.
|
|
27
|
-
|
|
28
|
-
Returns
|
|
29
|
-
-------
|
|
30
|
-
MSATools
|
|
31
|
-
An MSATools instance with the appropriate list of (header, sequence) tuples where sequences are simplified and converted to single line format.
|
|
32
|
-
"""
|
|
33
|
-
msa_entries: list[tuple[str, str]] = []
|
|
34
|
-
with open(msa_filepath, 'r') as fs:
|
|
35
|
-
data = fs.read()
|
|
36
|
-
split_data = data.split(">")[1:]
|
|
37
|
-
for entry in split_data:
|
|
38
|
-
line_split_entry = entry.split("\n")
|
|
39
|
-
header = line_split_entry[0]
|
|
40
|
-
sequence = "".join(line_split_entry[1:])
|
|
41
|
-
msa_entries.append((">"+header, sequence))
|
|
42
|
-
return MSATools(msa_entries)
|
|
43
|
-
|
|
44
|
-
@staticmethod
|
|
45
|
-
def get_sequence_max_cont_gaps(sequence: str) -> int:
|
|
46
|
-
"""
|
|
47
|
-
Find maximum number of continuous gaps in a specific sequence.
|
|
48
|
-
|
|
49
|
-
Parameters
|
|
50
|
-
----------
|
|
51
|
-
sequence : str
|
|
52
|
-
Sequence of characters, potentially containing multiple of '-', a gap character.
|
|
53
|
-
|
|
54
|
-
Returns
|
|
55
|
-
-------
|
|
56
|
-
int
|
|
57
|
-
The maximum number of continuous gaps in a sequence.
|
|
58
|
-
"""
|
|
59
|
-
dash_match = re.findall(r"-+", sequence)
|
|
60
|
-
gap_counts = [len(match) for match in dash_match]
|
|
61
|
-
if len(gap_counts) > 0:
|
|
62
|
-
return max(gap_counts)
|
|
63
|
-
else:
|
|
64
|
-
return 0
|
|
65
|
-
|
|
66
|
-
def gap_frequency(self) -> tuple[dict[int, int], dict[int, float]]:
|
|
67
|
-
"""
|
|
68
|
-
Calculates the frequency of maximum continuous gaps throughout the MSA where the key corresponds to the number of continous gaps and the value corresponds to the number of sequences or the cumulative percentage of their sequences.
|
|
69
|
-
|
|
70
|
-
Returns
|
|
71
|
-
-------
|
|
72
|
-
tuple of dict of int, int and dict of int, int
|
|
73
|
-
Two element tuple where first element is a frequency count dictionary and the second element is a cumulative percentage of sequences with a specific maximum number of continous gaps.
|
|
74
|
-
"""
|
|
75
|
-
max_gap_counts = []
|
|
76
|
-
for header, sequence in self.MSA:
|
|
77
|
-
max_gap_counts.append(MSATools.get_sequence_max_cont_gaps(sequence))
|
|
78
|
-
frequency_count_dict = dict(Counter(max_gap_counts))
|
|
79
|
-
cumul_perc_dict = {}
|
|
80
|
-
cumul_count = 0
|
|
81
|
-
for key in sorted(frequency_count_dict.keys()):
|
|
82
|
-
value = frequency_count_dict[key]
|
|
83
|
-
cumul_count += value
|
|
84
|
-
cumul_perc_dict[key] = cumul_count / len(self.MSA)
|
|
85
|
-
return (frequency_count_dict, cumul_perc_dict)
|
|
86
|
-
|
|
87
|
-
def filter_by_continuous_gaps(self, max_gaps: Optional[int]=None) -> list[tuple[str, str]]:
|
|
88
|
-
"""
|
|
89
|
-
Filter out entries in your MSA by the number of maximum continuous gaps specified unless None is provided. Also, removes .s and lowercase letters from the sequence.
|
|
90
|
-
|
|
91
|
-
Parameters
|
|
92
|
-
----------
|
|
93
|
-
max_gaps : int
|
|
94
|
-
The maximum allowed number of continuous gaps in a sequence
|
|
95
|
-
|
|
96
|
-
Returns
|
|
97
|
-
-------
|
|
98
|
-
list of tuple of str, str
|
|
99
|
-
List of entries that are valid in that their sequences' number of maximum continuous gaps is within the threshold supplied as `max_gaps`.
|
|
100
|
-
"""
|
|
101
|
-
table = str.maketrans('', '', string.ascii_lowercase+".")
|
|
102
|
-
if max_gaps == None:
|
|
103
|
-
kept_entries = []
|
|
104
|
-
for header, sequence in self.MSA:
|
|
105
|
-
sequence = sequence.translate(table)
|
|
106
|
-
kept_entries.append((header, sequence))
|
|
107
|
-
return kept_entries
|
|
108
|
-
else:
|
|
109
|
-
kept_entries = []
|
|
110
|
-
for header, sequence in self.MSA:
|
|
111
|
-
sequence = sequence.translate(table)
|
|
112
|
-
if MSATools.get_sequence_max_cont_gaps(sequence) <= max_gaps:
|
|
113
|
-
kept_entries.append((header, sequence))
|
|
114
|
-
return kept_entries
|
|
115
|
-
|
|
116
|
-
def write(self, filepath: str) -> None:
|
|
117
|
-
"""
|
|
118
|
-
Writes this MSA's headers and sequences to the filepath specified.
|
|
119
|
-
|
|
120
|
-
Parameters
|
|
121
|
-
----------
|
|
122
|
-
filepath : str
|
|
123
|
-
Filepath to write the MSA supplied to.
|
|
124
|
-
|
|
125
|
-
Returns
|
|
126
|
-
-------
|
|
127
|
-
None
|
|
128
|
-
"""
|
|
129
|
-
with open(filepath, 'w') as fs:
|
|
130
|
-
for header, sequence in self.MSA:
|
|
131
|
-
fs.write(header)
|
|
132
|
-
fs.write("\n")
|
|
133
|
-
fs.write(sequence)
|
|
134
|
-
fs.write("\n")
|
|
135
|
-
|
|
136
|
-
def __len__(self):
|
|
137
|
-
"""
|
|
138
|
-
Returns the number of sequences, and equivalently, the number of headers in the MSA.
|
|
139
|
-
|
|
140
|
-
Returns
|
|
141
|
-
-------
|
|
142
|
-
int
|
|
143
|
-
length of the MSA list of header, sequence tuples.
|
|
144
|
-
"""
|
|
1
|
+
import re
|
|
2
|
+
from collections import Counter
|
|
3
|
+
from typing import Optional
|
|
4
|
+
import string
|
|
5
|
+
|
|
6
|
+
class MSATools:
|
|
7
|
+
"""
|
|
8
|
+
Tools and interface for encapsulating MSA data and providing functionality for filtering and analysis.
|
|
9
|
+
|
|
10
|
+
Parameters
|
|
11
|
+
----------
|
|
12
|
+
MSA : list of tuple of str, str
|
|
13
|
+
Loaded MSA that is a list of tuples where the first element is the header and the second element is its corresponding sequence.
|
|
14
|
+
"""
|
|
15
|
+
def __init__(self, MSA: list[tuple[str, str]]):
|
|
16
|
+
self.MSA = MSA
|
|
17
|
+
|
|
18
|
+
@staticmethod
|
|
19
|
+
def load_from_file(msa_filepath: str) -> 'MSATools':
|
|
20
|
+
"""
|
|
21
|
+
Generates MSATools object from an MSA file in ".afa" format.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
msa_filepath : str
|
|
26
|
+
Filepath of the MSA in ".afa" format that is provided.
|
|
27
|
+
|
|
28
|
+
Returns
|
|
29
|
+
-------
|
|
30
|
+
MSATools
|
|
31
|
+
An MSATools instance with the appropriate list of (header, sequence) tuples where sequences are simplified and converted to single line format.
|
|
32
|
+
"""
|
|
33
|
+
msa_entries: list[tuple[str, str]] = []
|
|
34
|
+
with open(msa_filepath, 'r') as fs:
|
|
35
|
+
data = fs.read()
|
|
36
|
+
split_data = data.split(">")[1:]
|
|
37
|
+
for entry in split_data:
|
|
38
|
+
line_split_entry = entry.split("\n")
|
|
39
|
+
header = line_split_entry[0]
|
|
40
|
+
sequence = "".join(line_split_entry[1:])
|
|
41
|
+
msa_entries.append((">"+header, sequence))
|
|
42
|
+
return MSATools(msa_entries)
|
|
43
|
+
|
|
44
|
+
@staticmethod
|
|
45
|
+
def get_sequence_max_cont_gaps(sequence: str) -> int:
|
|
46
|
+
"""
|
|
47
|
+
Find maximum number of continuous gaps in a specific sequence.
|
|
48
|
+
|
|
49
|
+
Parameters
|
|
50
|
+
----------
|
|
51
|
+
sequence : str
|
|
52
|
+
Sequence of characters, potentially containing multiple of '-', a gap character.
|
|
53
|
+
|
|
54
|
+
Returns
|
|
55
|
+
-------
|
|
56
|
+
int
|
|
57
|
+
The maximum number of continuous gaps in a sequence.
|
|
58
|
+
"""
|
|
59
|
+
dash_match = re.findall(r"-+", sequence)
|
|
60
|
+
gap_counts = [len(match) for match in dash_match]
|
|
61
|
+
if len(gap_counts) > 0:
|
|
62
|
+
return max(gap_counts)
|
|
63
|
+
else:
|
|
64
|
+
return 0
|
|
65
|
+
|
|
66
|
+
def gap_frequency(self) -> tuple[dict[int, int], dict[int, float]]:
|
|
67
|
+
"""
|
|
68
|
+
Calculates the frequency of maximum continuous gaps throughout the MSA where the key corresponds to the number of continous gaps and the value corresponds to the number of sequences or the cumulative percentage of their sequences.
|
|
69
|
+
|
|
70
|
+
Returns
|
|
71
|
+
-------
|
|
72
|
+
tuple of dict of int, int and dict of int, int
|
|
73
|
+
Two element tuple where first element is a frequency count dictionary and the second element is a cumulative percentage of sequences with a specific maximum number of continous gaps.
|
|
74
|
+
"""
|
|
75
|
+
max_gap_counts = []
|
|
76
|
+
for header, sequence in self.MSA:
|
|
77
|
+
max_gap_counts.append(MSATools.get_sequence_max_cont_gaps(sequence))
|
|
78
|
+
frequency_count_dict = dict(Counter(max_gap_counts))
|
|
79
|
+
cumul_perc_dict = {}
|
|
80
|
+
cumul_count = 0
|
|
81
|
+
for key in sorted(frequency_count_dict.keys()):
|
|
82
|
+
value = frequency_count_dict[key]
|
|
83
|
+
cumul_count += value
|
|
84
|
+
cumul_perc_dict[key] = cumul_count / len(self.MSA)
|
|
85
|
+
return (frequency_count_dict, cumul_perc_dict)
|
|
86
|
+
|
|
87
|
+
def filter_by_continuous_gaps(self, max_gaps: Optional[int]=None) -> list[tuple[str, str]]:
|
|
88
|
+
"""
|
|
89
|
+
Filter out entries in your MSA by the number of maximum continuous gaps specified unless None is provided. Also, removes .s and lowercase letters from the sequence.
|
|
90
|
+
|
|
91
|
+
Parameters
|
|
92
|
+
----------
|
|
93
|
+
max_gaps : int
|
|
94
|
+
The maximum allowed number of continuous gaps in a sequence
|
|
95
|
+
|
|
96
|
+
Returns
|
|
97
|
+
-------
|
|
98
|
+
list of tuple of str, str
|
|
99
|
+
List of entries that are valid in that their sequences' number of maximum continuous gaps is within the threshold supplied as `max_gaps`.
|
|
100
|
+
"""
|
|
101
|
+
table = str.maketrans('', '', string.ascii_lowercase+".")
|
|
102
|
+
if max_gaps == None:
|
|
103
|
+
kept_entries = []
|
|
104
|
+
for header, sequence in self.MSA:
|
|
105
|
+
sequence = sequence.translate(table)
|
|
106
|
+
kept_entries.append((header, sequence))
|
|
107
|
+
return kept_entries
|
|
108
|
+
else:
|
|
109
|
+
kept_entries = []
|
|
110
|
+
for header, sequence in self.MSA:
|
|
111
|
+
sequence = sequence.translate(table)
|
|
112
|
+
if MSATools.get_sequence_max_cont_gaps(sequence) <= max_gaps:
|
|
113
|
+
kept_entries.append((header, sequence))
|
|
114
|
+
return kept_entries
|
|
115
|
+
|
|
116
|
+
def write(self, filepath: str) -> None:
|
|
117
|
+
"""
|
|
118
|
+
Writes this MSA's headers and sequences to the filepath specified.
|
|
119
|
+
|
|
120
|
+
Parameters
|
|
121
|
+
----------
|
|
122
|
+
filepath : str
|
|
123
|
+
Filepath to write the MSA supplied to.
|
|
124
|
+
|
|
125
|
+
Returns
|
|
126
|
+
-------
|
|
127
|
+
None
|
|
128
|
+
"""
|
|
129
|
+
with open(filepath, 'w') as fs:
|
|
130
|
+
for header, sequence in self.MSA:
|
|
131
|
+
fs.write(header)
|
|
132
|
+
fs.write("\n")
|
|
133
|
+
fs.write(sequence)
|
|
134
|
+
fs.write("\n")
|
|
135
|
+
|
|
136
|
+
def __len__(self):
|
|
137
|
+
"""
|
|
138
|
+
Returns the number of sequences, and equivalently, the number of headers in the MSA.
|
|
139
|
+
|
|
140
|
+
Returns
|
|
141
|
+
-------
|
|
142
|
+
int
|
|
143
|
+
length of the MSA list of header, sequence tuples.
|
|
144
|
+
"""
|
|
145
145
|
return len(self.MSA)
|