dna-parser 0.3.0__cp313-cp313-win_amd64.whl

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.
dna_parser/__init__.py ADDED
@@ -0,0 +1,7 @@
1
+ from .dna_parser import *
2
+ from .call_functions import *
3
+ from .tfidf_class import *
4
+
5
+ __doc__ = dna_parser.__doc__
6
+ if hasattr(dna_parser, "__all__"):
7
+ __all__ = dna_parser.__all__
@@ -0,0 +1,73 @@
1
+ from .dna_parser import *
2
+
3
+
4
+ def onehot_encoding(sequences, pad_type= "after", pad_length= -2, n_jobs= 1):
5
+
6
+ return onehot_encoding_rust(sequences, pad_type, pad_length, n_jobs)
7
+
8
+ def real_encoding(sequences, pad_type= "after", pad_length= -2, n_jobs= 1):
9
+
10
+ return real_encoding_rust(sequences, pad_type, pad_length, n_jobs)
11
+
12
+ def cross_encoding(sequences, pad_type= "after", pad_length= -2, n_jobs= 1):
13
+
14
+ return cross_encoding_rust(sequences, pad_type, pad_length, n_jobs)
15
+
16
+ def random_seq(length, nb_of_seq, seq_type= "dna", n_jobs= 1):
17
+
18
+ return random_seq_rust(length, nb_of_seq, seq_type, n_jobs)
19
+
20
+ def zcurve_encoding(sequences, pad_type= "after", pad_length= -2, n_jobs= 1):
21
+
22
+ return zcurve_encoding_rust(sequences, pad_type, pad_length, n_jobs)
23
+
24
+ def chaos_encoding(sequences, pad_type= "after", pad_length= -2, n_jobs= 1):
25
+
26
+ return chaos_encoding_rust(sequences, pad_type, pad_length, n_jobs)
27
+
28
+ def eiip_encoding(sequences, pad_type= "after", pad_length= -2, n_jobs= 1):
29
+
30
+ return eiip_encoding_rust(sequences, pad_type, pad_length, n_jobs)
31
+
32
+ def dna_walk(sequences, pad_type= "after", pad_length= -2, n_jobs= 1):
33
+
34
+ return dna_walk_rust(sequences, pad_type, pad_length, n_jobs)
35
+
36
+ def fickett_score(sequences, n_jobs= 1):
37
+
38
+ return fickett_score_rust(sequences, n_jobs)
39
+
40
+ def atomic_encoding(sequences, pad_type= "after", pad_length= -2, n_jobs= 1):
41
+
42
+ return atomic_encoding_rust(sequences, pad_type, pad_length, n_jobs)
43
+
44
+ def load_fasta(path):
45
+
46
+ if type(path) is str:
47
+ return load_fasta_rust(path)
48
+
49
+ elif type(path) is list:
50
+
51
+ sequences= [ seq for current_file in path for seq in load_fasta_rust(current_file)]
52
+ return sequences
53
+
54
+ def load_metadata(path):
55
+
56
+ if type(path) is str:
57
+ return metadata_from_fasta_rust(path)
58
+
59
+ elif type(path) is list:
60
+
61
+ sequences= [ seq for current_file in path for seq in metadata_from_fasta_rust(current_file)]
62
+ return sequences
63
+
64
+
65
+ def load_sequences(path):
66
+
67
+ if type(path) is str:
68
+ return seq_from_fasta_rust(path)
69
+
70
+ elif type(path) is list:
71
+
72
+ sequences= [ seq for current_file in path for seq in seq_from_fasta_rust(current_file)]
73
+ return sequences
@@ -0,0 +1,114 @@
1
+ from .dna_parser import *
2
+ from scipy.sparse import csr_matrix
3
+ import numpy as np
4
+ from sklearn.utils.sparsefuncs_fast import inplace_csr_row_normalize_l2
5
+
6
+
7
+ class NotFittedError(Exception):
8
+ pass
9
+
10
+ class Tfidf:
11
+
12
+ def __init__(self, corpus , kmer, vocabulary= None, n_jobs=1):
13
+
14
+ #check if corpus a string (path to fasta) or a list of string
15
+ #check if vocabulary is string (path to file) or a list of string
16
+
17
+ self.vocabulary= vocabulary
18
+ self.corpus= corpus
19
+ self.kmer_size= kmer
20
+ self.idf= None
21
+ self.is_idf_uptodate= False
22
+ self.n_jobs= n_jobs
23
+
24
+ def set_vocabulary(self, vocabulary):
25
+
26
+ self.vocabulary= vocabulary
27
+ self.is_idf_uptodate= False
28
+
29
+ def set_threads(self, n_jobs):
30
+
31
+ self.n_jobs= n_jobs
32
+
33
+
34
+ def add_to_corpus(self, new_corpus):
35
+ self.corpus.extend(new_corpus)
36
+ self.is_idf_uptodate= False
37
+
38
+ def compute_idf(self, matrix):
39
+
40
+ term_freq= (matrix > 0).sum(0)
41
+ self.idf= np.squeeze(np.asarray(np.log(matrix.shape[0]/term_freq)))
42
+ self.is_idf_uptodate= True
43
+
44
+ def fit(self):
45
+
46
+ #check if vocabulary was set by user if not compile vocabulary !
47
+ if not self.vocabulary:
48
+ self.vocabulary= fit_rust(self.corpus, self.kmer_size, self.n_jobs)
49
+
50
+ (val, row, col)= transform_rust(self.corpus, self.vocabulary, self.kmer_size, self.n_jobs)
51
+ matrix_count= csr_matrix(arg1= (val,(row,col)),
52
+ shape= (len(self.corpus),len(self.vocabulary)),
53
+ dtype= np.float64)
54
+
55
+ self.compute_idf(matrix_count)
56
+
57
+
58
+
59
+ def transform(self, sequences= None, normalization= "L2"):
60
+
61
+ #check sequences
62
+
63
+ if not self.is_idf_uptodate:
64
+ raise NotFittedError("This Tidf instance is not fitted. Please use fit()")
65
+
66
+ if not sequences:
67
+ val, row, col= transform_rust(self.corpus, self.vocabulary, self.kmer_size, self.n_jobs)
68
+ matrix_count= csr_matrix(arg1= (val,(row,col)),
69
+ shape= (len(self.corpus),len(self.vocabulary)),
70
+ dtype= np.float64)
71
+
72
+ else:
73
+ val, row, col= transform_rust(sequences, self.vocabulary, self.kmer_size, self.n_jobs)
74
+ matrix_count= csr_matrix(arg1= (val,(row,col)),
75
+ shape= (len(self.corpus),len(self.vocabulary)),
76
+ dtype= np.float64)
77
+
78
+ matrix_count.data *= np.take(a=self.idf, indices=matrix_count.indices)
79
+
80
+ if normalization== "L2":
81
+ inplace_csr_row_normalize_l2(matrix_count)
82
+
83
+ return matrix_count
84
+
85
+
86
+ def fit_transform(self, normalization= "L2"):
87
+
88
+ if not self.vocabulary:
89
+
90
+ self.vocabulary, val, row, col= fit_transform_rust(self.corpus, self.kmer_size, self.n_jobs)
91
+
92
+ else:
93
+ val, row, col= transform_rust(self.corpus, self.vocabulary, self.kmer_size, self.n_jobs)
94
+
95
+ matrix_count= csr_matrix(arg1= (val,(row,col)),
96
+ shape= (len(self.corpus),len(self.vocabulary)),
97
+ dtype= np.float64)
98
+ self.compute_idf(matrix_count)
99
+
100
+
101
+
102
+ matrix_count.data *= np.take(a=self.idf, indices=matrix_count.indices)
103
+
104
+ if normalization== "L2":
105
+ inplace_csr_row_normalize_l2(matrix_count)
106
+
107
+ return matrix_count
108
+
109
+
110
+
111
+
112
+
113
+
114
+
@@ -0,0 +1,57 @@
1
+ Metadata-Version: 2.4
2
+ Name: dna_parser
3
+ Version: 0.3.0
4
+ Classifier: Programming Language :: Rust
5
+ Classifier: Programming Language :: Python :: Implementation :: CPython
6
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
7
+ Requires-Dist: numpy >=1.16.0
8
+ Requires-Dist: scipy >=1.3.0
9
+ Requires-Dist: scikit-learn >=1.5.0
10
+ Requires-Dist: pytest ; extra == 'dev'
11
+ Requires-Dist: mkdocs ; extra == 'dev'
12
+ Provides-Extra: dev
13
+ License-File: LICENSE
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
16
+
17
+ # dna-parser
18
+ ![Build Status](https://github.com/Mvila035/dna_parser/workflows/CI/badge.svg)
19
+
20
+ dna-parser is a Python library written in Rust to encode (or perform feature extraction on) DNA/RNA sequences for machine learning.
21
+
22
+ the source code is available on [GitHub](https://github.com/Mvila035/dna_parser)
23
+
24
+ ## Installation
25
+
26
+ To install dna-parser simply run:
27
+ ```sh
28
+ pip install dna-parser
29
+ ```
30
+
31
+ If there is no Python wheel available for your OS you can install Rust and re-install dna-parser which should now compile on your machine.
32
+ Run the following command on Unix-like OS to install Rust:
33
+ ```sh
34
+ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
35
+ ```
36
+ or see more options at [https://www.rust-lang.org/tools/install](https://www.rust-lang.org/tools/install).
37
+
38
+ ## Quick Start
39
+
40
+ ```python
41
+ import dna_parser as dps
42
+
43
+ sequences= ["agt","acc"]
44
+ encodings= dps.onehot_encoding(sequences)
45
+ print(encodings)
46
+
47
+ # Output:
48
+ #[[[0 0 1 0]
49
+ # [0 1 0 0]
50
+ # [0 0 0 1]]
51
+
52
+ # [[0 0 1 0]
53
+ # [1 0 0 0]
54
+ # [1 0 0 0]]]
55
+ ```
56
+ All encodings with examples are available in the [Documentation](https://mvila035.github.io/dna_parser/documentation/) section.
57
+
@@ -0,0 +1,8 @@
1
+ dna_parser-0.3.0.dist-info/METADATA,sha256=hVbKcyAmx1qqfeHcR1cg5n--VVL7N_K5QGqTtueAmGE,1717
2
+ dna_parser-0.3.0.dist-info/WHEEL,sha256=yPzXoqupHg8BR9P7lkXvHgNDRzRuD8h77-w0fWKSUok,96
3
+ dna_parser-0.3.0.dist-info/licenses/LICENSE,sha256=Vvbjeik3sJC1JpZH-bFF82bGY6aDfFMThI3CeCl0VZI,1086
4
+ dna_parser/call_functions.py,sha256=6qqXK9Hk-4kcGomfuMlYbOQBG0oDuhy3tV_fczhpn_s,2308
5
+ dna_parser/tfidf_class.py,sha256=1UZIDo_Ivtg7pk_5vzwbXHAsAJmhDJZYYC-2tptB5b4,3742
6
+ dna_parser/__init__.py,sha256=zDXZxxl17i-cGhOIxLt2mnfbQPdKWq_5T8AOWa3ZTqg,186
7
+ dna_parser/dna_parser.cp313-win_amd64.pyd,sha256=3oY91QXU4Vpc_ctJuBrVFH4apBlxKwHU0hGpgdYtpKo,686080
8
+ dna_parser-0.3.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.8.1)
3
+ Root-Is-Purelib: false
4
+ Tag: cp313-cp313-win_amd64
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Mvila035
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.