Skip to content

Instantly share code, notes, and snippets.

@cmdcolin
Last active August 30, 2024 17:47
Show Gist options
  • Save cmdcolin/3f2d4c205c06445507aa5995fbce5bd8 to your computer and use it in GitHub Desktop.
Save cmdcolin/3f2d4c205c06445507aa5995fbce5bd8 to your computer and use it in GitHub Desktop.
// usage:
// download this file to a file unprepare_seqs.js
// then run:
// node unprepare_seqs.js /path/to/seq/dir output_file.fa
// after that, fold the lines to a constant line length with:
// fold output_file.fa > output_file2.fa
const fs = require('fs')
const path = require('path')
const dir = process.argv[2] || '.'
const output = process.argv[3] || 'out.fa'
const obj = {}
fs.readdirSync(dir, { recursive: true }).forEach(d => {
const ret = d.lastIndexOf('/')
if (d.indexOf('-') !== -1) {
const [chr] = d.slice(ret + 1).split('-')
if (!obj[chr]) {
obj[chr] = []
}
obj[chr].push(d)
}
})
let ret = ''
Object.entries(obj).forEach(([chr, files]) => {
let arg = ''
for (const file of files) {
arg += fs.readFileSync(path.join(dir, file), 'utf8')
}
ret += `>${chr}\n${arg}\n`
})
fs.writeFileSync(output, ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment