-
Notifications
You must be signed in to change notification settings - Fork 2
/
indexFastaForBowTie2Alignment.ts
116 lines (94 loc) · 4.18 KB
/
indexFastaForBowTie2Alignment.ts
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
107
108
109
110
111
112
113
114
115
116
import * as atomic from "./atomicOperations";
import {Fasta,getFaiPath} from "../fasta";
import {getContigsFromFastaFile} from "../fastaContigLoader";
import {getPath} from "../file";
import {getReadable,getReadableAndWritable} from "../getAppPath";
import {Job} from "../main/Job";
import {bowTie2Build} from "./indexFasta/bowTie2Build";
import {samToolsFaidx} from "./indexFasta/samToolsFaidx";
export class IndexFastaForBowTie2Alignment extends atomic.AtomicOperation
{
public fasta : Fasta;
public samToolsExe : string;
public bowtie2BuildExe : string;
public faiPath : string;
public faiJob : Job;
public faiFlags : atomic.CompletionFlags;
public bowTieIndexPath : string;
public bowtieJob : Job;
public bowtieFlags : atomic.CompletionFlags;
public bowtieSizeThreshold : number;
public bowtieIndices : Array<string>;
constructor()
{
super();
this.faiFlags = new atomic.CompletionFlags();
this.bowtieFlags = new atomic.CompletionFlags();
this.bowtieIndices = new Array<string>();
//the size threshold between being 32-bit and being 64-bit
this.bowtieSizeThreshold = 4294967096;
this.samToolsExe = getReadable('samtools');
if(process.platform == "linux")
this.bowtie2BuildExe = getReadable('bowtie2-build');
else if(process.platform == "win32")
this.bowtie2BuildExe = getReadable('python/python.exe');
}
public setData(data : Fasta) : void
{
this.fasta = data;
this.faiPath = getFaiPath(this.fasta);
this.destinationArtifacts.push(this.faiPath);
//samtool faidx will write the .fai beside the input fasta
this.generatedArtifacts.push(`${getPath(this.fasta)}.fai`);
this.bowTieIndexPath = getReadableAndWritable(`rt/indexes/${this.fasta.uuid}`);
//if 64-bit, add a 1 to the file extension
let x64 : string = (this.fasta.size > this.bowtieSizeThreshold ? "1" : "");
this.bowtieIndices.push(`${this.bowTieIndexPath}.1.bt2${x64}`);
this.bowtieIndices.push(`${this.bowTieIndexPath}.2.bt2${x64}`);
this.bowtieIndices.push(`${this.bowTieIndexPath}.3.bt2${x64}`);
this.bowtieIndices.push(`${this.bowTieIndexPath}.4.bt2${x64}`);
this.bowtieIndices.push(`${this.bowTieIndexPath}.rev.1.bt2${x64}`);
this.bowtieIndices.push(`${this.bowTieIndexPath}.rev.2.bt2${x64}`);
this.destinationArtifacts.concat(this.bowtieIndices);
}
//bowTie2Build -> samTools faidx
public run() : void
{
this.logRecord = atomic.openLog(this.name,"Index Fasta for Alignment");
let self = this;
(async function(){
return new Promise<void>(async (resolve,reject) => {
try
{
self.progressMessage = "Building bowtie2 index";
self.update();
await bowTie2Build(self);
self.setSuccess(self.bowtieFlags);
self.update();
self.progressMessage = "Building fai index";
self.update();
await samToolsFaidx(self.fasta,self);
self.setSuccess(self.faiFlags);
self.update();
self.progressMessage = "Reading contigs";
self.update();
//don't reparse contigs if we don't have to
//contigs are parsed during viz indexing as well
//if we reparse, we will clobber contig uuids and all references which point to them
if(!self.fasta.contigs || self.fasta.contigs.length == 0)
{
//contig information is required by the coverage distillation step of aligning
self.fasta.contigs = await getContigsFromFastaFile(getPath(self.fasta));
}
self.setSuccess(self.flags);
self.fasta.indexed = true;
self.update();
}
catch(err)
{
self.abortOperationWithMessage(err);
}
});
})();
}
}