forked from wtsi-npg/simtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManifest.h
142 lines (110 loc) · 4.05 KB
/
Manifest.h
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//
// Manifest.h
//
// Author: Jennifer Liddle (js10)
//
// $Id: Manifest.h 1354 2010-11-11 16:20:09Z js10 $
//
// Author: Jennifer Liddle <js10@sanger.ac.uk, jennifer@jsquared.co.uk>
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation and/or
// other materials provided with the distribution.
// 3. Neither the name of the Genome Research Ltd nor the names of its contributors
// may be used to endorse or promote products derived from software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. EVENT SHALL GENOME RESEARCH LTD. BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
// THE POSSIBILITY OF SUCH DAMAGE.
//
#ifndef _MANIFEST_H
#define _MANIFEST_H
#include <map>
#include <string>
#include <vector>
#ifndef SWIG
#include <hash_map> // SGI extension to C++ STL standard
#endif
using namespace std;
class snpClass {
public:
snpClass(void) {
index = -1;
name = "?";
chromosome = "?";
position = -1;
score = -1;
snp[0] = '?';
snp[1] = '?';
iStrand = '?';
cStrand = '?';
normId = -1;
BeadSetID = -1;
};
int index;
string name;
string chromosome;
long position;
float score;
char snp [2]; // 'GT' or 'AG' for example. Defined to be A/B for TOP strand.
char iStrand; // Illumina Strand: B (Bottom) or T (Top)
char cStrand; // Customer Strand: B (Bottom) or T (Top)
int normId; // index into normalisation table
int BeadSetID; // Only available from "wide format" manifest files (.csv not .bpm.csv)
};
struct eqstr
{
bool operator()(string s1, string s2) const
{
return s1.compare(s2) == 0;
}
};
class Manifest {
public:
Manifest();
void open(char *filename, bool wide = false);
void open(string filename, bool wide = false);
void open (string filename, string chromosome, bool wide = false);
void order_by_position();
string filename;
vector<snpClass> snps; // If your code removes elements from this vector after
// it's been populated, for now you must not use code
// which uses the hash_map snpNames for lookup.
map<int,int> normIdMap;
void dump(void);
snpClass* lookup_SNP_by_name (string snpname); // Caller must delete object returned.
// snpClass* lookup_SNP_by_position (long pos); // Ditto.
snpClass* findSNP(string snpname) {
int n = snp2idx((char*)snpname.c_str());
return ((n == -1) ? NULL : &(snps[n]));
}
string get_chromosome_for_SNP (string snpname);
int snp2idx(char *snp) { return snpNames.find(snp) == snpNames.end() ? -1 : snpNames[snp]; }
void exclude_cnvs();
protected:
void populate_hashmap();
void convert (snpClass* snip, std::string input_snp); // Convert BOT SNPs to TOP format.
void test_convert();
bool find_wide_columns(string& linestr, map<string,int>& dict);
int get_map_value (map<string, int>& mymap, const char* const treasure);
// For fast lookup by SNP name. Key = name of SNP. Value = index in "snps" vector.
#ifdef SWIG
map<string, int> snpNames;
#else
hash_map<string, int, hash<string>, eqstr> snpNames;
#endif
string selectedChromosome; // Used if we are only concerned with a specific chromosome.
bool EXCLUDE_CNVS;
};
#endif // _MANIFEST_H