Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bioutils

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bioutils - npm Package Compare versions

Comparing version 0.1.0-alpha.1 to 0.1.0-alpha.2

test/nexusParser.test.js

2

package.json
{
"name": "bioutils",
"version": "0.1.0-alpha.01",
"version": "0.1.0-alpha.02",
"license": "MIT",

@@ -5,0 +5,0 @@ "main": "src/bioUtils.js",

@@ -11,2 +11,3 @@ // io

const newickParser = require('./parsers/newickParser');
const nexusParser = require('./parsers/nexusParser');

@@ -31,2 +32,3 @@ // stats

'newickParser': newickParser,
'nexusParser': nexusParser,
'containsStopCodons': containsStopCodons,

@@ -33,0 +35,0 @@ 'numberOfSites': numberOfSites,

/**
* Converts a newick string into a bioUtils object
* TODO: This is currently only handling a small subset of nexus formats and data.
* TODO: This was written with simplicity and readability in mind; it can and should be speed up a bit though.
* @param {string} nexusString input newick string using '\n' for line breaks
* @param {object} metaData any metadata to be appended to the bioUtils JSON object
* @returns {object} the bioUtils JSON object {'sequences': []],'tree': string,'metaData': {'fileType': string, (metaData param)}}
* @returns {object} the bioUtils JSON object {'sequences': [],'tree': string,'metaData': {'fileType': string, (metaData param)}}
*/
function nexusParser(nexusString, metaData) {
/** TODO:
const nexusLines = nexusString.split("\n");
// 1. Parse out the sequences.
// 1a. Get a list of the labels
const taxaLabelsIndex = nexusLines.indexOf("\tTAXLABELS") + 1;
const taxaLabels = nexusLines[taxaLabelsIndex]
.slice(0, -1)
.trim()
.split(" ")
.map(name => name.slice(1, -1));
// 1b. Go through the list of labels and add the sequence character strings
const sequenceStartIndex = nexusLines.indexOf("MATRIX") + 1;
var sequences = [];
for (let i=0; i<taxaLabels.length; i++) {
const sequenceObject = {'name': taxaLabels[i], 'sequence': nexusLines[sequenceStartIndex + i].replace(';','').replace(' ','')}
sequences.push(sequenceObject)
}
// 2. Parse out the tree.
var tree;
const treeIndex = nexusLines.indexOf("BEGIN TREES;") + 1;
if (treeIndex == 1) {
tree = undefined;
} else {
const numberOfTrees = nexusLines.slice(treeIndex).indexOf("END;");
if (numberOfTrees >1) {
console.log('multiple trees not yet supported; the fist tree was used')
}
const treeLine = nexusLines[treeIndex];
tree = treeLine.substring(treeLine.indexOf("("));
}
// 3. Add the metaData
var objectMetaData;
metaData ? objectMetaData = metaData : objectMetaData = {'fileType': 'newick'}
metaData ? objectMetaData = metaData : objectMetaData = {'fileType': 'nexus'}
// 4. Create and return the object
const bioUtilsJson = {
'sequences': [],
'sequences': sequences,
'tree': tree,
'metaData': objectMetaData
}
return bioUtilsJson
*/
return 'nexusParser not implemented yet'
return bioUtilsJson
}
module.exports = nexusParser;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc