Created
October 6, 2018 11:54
-
-
Save tryshchenko/254e3a23fce231f9b7f95139f988e87f to your computer and use it in GitHub Desktop.
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
const fs = require('fs'); | |
const BLOCKS_LENGTH = 4; | |
const GENO_PAIR_OFFSET = 3; | |
const isCommentLine = (el) => el.indexOf('#') > -1; | |
const isValidSequenceLine = (line) => line.length !== BLOCKS_LENGTH; | |
module.exports = (genomePath) => { | |
const data = fs.readFileSync(genomePath, 'utf-8'); | |
return data.split('\n').reduce((prev, el) => { | |
if (isCommentLine(el)) { | |
return prev; | |
} | |
const splitter = el.indexOf('\t') > 0 ? '\t' : ' '; | |
const trimmed = el.split(splitter).filter(x => x !== ''); | |
const geno = trimmed[0]; | |
if (!geno || !trimmed[GENO_PAIR_OFFSET] || isValidSequenceLine(trimmed)) { | |
return prev; | |
} | |
prev[geno] = prev[geno] || []; | |
prev[geno].push(trimmed[GENO_PAIR_OFFSET]); | |
return prev; | |
}, {}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment