npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dna

v0.1.6

Published

utility functions to handle DNA/RNA string data

Downloads

59

Readme

dna

Utility functions to handle DNA/RNA strings in bioinformatics. (Node.js)

Installation

git clone git://github.com/shinout/dna.git

OR

npm install dna

API Documentation

  • dna.complStrand(str, rev, rna)
  • dna.getRandomSeq(len, rna)
  • dna.getFormat(chr, start, end, strand)
  • dna.parseFormat(str, objFormat)
  • dna.writeFasta(rname, seq, wstream, num)
  • dna.padN(seq, len, options)
  • dna.writeFastq(name, seq, qual, wstream)
  • dna.getPosLen(start, end)
  • dna.getStartEnd(pos, len)
  • dna.numberize()

dna.complStrand(str, rev, rna)

Gets a complementary strand of str.

If rev is true, reverse the sequence. (5' -> 3').

If rna is true, T -> U .

dna.complStrand("ACCTG") // TGGAC
dna.complStrand("ACCTG", true) // CAGGT
dna.complStrand("ACCTG", null, true) // UGGAC
dna.complStrand("ACCTG", true, true) // CAGGU

dna.getRandomSeq(len, rna)

Gets a random sequence with length len.

If rna is true, T -> U.

dna.getFormat(chr, start, end, strand)

Gets a formatted position expression by four information.

Here is the formatted position expression.

chr13:12345678-13456789,-
<reference name>:<0 based start>-<0 based end>,<strand>

So this function returns

chr:start-end,strand

dna.parseFormat(str, objFormat)

Parses str as a formatted position expression.

if objFormat is true, returns

{ chr    : "chr13",
  start  : 12345678,
  end    : 13456789,
  strand : '-'
}

By default, returns an array.

["chr13", 12345678, 13456789, '-']

dna.writeFasta(rname, seq, wstream, num)

Writes fasta to wstream.

rname is the reference name. Required.

seq is the sequence to write. Required.

wstream is a writable stream. By default, process.stdout.

num is number to fold. By default, 50.

Returns nothing.

dna.writeFasta("title", "GCTTCAA");
// >title
// GCTTCAA

dna.padN(seq, len, options)

Pads N till the seq.length becomes len.

seq is a string. len is a number.

options is optional object.

If options.cutIfOver is true, and seq.length > len already, cuts the seq.

If options.left is true, pads Ns to the right of seq. (N are padded at the right by default.)

dna.padN("ACGA", 10) // ACGANNNNNN
dna.padN("ACGA", 3)  // ACGA
dna.padN("ACGA", 3, {cutIfOver: true})  // ACG
dna.padN("ACGA", 10, {left: true}) // NNNNNNACGA

dna.writeFastq(name, seq, qual, wstream)

Writes fastq to wstream.

name is the name of the sequence. Required.

seq is the sequence to write. Required.

qual is the base quality of the sequence. qual.length === seq.length.

wstream is a writable stream. By default, process.stdout.

Returns boolean (the wstream is writable or not).

dna.writeFastq("title", "GCTTCAA", "IIHHHAI");
// @title
// GCTTCAA
// +
// IIHHHAI

dna.getPosLen(start, end)

Returns 1-based coordinate position and the length from 0-based coordinate start and end.

Returns an array.

Returns [start+1, end-start]

dna.getPosLen(3, 10) // [4, 7]

dna.getStartEnd(pos, len)

Returns 0-based coordinate start and end from 1-based coordinate position and the length.

Returns an array.

Returns [pos-1, pos + len -1]

dna.getStartEnd(3, 10) // [2, 12]

dna.numberize(num, _default)

dna.numberize(num, name)

Numberize num.

If Number(num) is NaN, returns _default if given. Otherwise throw an error. name is used to specify which number occurs the error.

dna.numberize("14") // 14
dna.numberize("AA", 10) // 10
dna.numberize("AA", "position") // throws an error: "position is NaN"

unstable APIs

dna.getChromCode(name, nothrow)

Gets the code (id) of a given chromosome

  • chr9 -> 9
  • chr22 -> 22
  • chrX -> 23
  • chrY -> 24
  • chrM -> 25
  • others: -> an exception is thrown.

name is the name of a chromosome.

If nothrow is true and not found, returns the original value.

dna.getRegularName(name)

Gets the canonical names of a given chromosome.

  • 9 -> chr9
  • chromosome22 -> chr22
  • CHRUN_GN000239 -> chrUn_gl000239
  • others: -> throw exception

name is the name of a chromosome

dna.getChromList(code, fn)

Gets possible reference names from the code

  • 9 -> [9, chr9, Chr9, CHR9, chrom9, Chrom9, CHROM9]

code is a chromosome code or chromosome name

fn is optional. Function with its arguments each rname candidate. Returns some value when rname is valid, Returns false when invalid. If this argument is set, dna.getChromList() returns the value fn returns.