Skip to content

Commit 488541f

Browse files
author
Iain Bancarz
committed
Read intensities into arrays, not vectors
1 parent ccfe087 commit 488541f

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

simtools.cpp

+35-33
Original file line numberDiff line numberDiff line change
@@ -170,34 +170,32 @@ void commandView(string infile, bool verbose)
170170
cout << endl;
171171

172172
char *sampleName = new char[sim->sampleNameSize];
173-
int vectorSize = sim->numSamples * sim->numProbes;
174-
vector<uint16_t> *intensity_int = new vector<uint16_t>;
175-
vector<float> *intensity_float = new vector<float>;
176-
intensity_int->reserve(vectorSize);
177-
intensity_float->reserve(vectorSize);
173+
uint16_t *intensity_int =
174+
(uint16_t *) calloc(sim->sampleIntensityTotal, sizeof(uint16_t));
175+
float *intensity_float =
176+
(float *) calloc(sim->sampleIntensityTotal, sizeof(float));
178177

178+
int i;
179179
for (unsigned int n = 0; n < sim->numSamples; n++) {
180-
intensity_int->clear();
181-
intensity_float->clear();
182180
if (sim->numberFormat == 0) sim->getNextRecord(sampleName,intensity_float);
183181
else sim->getNextRecord(sampleName,intensity_int);
184182
cout << sampleName << "\t: ";
185183
if (verbose) { // dump intensities as well as sample names
186184
// there *must* be a better way of doing this...
187185
if (sim->numberFormat == 0) {
188-
for (vector<float>::iterator i = intensity_float->begin(); i != intensity_float->end(); i++) {
189-
cout << *i << " ";
190-
}
186+
for (i=0; i<sim->sampleIntensityTotal; i++) {
187+
cout << intensity_float[i] << " ";
188+
}
191189
} else {
192-
for (vector<uint16_t>::iterator i = intensity_int->begin(); i != intensity_int->end(); i++) {
193-
cout << *i << " ";
194-
}
190+
for (i=0; i<sim->sampleIntensityTotal; i++) {
191+
cout << intensity_int[i] << " ";
192+
}
195193
}
196194
}
197195
cout << endl;
198196
}
199-
delete intensity_int;
200-
delete intensity_float;
197+
free(intensity_int);
198+
free(intensity_float);
201199
delete sampleName;
202200
}
203201

@@ -269,7 +267,9 @@ void commandCreate(string infile, string outfile, bool normalize, string manfile
269267
sort(manifest->snps.begin(), manifest->snps.end(), SortByPosition);
270268

271269
// Create the SIM file and write the header
270+
cerr << "Ready to create .sim file." << endl;
272271
sim->createFile(outfile);
272+
cerr << "Writing header." << endl;
273273
sim->writeHeader(infiles.size(),gtc->numSnps, 2, numberFormat);
274274

275275
// For each GTC file, write the sample name and intensities to the SIM file
@@ -333,7 +333,7 @@ void commandCreate(string infile, string outfile, bool normalize, string manfile
333333
}
334334

335335
}
336-
336+
cerr << "Closing sim file" << endl;
337337
sim->close();
338338
}
339339

@@ -353,8 +353,6 @@ void commandIlluminus(string infile, string outfile, string manfile, int start_p
353353
ofstream outFStream;
354354
ostream *outStream;
355355
char *sampleName;
356-
vector<uint16_t> *intensity_int = new vector<uint16_t>;
357-
vector<float> *intensity_float = new vector<float>;
358356
vector<vector<float> > SampleArray;
359357
Manifest *manifest = new Manifest();
360358

@@ -368,7 +366,10 @@ void commandIlluminus(string infile, string outfile, string manfile, int start_p
368366
sim->open(infile);
369367

370368
if (sim->numChannels != 2) throw("simtools can only handle SIM files with exactly 2 channels at present");
371-
369+
uint16_t *intensity_int =
370+
(uint16_t *) calloc(sim->sampleIntensityTotal, sizeof(uint16_t));
371+
float *intensity_float =
372+
(float *) calloc(sim->sampleIntensityTotal, sizeof(float));
372373
sampleName = new char[sim->sampleNameSize];
373374

374375
// We need a manifest file to sort the SNPs
@@ -384,16 +385,14 @@ void commandIlluminus(string infile, string outfile, string manfile, int start_p
384385
for(unsigned int n=0; n < sim->numSamples; n++) {
385386
vector<float> *s = new vector<float>;
386387
if (!s) { cerr << "new s failed" << endl; exit(1); }
387-
intensity_float->clear();
388-
intensity_int->clear();
389388
if (sim->numberFormat == 0) sim->getNextRecord(sampleName, intensity_float);
390389
else sim->getNextRecord(sampleName, intensity_int);
391390
for (int i=start_pos; i <= end_pos; i++) {
392391
for (int c=0; c < sim->numChannels; c++) {
393392
float v;
394393
int k = i * sim->numChannels + c;
395-
if (sim->numberFormat==0) v = intensity_float->at(k);
396-
else v = intensity_int->at(k);
394+
if (sim->numberFormat==0) v = intensity_float[k];
395+
else v = intensity_int[k];
397396
s->push_back(v);
398397
}
399398
}
@@ -416,7 +415,8 @@ void commandIlluminus(string infile, string outfile, string manfile, int start_p
416415
}
417416
*outStream << endl;
418417
}
419-
418+
free(intensity_int);
419+
free(intensity_float);
420420
}
421421

422422
void commandGenoSNP(string infile, string outfile, string manfile, int start_pos, int end_pos, bool verbose)
@@ -437,20 +437,22 @@ void commandGenoSNP(string infile, string outfile, string manfile, int start_pos
437437
if (end_pos == -1) end_pos = sim->numSamples - 1;
438438

439439
char *sampleName = new char[sim->sampleNameSize];
440-
vector<uint16_t> *intensity = new vector<uint16_t>;;
440+
uint16_t *intensity = (uint16_t *) calloc(sim->sampleIntensityTotal,
441+
sizeof(uint16_t));
441442
for (int n=0; n <= end_pos ; n++) {
442-
intensity->clear();
443443
sim->getNextRecord(sampleName, intensity);
444444
if (n < start_pos) continue;
445-
*outStream << sampleName << "\t" << sampleName;
446-
for (vector<uint16_t>::iterator i = intensity->begin(); i != intensity->end(); i+=2) {
447-
*outStream << "\t" << std::fixed << setprecision(3) << *i;
448-
*outStream << " " << std::fixed << setprecision(3) << *(i+1);
449-
}
450-
*outStream << endl;
445+
*outStream << sampleName << "\t" << sampleName;
446+
for (int i=0; i<sim->sampleIntensityTotal; i+=2) {
447+
*outStream << "\t" << std::fixed << setprecision(3) << intensity[i];
448+
*outStream << " " << std::fixed << setprecision(3) << intensity[i+1];
451449
}
450+
*outStream << endl;
451+
}
452452

453-
delete sim;
453+
free(sampleName);
454+
free(intensity);
455+
delete sim;
454456
}
455457

456458
void commandQC(string infile, string magnitude, string xydiff, bool verbose)

0 commit comments

Comments
 (0)