Skip to content

Commit

Permalink
feat: major ramachandraw-1.0.1 release. (#10)
Browse files Browse the repository at this point in the history
Co-authored-by: Fabian <fabian.tann@mni.thm.de>
  • Loading branch information
alxdrcirilo and Aquaplant committed Mar 1, 2024
1 parent e90c167 commit 34d9075
Show file tree
Hide file tree
Showing 29 changed files with 1,651 additions and 6,216 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/coveralls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: ramachandraw

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
coveralls:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.10.13

- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true

- name: Install dependencies
run: poetry install --no-interaction

- name: Run tests with coverage
run: |
source .venv/bin/activate
pytest --cov=ramachandraw
coverage lcov
- name: Upload coverage to Coveralls
uses: coverallsapp/github-action@v2.1.0
with:
github-token: ${{ secrets.COVERALLS_REPO_TOKEN }}
file: coverage.lcov
Empty file.
165 changes: 163 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,163 @@
# Project exclude paths
/venv/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# MacOS
.DS_Store
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.PHONY: clean format test all

clean:
pyclean .
rm -rf .pdb/ obsolete/ .mypy_cache/ .pytest_cache/ .ruff_cache/ htmlcov/ .coverage

format:
ruff format ramachandraw/ tests/ scripts/
ruff --fix ramachandraw/ tests/ scripts/

test:
pytest --cov=ramachandraw --cov-report html

all: clean format test
115 changes: 67 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,94 +1,113 @@
# Ramachandran plotting tool
![PyPI](https://img.shields.io/pypi/v/RamachanDraw)
![PyPI - Downloads](https://img.shields.io/pypi/dm/RamachanDraw)
![PyPI - License](https://img.shields.io/pypi/l/RamachanDraw)

Draws a Ramachandran plot based on the input PDB file (e.g. 1MBN.pdb). Makes use of a Gaussian KDE (kernel density estimation) to plot the density of favoured torsion angles (&phi; and &psi;).
[![ramachandraw](https://github.com/alxdrcirilo/ramachandraw/actions/workflows/coveralls.yaml/badge.svg)](https://github.com/alxdrcirilo/ramachandraw/actions/workflows/coveralls.yaml)
[![coverage](https://coveralls.io/repos/github/alxdrcirilo/ramachandraw/badge.svg?branch=master)](https://coveralls.io/github/alxdrcirilo/ramachandraw?branch=master)
[![python version](https://img.shields.io/badge/python-3.9|3.10|3.11|3.12-blue)](https://www.python.org/)
[![Poetry](https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json)](https://python-poetry.org/)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![license: MIT](https://img.shields.io/badge/license-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
![PyPI](https://img.shields.io/pypi/v/ramachandraw)
![PyPI - Downloads](https://img.shields.io/pypi/dm/ramachandraw)

![](https://raw.githubusercontent.com/alxdrcirilo/RamachanDraw/master/extras/plot.png)
Draws a [Ramachandran plot](https://en.wikipedia.org/wiki/Ramachandran_plot) based on the input PDB file (e.g. `1mbn.pdb`). Makes use of a Gaussian KDE (kernel density
estimation) to plot the density of favoured torsion angles (&phi; and &psi;).

Single mode | Batch mode
:-------------------------:|:-------------------------:
![](https://raw.githubusercontent.com/alxdrcirilo/ramachandraw/master/images/plot_single.png) | ![](https://raw.githubusercontent.com/alxdrcirilo/ramachandraw/master/images/plot_batch.png)

## Installation

RamachanDraw is hosted on [PyPi](https://pypi.org/project/RamachanDraw/).

```
pip install RamachanDraw
```bash
pip install ramachandraw
```

## Usage

RamachanDraw includes useful functions to effortlessly draw a Ramachandran plot.

### Fetch the PDB file from the online repository
### Fetch the PDB file

To draw a Ramachandran plot, we need a PDB file. You can use a local PDB file by specifying the path. Alternatively, RamachanDraw conveniently includes a function to automatically fetch and locally store the PDB file for the given PDB id.
To draw a Ramachandran plot, we need a PDB file. RamachanDraw conveniently includes a function to automatically fetch and locally store the PDB file for the given PDB id.

#### Arguments
#### Example

```
fetch(pdb_file)
```python
from ramachandraw.utils import fetch_pdb

fetch_pdb(pdb_id, verbose)
```

- ```pdb_file (str|list)```: PDB id(s) corresponding to the PDB entry to be downloaded.
- ```Returns```: path to PDB file.
- `pdb_id (str|list|tuple)`: PDB id(s) corresponding to the PDB file(s) to be downloaded
- `verbose (bool)` (*optional*): set the verbosity, defaults to `False`
- **Returns**: path(s) to PDB file(s)

### Extract &phi; and &psi; angles
### Extract &phi; and &psi; torsion angles

RamachanDraw extracts the &phi; and &psi; angles from the PDB file by taking advantage of the [Biopython](https://biopython.org/) module.
Additionally, aminoacid residues that were not drawn on the plot can be extract using the ```return_ignored``` argument.
RamachanDraw extracts the &phi; and &psi; torsion angles from the PDB file by taking advantage of the [Biopython](https://biopython.org/) module. Additionally, aminoacid residues that were not drawn on the plot can be extract using the `return_ignored` argument.

#### Arguments
#### Example

```
phi_psi(pdb_file, return_ignored)
```python
from ramachandraw.parser import get_phi_psi

phi_psi(pdb_filepath, prune, hide_warnings)
```

- ```pdb_file (str)```: PDB id corresponding to the PDB entry to be downloaded.
- ```return_ignored (bool)```:
- ```True``` returns a list of tuple with the format (aminoacid, (phi, psi))
- ```Returns```: Dictionary with keys as aminoacid residues and values as (phi, psi) angle values.
- `pdb_id (str|list|tuple)`: PDB filepath(s)
- `prune (bool)` (*optional*): prunes aminoacids with missing torsion angle(s), defaults to `True`
- `hide_warnings (bool)` (*optional*): sets the verbosity of the PDB structure parser, defaults to `True`
- **Returns**: Dictionary with keys as aminoacid residues and values as (&phi;, &psi;) angles.

### Ramachandran plot

Makes use of the [matplotlib](https://matplotlib.org/) module to draw a highly customizable Ramachandran plot.

#### Arguments
#### Example

```
plot(pdb_file, cmap='viridis', alpha=0.75, dpi=100, save=True, show=False, out='plot.png')
```python
from ramachandraw.utils import plot

plot(pdb_filepath, cmap="viridis", alpha=0.75, dpi=100, save=True, show=False, filename="plot.png")
```

- ```pdb_file (str|list)```: PDB id(s) corresponding to the PDB entry to be downloaded.
- ```cmap (str)```: colormap to be used (from matplotlib) for the density of the favoured ("allowed") regions; default is <em>viridis</em>.
- ```alpha (float)```: sets the opacity of the colormap (value between 0-1); default is 0.75.
- ```dpi (int)```: resolution (<em>dots per inch</em>); default is 100.
- ```save (bool)```:
- ```True```: saves the plot locally; default is True.
- ```show (bool)```:
- ```True```: shows the plot using the Qt5Agg backend; default is False.
- ```out (str)```: filename to be used in case the plot is saved (i.e. ```save=True```); default is <em>plot.png</em>.
- ```Returns```: Ramachandran plot (can be saved locally).
- `pdb_file (str|list|tuple)`: PDB id(s) corresponding to the PDB entry to be downloaded
- `cmap (str)` (*optional*): colormap to be used (from `matplotlib`) for the density of the favoured ("allowed") regions; default
is *viridis*.
- `alpha (float)` (*optional*): sets the opacity of the colormap (value between 0-1); default is 0.75.
- `dpi (int)` (*optional*): resolution (in *dots per inch*); default is `100`.
- `save (bool)` (*optional*):
- `True`: saves the plot locally; default is True.
- `show (bool)` (*optional*):
- `True`: shows the plot using the Qt5Agg backend; default is False.
- `filename (str)` (*optional*): filename to be used in case the plot is saved (i.e. `save=True`); default is `plot.png`.
- **Returns**: Ramachandran plot (`matplotlib.axes.Axes` object) that can be further customized if needed

## Example

Herein you will find an example from the PDB id corresponding to the myoglobin entry - [1MBN](https://www.ebi.ac.uk/pdbe/entry/pdb/1mbn/index) - in the Protein Data Bank.
Herein you will find an example from the PDB id corresponding to the myoglobin entry: [1MBN](https://www.ebi.ac.uk/pdbe/entry/pdb/1mbn/index) - in the Protein Data Bank.

```
from RamachanDraw import fetch, phi_psi, plot
```python
from ramachandraw.parser import get_phi_psi
from ramachandraw.utils import fetch_pdb, plot

# PDB id to be downloaded
PDB_id = '1MBN'
# PDB id
pdb_id = "1mbn"

# Drawing the Ramachandran plot
plot(fetch(PDB_id))
# Draw the Ramachandran plot
plot(fetch_pdb(pdb_id))

# Generate a dictionary to store the (phi, psi) torsion angles
torsion_angles = get_phi_psi(fetch_pdb(pdb_id))

# Generating a dictionary to store the phi and psi angles
# And returning the ignored aminoacid residues
phi_psi_dict, ignored_res = phi_psi(fetch(PDB_id), return_ignored=True)
```

## Contributing
Feedback and constructive criticism is welcome. If necessary, open an issue in the *issues* tab.

Feedback and constructive criticism is welcome. If necessary, open an issue in the [issues](https://github.com/alxdrcirilo/ramachandraw/issues) tab.

## License

[MIT](https://choosealicense.com/licenses/mit/)
3 changes: 0 additions & 3 deletions RamachanDraw/__init__.py

This file was deleted.

Loading

0 comments on commit 34d9075

Please sign in to comment.