|
34 | 34 | //
|
35 | 35 | #include "Gtc.h"
|
36 | 36 | #include <cstring>
|
| 37 | +#include <cstdio> |
37 | 38 | #include <iostream>
|
38 | 39 | #include <fstream>
|
39 | 40 | #include <sstream>
|
40 | 41 | #include <vector>
|
41 | 42 |
|
42 | 43 | using namespace std;
|
43 | 44 |
|
44 |
| -XFormClass::XFormClass(void) |
| 45 | +XFormClass::XFormClass(int version, float xOffset, float yOffset, |
| 46 | + float xScale, float yScale, float shear, float theta) |
45 | 47 | {
|
| 48 | + this->version = version; |
| 49 | + this->xOffset = xOffset; |
| 50 | + this->yOffset = yOffset; |
| 51 | + this->xScale = xScale; |
| 52 | + this->yScale = yScale; |
| 53 | + this->shear = shear; |
| 54 | + this->theta = theta; |
| 55 | +} |
| 56 | + |
| 57 | +void XFormClass::normalize(unsigned short x_raw, unsigned short y_raw, |
| 58 | + double &x_norm, double &y_norm) |
| 59 | +{ |
| 60 | + // This is the intensity normalization calculation, according to Illumina |
| 61 | + double tempx = x_raw - xOffset; |
| 62 | + double tempy = y_raw - yOffset; |
| 63 | + double cos_theta = cos(theta); |
| 64 | + double sin_theta = sin(theta); |
| 65 | + double tempx2 = cos_theta * tempx + sin_theta * tempy; |
| 66 | + double tempy2 = -sin_theta * tempx + cos_theta * tempy; |
| 67 | + double tempx3 = tempx2 - shear * tempy2; |
| 68 | + double tempy3 = tempy2; |
| 69 | + x_norm = tempx3 / xScale; |
| 70 | + y_norm = tempy3 / yScale; |
| 71 | +} |
| 72 | + |
| 73 | +string XFormClass::toString(void) |
| 74 | +{ |
| 75 | + int bufSize = 1000; |
| 76 | + char buffer[bufSize]; |
| 77 | + string v, xoff, yoff, xsca, ysca, shr, th; |
| 78 | + int n; |
| 79 | + const char *float_format = "%.6f"; |
| 80 | + try { // attempt to convert other data types to strings |
| 81 | + n = snprintf(buffer, bufSize, "%d", version); |
| 82 | + if (n >= bufSize) { throw 1; } |
| 83 | + v = string(buffer, n); |
| 84 | + |
| 85 | + n = snprintf(buffer, bufSize, float_format, xOffset); |
| 86 | + if (n >= bufSize) { throw 1; } |
| 87 | + xoff = string(buffer, n); |
| 88 | + |
| 89 | + n = snprintf(buffer, bufSize, float_format, yOffset); |
| 90 | + if (n >= bufSize) { throw 1; } |
| 91 | + yoff = string(buffer, n); |
| 92 | + |
| 93 | + n = snprintf(buffer, bufSize, float_format, xScale); |
| 94 | + if (n >= bufSize) { throw 1; } |
| 95 | + xsca = string(buffer, n); |
| 96 | + |
| 97 | + n = snprintf(buffer, bufSize, float_format, yScale); |
| 98 | + if (n >= bufSize) { throw 1; } |
| 99 | + ysca = string(buffer, n); |
| 100 | + |
| 101 | + n = snprintf(buffer, bufSize, float_format, shear); |
| 102 | + if (n >= bufSize) { throw 1; } |
| 103 | + shr = string(buffer, n); |
| 104 | + |
| 105 | + n = snprintf(buffer, bufSize, float_format, theta); |
| 106 | + if (n >= bufSize) { throw 1; } |
| 107 | + th = string(buffer, n); |
| 108 | + } catch (int param) { |
| 109 | + cerr << "Error: Unable to convert variable from GTC XForm to " |
| 110 | + << "string format. Bad input or corrupt GTC file?" << endl; |
| 111 | + throw; |
| 112 | + } |
| 113 | + string xf = "Version: "+v+"\nXOffset: "+xoff+"\nYOffset: "+yoff\ |
| 114 | + +"\nXScale: "+xsca+"\nYScale: "+ysca+"\nShear: "+shr+"\nTheta: "+th; |
| 115 | + return xf; |
| 116 | + |
46 | 117 | }
|
47 | 118 |
|
48 | 119 | Gtc::Gtc(void)
|
@@ -219,48 +290,38 @@ string Gtc::json_dump(void)
|
219 | 290 | return s.str();
|
220 | 291 | }
|
221 | 292 |
|
222 |
| -void Gtc::normalizeIntensity(double x_raw, double y_raw, |
223 |
| - double &x_norm, double &y_norm, |
224 |
| - unsigned int norm_id) { |
225 |
| - // This is the normalization calculation, according to Illumina |
226 |
| - XFormClass *XF = &(this->XForm[norm_id]); |
227 |
| - double tempx = x_raw - XF->xOffset; |
228 |
| - double tempy = y_raw - XF->yOffset; |
229 |
| - double cos_theta = cos(XF->theta); |
230 |
| - double sin_theta = sin(XF->theta); |
231 |
| - double tempx2 = cos_theta * tempx + sin_theta * tempy; |
232 |
| - double tempy2 = -sin_theta * tempx + cos_theta * tempy; |
233 |
| - double tempx3 = tempx2 - XF->shear * tempy2; |
234 |
| - double tempy3 = tempy2; |
235 |
| - x_norm = tempx3 / XF->xScale; |
236 |
| - y_norm = tempy3 / XF->yScale; |
237 |
| -} |
238 |
| - |
239 | 293 | void Gtc::readXForm(ifstream &file, int offset)
|
240 | 294 | {
|
241 | 295 | int arrayLen;
|
| 296 | + int total_reserved = 6; // 'reserved' floats after the xform fields |
242 | 297 | float reserved;
|
243 | 298 |
|
| 299 | + int version; |
| 300 | + float xOffset; |
| 301 | + float yOffset; |
| 302 | + float xScale; |
| 303 | + float yScale; |
| 304 | + float shear; |
| 305 | + float theta; |
| 306 | + |
244 | 307 | ios::pos_type pos = file.tellg();
|
245 | 308 | file.seekg(offset);
|
246 | 309 | file.read((char*)&arrayLen,4);
|
247 | 310 |
|
248 |
| - for (int n=0; n<arrayLen; n++) { |
249 |
| - XFormClass X; |
250 |
| - file.read((char*)&X.version, 4); |
251 |
| - file.read((char*)&X.xOffset, 4); |
252 |
| - file.read((char*)&X.yOffset, 4); |
253 |
| - file.read((char*)&X.xScale, 4); |
254 |
| - file.read((char*)&X.yScale, 4); |
255 |
| - file.read((char*)&X.shear, 4); |
256 |
| - file.read((char*)&X.theta, 4); |
257 |
| - file.read((char*)&reserved, 4); |
258 |
| - file.read((char*)&reserved, 4); |
259 |
| - file.read((char*)&reserved, 4); |
260 |
| - file.read((char*)&reserved, 4); |
261 |
| - file.read((char*)&reserved, 4); |
262 |
| - file.read((char*)&reserved, 4); |
263 |
| - this->XForm.push_back(X); |
| 311 | + for (int i=0; i<arrayLen; i++) { |
| 312 | + file.read((char*)&version, 4); |
| 313 | + file.read((char*)&xOffset, 4); |
| 314 | + file.read((char*)&yOffset, 4); |
| 315 | + file.read((char*)&xScale, 4); |
| 316 | + file.read((char*)&yScale, 4); |
| 317 | + file.read((char*)&shear, 4); |
| 318 | + file.read((char*)&theta, 4); |
| 319 | + XFormClass X = XFormClass(version, xOffset, yOffset, xScale, |
| 320 | + yScale, shear, theta); |
| 321 | + this->XForm.push_back(X); |
| 322 | + for (int j=0; j<total_reserved; j++) { |
| 323 | + file.read((char*)&reserved, 4); |
| 324 | + } |
264 | 325 | }
|
265 | 326 | file.seekg(pos);
|
266 | 327 | }
|
|
0 commit comments