├── conda ├── others │ ├── bld.bat │ └── build.sh └── meta.yaml ├── pyproject.toml ├── reliontomotools ├── _version.py ├── __init__.py ├── relion2motl.py ├── utils.py ├── motl2relion.py ├── fileIO.py └── warptomo2relion.py ├── README.md ├── doc └── build.txt ├── LICENSE ├── .github └── workflows │ └── python-publish.yml ├── setup.py └── templates └── create_tomogram_input.sh /conda/others/bld.bat: -------------------------------------------------------------------------------- 1 | "%PYTHON%" setup.py install 2 | if errorlevel 1 exit 1 3 | 4 | -------------------------------------------------------------------------------- /conda/others/build.sh: -------------------------------------------------------------------------------- 1 | $PYTHON setup.py install # Python command to install the script. 2 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ 3 | "setuptools>=42", 4 | "wheel" 5 | ] 6 | build-backend = "setuptools.build_meta" 7 | -------------------------------------------------------------------------------- /reliontomotools/_version.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | __version_info__ = ('1', '0', '0') 4 | __version__ = '.'.join(__version_info__) -------------------------------------------------------------------------------- /reliontomotools/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from ._version import __version__ 4 | from .fileIO import * 5 | from .warptomo2relion import * 6 | 7 | -------------------------------------------------------------------------------- /conda/meta.yaml: -------------------------------------------------------------------------------- 1 | package: 2 | name: "reliontomotools" 3 | version: "1.0.0" 4 | 5 | source: 6 | git_rev: v1.0.0 7 | git_url: https://github.com/joton/reliontomotools 8 | 9 | build: 10 | script: {{ PYTHON }} setup.py install --single-version-externally-managed --record=record.txt 11 | 12 | requirements: 13 | build: 14 | - python 15 | - setuptools 16 | 17 | host: 18 | - python 19 | - setuptools 20 | 21 | run: 22 | - python 23 | - numpy>=1.19 24 | - pandas 25 | - xmltodict 26 | - docopt 27 | - scipy 28 | - tqdm 29 | - mrcfile 30 | - emfile 31 | - transforms3d 32 | 33 | 34 | about: 35 | home: https://github.com/joton/reliontomotools 36 | license: MIT 37 | license_familY: MIT 38 | license_file: LICENSE 39 | summary: "Additional tools for Relion tomo" 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # reliontomotools 2 | 3 | Additional tools for subtomogram analysis in Relion tomo. 4 | 5 | 6 | ## Install 7 | ```bash 8 | pip install reliontomotools 9 | ``` 10 | 11 | ## Scripts 12 | 13 | ```python 14 | warptomo2relion 15 | 16 | motl2relion 17 | 18 | relion2motl 19 | ``` 20 | 21 | Converts refinement of deformation models, particle poses and CTF paramaters from WARP/M to Relion tomo. 22 | 23 | ### Example 24 | ```bash 25 | warptomo2relion -i 'WarpXML/TS_*.xml' -s 'tomograms/TS_*/TS_*_aligned.mrc' -d 1800 -o WarpConverted -p Refine3D/job010/run_data.star 26 | 27 | motl2relion allmotl_at_17.em -o allmotl_at_17.star -p 1.75 28 | motl2relion --evenodd allmotl_at_even_17.em allmotl_at_odd_17.em -o allmotl_at_17_2.star -p 1.75 29 | 30 | relion2motl -i allmotl_at_17.star -o allmotl_at_17_star.em --angpix 1.75 31 | ``` 32 | -------------------------------------------------------------------------------- /doc/build.txt: -------------------------------------------------------------------------------- 1 | # Developer install 2 | 3 | python setup.py develop 4 | 5 | # Manual installation, files location 6 | 7 | python setup.py install --record files.txt 8 | 9 | # PyPI package building 10 | 11 | python -m build 12 | 13 | # PyPI TEST upload 14 | 15 | twine upload --repository testpypi dist/reliontomotools-X.X.X* 16 | 17 | 18 | # PyPI upload 19 | 20 | twine upload dist/reliontomotools-X.X.X* 21 | 22 | # Conda package building 23 | 24 | cd conda 25 | conda build . -c conda-forge --output-folder pckg 26 | 27 | # Conda local package installation 28 | 29 | conda install --use-local reliontomotools 30 | 31 | # Conda platform conversion 32 | 33 | conda convert --platform all /lmb/home/joton/opt/anaconda3/conda-bld/linux-64/reliontomotools-0.0.1-py37_0.tar.bz2 -o allplatforms/ 34 | conda convert --platform all pckg/linux-64/reliontomotools-0.0.3-py37_0.tar.bz2 -o pckg 35 | 36 | # Conda upload 37 | 38 | anaconda upload /lmb/home/joton/opt/anaconda3/conda-bld/linux-64/reliontomotools-0.0.1-py37_0.tar.bz2 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Joaquin Oton 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. 22 | -------------------------------------------------------------------------------- /.github/workflows/python-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will upload a Python Package using Twine when a release is created 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries 3 | 4 | # This workflow uses actions that are not certified by GitHub. 5 | # They are provided by a third-party and are governed by 6 | # separate terms of service, privacy policy, and support 7 | # documentation. 8 | 9 | name: Upload Python Package 10 | 11 | on: 12 | release: 13 | types: [published] 14 | 15 | permissions: 16 | contents: read 17 | 18 | jobs: 19 | deploy: 20 | 21 | runs-on: ubuntu-latest 22 | 23 | steps: 24 | - uses: actions/checkout@v3 25 | - name: Set up Python 26 | uses: actions/setup-python@v3 27 | with: 28 | python-version: '3.x' 29 | - name: Install dependencies 30 | run: | 31 | python -m pip install --upgrade pip 32 | pip install build 33 | - name: Build package 34 | run: python -m build 35 | - name: Publish package 36 | uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 37 | with: 38 | user: __token__ 39 | password: ${{ secrets.PYPI_API_TOKEN }} 40 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | with open("README.md", "r", encoding="utf-8") as fh: 4 | long_description = fh.read() 5 | 6 | pkg = 'reliontomotools' 7 | exec(open(f'{pkg}/_version.py').read()) 8 | 9 | setup( 10 | name=pkg, 11 | version=__version__, 12 | author="Joaquín Otón", 13 | description="Additional tools for Relion tomo", 14 | long_description=long_description, 15 | long_description_content_type="text/markdown", 16 | url="https://github.com/joton/reliontomotools", 17 | project_urls={ 18 | "Bug Tracker": "https://github.com/joton/reliontomotools/issues", 19 | }, 20 | classifiers=[ 21 | "Programming Language :: Python :: 3", 22 | "License :: OSI Approved :: MIT License", 23 | "Operating System :: OS Independent", 24 | ], 25 | packages=[pkg], 26 | license='MIT', 27 | entry_points={ 28 | "console_scripts": [ 29 | f"warptomo2relion = {pkg}.warptomo2relion:warpTomo2RelionProgram", 30 | f"motl2relion = {pkg}.motl2relion:motl2RelionProgram", 31 | f"relion2motl = {pkg}.relion2motl:relion2motlProgram", 32 | ] 33 | }, 34 | python_requires=">=3.7", 35 | install_requires=[ 36 | 'numpy', 37 | 'pandas', 38 | 'xmltodict', 39 | 'docopt', 40 | 'scipy', 41 | 'tqdm', 42 | 'transforms3d', 43 | 'mrcfile', 44 | 'emfile', 45 | ] 46 | 47 | ) 48 | -------------------------------------------------------------------------------- /reliontomotools/relion2motl.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | import numpy as np 5 | import copy 6 | import pandas as pd 7 | from docopt import docopt 8 | from ._version import __version__ 9 | import emfile 10 | from reliontomotools.fileIO import relion4ToMotl, readStarFile 11 | 12 | __all__ = ['relion2motlProgram'] 13 | # % Subtom motl file To Relion Converter 14 | 15 | def relion2motlProgram(args=None): 16 | doc = """relion2motl: converts relion starfile to subtom motl metadata. 17 | 18 | Usage: 19 | star_to_motl.py -i -o [--bin=]\ 20 | [--angpix=] [--tomo_angles] 21 | 22 | Arguments: 23 | Relion star file containing data_optics and 24 | data_particles tables. 25 | EM file containing converted orientations to subtom 26 | motl list. 27 | 28 | Options: 29 | --bin= Bin factor for output motl list [default: 1] 30 | -p --angpix= Pixel size at bin 1 (in angstroms). If negative, 31 | pixel size is obtained from optics table [default: -1] 32 | 33 | -t --tomo_angles Instead of rlnAngle{Rot,Tilt,AnglePsi}, angles from 34 | rlnTomoSubtomogram{Rot,Tilt,AnglePsi} are used. 35 | 36 | -h --help Show this screen. 37 | -v --version Show version. 38 | 39 | """ 40 | 41 | arguments = docopt(doc, version=__version__) 42 | 43 | starFile = arguments[''] 44 | emFile = arguments[''] 45 | binning = int(arguments['--bin']) 46 | useTomoAngles = arguments['--tomo_angles'] 47 | pixelSize = float(arguments['--angpix']) 48 | 49 | dataStar = readStarFile(starFile) 50 | 51 | print(pixelSize) 52 | if pixelSize < 0: 53 | if 'data_optics' in dataStar: 54 | print(pixelSize) 55 | datao = dataStar['data_optics'] 56 | pixelSize = float(datao['_rlnTomoTiltSeriesPixelSize']) 57 | else: 58 | raise Exception(f"File {starFile} does not contain data_optics table " 59 | "or rlnTomoTiltSeriesPixelSize parameter.") 60 | 61 | motl = relion4ToMotl(dataStar, pixelSize, binning, useTomoAngles) 62 | emfile.write(emFile, motl.astype(np.float32)[np.newaxis, ...], overwrite=True) 63 | -------------------------------------------------------------------------------- /reliontomotools/utils.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | import numpy as np 5 | # from transforms3d.euler import euler2mat, mat2euler 6 | 7 | 8 | # % Euler transformations 9 | 10 | 11 | def rotX(angle): 12 | 13 | c = np.cos(np.deg2rad(angle)) 14 | s = np.sin(np.deg2rad(angle)) 15 | 16 | A = np.matrix([[1, 0, 0, 0], 17 | [0, c,-s, 0], 18 | [0, s, c, 0], 19 | [0, 0, 0, 1]]) 20 | return A 21 | 22 | 23 | def rotY(angle): 24 | 25 | c = np.cos(np.deg2rad(angle)) 26 | s = np.sin(np.deg2rad(angle)) 27 | 28 | A = np.matrix([[c, 0, s, 0], 29 | [0, 1, 0, 0], 30 | [-s,0, c, 0], 31 | [0, 0, 0, 1]]) 32 | return A 33 | 34 | 35 | def rotZ(angle): 36 | 37 | c = np.cos(np.deg2rad(angle)) 38 | s = np.sin(np.deg2rad(angle)) 39 | 40 | A = np.matrix([[c,-s, 0, 0], 41 | [s, c, 0, 0], 42 | [0, 0, 1, 0], 43 | [0, 0, 0, 1.]]) 44 | return A 45 | 46 | 47 | def getShiftMatrix(shifts): 48 | 49 | shiftM = np.matrix([[1, 0, 0, shifts[0]], 50 | [0, 1, 0, shifts[1]], 51 | [0, 0, 1, shifts[2]], 52 | [0, 0, 0, 1.]]) 53 | return shiftM 54 | 55 | 56 | # def getTransMatrix(angles=np.array([0, 0, 0]), shifts=np.array([0, 0, 0])): 57 | # """ 58 | # Parameters 59 | # ---------- 60 | # angles : 1D array 61 | # with Rot, Tilt and Psi Relion angles 62 | # shifts : 1D array 63 | # Xshift, Yshift and Zshift 64 | 65 | # Returns 66 | # ------- 67 | # Trans matrix : 2D array with transformation matrix which applies from 68 | # reference to particle 69 | # """ 70 | 71 | # if not isinstance(angles, np.ndarray): 72 | # angles = np.array(angles) 73 | # if not isinstance(shifts, np.ndarray): 74 | # shifts = np.array(shifts) 75 | 76 | # transMat = np.zeros((4, 4)) 77 | # transMat[3, 3] = 1 78 | # transMat[:3, :3] = euler2mat(*(np.pi/180*angles), 'sxyz') 79 | # transMat[:3, 3] = shifts 80 | 81 | # return transMat 82 | 83 | 84 | # def getTransFromMatrix(transMatrix): 85 | 86 | # shifts = transMatrix[0:3, 3] 87 | 88 | # angles = np.array(mat2euler(transMatrix[0:3, 0:3], 'sxyz'))*180/np.pi 89 | 90 | # if angles[1] < 0: 91 | # angles[[0, 2]] += 180 92 | # angles[1] *= -1 93 | 94 | # return angles, shifts 95 | 96 | -------------------------------------------------------------------------------- /reliontomotools/motl2relion.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | import numpy as np 5 | import copy 6 | import pandas as pd 7 | from docopt import docopt 8 | from ._version import __version__ 9 | import emfile 10 | from reliontomotools.fileIO import motlToRelion4, writeStarFile 11 | 12 | __all__ = ['motl2RelionProgram'] 13 | # % Subtom motl file To Relion Converter 14 | 15 | def motl2RelionProgram(args=None): 16 | doc = """motl2relion: converts subtom motl metadata to Relion. 17 | 18 | Usage: 19 | motl2relion.py ( | --evenodd )\ 20 | -o -p= [--bin=]\ 21 | [-t=