{"id":17715668,"url":"https://github.com/jmjuanes/bedjs","last_synced_at":"2025-03-31T11:23:11.160Z","repository":{"id":57189405,"uuid":"49022094","full_name":"jmjuanes/bedjs","owner":"jmjuanes","description":"Manage BED files with Node.JS (Bioinformatics)","archived":false,"fork":false,"pushed_at":"2016-12-06T11:34:52.000Z","size":56,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-09T01:06:25.791Z","etag":null,"topics":["bed","bioinformatics","fasta"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/bedjs","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jmjuanes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-04T20:45:12.000Z","updated_at":"2020-04-27T23:20:41.000Z","dependencies_parsed_at":"2022-09-15T06:02:19.110Z","dependency_job_id":null,"html_url":"https://github.com/jmjuanes/bedjs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmjuanes%2Fbedjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmjuanes%2Fbedjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmjuanes%2Fbedjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmjuanes%2Fbedjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jmjuanes","download_url":"https://codeload.github.com/jmjuanes/bedjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246458816,"owners_count":20780828,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bed","bioinformatics","fasta"],"created_at":"2024-10-25T12:06:41.152Z","updated_at":"2025-03-31T11:23:11.138Z","avatar_url":"https://github.com/jmjuanes.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bedJS\n\n[![npm](https://img.shields.io/npm/v/bedjs.svg?style=flat-square)](https://www.npmjs.com/package/bedjs)\n[![npm](https://img.shields.io/npm/dt/bedjs.svg?style=flat-square)](https://www.npmjs.com/package/bedjs)\n\nManage BED (Browser Extensible Data) files with Node.JS (Bioinformatics).\n\n## Install\n\nUse NPM to install the package:\n\n```\nnpm install bedjs\n```\n\n## Overview\n\n### About the BED file format\n\nA 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:\n\n| KEY | Description | Type |\n|-----|-------------|------|\n| chromosome | Chromosome name | String |\n| start | Start position of the feature | Integer |\n| end | End position of the feature | Integer |\n| name | Name of the line | String |\n| score | Score between 0 and 1000 | Integer |\n| strand | Strand of the feature ('+' or '-') | String |\n| thickStart | Start position at which the feature is drawn thickly | Integer |\n| thickEnd | End position at which the feature is drawn thickly | Integer |\n| itemRgb | RGB value in format R,G,B | String |\n| blockCount | The number of blocks (exons) in the BED line | Integer |\n| blockSizes | A comma-separated list of the block sizes | String |\n| blockStarts | A comma-separated list of block starts | String |\n\nYou can read more about the BED format [here](http://Mar2016.archive.ensembl.org/info/website/upload/bed.html).\n\n### The BED object\n\nThis 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.\n\nExample of a BED file:\n\n```\n1\t6579260\t6579725\tPLEKHG5\n1\t10292069\t10292214\tKIF1B\n1\t33282660\t33282997\tYARS\n1\t156084621\t156085204\tLMNA\n```\n\nThe previous BED file converted to a BED object will be:\n\n```javascript\n[\n  { chromosome: '1', start: 6579260, end: 6579725, name: 'PLEKHG5' },\n  { chromosome: '1', start: 10292069, end: 10292214, name: 'KIF1B' },\n  { chromosome: '1', start: 33282660, end: 33282997, name: 'YARS' },\n  { chromosome: '1', start: 156084621, end: 156085204, name: 'LMNA' }\n]\n```\n\n## API\n\nInclude the package in your JavaScript code using:\n\n```javascript\nvar bedJS = require('bedjs');\n```\n\n### bedJS.Read(file)\n\nRead a BED file. Returns an array with one BED object for each line of the BED file.\n\n```javascript\nvar bed = bedJS.Read('example.bed');\n```\n\n### bedJS.Write(file, bed)\n\nSave an array with BED objects to a BED file.\n\n```javascript\nbedJS.Write('newfile.bed', bed);\n```\n\n### bedJS.Collapse\n\nA class to combine all BED objects into a new object. The following combining methods are available:\n\n#### bedJS.Collapse.ByRegion(bed)\n\nCombines 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.\n\nExample of a BED object:\n\n```javascript\n[\n  { \"chromosome\": \"2\", \"start\": 500, \"end\": 600, \"name\": \"REGION1\", \"score\": 0, \"strand\": \"+\" },\n  { \"chromosome\": \"2\", \"start\": 550, \"end\": 700, \"name\": \"REGION2\", \"score\": 0, \"strand\": \"+\" },\n  { \"chromosome\": \"2\", \"start\": 500, \"end\": 700, \"name\": \"REGION3\", \"score\": 0, \"strand\": \"-\" }\n]\n```\n\nIf now we run:\n\n```javascript\nvar bed2 = bedJS.Collapse.ByRegion(bed);\n```\n\nThis will return the following array:\n\n```javascript\n[\n  { \"chromosome\": \"2\", \"start\": 500, \"end\": 700, \"name\": \"REGION1,REGION2\", \"score\": 0, \"strand\": \"+\" },\n  { \"chromosome\": \"2\", \"start\": 500, \"end\": 700, \"name\": \"REGION3\", \"score\": 0, \"strand\": \"-\" }\n]\n```\n\n#### bedJS.Collapse.ByName(bed)\n\nCombines 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.\n\nExample of a BED object:\n\n```javascript\n[\n  { \"chromosome\": \"2\", \"start\": 500, \"end\": 600, \"name\": \"REGION1\", \"score\": 0, \"strand\": \"+\" },\n  { \"chromosome\": \"2\", \"start\": 700, \"end\": 800, \"name\": \"REGION1\", \"score\": 0, \"strand\": \"+\" },\n  { \"chromosome\": \"2\", \"start\": 500, \"end\": 700, \"name\": \"REGION2\", \"score\": 0, \"strand\": \"-\" }\n]\n```\n\nIf now we run:\n\n```javascript\nvar bed2 = bedJS.Collapse.ByName(bed);\n```\n\nThis will return the following array:\n\n```javascript\n[\n  { \"chromosome\": \"2\", \"start\": 500, \"end\": 800, \"name\": \"REGION1\", \"score\": 0, \"strand\": \"+\" },\n  { \"chromosome\": \"2\", \"start\": 500, \"end\": 700, \"name\": \"REGION3\", \"score\": 0, \"strand\": \"-\" }\n]\n```\n\n### bedJS.Fasta\n\nA set of tools to work with Fasta files.\n\n#### bedJS.Fasta.Index(file)\n\nCreate an index of your Fasta file in JSON format. This index is required if you want to use the `bedJS.Fasta.Get` function.\n\n```javascript\nbedJS.Fasta.Index('fasta_file.fa');\n```\n\nThe 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.\n\n#### bedJS.Fasta.Get(fasta, bed, opt)\n\nA 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:\n\n- `fasta`: the path of your fasta file where you will extract the sequence.\n- `bed`: a BED object or the path to a BED file with the regions where you want to extract the sequence.\n- `opt`: an object with the following keys:\n  - `strand`: set it to `true` if you want to extract the sequence with the same orientation defined in the BED file. Default is `false`.\n\nThis will return an array with the sequence for each BED object.\n\nNote that you must run `bedJS.Fasta.Index` to index the Fasta file before run this function.\n\nExample of a Fasta file:\n```\ntest.fa:\n\u003e1\nACTGAAAAACCCGGTTTAACGTACCGG\n```\n\nExample of a bed file\n```\ntest.bed:\n1 5 10\n```\n\nIf you run:\n\n```javascript\nvar sequence = bedJS.Fasta.Get('test.fa', 'test.bed', { strand: false });\n\n// -\u003e sequence = [ { \"head\": \"1:5-10\", \"sequence\": \"AAAAC\"}] \n```\n\n## License\n\n\u0026copy; [MIT LICENSE](./LICENSE) Jose M. Juanes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmjuanes%2Fbedjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjmjuanes%2Fbedjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmjuanes%2Fbedjs/lists"}