-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathphyloxml_parser_example.js
More file actions
62 lines (51 loc) · 2.17 KB
/
phyloxml_parser_example.js
File metadata and controls
62 lines (51 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* Copyright (C) 2016 Christian M. Zmasek
* Copyright (C) 2016 J. Craig Venter Institute
* All rights reserved
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
* Created by czmasek on 7/7/2016.
*/
"use strict";
var px = require('./phyloxml').phyloXml;
var fs = require('fs');
var a = require('path').join(__dirname, "./data/two_trees.xml");
var b = require('path').join(__dirname, "./data/example_2.xml");
var c = require('path').join(__dirname, "./data/apaf.xml");
var d = require('path').join(__dirname, "./data/amphi_frost.xml");
var e = require('path').join(__dirname, "./data/phyloxml_test1.xml");
var f = require('path').join(__dirname, "./data/phyloxml_test2.xml");
[a, b, c, d, e, f].forEach(test);
function test(element, index) {
console.log(index);
var text = fs.readFileSync(element, 'utf8');
px.parse(text, {trim: true, normalize: true});
}
var xmlfile = require('path').join(__dirname, "./data/H1_tree_June2016_colored.xml");
// Synchronous parsing of phyloXML-formatted string:
var text = fs.readFileSync(xmlfile, 'utf8');
var phys = px.parse(text, {trim: true, normalize: true});
var len = phys.length;
console.log("Parsed " + len + " tree:");
for (var i = 0; i < len; i++) {
console.log();
console.log("Tree " + i + ":");
var str = px.toPhyloXML(phys[i], 3);
console.log(str);
}
// Asynchronous parsing of phyloXML-formatted stream:
var stream = fs.createReadStream(xmlfile, {encoding: 'utf8'});
px.parseAsync(stream, {trim: true, normalize: true});