This repository was archived by the owner on Mar 19, 2020. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathcli.js
More file actions
106 lines (92 loc) · 3 KB
/
Copy pathcli.js
File metadata and controls
106 lines (92 loc) · 3 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env node
/**
* Module dependencies.
*/
const program = require('commander')
const tubeify = require('./dist/index.js')
const fs = require('fs')
const parse = require('parse-jsonp')
// This is a testing method.
/*
let tubes = new tubeify.Tubeify(30, 300, 1000);
console.log(tubes.tiles_range);
console.log(tubes.tiles(0)) // 0
console.log(tubes.tiles(1)) // 0
console.log(tubes.tiles(9)) // 0
console.log(tubes.tiles(10)) //1
console.log(tubes.tiles(11)) //1
console.log(tubes.tiles(290)) //29
console.log(tubes.tiles(300)) //289
*/
program
.option('-b, --bins <bins>', '# of bins are provided in total')
.option('-t, --tiles <tiles>', '# of tiles, default: -1 (one bin equals one tile)')
.option('-l, --bin_length <length>', 'Length of nucleotide sequence per bin')
.option('-j, --json <file>', 'odgi-bin JSON file')
.option('-p, --jsonp <file>', 'odgi-bin JSONP file')
.option('-k, --tile_json <file>', 'tile JSON file')
.version('0.0.1', '-v, --version')
.parse(process.argv);
function readLines(input, func, callback) {
var remaining = '';
input.on('data', function(data) {
remaining += data;
var index = remaining.indexOf('\n');
var last = 0;
while (index > -1) {
var line = remaining.substring(last, index);
last = index + 1;
func(line);
index = remaining.indexOf('\n', last);
}
remaining = remaining.substring(last);
});
input.on('end', function() {
if (remaining.length > 0) {
func(remaining);
}
callback()
});
}
// console.log(program)
// If an input file is JSONP.
global.data = []
function func(line) {
global.data.push(JSON.parse(line))
}
function callback(from_json) {
let data = global.data
let input = []
data.forEach(item => {
item.bin_id = parseInt(item.bin_id) + 1
if (from_json) {
item.begins = JSON.parse(item["begins"])
item.ends = JSON.parse(item["ends"])
}
});
let tube = new tubeify.Tubeify(parseInt(program.tiles), parseInt(program.bin_length), parseInt(program.bins));
// let tube = new tubeify.Tubeify(30, 300, 1000); For given 300 bins, we would like to have 30 tiles.
let json = tube.tubeify(data);
console.log(JSON.stringify(json))
}
if (program.jsonp) {
var input_data = fs.createReadStream(program.jsonp);
readLines(input_data, func, callback);
} else {
// If an input file is JSON.
global.data = JSON.parse(fs.readFileSync(program.json, 'utf8'));
callback(true)
}
/*
let data = global.data
let input = []
data.forEach(item => {
item.bin_id = parseInt(item.bin_id)
item.begins = JSON.parse(item["begins"])
item.ends = JSON.parse(item["ends"])
});
let tube = new tubeify.Tubeify(parseInt(program.tiles), parseInt(program.bin_length), parseInt(program.bins));
// let tube = new tubeify.Tubeify(30, 300, 1000); For given 300 bins, we would like to have 30 tiles.
let json = tube.tubeify(data);
console.log(JSON.stringify(json))
*/