Comparing version 0.1.0-alpha.1 to 0.1.0-alpha.2
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
1634246
2430
4