Skip to main content

No project description provided

Project description

dna_parser

dna_parser is a small python library written in rust to perform encoding/feature extraction for machine learning on dna and rna sequences.

Table of contents

  1. Install
  2. Usage
    1. Loading Fasta Files
    2. Encodings
    3. Other Functions

Install

For now, you need to have the rust programming language installed on your computer to install the library.

Run the following command on Unix-like OS to install rust:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

or see more options at https://www.rust-lang.org/tools/install.

then, to install the test version you can run:

pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple dna-parser

Usage

import dna_parser

Loading Fasta Files

#load both metadata and sequence in tuples (metadata,sequences)
metadata_and_sequences= dna_parser.load_fasta("path/to/fasta/file")

#load sequence only
sequences= dna_parser.seq_from_fasta("path/to/fasta/file")

#load metadata only
metadata= dna_parser.metadata_from_fasta("path/to/fasta/file")

Encodings

Currently only support ordinal encoding, onehot encoding and Term Frequency Inverse Document Frequency (TF-IDF).

Ordinal Encoding

Nucleotides are currently encoded as follow:

  • A= 0.25
  • C= 0.50
  • G= 0.75
  • T/U= 0.75
  • Other characters or gaps = 0
#returns a list of 1D numpy arrays representing the encoding
encoding= dna_parser.ordinal_encoding(sequences, pad_type, pad_length, n_jobs)

Function Arguments:

  • sequences: List of strings (representing your sequences).
  • pad_type: pad (or trim) "before" the sequence or "after" the sequences.
  • pad_length: -2 to pad according to the longest sequence, -1 to trim to shortest, 0 for no paddding, any positive number for a fixed length.
  • n_jobs: number of threads to use to encode the sequences. 0 to use all cpus available.

OneHot Encoding

Nucleotides are currently encoded as follow:

  • A= [1,0,0,0]
  • C= [0,1,0,0]
  • G= [0,0,1,0]
  • T/U= [0,0,0,1]
  • Other characters or gaps = [0,0,0,0]
#returns a list of 2D numpy arrays representing the encoding
encoding= dna_parser.onehot_encoding(sequences, pad_type, pad_length, n_jobs)

Function Arguments:

  • sequences: List of strings (representing your sequences).
  • pad_type: pad (or trim) "before" the sequence or "after" the sequences.
  • pad_length: -2 to pad according to the longest sequence, -1 to trim to shortest, 0 for no paddding, any positive number for a fixed length.
  • n_jobs: number of threads to use to encode the sequences. 0 to use all cpus available.

TF-IDF Encoding

Note that for this function, your sequences need to be split up in words (or k-mers) where each word is separated by a whitespace. To do so you can use the make_kmers function (see Other Functions section)

encoding= dna_parser.tfidf_encoding(corpus)

Function Arguments:

  • corpus: List of strings (representing your sequences).

Other Functions

Generating Random sequences

This function generates random dna, rna or amino acid sequences and returns them in a list.

sequences= dna_parser.random_seq(lenght, nb_of_seq, seq_type, n_jobs)

Function Arguments:

  • length: integer representing the length of the sequences
  • nb_of_seq: integer representing the number of sequences to generate
  • seq_type: string representing the type of sequence. dna, rna or aa (for amino acid)
  • n_jobs: number of threads to use to generate the sequences. 0 to use all cpus available.

Making K-mers in Sequences

this function takes a string and returns a new one with withspaces inserted to form words of length k.

seq_k_mers= dna_parser.make_kmers(seq, k)

Function Arguments:

  • seq: string representing a sequence
  • k: integer representing the length of words to form

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

dna_parser-0.1.0.tar.gz (13.4 kB view hashes)

Uploaded Source

Built Distributions

dna_parser-0.1.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

dna_parser-0.1.0-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

dna_parser-0.1.0-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

dna_parser-0.1.0-cp311-none-win_amd64.whl (194.0 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

dna_parser-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

dna_parser-0.1.0-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (649.1 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

dna_parser-0.1.0-cp310-none-win_amd64.whl (194.0 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

dna_parser-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

dna_parser-0.1.0-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (649.1 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

dna_parser-0.1.0-cp39-none-win_amd64.whl (194.2 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

dna_parser-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

dna_parser-0.1.0-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (650.4 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

dna_parser-0.1.0-cp38-none-win_amd64.whl (194.7 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

dna_parser-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

dna_parser-0.1.0-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (649.8 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

dna_parser-0.1.0-cp37-none-win_amd64.whl (194.6 kB view hashes)

Uploaded CPython 3.7 Windows x86-64

dna_parser-0.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

dna_parser-0.1.0-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (649.7 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

Supported by

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