-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathchromosomes.cpp
More file actions
33 lines (29 loc) · 870 Bytes
/
chromosomes.cpp
File metadata and controls
33 lines (29 loc) · 870 Bytes
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
#include "chromosomes.hpp"
KSEQ_INIT(gzFile, gzread)
// FIXME: avoid this
vector<string> chromosomes;
unordered_map<string, char *> chromosome_seqs;
void load_chromosomes(string path) {
spdlog::info("Loading reference genome from {}..", path);
gzFile fp = gzopen(path.c_str(), "r");
kseq_t *seq = kseq_init(fp);
int l;
while ((l = kseq_read(seq)) >= 0) {
string name(seq->name.s);
spdlog::debug("Extracted {} ({}bp)", seq->name.s, l);
for (int i = 0; i < l; i++)
seq->seq.s[i] = toupper(seq->seq.s[i]);
chromosomes.push_back(seq->name.s);
char *s = (char *)malloc(sizeof(char) * (l + 1));
memcpy(s, seq->seq.s, l + 1);
s[l] = '\0';
chromosome_seqs[seq->name.s] = s;
}
kseq_destroy(seq);
gzclose(fp);
}
void destroy_chromosomes() {
for(const auto &chrom : chromosomes) {
free(chromosome_seqs[chrom]);
}
}