Skip to main content

Trajpy - empowering feature engineering for trajectory analysis across domains.

Project description

PyPI version Build Status Documentation Status Python3 License: GPL v3 DOI Binder

TrajPy

Trajectory analysis is a challenging task and fundamental for understanding the movement of living organisms in various scales.

We propose TrajPy as an easy pythonic solution to be applied in studies that demand trajectory analysis. With a friendly graphic user interface (GUI) it requires little knowledge of computing and physics to be used by nonspecialists.

TrajPy is composed of three main units of code:

  • Basic usage:
    • The GUI: it is where you interact with trajpy and the only thing you need to know to start using it
  • Advanced
    • trajpy.py: it's the heart of trajpy, it computes the Features for characterizing the trajectories
    • traj_generator.py: a trajectory generator that can be used to build a dataset for trajectory classification

Our dataset and Machine Learning (ML) model are available for use, as well the generator for building your own database.

Installation

We have the package hosted at PyPi, for installing use the command line:

pip3 install trajpy trajpy-ui

If you want to test the development version, clone the repository at your local directory from your terminal:

git clone https://github.com/ocbe-uio/trajpy

Then run the setup.py for installing

python setup.py --install

Basic Usage Example

Using the Graphic User Interface (GUI)

Since the version 1.4.4 we moved the user interface to a separate package named trajpy-ui.

Open a terminal and execute the line bellow

python3 -m trajpy_ui.ui

Check the respository trajpy-ui for more details about the GUI.

File formats

Comma separated values (CSV)

Currently trajpy support CSV files organized in 4 columns: time t and 3 spatial coordinates x, y, z:

t x y z
1.00 10.00  50.00 50.00
2.00 11.00 50.00 50.00
3.00 11.00 50.00 50.00
4.00 12.00 50.00 50.00
5.00 12.00 50.00 50.00
6.00 13.00 50.00 50.00

See the sample file provided in this repository as example.

LAMMPS YAML dump format

LAMMPS YAML files are defined with the following structure:

    ---
    time: 0.0
    natoms: 100
    keywords: [id, type, x, y, z, vx, vy, vz, fx, fy, fz]
    data:
    - [1, 1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -nan, -nan, -nan]
    - [2, 1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -nan, -nan, -nan]
    - [3, 1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -nan, -nan, -nan]
    ...

We provide support for parsing this type of data files with the function parse_lammps_dump_yaml().

Scripting

First we import the package

import trajpy.trajpy as tj

Then we load the data sample provided in this repository, we pass the arguments skip_header=1 to skip the first line of the file and delimiter=',' to specify the file format

filename = 'data/samples/sample.csv'
r = tj.Trajectory(filename,
                  skip_header=1,
                  delimiter=',')

Finally, for computing a set of features for trajectory analysis we can simple run the function r.compute_features()

    r.compute_features()

The features will be stored in the object r, for instance:

  >>> r.asymmetry
  >>> 0.5782095322093505
  >>> r.fractal_dimension
  >>> 1.04
  >>> r.efficiency
  >>> 0.29363293632936327
  >>> r.gyration_radius
  >>> array([[30.40512689,  5.82735002,  0.96782673],
  >>>     [ 5.82735002,  2.18625318,  0.27296851],
  >>>     [ 0.96782673,  0.27296851,  2.41663589]])

For more examples please consult the extended documentation: https://trajpy.readthedocs.io/

Requirements

  • numpy >= 1.14.3
  • scipy >= 1.7.1
  • ttkthemes >= 2.4.0
  • Pillow >= 8.1.0
  • PyYAML >= 5.3.1

How to cite?

If using TrajPy for academic work, please cite our methodological paper and Software DOI:

@article{10.1093/bioadv/vbae026,
    author = {Moreira-Soares, Maurício and Mossmann, Eduardo and Travasso, Rui D M and Bordin, José Rafael},
    title = "{TrajPy: empowering feature engineering for trajectory analysis across domains}",
    journal = {Bioinformatics Advances},
    volume = {4},
    number = {1},
    pages = {vbae026},
    year = {2024},
    month = {02},
    issn = {2635-0041},
    doi = {10.1093/bioadv/vbae026},
    url = {https://doi.org/10.1093/bioadv/vbae026},
    eprint = {https://academic.oup.com/bioinformaticsadvances/article-pdf/4/1/vbae026/56926570/vbae026.pdf},
}

@software{mauricio_moreira_2020_3978699,
  author       = {Mauricio Moreira and Eduardo Mossmann},
  title        = {phydev/trajpy: TrajPy 1.3.1},
  month        = aug,
  year         = 2020,
  publisher    = {Zenodo},
  version      = {1.3.1},
  doi          = {10.5281/zenodo.3978699},
  url          = {https://doi.org/10.5281/zenodo.3978699}
}

Contribution

This is an open source project, and all contributions are welcome. Feel free to open an Issue, a Pull Request, or to e-mail us.

Publications using trajpy

Moreira-Soares M., Mossmann E., Travasso R. D. M, Bordin J. R., TrajPy: empowering feature engineering for trajectory analysis across domains, Bioinformatics Advances, Volume 4, Issue 1, 2024, vbae026, doi:10.1093/bioadv/vbae026

Eduardo Henrique Mossmann. A physics based feature engineering framework for trajectory analysis. MSc dissertation. Federal University of Pelotas 2022, Brazil.

Simões, RF, Pino, R, Moreira-Soares, M, et al. Quantitative Analysis of Neuronal Mitochondrial Movement Reveals Patterns Resulting from Neurotoxicity of Rotenone and 6-Hydroxydopamine. FASEB J. 2021; 35:e22024. doi:10.1096/fj.202100899R

Moreira-Soares, M., Pinto-Cunha, S., Bordin, J. R., Travasso, R. D. M. Adhesion modulates cell morphology and migration within dense fibrous networks. https://doi.org/10.1088/1361-648X/ab7c17

References

Arkin, H. and Janke, W. 2013. Gyration tensor based analysis of the shapes of polymer chains in an attractive spherical cage. J Chem Phys 138, 054904.

Wagner, T., Kroll, A., Haramagatti, C.R., Lipinski, H.G. and Wiemann, M. 2017. Classification and Segmentation of Nanoparticle Diffusion Trajectories in Cellular Micro Environments. PLoS One 12, e0170165.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trajpy-1.4.4.tar.gz (128.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trajpy-1.4.4-py3-none-any.whl (124.6 kB view details)

Uploaded Python 3

File details

Details for the file trajpy-1.4.4.tar.gz.

File metadata

  • Download URL: trajpy-1.4.4.tar.gz
  • Upload date:
  • Size: 128.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for trajpy-1.4.4.tar.gz
Algorithm Hash digest
SHA256 0c7fb3632b462a51ffc3f7dcc40eb12e7061ff4fe5e3a97a9c9e0c0fca49f55f
MD5 3a2e3d8ab75ca60ef554647d65b4ef31
BLAKE2b-256 b7dcbd4fe6f62674e63ebf8b3fca5d8eedfb8c414acbadaf0bd1e6675f3b5951

See more details on using hashes here.

Provenance

The following attestation bundles were made for trajpy-1.4.4.tar.gz:

Publisher: python-publish.yml on ocbe-uio/trajpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trajpy-1.4.4-py3-none-any.whl.

File metadata

  • Download URL: trajpy-1.4.4-py3-none-any.whl
  • Upload date:
  • Size: 124.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for trajpy-1.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 df8b30e9399084d6df02bf67282f46359e7fd786eaa5dbdf534f0abe504c6329
MD5 37f4a06b4c387db345412a65e78233e0
BLAKE2b-256 3260fa13573a5b1aa12d2191f273dabc5a3abb39135485db544e1c44bca60ad9

See more details on using hashes here.

Provenance

The following attestation bundles were made for trajpy-1.4.4-py3-none-any.whl:

Publisher: python-publish.yml on ocbe-uio/trajpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page