Beispiel #1
0
void commandGenoSNP(string infile, string outfile, string manfile, int start_pos, int end_pos, bool verbose)
{
	Sim *sim = new Sim();
	ofstream outFStream;
	ostream *outStream;

	outStream = &cout;
	if (outfile == "-") {
	} else {
		outFStream.open(outfile.c_str(),ios::binary | ios::trunc | ios::out);
		outStream = &outFStream;
	}

	sim->open(infile);

	if (end_pos == -1) end_pos = sim->numSamples - 1;

	char *sampleName = new char[sim->sampleNameSize];
    vector<uint16_t> *intensity = new vector<uint16_t>;;
    for (int n=0; n <= end_pos ; n++) {
        intensity->clear();
        sim->getNextRecord(sampleName, intensity);
	if (n < start_pos) continue;
		*outStream << sampleName << "\t" << sampleName;
		for (vector<uint16_t>::iterator i = intensity->begin(); i != intensity->end(); i+=2) {
			*outStream << "\t" << std::fixed << setprecision(3) << *i;
			*outStream << " " << std::fixed << setprecision(3) << *(i+1);
		}
		*outStream << endl;
	}

	delete sim;
}
Beispiel #2
0
void commandView(string infile, bool verbose)
{
	Sim *sim = new Sim();

	cout << endl << "Reading SIM file: " << infile << endl;
	sim->open(infile);
	if (!sim->errorMsg.empty()) {
		cout << sim->errorMsg << endl;
		exit(1);
	}
	cout << "Magic:     " << sim->magic << endl;
	cout << "Version:   " << (int)sim->version << endl;
	cout << "Name Size: " << sim->sampleNameSize << endl;
	cout << "Samples:   " << sim->numSamples << endl;
	cout << "Probes:    " << sim->numProbes << endl;
	cout << "Channels:  " << (int)sim->numChannels << endl;
	cout << "Format:    " << (int)sim->numberFormat << endl;
	cout << "RecLength: " << (int)sim->recordLength << endl;
	cout << endl;

	char *sampleName = new char[sim->sampleNameSize];
	vector<uint16_t> *intensity_int = new vector<uint16_t>;
	vector<float> *intensity_float = new vector<float>;
	for (unsigned int n = 0; n < sim->numSamples; n++) {
		intensity_int->clear();
		intensity_float->clear();
		if (sim->numberFormat == 0) sim->getNextRecord(sampleName,intensity_float);
		else                        sim->getNextRecord(sampleName,intensity_int);
		cout << sampleName << "\t: ";
		if (verbose) {	// dump intensities as well as sample names
			// there *must* be a better way of doing this...
			if (sim->numberFormat == 0) {
				for (vector<float>::iterator i = intensity_float->begin(); i != intensity_float->end(); i++) {
					cout << *i << " ";
				}
			} else {
				for (vector<uint16_t>::iterator i = intensity_int->begin(); i != intensity_int->end(); i++) {
					cout << *i << " ";
				}
			}
		}
		cout << endl;
	}
	delete intensity_int;
	delete intensity_float;
	delete sampleName;
}
Beispiel #3
0
//
// Generate Illuminus output
//
// infile		is a filename or '-' for stdin
// outfile		is a filename or '-' for stdout
// manfile 		is the full path to the manifest file
// start_pos	is the Probe number (starting from 0) to start from
// end_pos		is the Probe number (from 0 to numProbes-1) to end at, or -1
// verbose		if true will display progress messages to stderr
//
void commandIlluminus(string infile, string outfile, string manfile, int start_pos, int end_pos, bool verbose)
{
	Sim *sim = new Sim();
	ofstream outFStream;
	ostream *outStream;
	char *sampleName;
    vector<uint16_t> *intensity_int = new vector<uint16_t>;
    vector<float> *intensity_float = new vector<float>;
	vector<vector<float> > SampleArray;
	Manifest *manifest = new Manifest();

	if (outfile == "-") {
		outStream = &cout;
	} else {
		outFStream.open(outfile.c_str(),ios::binary | ios::trunc | ios::out);
		outStream = &outFStream;
	}

	sim->open(infile);

	if (sim->numChannels != 2) throw("simtools can only handle SIM files with exactly 2 channels at present");

	sampleName = new char[sim->sampleNameSize];

	// We need a manifest file to sort the SNPs
	loadManifest(manifest, manfile);
	// Sort the SNPs into position order
	sort(manifest->snps.begin(), manifest->snps.end(), SortByPosition);

	if (end_pos == -1) end_pos = sim->numProbes - 1;

	// load the (relevant parts of) the SIM file
	if (verbose) cerr << "Reading SIM file " << infile << endl;
	*outStream << "SNP\tCoor\tAlleles";
	for(unsigned int n=0; n < sim->numSamples; n++) {
		vector<float> *s = new vector<float>; 
		if (!s) { cerr << "new s failed" << endl; exit(1); }
		intensity_float->clear();
		intensity_int->clear();
		if (sim->numberFormat == 0) sim->getNextRecord(sampleName, intensity_float);
		else                        sim->getNextRecord(sampleName, intensity_int);
		for (int i=start_pos; i <= end_pos; i++) {
			for (int c=0; c < sim->numChannels; c++) {
				float v;
				int k = i * sim->numChannels + c;
				if (sim->numberFormat==0) v = intensity_float->at(k);
				else                      v = intensity_int->at(k);
				s->push_back(v);
			}
		}
		SampleArray.push_back(*s);
		// Ooops! This is hardcoded for two channels. To Be Fixed. FIXME
		*outStream << "\t" << sampleName << "A\t" << sampleName << "B";
	}
	*outStream << endl;

	// Now write it out in Illuminus format
	if (verbose) cerr << "Writing Illuminus file " << outfile << endl;
	for (int n = start_pos; n <= end_pos; n++) {
		*outStream << manifest->snps[n].name << "\t" << manifest->snps[n].position << "\t" << manifest->snps[n].snp[0] << manifest->snps[n].snp[1];
		for (unsigned int i = 0; i < sim->numSamples; i++) {
			vector<float> s = SampleArray[i];
			for (unsigned int j=0; j < sim->numChannels; j++) {
				int k = (n - start_pos) * sim->numChannels + j;
				*outStream << '\t' << setw(7) << std::fixed << setprecision(3) << s[k];
			}
		}
		*outStream << endl;
	}

}