-
Notifications
You must be signed in to change notification settings - Fork 1
/
read_referror.cpp
executable file
·72 lines (66 loc) · 2.11 KB
/
read_referror.cpp
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
// pls check the header file: read_referror.h for more info about this function. //
// this function is similar to read_chromosome(FILE* fp).
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include "globals.h"
#include "is_number.h"
bool read_referror(char* freferror)
{
if(verbose) printf("Reading ref errors from file:\t\t%s...", freferror);
FILE* fp = fopen(freferror, "r");
if(fp == NULL)
{
printf("Ref-error File \'%s\' does NOT exist. Exited.\n", freferror);
exit(1);
}
if (!fp) return false;
// caution size of word
char word[1024];
std::string id_chr;
std::string po_err;
// global map
REFERROR.clear();
while(!feof(fp))
{
id_chr = "";
po_err = "";
// read chroms id
fscanf(fp, "%s\n", word);
// check chroms id
std::string id_chr(word);
if(CHR2SIZE.find(id_chr) == CHR2SIZE.end()) {//1.ignore entry not in given list
fscanf(fp, "%s\n", word);
continue;
}
// read error pos
fscanf(fp, "%s\n", word);
// check error pos
if(!is_number(word)) continue; // 2.ignore entry that is not a number
if(atol(word) > CHR2SIZE[id_chr]) continue; // 3.ignore entry that exceeds bounds
std::string po_err(word);
// record if not found in map
if(id_chr.length()>0 && po_err.length()>0)
REFERROR.insert(std::pair<std::string,bool>(id_chr+".#."+po_err, true));
}
fclose(fp);
// if no records found
if (REFERROR.size()==0)
{
if(CMD.find("-verbose")!=CMD.end())
printf("no error reference provided: \n");
return false;
}
// print records
if(verbose) printf("done.\n");
if (verbose)
{
printf("ref errors provided. \n");
map<std::string, bool>::iterator iter;
for (iter = REFERROR.begin(); iter != REFERROR.end(); iter++)
{
printf("\t\t\t\t\t%s, %ld\n", (*iter).first.c_str(), (unsigned long)(*iter).second);
}
}
return true;
}