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

bedjs

v1.0.3

Published

Manage BED (Browser Extensible Data) files with Node.JS (Bioinformatics)

Downloads

870

Readme

bedJS

npm npm

Manage BED (Browser Extensible Data) files with Node.JS (Bioinformatics).

Install

Use NPM to install the package:

npm install bedjs

Overview

About the BED file format

A BED file is a tab delimited containing one feature of interest per line. Each line must contain at least the three first fields listed below:

| KEY | Description | Type | |-----|-------------|------| | chromosome | Chromosome name | String | | start | Start position of the feature | Integer | | end | End position of the feature | Integer | | name | Name of the line | String | | score | Score between 0 and 1000 | Integer | | strand | Strand of the feature ('+' or '-') | String | | thickStart | Start position at which the feature is drawn thickly | Integer | | thickEnd | End position at which the feature is drawn thickly | Integer | | itemRgb | RGB value in format R,G,B | String | | blockCount | The number of blocks (exons) in the BED line | Integer | | blockSizes | A comma-separated list of the block sizes | String | | blockStarts | A comma-separated list of block starts | String |

You can read more about the BED format here.

The BED object

This tool will convert each line of a BED file in one JavaScript object, where each column of the BED file will be saved with the format key=value. The key attribute will be one of the previous table.

Example of a BED file:

1	6579260	6579725	PLEKHG5
1	10292069	10292214	KIF1B
1	33282660	33282997	YARS
1	156084621	156085204	LMNA

The previous BED file converted to a BED object will be:

[
  { chromosome: '1', start: 6579260, end: 6579725, name: 'PLEKHG5' },
  { chromosome: '1', start: 10292069, end: 10292214, name: 'KIF1B' },
  { chromosome: '1', start: 33282660, end: 33282997, name: 'YARS' },
  { chromosome: '1', start: 156084621, end: 156085204, name: 'LMNA' }
]

API

Include the package in your JavaScript code using:

var bedJS = require('bedjs');

bedJS.Read(file)

Read a BED file. Returns an array with one BED object for each line of the BED file.

var bed = bedJS.Read('example.bed');

bedJS.Write(file, bed)

Save an array with BED objects to a BED file.

bedJS.Write('newfile.bed', bed);

bedJS.Collapse

A class to combine all BED objects into a new object. The following combining methods are available:

bedJS.Collapse.ByRegion(bed)

Combines all BED objects with overlapping features into a new BED object. This method only combines all features that have the same chromosome and the same strand.

Example of a BED object:

[
  { "chromosome": "2", "start": 500, "end": 600, "name": "REGION1", "score": 0, "strand": "+" },
  { "chromosome": "2", "start": 550, "end": 700, "name": "REGION2", "score": 0, "strand": "+" },
  { "chromosome": "2", "start": 500, "end": 700, "name": "REGION3", "score": 0, "strand": "-" }
]

If now we run:

var bed2 = bedJS.Collapse.ByRegion(bed);

This will return the following array:

[
  { "chromosome": "2", "start": 500, "end": 700, "name": "REGION1,REGION2", "score": 0, "strand": "+" },
  { "chromosome": "2", "start": 500, "end": 700, "name": "REGION3", "score": 0, "strand": "-" }
]

bedJS.Collapse.ByName(bed)

Combines all BED objects that have the same feature name. The output object will have the minimum start position and the maximum end position of all objects combined.

Example of a BED object:

[
  { "chromosome": "2", "start": 500, "end": 600, "name": "REGION1", "score": 0, "strand": "+" },
  { "chromosome": "2", "start": 700, "end": 800, "name": "REGION1", "score": 0, "strand": "+" },
  { "chromosome": "2", "start": 500, "end": 700, "name": "REGION2", "score": 0, "strand": "-" }
]

If now we run:

var bed2 = bedJS.Collapse.ByName(bed);

This will return the following array:

[
  { "chromosome": "2", "start": 500, "end": 800, "name": "REGION1", "score": 0, "strand": "+" },
  { "chromosome": "2", "start": 500, "end": 700, "name": "REGION3", "score": 0, "strand": "-" }
]

bedJS.Fasta

A set of tools to work with Fasta files.

bedJS.Fasta.Index(file)

Create an index of your Fasta file in JSON format. This index is required if you want to use the bedJS.Fasta.Get function.

bedJS.Fasta.Index('fasta_file.fa');

The previous command will generate a file called fasta_file.fa.json. Once you have created the index file, you don't need to run it again.

bedJS.Fasta.Get(fasta, bed, opt)

A method to extract sequences from a Fasta file using the regions delimited in your BED file or in your BED object. The inputs of this method are:

  • fasta: the path of your fasta file where you will extract the sequence.
  • bed: a BED object or the path to a BED file with the regions where you want to extract the sequence.
  • opt: an object with the following keys:
    • strand: set it to true if you want to extract the sequence with the same orientation defined in the BED file. Default is false.

This will return an array with the sequence for each BED object.

Note that you must run bedJS.Fasta.Index to index the Fasta file before run this function.

Example of a Fasta file:

test.fa:
>1
ACTGAAAAACCCGGTTTAACGTACCGG

Example of a bed file

test.bed:
1 5 10

If you run:

var sequence = bedJS.Fasta.Get('test.fa', 'test.bed', { strand: false });

// -> sequence = [ { "head": "1:5-10", "sequence": "AAAAC"}] 

License

© MIT LICENSE Jose M. Juanes.