Name | cryoet-alignment JSON |
Version |
0.0.8
JSON |
| download |
home_page | None |
Summary | Alignment format conversion for cryoET. |
upload_time | 2024-11-15 21:07:58 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | MIT License Copyright (c) 2024 Utz Ermel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
alignment
cryo-et
cryoet
tomography
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# cryoet-alignment
Convert between different alignment formats used in cryo-ET.
Supported formats:
- IMOD
- AreTomo3
- cryoet-data-portal
# Installation
`cryoet-alignment` can be installed using pip:
```bash
pip install cryoet-alignment
```
# Usage
## Reading and writing alignment files
`cryoet-alignment` provides a simple API to read and write alignment files from different software packages.
### IMOD
When processing tomography data using IMOD/etomo, files containing relevant alignment information are usually stored
following the naming convention `basename.xf` (in-plane parameters), `basename.tlt` (tilt angles),
`basename.xtilt` (x-rotation), `basename.mrc` (unaligned tilt series) and `basename_full_rec.mrc` (tomogram).
This layout is assumed when reading and writing IMOD alignment files as shown below. Any present `tilt.com` and
`newst.com` file in the same directory may also be read.
```python
from cryoet_alignment import read
from cryoet_alignment import write
# Read IMOD alignment files using etomo basename
imod_alignment = read("/path/to/imod_dir/basename")
# Write IMOD file
write(imod_alignment, "/path/to/imod_dir/basename")
```
### AreTomo3
When processing tomography data using AreTomo3, alignment information is stored in a single `.aln` file. This file can be
read and written as shown below.
```python
from cryoet_alignment import read
from cryoet_alignment import write
# Read AreTomo3 alignment files
aretomo3_alignment = read("/path/to/alignment_file.aln")
# Write AreTomo3 file
write(aretomo3_alignment, "/path/to/alignment_file.aln")
```
### cryoet-data-portal
Alignment information from the cryoet-data-portal is stored in a JSON file with a schema described here. This file can
be read and written as shown below.
```python
from cryoet_alignment import read
from cryoet_alignment import write
# Read cryoet-data-portal alignment files
cryoet_data_portal_alignment = read("/path/to/alignment_file.json")
# Write cryoet-data-portal file
write(cryoet_data_portal_alignment, "/path/to/alignment_file.json")
```
## Convert between different alignment formats
`cryoet-alignment` provides the ability to convert between different alignment formats. For any conversion, the
alignment object must be read first using the appropriate `read` function, and then converted to the cryoet-data-portal
format before converting and writing to the desired format.
### IMOD to AreTomo3
```python
from cryoet_alignment import read, write
from cryoet_alignment.io.cryoet_data_portal import Alignment
# Read IMOD alignment files using etomo basename
imod_alignment = read("/path/to/imod_dir/basename")
# Convert IMOD to AreTomo3
cdp_alignment = Alignment.from_imod(imod_alignment)
# Write AreTomo3 file
tilt_series_dim = (4096, 4096, 41)
write(cdp_alignment.to_aretomo(ts_size=tilt_series_dim), "/path/to/alignment_file.aln")
```
### cryoet-data-portal to IMOD
It is also possible to convert directly from the cryoet-data-portal client to IMOD/AreTomo format. This is demonstrated
below. This requires additional dependencies to be installed using the following command:
```bash
pip install cryoet-alignment[cdp]
```
To convert from the cryoet-data-portal to IMOD, the below code can be used. Briefly, given a tomogram ID, the snippet
fetches the alignment information from the cryoet-data-portal, reads the tilt series metadata, and converts the alignment
to IMOD format. The resulting alignment files are written to the specified directory with the portal's run name as
the base name.
```python
import cryoet_data_portal as cdp
import zarr
from cryoet_alignment.io.cryoet_data_portal import Alignment
from cryoet_alignment import write
# Target tomogram ID
# This is an example from dataset 10004 (https://cryoetdataportal.czscience.com/runs/333)
TOMO_ID = 771
# Get the tomogram from the cryoet-data-portal
client = cdp.Client()
tomogram = cdp.Tomogram.get_by_id(client, TOMO_ID)
# Read cryoet-data-portal alignment from S3
cdp_ali = Alignment.from_s3(tomogram.alignment.s3_alignment_metadata)
# Get the tilt series metadata
#tilt_series = tomogram.alignment.tiltseries < currently unavailable due to a bug in the data portal client
tilt_series = tomogram.run.tiltseries[0]
pixel_size = tilt_series.pixel_spacing
dim_z, dim_y, dim_x = zarr.open(tilt_series.s3_omezarr_dir)['0'].shape
# Convert to IMOD format
imod_ali = cdp_ali.to_imod(ts_size=(dim_x, dim_y, dim_z), ts_spacing=pixel_size)
write(imod_ali, f"/tmp/test/{tomogram.run.name}")
```
Raw data
{
"_id": null,
"home_page": null,
"name": "cryoet-alignment",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "alignment, cryo-et, cryoet, tomography",
"author": null,
"author_email": "\"Utz H. Ermel\" <utz.ermel@czii.org>",
"download_url": "https://files.pythonhosted.org/packages/3e/7a/824834b484aff7b9c014d987a537acd9a9141f8923ac006f413a1172a03d/cryoet_alignment-0.0.8.tar.gz",
"platform": null,
"description": "# cryoet-alignment\n\nConvert between different alignment formats used in cryo-ET.\n\nSupported formats:\n- IMOD\n- AreTomo3\n- cryoet-data-portal\n\n# Installation\n\n`cryoet-alignment` can be installed using pip:\n\n```bash\npip install cryoet-alignment\n```\n\n# Usage\n\n## Reading and writing alignment files\n\n`cryoet-alignment` provides a simple API to read and write alignment files from different software packages.\n\n### IMOD\nWhen processing tomography data using IMOD/etomo, files containing relevant alignment information are usually stored\nfollowing the naming convention `basename.xf` (in-plane parameters), `basename.tlt` (tilt angles),\n`basename.xtilt` (x-rotation), `basename.mrc` (unaligned tilt series) and `basename_full_rec.mrc` (tomogram).\n\nThis layout is assumed when reading and writing IMOD alignment files as shown below. Any present `tilt.com` and\n`newst.com` file in the same directory may also be read.\n\n```python\nfrom cryoet_alignment import read\nfrom cryoet_alignment import write\n\n# Read IMOD alignment files using etomo basename\nimod_alignment = read(\"/path/to/imod_dir/basename\")\n\n# Write IMOD file\nwrite(imod_alignment, \"/path/to/imod_dir/basename\")\n```\n\n### AreTomo3\nWhen processing tomography data using AreTomo3, alignment information is stored in a single `.aln` file. This file can be\nread and written as shown below.\n\n```python\nfrom cryoet_alignment import read\nfrom cryoet_alignment import write\n\n# Read AreTomo3 alignment files\naretomo3_alignment = read(\"/path/to/alignment_file.aln\")\n\n# Write AreTomo3 file\nwrite(aretomo3_alignment, \"/path/to/alignment_file.aln\")\n```\n\n### cryoet-data-portal\nAlignment information from the cryoet-data-portal is stored in a JSON file with a schema described here. This file can\nbe read and written as shown below.\n\n```python\nfrom cryoet_alignment import read\nfrom cryoet_alignment import write\n\n# Read cryoet-data-portal alignment files\ncryoet_data_portal_alignment = read(\"/path/to/alignment_file.json\")\n\n# Write cryoet-data-portal file\nwrite(cryoet_data_portal_alignment, \"/path/to/alignment_file.json\")\n```\n\n## Convert between different alignment formats\n\n`cryoet-alignment` provides the ability to convert between different alignment formats. For any conversion, the\nalignment object must be read first using the appropriate `read` function, and then converted to the cryoet-data-portal\nformat before converting and writing to the desired format.\n\n### IMOD to AreTomo3\n```python\nfrom cryoet_alignment import read, write\nfrom cryoet_alignment.io.cryoet_data_portal import Alignment\n\n# Read IMOD alignment files using etomo basename\nimod_alignment = read(\"/path/to/imod_dir/basename\")\n\n# Convert IMOD to AreTomo3\ncdp_alignment = Alignment.from_imod(imod_alignment)\n\n# Write AreTomo3 file\ntilt_series_dim = (4096, 4096, 41)\nwrite(cdp_alignment.to_aretomo(ts_size=tilt_series_dim), \"/path/to/alignment_file.aln\")\n```\n\n### cryoet-data-portal to IMOD\n\nIt is also possible to convert directly from the cryoet-data-portal client to IMOD/AreTomo format. This is demonstrated\nbelow. This requires additional dependencies to be installed using the following command:\n\n```bash\npip install cryoet-alignment[cdp]\n```\n\nTo convert from the cryoet-data-portal to IMOD, the below code can be used. Briefly, given a tomogram ID, the snippet\nfetches the alignment information from the cryoet-data-portal, reads the tilt series metadata, and converts the alignment\nto IMOD format. The resulting alignment files are written to the specified directory with the portal's run name as\nthe base name.\n\n```python\nimport cryoet_data_portal as cdp\nimport zarr\nfrom cryoet_alignment.io.cryoet_data_portal import Alignment\nfrom cryoet_alignment import write\n\n# Target tomogram ID\n# This is an example from dataset 10004 (https://cryoetdataportal.czscience.com/runs/333)\nTOMO_ID = 771\n\n# Get the tomogram from the cryoet-data-portal\nclient = cdp.Client()\ntomogram = cdp.Tomogram.get_by_id(client, TOMO_ID)\n\n# Read cryoet-data-portal alignment from S3\ncdp_ali = Alignment.from_s3(tomogram.alignment.s3_alignment_metadata)\n\n# Get the tilt series metadata\n#tilt_series = tomogram.alignment.tiltseries < currently unavailable due to a bug in the data portal client\ntilt_series = tomogram.run.tiltseries[0]\npixel_size = tilt_series.pixel_spacing\ndim_z, dim_y, dim_x = zarr.open(tilt_series.s3_omezarr_dir)['0'].shape\n\n# Convert to IMOD format\nimod_ali = cdp_ali.to_imod(ts_size=(dim_x, dim_y, dim_z), ts_spacing=pixel_size)\nwrite(imod_ali, f\"/tmp/test/{tomogram.run.name}\")\n```\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 Utz Ermel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"summary": "Alignment format conversion for cryoET.",
"version": "0.0.8",
"project_urls": {
"Issues": "https://github.com/uermel/cryoet-alignment/issues",
"Repository": "https://github.com/uermel/cryoet-alignment.git"
},
"split_keywords": [
"alignment",
" cryo-et",
" cryoet",
" tomography"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0a851c539540e33e5a3fc815b2fb74bd810f95c78795f2d116a9951937ec3221",
"md5": "a7ac7c1bed5d802c37fbbd63f709ed43",
"sha256": "8b04a3a9e03230f853e3a9994acd87a2cf34856bcba158d87f4a97e8fd484474"
},
"downloads": -1,
"filename": "cryoet_alignment-0.0.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a7ac7c1bed5d802c37fbbd63f709ed43",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 20946,
"upload_time": "2024-11-15T21:07:56",
"upload_time_iso_8601": "2024-11-15T21:07:56.965220Z",
"url": "https://files.pythonhosted.org/packages/0a/85/1c539540e33e5a3fc815b2fb74bd810f95c78795f2d116a9951937ec3221/cryoet_alignment-0.0.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3e7a824834b484aff7b9c014d987a537acd9a9141f8923ac006f413a1172a03d",
"md5": "0fdf02c5fb9311d3b3474fe8dd2fb02a",
"sha256": "0c3a320b6bfe8176d251236254fa2dc78192f52ee3aaaeb8cbac934425546507"
},
"downloads": -1,
"filename": "cryoet_alignment-0.0.8.tar.gz",
"has_sig": false,
"md5_digest": "0fdf02c5fb9311d3b3474fe8dd2fb02a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 21847,
"upload_time": "2024-11-15T21:07:58",
"upload_time_iso_8601": "2024-11-15T21:07:58.558787Z",
"url": "https://files.pythonhosted.org/packages/3e/7a/824834b484aff7b9c014d987a537acd9a9141f8923ac006f413a1172a03d/cryoet_alignment-0.0.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-15 21:07:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "uermel",
"github_project": "cryoet-alignment",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "cryoet-alignment"
}