-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add preliminary Nexus support (#458)
* update * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * clarify * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update localBackendWorker.js * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
3ed4648
commit 7edb069
Showing
7 changed files
with
79 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// get nexusString from tree.nexus | ||
function nexusToNewick(nexusString) { | ||
// get Translate section if present | ||
const translateBlock = nexusString.match(/Translate(.*?);/gims); | ||
const translate = translateBlock[0]; | ||
|
||
let translations = {}; | ||
|
||
// get all the translations | ||
translate.split("\n").forEach((line) => { | ||
line = line.trim(); | ||
const parts = line.split(" "); | ||
if (parts.length === 2) { | ||
const key = parts[0]; | ||
const value = parts[1].replace(",", ""); | ||
translations[key] = value; | ||
} | ||
}); | ||
|
||
// get all the trees | ||
|
||
const treeBlock = nexusString.match(/tree TREE1 = (.*?;)/gims); | ||
|
||
// get the Newick string from the tree block | ||
const newickString = treeBlock[0].match(/\((.*?)\).+;/gims)[0]; | ||
|
||
//remove comments, which are indicated by [...] | ||
|
||
const newick = newickString.replace(/\[(.*?)\]/gims, ""); | ||
|
||
// translate the taxon labels in the Newick string | ||
const translatedNewickString = newick.replace( | ||
/([^:\,\(\)]+)/gims, | ||
(match) => { | ||
//console.log(translations[match]) | ||
return translations[match] || match; | ||
} | ||
); | ||
|
||
return translatedNewickString; | ||
} | ||
|
||
export default nexusToNewick; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7edb069
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
cov2tree – ./
vbigtree.vercel.app
taxonomy.taxonium.org
cov2tree.org
mpx.taxonium.org
taxonium.org
www.cov2tree.org
www.taxonium.org
taxodium.org
www.taxodium.org
visualtreeoflife.taxonium.org
cov2tree-theosanderson.vercel.app
cov2tree-git-master-theosanderson.vercel.app