forked from samuell/gccontent-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gc.js
executable file
·36 lines (31 loc) · 832 Bytes
/
gc.js
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
#!/usr/bin/env node
const fs = require('fs')
const readline = require('readline')
const rl = readline.createInterface({
input: fs.createReadStream('chry_multiplied.fa')
})
// https://stackoverflow.com/a/60361745 - performance recommendation
function countCharacter (str, char) {
var start = 0
var count = 0
while ((start = str.indexOf(char, start) + 1) !== 0) {
count++
}
return count
}
var gc = 0
var total = 0
rl.on('line', (line) => {
if (!(line.startsWith('>'))) {
var countA = countCharacter(line, 'A')
var countC = countCharacter(line, 'C')
var countG = countCharacter(line, 'G')
var countT = countCharacter(line, 'T')
gc += countC + countG
total += countA + countC + countG + countT
}
})
rl.on('close', () => {
var gcFraction = gc / total
console.log(gcFraction * 100)
})