-
Notifications
You must be signed in to change notification settings - Fork 0
/
oneTimeJob.js
58 lines (53 loc) · 1.49 KB
/
oneTimeJob.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
'use strict'
const fs = require('fs')
const Genomes = require('./src/Genomes')
const Genes = require('./src/Genes')
const MakeFasta = require('./src/MakeFasta')
const genomes = new Genomes()
const genes = new Genes()
async function writeSampleFasta(genomeInfoAll) {
const readUp = fs.readFileSync('./geneSample.fa').toString().split('\n')
const inFile = []
readUp.forEach((line) => {
if (line[0] === '>')
inFile.push(line.split('|')[1].split('-')[0])
})
const selectedGenomes = genomeInfoAll.filter((genomeInfo) => {
return inFile.indexOf(genomeInfo.version) === -1
})
const writeDown = fs.createWriteStream('./geneSample.fa', {flags: 'a'})
mainLoop:
for (let i = 0, N = selectedGenomes.length; i < N; i++){
const genomeInfo = selectedGenomes[i]
console.log(`${genomeInfo.version} - ${i}/${N}`)
try {
await genes.byGenomeVersionPerPage(genomeInfo.version, 3)
.catch((err) => {
throw err
})
.then((genesInfo) => {
// console.log(genesInfo[0])
const goodGenes = genesInfo.filter(
(gene) => {
return gene.aseq_id !== null
})
return genes.addAseqInfo(goodGenes)
})
.then((genesPlus) => {
console.log(`Adding: ${genesPlus[0].stable_id}`)
const sampleGene = genesPlus[0]
const mkFasta = new MakeFasta(genomeInfo)
const fasta = mkFasta.processOne(sampleGene)
writeDown.write(fasta)
})
}
catch (err) {
continue mainLoop
}
}
}
genomes.getInfoAll()
.then(writeSampleFasta)
.catch((err) => {
throw err
})