seqbank 0.1.2__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.
- seqbank-0.1.2/PKG-INFO +249 -0
- seqbank-0.1.2/README.rst +220 -0
- seqbank-0.1.2/pyproject.toml +44 -0
- seqbank-0.1.2/seqbank/__init__.py +2 -0
- seqbank-0.1.2/seqbank/dfam.py +85 -0
- seqbank-0.1.2/seqbank/exceptions.py +7 -0
- seqbank-0.1.2/seqbank/io.py +158 -0
- seqbank-0.1.2/seqbank/main.py +166 -0
- seqbank-0.1.2/seqbank/refseq.py +43 -0
- seqbank-0.1.2/seqbank/seqbank.py +537 -0
- seqbank-0.1.2/seqbank/transform.py +63 -0
- seqbank-0.1.2/seqbank/utils.py +24 -0
seqbank-0.1.2/PKG-INFO
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: seqbank
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: A database to quickly read and write DNA sequence data in numerical form.
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Author: Robert Turnbull
|
|
7
|
+
Author-email: robert.turnbull@unimelb.edu.au
|
|
8
|
+
Requires-Python: >=3.10,<3.13
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Requires-Dist: attrs (>=23.1.0)
|
|
15
|
+
Requires-Dist: biopython (>=1.81)
|
|
16
|
+
Requires-Dist: h5py (>=3.9.0)
|
|
17
|
+
Requires-Dist: joblib (>=1.3.2)
|
|
18
|
+
Requires-Dist: kaleido (==0.2.1)
|
|
19
|
+
Requires-Dist: numpy (>=1.22.0)
|
|
20
|
+
Requires-Dist: pandas (>=2.0.0)
|
|
21
|
+
Requires-Dist: plotly (>=5.0.0)
|
|
22
|
+
Requires-Dist: pyfastx (>=1.1.0)
|
|
23
|
+
Requires-Dist: requests (>=2.31.0)
|
|
24
|
+
Requires-Dist: rich (>=10.16.1)
|
|
25
|
+
Requires-Dist: speedict (>=0.3.11)
|
|
26
|
+
Requires-Dist: typer (>=0.4.0)
|
|
27
|
+
Description-Content-Type: text/x-rst
|
|
28
|
+
|
|
29
|
+
================
|
|
30
|
+
Seqbank
|
|
31
|
+
================
|
|
32
|
+
|
|
33
|
+
.. start-badges
|
|
34
|
+
|
|
35
|
+
|testing badge| |coverage badge| |docs badge| |black badge| |git3moji badge|
|
|
36
|
+
|
|
37
|
+
.. |testing badge| image:: https://github.com/rbturnbull/seqbank/actions/workflows/testing.yml/badge.svg
|
|
38
|
+
:target: https://github.com/rbturnbull/seqbank/actions
|
|
39
|
+
|
|
40
|
+
.. |docs badge| image:: https://github.com/rbturnbull/seqbank/actions/workflows/docs.yml/badge.svg
|
|
41
|
+
:target: https://rbturnbull.github.io/seqbank
|
|
42
|
+
|
|
43
|
+
.. |black badge| image:: https://img.shields.io/badge/code%20style-black-000000.svg
|
|
44
|
+
:target: https://github.com/psf/black
|
|
45
|
+
|
|
46
|
+
.. |coverage badge| image:: https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/rbturnbull/b1625e7f45428007f0982543d9d346d0/raw/coverage-badge.json
|
|
47
|
+
:target: https://rbturnbull.github.io/seqbank/coverage/
|
|
48
|
+
|
|
49
|
+
.. |git3moji badge| image:: https://img.shields.io/badge/git3moji-%E2%9A%A1%EF%B8%8F%F0%9F%90%9B%F0%9F%93%BA%F0%9F%91%AE%F0%9F%94%A4-fffad8.svg
|
|
50
|
+
:target: https://robinpokorny.github.io/git3moji/
|
|
51
|
+
|
|
52
|
+
.. end-badges
|
|
53
|
+
|
|
54
|
+
.. start-quickstart
|
|
55
|
+
|
|
56
|
+
SeqBank is a powerful and flexible command-line application designed to simplify the management and processing of large DNA sequence datasets. Whether you're working with local sequence files,
|
|
57
|
+
retrieving data from remote URLs, or integrating sequences from databases like RefSeq and DFam, SeqBank provides an efficient, user-friendly solution.
|
|
58
|
+
|
|
59
|
+
SeqBank allows users to quickly add, organize, and manipulate sequences using a structured, numerical format optimized for fast retrieval and analysis.
|
|
60
|
+
It's especially useful for bioinformatics professionals who regularly handle vast amounts of genomic data.
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
Installation
|
|
64
|
+
============
|
|
65
|
+
|
|
66
|
+
To install the latest version from the repository, you can use this command:
|
|
67
|
+
|
|
68
|
+
.. code-block:: bash
|
|
69
|
+
|
|
70
|
+
pip install git+https://github.com/rbturnbull/seqbank.git
|
|
71
|
+
|
|
72
|
+
.. note ::
|
|
73
|
+
|
|
74
|
+
Soon seqbank will be able to be installed using conda and PyPI
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
Usage
|
|
78
|
+
===========
|
|
79
|
+
|
|
80
|
+
SeqBank provides a command-line interface (CLI) for managing DNA sequence data efficiently. Below are the main tools, along with examples of how to use them in practical workflows.
|
|
81
|
+
|
|
82
|
+
Adding Sequences
|
|
83
|
+
----------------
|
|
84
|
+
|
|
85
|
+
SeqBank allows you to import sequence data from files or URLs into the database. The system supports multiple sequence formats, providing flexibility in handling various datasets.
|
|
86
|
+
|
|
87
|
+
**Example:**
|
|
88
|
+
|
|
89
|
+
To add sequences from one or more local files:
|
|
90
|
+
|
|
91
|
+
.. code-block:: bash
|
|
92
|
+
|
|
93
|
+
seqbank add /path/to/seqbank /path/to/sequence1.fasta /path/to/sequence2.fasta --format fasta
|
|
94
|
+
|
|
95
|
+
To add sequences from a list of URLs:
|
|
96
|
+
|
|
97
|
+
.. code-block:: bash
|
|
98
|
+
|
|
99
|
+
seqbank url /path/to/seqbank https://example.com/sequence1.fasta https://example.com/sequence2.fasta --format fasta --workers 4
|
|
100
|
+
|
|
101
|
+
**Use case:**
|
|
102
|
+
Suppose you have a new set of genome sequences in FASTA format stored locally or accessible via URLs. You can quickly import these sequences into your SeqBank database for centralized storage and further analysis.
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
Managing Databases
|
|
106
|
+
------------------
|
|
107
|
+
|
|
108
|
+
SeqBank provides commands to manage and query the sequences in your database. You can list, count, and delete sequences, allowing efficient database management.
|
|
109
|
+
|
|
110
|
+
**Example:**
|
|
111
|
+
|
|
112
|
+
To list all sequences in the database:
|
|
113
|
+
|
|
114
|
+
.. code-block:: bash
|
|
115
|
+
|
|
116
|
+
seqbank ls /path/to/seqbank
|
|
117
|
+
|
|
118
|
+
To count the number of sequences stored:
|
|
119
|
+
|
|
120
|
+
.. code-block:: bash
|
|
121
|
+
|
|
122
|
+
seqbank count /path/to/seqbank
|
|
123
|
+
|
|
124
|
+
To delete a specific sequence by accession number:
|
|
125
|
+
|
|
126
|
+
.. code-block:: bash
|
|
127
|
+
|
|
128
|
+
seqbank delete /path/to/seqbank ABC123DEF456
|
|
129
|
+
|
|
130
|
+
**Use case:**
|
|
131
|
+
If you're managing a growing sequence database, the `ls` command can help you track the sequences, while `delete` can be used to remove outdated or incorrect entries.
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
Exporting Sequences
|
|
135
|
+
-------------------
|
|
136
|
+
|
|
137
|
+
You can export your stored sequences to common formats like FASTA for easy sharing and use with other bioinformatics tools. This ensures compatibility with external platforms.
|
|
138
|
+
|
|
139
|
+
**Example:**
|
|
140
|
+
|
|
141
|
+
To export sequences in FASTA format to a specific output directory:
|
|
142
|
+
|
|
143
|
+
.. code-block:: bash
|
|
144
|
+
|
|
145
|
+
seqbank export /path/to/seqbank /output/directory --format fasta
|
|
146
|
+
|
|
147
|
+
**Use case:**
|
|
148
|
+
After storing a collection of curated sequences, you may need to export them in FASTA format for downstream analysis using tools like BLAST or multiple sequence alignment software.
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
Integration with RefSeq and DFam
|
|
152
|
+
--------------------------------
|
|
153
|
+
|
|
154
|
+
SeqBank integrates with popular genomic databases like RefSeq and DFam, allowing users to download and incorporate sequences from these sources.
|
|
155
|
+
|
|
156
|
+
**Example:**
|
|
157
|
+
|
|
158
|
+
To download and add RefSeq sequences with a maximum of 1000 sequences using 4 workers:
|
|
159
|
+
|
|
160
|
+
.. code-block:: bash
|
|
161
|
+
|
|
162
|
+
seqbank refseq /path/to/seqbank --max 1000 --workers 4
|
|
163
|
+
|
|
164
|
+
To download and add DFam sequences from the current release with curated data:
|
|
165
|
+
|
|
166
|
+
.. code-block:: bash
|
|
167
|
+
|
|
168
|
+
seqbank dfam /path/to/seqbank --release current --curated
|
|
169
|
+
|
|
170
|
+
**Use case:**
|
|
171
|
+
If you are studying repetitive elements in a genome, you can easily integrate sequences from DFam into your SeqBank database for comprehensive analysis.
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
Visualization of Sequence Data
|
|
175
|
+
------------------------------
|
|
176
|
+
|
|
177
|
+
SeqBank includes built-in functionality for generating histograms of sequence lengths, providing a visual summary of the data.
|
|
178
|
+
|
|
179
|
+
**Example:**
|
|
180
|
+
|
|
181
|
+
To generate and save a histogram of sequence lengths:
|
|
182
|
+
|
|
183
|
+
.. code-block:: bash
|
|
184
|
+
|
|
185
|
+
seqbank histogram /path/to/seqbank --output histogram.png --nbins 50
|
|
186
|
+
|
|
187
|
+
To generate and display the histogram interactively:
|
|
188
|
+
|
|
189
|
+
.. code-block:: bash
|
|
190
|
+
|
|
191
|
+
seqbank histogram /path/to/seqbank --show --nbins 50
|
|
192
|
+
|
|
193
|
+
**Use case:**
|
|
194
|
+
When working with a dataset of varying sequence lengths, generating a histogram can help visualize the distribution and detect outliers or inconsistencies in the data.
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
Copying Databases
|
|
198
|
+
-----------------
|
|
199
|
+
|
|
200
|
+
SeqBank allows you to copy sequences from one SeqBank database to another, facilitating data migration or backup processes.
|
|
201
|
+
|
|
202
|
+
**Example:**
|
|
203
|
+
|
|
204
|
+
To copy sequences from a source SeqBank to a destination SeqBank:
|
|
205
|
+
|
|
206
|
+
.. code-block:: bash
|
|
207
|
+
|
|
208
|
+
seqbank cp /path/to/source_seqbank /path/to/destination_seqbank
|
|
209
|
+
|
|
210
|
+
**Use case:**
|
|
211
|
+
For maintaining backups of your sequence database or migrating data to a new location, the `cp` command provides a straightforward method to duplicate your SeqBank data.
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
Filtering Sequences and Custom Workflows
|
|
215
|
+
----------------------------------------
|
|
216
|
+
|
|
217
|
+
SeqBank supports filtering sequences based on criteria such as sequence length or file format before adding them to the database. Additionally, multi-threaded downloading allows you to download and process sequences more efficiently.
|
|
218
|
+
|
|
219
|
+
**Example:**
|
|
220
|
+
|
|
221
|
+
To filter sequences longer than 1000 bp before adding them:
|
|
222
|
+
|
|
223
|
+
.. code-block:: bash
|
|
224
|
+
|
|
225
|
+
seqbank add /path/to/seqbank /path/to/sequences.fasta --format fasta --filter /path/to/filter_file
|
|
226
|
+
|
|
227
|
+
To enable multi-threaded downloading when adding sequences from URLs:
|
|
228
|
+
|
|
229
|
+
.. code-block:: bash
|
|
230
|
+
|
|
231
|
+
seqbank url /path/to/seqbank https://example.com/sequence1.fasta https://example.com/sequence2.fasta --format fasta --workers 4 --tmp-dir /path/to/tmp
|
|
232
|
+
|
|
233
|
+
**Use case:**
|
|
234
|
+
In projects where only sequences longer than a specific threshold are required, the filtering feature ensures that only relevant sequences are stored. Multi-threaded downloading can be utilized when processing large datasets to save time.
|
|
235
|
+
|
|
236
|
+
.. end-quickstart
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
Credits
|
|
240
|
+
==================================
|
|
241
|
+
|
|
242
|
+
.. start-credits
|
|
243
|
+
|
|
244
|
+
* Robert Turnbull <robert.turnbull@unimelb.edu.au>
|
|
245
|
+
* Rafsan Al Mamun <rafsan7238@gmail.com>
|
|
246
|
+
|
|
247
|
+
.. end-credits
|
|
248
|
+
|
|
249
|
+
|
seqbank-0.1.2/README.rst
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
================
|
|
2
|
+
Seqbank
|
|
3
|
+
================
|
|
4
|
+
|
|
5
|
+
.. start-badges
|
|
6
|
+
|
|
7
|
+
|testing badge| |coverage badge| |docs badge| |black badge| |git3moji badge|
|
|
8
|
+
|
|
9
|
+
.. |testing badge| image:: https://github.com/rbturnbull/seqbank/actions/workflows/testing.yml/badge.svg
|
|
10
|
+
:target: https://github.com/rbturnbull/seqbank/actions
|
|
11
|
+
|
|
12
|
+
.. |docs badge| image:: https://github.com/rbturnbull/seqbank/actions/workflows/docs.yml/badge.svg
|
|
13
|
+
:target: https://rbturnbull.github.io/seqbank
|
|
14
|
+
|
|
15
|
+
.. |black badge| image:: https://img.shields.io/badge/code%20style-black-000000.svg
|
|
16
|
+
:target: https://github.com/psf/black
|
|
17
|
+
|
|
18
|
+
.. |coverage badge| image:: https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/rbturnbull/b1625e7f45428007f0982543d9d346d0/raw/coverage-badge.json
|
|
19
|
+
:target: https://rbturnbull.github.io/seqbank/coverage/
|
|
20
|
+
|
|
21
|
+
.. |git3moji badge| image:: https://img.shields.io/badge/git3moji-%E2%9A%A1%EF%B8%8F%F0%9F%90%9B%F0%9F%93%BA%F0%9F%91%AE%F0%9F%94%A4-fffad8.svg
|
|
22
|
+
:target: https://robinpokorny.github.io/git3moji/
|
|
23
|
+
|
|
24
|
+
.. end-badges
|
|
25
|
+
|
|
26
|
+
.. start-quickstart
|
|
27
|
+
|
|
28
|
+
SeqBank is a powerful and flexible command-line application designed to simplify the management and processing of large DNA sequence datasets. Whether you're working with local sequence files,
|
|
29
|
+
retrieving data from remote URLs, or integrating sequences from databases like RefSeq and DFam, SeqBank provides an efficient, user-friendly solution.
|
|
30
|
+
|
|
31
|
+
SeqBank allows users to quickly add, organize, and manipulate sequences using a structured, numerical format optimized for fast retrieval and analysis.
|
|
32
|
+
It's especially useful for bioinformatics professionals who regularly handle vast amounts of genomic data.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
Installation
|
|
36
|
+
============
|
|
37
|
+
|
|
38
|
+
To install the latest version from the repository, you can use this command:
|
|
39
|
+
|
|
40
|
+
.. code-block:: bash
|
|
41
|
+
|
|
42
|
+
pip install git+https://github.com/rbturnbull/seqbank.git
|
|
43
|
+
|
|
44
|
+
.. note ::
|
|
45
|
+
|
|
46
|
+
Soon seqbank will be able to be installed using conda and PyPI
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
Usage
|
|
50
|
+
===========
|
|
51
|
+
|
|
52
|
+
SeqBank provides a command-line interface (CLI) for managing DNA sequence data efficiently. Below are the main tools, along with examples of how to use them in practical workflows.
|
|
53
|
+
|
|
54
|
+
Adding Sequences
|
|
55
|
+
----------------
|
|
56
|
+
|
|
57
|
+
SeqBank allows you to import sequence data from files or URLs into the database. The system supports multiple sequence formats, providing flexibility in handling various datasets.
|
|
58
|
+
|
|
59
|
+
**Example:**
|
|
60
|
+
|
|
61
|
+
To add sequences from one or more local files:
|
|
62
|
+
|
|
63
|
+
.. code-block:: bash
|
|
64
|
+
|
|
65
|
+
seqbank add /path/to/seqbank /path/to/sequence1.fasta /path/to/sequence2.fasta --format fasta
|
|
66
|
+
|
|
67
|
+
To add sequences from a list of URLs:
|
|
68
|
+
|
|
69
|
+
.. code-block:: bash
|
|
70
|
+
|
|
71
|
+
seqbank url /path/to/seqbank https://example.com/sequence1.fasta https://example.com/sequence2.fasta --format fasta --workers 4
|
|
72
|
+
|
|
73
|
+
**Use case:**
|
|
74
|
+
Suppose you have a new set of genome sequences in FASTA format stored locally or accessible via URLs. You can quickly import these sequences into your SeqBank database for centralized storage and further analysis.
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
Managing Databases
|
|
78
|
+
------------------
|
|
79
|
+
|
|
80
|
+
SeqBank provides commands to manage and query the sequences in your database. You can list, count, and delete sequences, allowing efficient database management.
|
|
81
|
+
|
|
82
|
+
**Example:**
|
|
83
|
+
|
|
84
|
+
To list all sequences in the database:
|
|
85
|
+
|
|
86
|
+
.. code-block:: bash
|
|
87
|
+
|
|
88
|
+
seqbank ls /path/to/seqbank
|
|
89
|
+
|
|
90
|
+
To count the number of sequences stored:
|
|
91
|
+
|
|
92
|
+
.. code-block:: bash
|
|
93
|
+
|
|
94
|
+
seqbank count /path/to/seqbank
|
|
95
|
+
|
|
96
|
+
To delete a specific sequence by accession number:
|
|
97
|
+
|
|
98
|
+
.. code-block:: bash
|
|
99
|
+
|
|
100
|
+
seqbank delete /path/to/seqbank ABC123DEF456
|
|
101
|
+
|
|
102
|
+
**Use case:**
|
|
103
|
+
If you're managing a growing sequence database, the `ls` command can help you track the sequences, while `delete` can be used to remove outdated or incorrect entries.
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
Exporting Sequences
|
|
107
|
+
-------------------
|
|
108
|
+
|
|
109
|
+
You can export your stored sequences to common formats like FASTA for easy sharing and use with other bioinformatics tools. This ensures compatibility with external platforms.
|
|
110
|
+
|
|
111
|
+
**Example:**
|
|
112
|
+
|
|
113
|
+
To export sequences in FASTA format to a specific output directory:
|
|
114
|
+
|
|
115
|
+
.. code-block:: bash
|
|
116
|
+
|
|
117
|
+
seqbank export /path/to/seqbank /output/directory --format fasta
|
|
118
|
+
|
|
119
|
+
**Use case:**
|
|
120
|
+
After storing a collection of curated sequences, you may need to export them in FASTA format for downstream analysis using tools like BLAST or multiple sequence alignment software.
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
Integration with RefSeq and DFam
|
|
124
|
+
--------------------------------
|
|
125
|
+
|
|
126
|
+
SeqBank integrates with popular genomic databases like RefSeq and DFam, allowing users to download and incorporate sequences from these sources.
|
|
127
|
+
|
|
128
|
+
**Example:**
|
|
129
|
+
|
|
130
|
+
To download and add RefSeq sequences with a maximum of 1000 sequences using 4 workers:
|
|
131
|
+
|
|
132
|
+
.. code-block:: bash
|
|
133
|
+
|
|
134
|
+
seqbank refseq /path/to/seqbank --max 1000 --workers 4
|
|
135
|
+
|
|
136
|
+
To download and add DFam sequences from the current release with curated data:
|
|
137
|
+
|
|
138
|
+
.. code-block:: bash
|
|
139
|
+
|
|
140
|
+
seqbank dfam /path/to/seqbank --release current --curated
|
|
141
|
+
|
|
142
|
+
**Use case:**
|
|
143
|
+
If you are studying repetitive elements in a genome, you can easily integrate sequences from DFam into your SeqBank database for comprehensive analysis.
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
Visualization of Sequence Data
|
|
147
|
+
------------------------------
|
|
148
|
+
|
|
149
|
+
SeqBank includes built-in functionality for generating histograms of sequence lengths, providing a visual summary of the data.
|
|
150
|
+
|
|
151
|
+
**Example:**
|
|
152
|
+
|
|
153
|
+
To generate and save a histogram of sequence lengths:
|
|
154
|
+
|
|
155
|
+
.. code-block:: bash
|
|
156
|
+
|
|
157
|
+
seqbank histogram /path/to/seqbank --output histogram.png --nbins 50
|
|
158
|
+
|
|
159
|
+
To generate and display the histogram interactively:
|
|
160
|
+
|
|
161
|
+
.. code-block:: bash
|
|
162
|
+
|
|
163
|
+
seqbank histogram /path/to/seqbank --show --nbins 50
|
|
164
|
+
|
|
165
|
+
**Use case:**
|
|
166
|
+
When working with a dataset of varying sequence lengths, generating a histogram can help visualize the distribution and detect outliers or inconsistencies in the data.
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
Copying Databases
|
|
170
|
+
-----------------
|
|
171
|
+
|
|
172
|
+
SeqBank allows you to copy sequences from one SeqBank database to another, facilitating data migration or backup processes.
|
|
173
|
+
|
|
174
|
+
**Example:**
|
|
175
|
+
|
|
176
|
+
To copy sequences from a source SeqBank to a destination SeqBank:
|
|
177
|
+
|
|
178
|
+
.. code-block:: bash
|
|
179
|
+
|
|
180
|
+
seqbank cp /path/to/source_seqbank /path/to/destination_seqbank
|
|
181
|
+
|
|
182
|
+
**Use case:**
|
|
183
|
+
For maintaining backups of your sequence database or migrating data to a new location, the `cp` command provides a straightforward method to duplicate your SeqBank data.
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
Filtering Sequences and Custom Workflows
|
|
187
|
+
----------------------------------------
|
|
188
|
+
|
|
189
|
+
SeqBank supports filtering sequences based on criteria such as sequence length or file format before adding them to the database. Additionally, multi-threaded downloading allows you to download and process sequences more efficiently.
|
|
190
|
+
|
|
191
|
+
**Example:**
|
|
192
|
+
|
|
193
|
+
To filter sequences longer than 1000 bp before adding them:
|
|
194
|
+
|
|
195
|
+
.. code-block:: bash
|
|
196
|
+
|
|
197
|
+
seqbank add /path/to/seqbank /path/to/sequences.fasta --format fasta --filter /path/to/filter_file
|
|
198
|
+
|
|
199
|
+
To enable multi-threaded downloading when adding sequences from URLs:
|
|
200
|
+
|
|
201
|
+
.. code-block:: bash
|
|
202
|
+
|
|
203
|
+
seqbank url /path/to/seqbank https://example.com/sequence1.fasta https://example.com/sequence2.fasta --format fasta --workers 4 --tmp-dir /path/to/tmp
|
|
204
|
+
|
|
205
|
+
**Use case:**
|
|
206
|
+
In projects where only sequences longer than a specific threshold are required, the filtering feature ensures that only relevant sequences are stored. Multi-threaded downloading can be utilized when processing large datasets to save time.
|
|
207
|
+
|
|
208
|
+
.. end-quickstart
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
Credits
|
|
212
|
+
==================================
|
|
213
|
+
|
|
214
|
+
.. start-credits
|
|
215
|
+
|
|
216
|
+
* Robert Turnbull <robert.turnbull@unimelb.edu.au>
|
|
217
|
+
* Rafsan Al Mamun <rafsan7238@gmail.com>
|
|
218
|
+
|
|
219
|
+
.. end-credits
|
|
220
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "seqbank"
|
|
3
|
+
version = "0.1.2"
|
|
4
|
+
description = "A database to quickly read and write DNA sequence data in numerical form."
|
|
5
|
+
authors = ["Robert Turnbull <robert.turnbull@unimelb.edu.au>"]
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
readme = "README.rst"
|
|
8
|
+
|
|
9
|
+
[tool.poetry.dependencies]
|
|
10
|
+
python = ">=3.10,<3.13"
|
|
11
|
+
typer = ">=0.4.0"
|
|
12
|
+
numpy = ">=1.22.0"
|
|
13
|
+
pyfastx = ">=1.1.0"
|
|
14
|
+
h5py = ">=3.9.0"
|
|
15
|
+
biopython = ">=1.81"
|
|
16
|
+
attrs = ">=23.1.0"
|
|
17
|
+
rich = ">=10.16.1"
|
|
18
|
+
requests = ">=2.31.0"
|
|
19
|
+
joblib = ">=1.3.2"
|
|
20
|
+
speedict = ">=0.3.11"
|
|
21
|
+
plotly = ">=5.0.0"
|
|
22
|
+
pandas = ">=2.0.0"
|
|
23
|
+
kaleido = "0.2.1"
|
|
24
|
+
|
|
25
|
+
[tool.poetry.group.dev.dependencies]
|
|
26
|
+
pytest = ">=7.4.1"
|
|
27
|
+
ipykernel = ">=6.6.1"
|
|
28
|
+
coverage = ">=5.5"
|
|
29
|
+
autopep8 = ">=1.5.7"
|
|
30
|
+
Sphinx = ">=5.0.0"
|
|
31
|
+
nbsphinx = ">=0.8.7"
|
|
32
|
+
sphinx-rtd-theme = ">=1.0.0"
|
|
33
|
+
sphinx-autobuild = ">=2021.3.14"
|
|
34
|
+
pre-commit = ">=2.15.0"
|
|
35
|
+
sphinx-copybutton = ">=0.4.0"
|
|
36
|
+
black = ">=21.10b0"
|
|
37
|
+
sphinx-click = {git = "https://github.com/rbturnbull/sphinx-click.git"}
|
|
38
|
+
|
|
39
|
+
[build-system]
|
|
40
|
+
requires = ["poetry-core"]
|
|
41
|
+
build-backend = "poetry.core.masonry.api"
|
|
42
|
+
|
|
43
|
+
[tool.poetry.scripts]
|
|
44
|
+
seqbank = "seqbank.main:app"
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import gzip
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
import h5py
|
|
4
|
+
import tempfile
|
|
5
|
+
import shutil
|
|
6
|
+
|
|
7
|
+
from .io import download_file
|
|
8
|
+
from .seqbank import SeqBank
|
|
9
|
+
|
|
10
|
+
def dfam_url(curated: bool = True, release: str = "current") -> str:
|
|
11
|
+
"""
|
|
12
|
+
Constructs the URL for the Dfam database file.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
curated (bool, optional): If True, fetches the curated-only version of the Dfam database. Defaults to True.
|
|
16
|
+
release (str, optional): The Dfam release version. Defaults to "current".
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
str: The URL for the Dfam HDF5 file.
|
|
20
|
+
"""
|
|
21
|
+
curated_str = "_curatedonly" if curated else ""
|
|
22
|
+
url = f"https://www.dfam.org/releases/{release}/families/Dfam{curated_str}.h5.gz"
|
|
23
|
+
return url
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def add_dfam(seqbank: SeqBank, local_path: Path) -> None:
|
|
27
|
+
"""
|
|
28
|
+
Adds sequences from a local Dfam HDF5 file to the SeqBank.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
seqbank (SeqBank): The SeqBank instance to add sequences to.
|
|
32
|
+
local_path (Path): The path to the local Dfam HDF5 file.
|
|
33
|
+
"""
|
|
34
|
+
file = h5py.File(local_path, 'r')
|
|
35
|
+
|
|
36
|
+
def visitor_func(name, node):
|
|
37
|
+
if isinstance(node, h5py.Dataset):
|
|
38
|
+
accession = node.attrs['accession']
|
|
39
|
+
seq = node.attrs['consensus']
|
|
40
|
+
seqbank.add(seq=seq, accession=accession)
|
|
41
|
+
|
|
42
|
+
file['Families/DF'].visititems(visitor_func)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def download_dfam(seqbank: SeqBank, curated: bool = True, release: str = "current", force: bool = False) -> bool:
|
|
46
|
+
"""
|
|
47
|
+
Downloads the Dfam HDF5 file, decompresses it, and adds sequences to the SeqBank.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
seqbank (SeqBank): The SeqBank instance to which the Dfam sequences will be added.
|
|
51
|
+
curated (bool, optional): If True, fetches the curated-only version of the Dfam database. Defaults to True.
|
|
52
|
+
release (str, optional): The Dfam release version. Defaults to "current".
|
|
53
|
+
force (bool, optional): If True, forces the download even if the URL has been previously processed. Defaults to False.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
bool: True if the download and addition were successful, False otherwise.
|
|
57
|
+
"""
|
|
58
|
+
url = dfam_url(curated, release)
|
|
59
|
+
url_key = seqbank.key_url(url)
|
|
60
|
+
|
|
61
|
+
if url_key in seqbank.file and not force:
|
|
62
|
+
print(f"Already downloaded: {url}")
|
|
63
|
+
return False
|
|
64
|
+
|
|
65
|
+
with tempfile.TemporaryDirectory() as tmpdirname:
|
|
66
|
+
local_gzip_path = Path(tmpdirname) / Path(url).name
|
|
67
|
+
try:
|
|
68
|
+
print(f"Downloading Dfam: {url}")
|
|
69
|
+
download_file(url, local_gzip_path)
|
|
70
|
+
|
|
71
|
+
# Decompress the gzipped file
|
|
72
|
+
local_path = local_gzip_path.with_suffix("")
|
|
73
|
+
with gzip.open(local_gzip_path, 'rb') as infile, open(local_path, 'wb') as outfile:
|
|
74
|
+
shutil.copyfileobj(infile, outfile)
|
|
75
|
+
|
|
76
|
+
# Add sequences to SeqBank
|
|
77
|
+
add_dfam(seqbank, local_path)
|
|
78
|
+
|
|
79
|
+
# Mark URL as processed
|
|
80
|
+
seqbank.save_seen_url(url)
|
|
81
|
+
except Exception as err:
|
|
82
|
+
print(f"Failed to add Dfam: {url}: {err}")
|
|
83
|
+
return False
|
|
84
|
+
|
|
85
|
+
return True
|