Git Product home page Git Product logo

seqalign's Introduction

seqalign

Collection of sequence alignment algorithms.

Travis (.org) Code Climate coverage Code Climate maintainability npm

Table of contents

Getting started

Install the package from npm:

$ npm install --save seqalign

Import the package in your project:

const { NWaligner, SWaligner } = require('seqalign');

Aligners

SWaligner and NWaligner are factory fucntions, you can create many aligners with different parameters and re-use each one multiple times. An aligner is configurable with the following parameters (all of them are optional):

  • similarityScoreFunction: takes two characters (string) as input and returns a similarity score (integer).
  • gapScoreFunction:
    • Smith-Waterman: takes one positive integer as input (gap length) and returns a score (integer).
    • Needleman-Wunsch: takes no input and returns a constant score used for scoring insertions and deletions in the alignment.
  • gapSymbol: a custom character (string) used to represent gaps in the alignment.

All the listed parameters are accessible from each aligner instance in addition with the following non configurable parameters:

  • directions: enum object used to define direction codes for the traceback matrix.

Defaults

Here are the default values for the aligner options:

// Smith-Waterman.
const similarityScoreFunction = (char1, char2) => (char1 === char2 ? 2 : -1);
const gapScoreFunction = k => -k;

//Needleman-Wunsch.
const similarityScoreFunction = (char1, char2) => (char1 === char2 ? 1 : -2);
const gapScoreFunction = () => -1;

// Common defaults.
const gapSymbol = '-';

Usage

Instantiating SWaligner or NWaligner returns an aligner object which exposes an align method. align accepts the two strings to align as input:

// Smith-Waterman.
const { SWaligner } = require('seqalign');

const defaultAligner = SWaligner();
const customAligner = SWaligner({
  gapScoreFunction: x => x / 2,
  gapSymbol: '~',
})

const defaultResult = defaultAligner.align('insertion', 'deletion');
const customResult = customAligner.align('insertion', 'deletion');

console.log(defaultResult.alignment)
// > ertion
// > e-tion

console.log(customResult.alignment)
// > inse~~rtion
// > ~~~ele~tion
// Needleman-Wunsch.
const { NWaligner } = require('seqalign');

const defaultAligner = NWaligner();
const customAligner = NWaligner({
  inDelScore: -3,
  gapSymbol: '~',
})

const defaultResult = defaultAligner.align('insertion', 'deletion');
const customResult = customAligner.align('insertion', 'deletion');

console.log(defaultResult.alignment)
// > -inse--rtion
// > d---ele-tion

console.log(customResult.alignment)
// > insertion
// > dele~tion

Alignment result

The align method of the aligner instances returns an object with the following properties:

  • score <int>: alignment score.
  • originalSequences Array<str>: original input sequences.
  • alignedSequences Array<str>: aligned sequences.
  • scoringMatrix Array<Array<int>>: alignment scores matrix.
  • tracebackMatrix Array<Array<int>>: alignment traceback directions matrix.
  • coordinateWalk Array<Array<int>>: coordinate walk from the traceback matrix.
  • alignment <str>: printable visual alignment string.

seqalign's People

Contributors

dependabot[bot] avatar lorenzocestaro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

codota

seqalign's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.