Пример #1
0
dataset GetInput(char *filename, int verbose){ // either char * or char *filename idk
	FILE *fin;
	int i;
	dataset output;

	if(verbose == 1)
		printf("Opening %s\n",filename);
	
	fin = fopen(filename, "r");

	if(fin==0 && verbose == 1) {
		printf("Could not open file.\n");
		return;
	}

	// file open routine complete, get linecount

	output.length = GetFileLineCount(filename);

	// number of data points counted, now to read in the actual data (and create a couple of temporary arrays)

	float x[output.length],y[output.length],yerr[output.length];
	
	for (i = 0; i < output.length; ++i){
		int invalid = fscanf(fin, "%f,%f,%f", &x[i], &y[i], &yerr[i]);
		if(invalid !=3){
			printf("Non-numeric data detected in file or more than 3 columns present. Please verify your data!\nProgram exiting.");
			return;
		}
		if (yerr[i] == 0){
			if (verbose == 1){
				printf("Your data contains errors that are equal to zero. This is invalid.\nProgram exiting.\n");
			}
			return;
		}
	}	 

	fclose(fin);

	// map temp stuff to actual output stuff to compensate for fscanf being hella gay

	for (int i = 0; i < output.length; ++i)
	{
		output.x[i] = x[i];
		output.y[i] = y[i];
		output.yerr[i] = yerr[i];
	}

	if (verbose == 1){
		printf("Your dataset has %d constituent points:\n\n",output.length);
		for (i = 0; i < output.length; ++i)
		{
			printf("x = %.2f\ty = %.2f\ty error = %.2f\n",output.x[i],output.y[i],output.yerr[i]);
		}
		printf("\n");
	}

	return output;
}
Пример #2
0
Likelihood::Likelihood( vector< vector<string> > & MEseq, SingleSampleInfo & si, string & ref_file_prefix )
{
	string bam_name = si.bam_name;
	avr_read_length = si.avr_read_length;
	max_ins_size = si.avr_ins_size + 3 * si.var_avr_ins_size;
	refStat.resize(NMEI);
	nref.resize(NMEI);
	log10_total.resize(NMEI);
	for(int i=0; i<NMEI; i++) {
		refStat[i].resize(3);
		nref[i].resize(3, -1);
		log10_total[i].resize(3);
	}
	vector<string> suffix_name;
	suffix_name.resize(3);
	suffix_name[2] = ".hom-stat.";
	suffix_name[1] = ".het-stat.";
	suffix_name[0] = ".neg-stat.";
	for (int m=0; m<3; m++) {
		for(int g=0; g<3; g++) {
			string ref_file_name = ref_file_prefix + suffix_name[g] + std::to_string(m);
			// line count first
			nref[m][g] = GetFileLineCount(ref_file_name);
			if (nref[m][g] <= 0) {
				string str = "[Likelihood::Likelihood] " + ref_file_name + "is empty";
				morphError(str, 35);
			}
			// read
			setFromRefFile( m, g, ref_file_name );
			// frequency to log
			int sum = 0;
			for(int i=0; i<refStat[m][g].frequency.size(); i++) {
				sum += refStat[m][g].frequency[i];
				refStat[m][g].frequency[i] = log10(refStat[m][g].frequency[i]);
			}
			log10_total[m][g] = log10(sum);
		}
	}

	// open bam
	OpenBamAndBai( bam, bam_header, bam_name );
	OpenBamAndBai( alt_bam, alt_bam_header, bam_name );
	pMEseq = &MEseq;
}