-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvcfline.cpp
207 lines (160 loc) · 3.65 KB
/
vcfline.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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
This file is part of CuteVCF.
Foobar is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Foobar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
@author : Sacha Schutz <[email protected]>
*/
#include "vcfline.h"
VcfLine::VcfLine()
{
mChromosom="chr3";
mPosition = 10;
}
VcfLine VcfLine::fromLine(const QByteArray &line)
{
VcfLine out;
QByteArrayList lines = line.split(QChar::Tabulation);
if ( line.count() >= 9)
{
out.setChromosom(lines.at(0));
out.setPosition(lines.at(1).toUInt());
out.setId(lines.at(2));
out.setRef(lines.at(3));
out.setAlt(lines.at(4));
out.setQual(lines.at(5).toInt());
out.setFilter(lines.at(6));
out.setRawInfos(lines.at(7));
out.setRawFormat(lines.value(8));
for (int i=9; i<lines.count(); ++i)
out.addRawSample(lines.at(i));
}
return out;
}
const QByteArray& VcfLine::chromosom() const
{
return mChromosom;
}
void VcfLine::setChromosom(const QByteArray &chromosom)
{
mChromosom = chromosom;
}
quint64 VcfLine::position() const
{
return mPosition;
}
void VcfLine::setPosition(const quint64 &position)
{
mPosition = position;
}
const QByteArray& VcfLine::id() const
{
return mId;
}
void VcfLine::setId(const QByteArray &id)
{
mId = id;
}
const QByteArray& VcfLine::ref() const
{
return mRef;
}
void VcfLine::setRef(const QByteArray &ref)
{
mRef = ref;
}
const QByteArray& VcfLine::alt() const
{
return mAlt;
}
void VcfLine::setAlt(const QByteArray &alt)
{
mAlt = alt;
}
int VcfLine::qual() const
{
return mQual;
}
void VcfLine::setQual(int qual)
{
mQual = qual;
}
const QByteArray& VcfLine::filter() const
{
return mFilter;
}
void VcfLine::setFilter(const QByteArray &filter)
{
mFilter = filter;
}
const QByteArray& VcfLine::rawFormat() const
{
return mFormat;
}
QByteArrayList VcfLine::formats() const
{
return rawFormat().split(':');
}
void VcfLine::setRawFormat(const QByteArray &format)
{
mFormat = format;
}
const QByteArray& VcfLine::rawInfos() const
{
return mInfos;
}
QHash<QByteArray, QVariant> VcfLine::infos() const
{
QHash<QByteArray, QVariant> out;
for (QByteArray item : rawInfos().split(';'))
{
QByteArrayList duo = item.split('=');
if (duo.size() == 2)
out[duo.at(0)] = duo.at(1);
}
return out;
}
void VcfLine::setRawInfos(const QByteArray &infos)
{
mInfos = infos;
}
QByteArray VcfLine::rawSample(int i) const
{
return mSamples.value(i,QByteArray());
}
QHash<QByteArray, QVariant> VcfLine::sample(int i)
{
QHash<QByteArray, QVariant> out;
QByteArrayList format = formats();
qDebug()<<rawSample(i);
QByteArrayList values = rawSample(i).split(':');
for (int i=0; i<values.size();++i)
{
if (i<format.count())
{
out.insert(format.at(i), values.at(i));
}
}
return out;
}
void VcfLine::addRawSample(const QByteArray &sample)
{
mSamples.append(sample);
}
int VcfLine::sampleCount() const
{
return mSamples.count();
}
QString VcfLine::location() const
{
QString c = mChromosom;
QString p = QString::number(mPosition);
return c+":"+p;
}