Introduction to alignment-js
alignment-js is a powerful JavaScript library designed to facilitate seamless alignment and manipulation of data structures. This comprehensive guide explores various APIs provided by alignment-js with practical code snippets.
Getting Started
Install the library using npm:
npm install alignment-js
Basic Alignment API
The align
function allows you to align two sequences:
const { align } = require('alignment-js');
const seq1 = 'GATTACA';
const seq2 = 'GCATGCU';
const result = align(seq1, seq2);
console.log(result);
Custom Scoring Function
You can define a custom scoring function for the alignment:
const scoring = (a, b) => (a === b ? 1 : -1);
const result = align(seq1, seq2, { scoringFunction: scoring });
console.log(result);
Global Alignment
Perform global alignment using the Needleman-Wunsch algorithm:
const { globalAlign } = require('alignment-js');
const result = globalAlign(seq1, seq2);
console.log(result);
Local Alignment
Perform local alignment using the Smith-Waterman algorithm:
const { localAlign } = require('alignment-js');
const result = localAlign(seq1, seq2);
console.log(result);
Adding Custom Gap Penalties
Include custom gap penalties for alignment:
const options = {
gapOpen: -2,
gapExtend: -1,
};
const result = globalAlign(seq1, seq2, options);
console.log(result);
App Example
Let’s build a simple app that aligns DNA sequences using the discussed APIs:
const express = require('express');
const { align, globalAlign, localAlign } = require('alignment-js');
const app = express();
app.get('/align', (req, res) => {
const { seq1, seq2 } = req.query;
const result = align(seq1, seq2);
res.send(result);
});
app.get('/globalAlign', (req, res) => {
const { seq1, seq2 } = req.query;
const result = globalAlign(seq1, seq2);
res.send(result);
});
app.get('/localAlign', (req, res) => {
const { seq1, seq2 } = req.query;
const result = localAlign(seq1, seq2);
res.send(result);
});
app.listen(3000, () => {
console.log('App listening on port 3000');
});
This simple app provides APIs to perform basic, global, and local alignments of DNA sequences.
Hash: 58bc03dab107e3b45427444511227972db1d865352a3c47e60b71b2dc4757c11