예제 #1
0
void Annotator::process_header_with_map() throw (AnnotatorException) {
	Descriptor* descriptor = NULL;
	char header_separator = '\0';
	char* header = NULL;
	char* token = NULL;
	int column_position = 0;
	const char* column_name = NULL;
	bool regions_append = false;

	if (gwafile == NULL) {
		return;
	}

	try {
		descriptor = gwafile->get_descriptor();
		header_separator = gwafile->get_header_separator();
		regions_append = gwafile->is_regions_append_on();

		if (reader.read_line() <= 0) {
			throw AnnotatorException("Annotator", "process_header_with_map()", __LINE__, 5, 1, gwafile->get_descriptor()->get_name());
		}

		header = *reader.line;

		if (regions_append) {
			header_backup = (char*)malloc((strlen(header) + 1u) * sizeof(char));
			if (header_backup == NULL) {
				throw AnnotatorException("Annotator", "process_header_with_map()", __LINE__, 2, ((strlen(header) + 1u) * sizeof(char)));
			}
			strcpy(header_backup, header);
		}

		total_columns = numeric_limits<int>::min();
		marker_column_pos = numeric_limits<int>::min();

		token = auxiliary::strtok(&header, header_separator);
		while (token != NULL) {
			column_name = descriptor->get_default_column(token, gwafile->is_case_sensitive());
			if (column_name != NULL) {
				if (strcmp(column_name, Descriptor::MARKER) == 0) {
					marker_column_pos = column_position;
				}
			}
			token = auxiliary::strtok(&header, header_separator);
			++column_position;
		}

		total_columns = column_position;

		if (marker_column_pos < 0) {
			throw AnnotatorException("Annotator", "process_header_with_map()", __LINE__, 7, ((column_name = descriptor->get_column(Descriptor::MARKER)) != NULL) ? column_name : Descriptor::MARKER, gwafile->get_descriptor()->get_name());
		}
	} catch (ReaderException &e) {
		AnnotatorException new_e(e);
		new_e.add_message("Annotator", "process_header_with_map()", __LINE__, 6, gwafile->get_descriptor()->get_name());
		throw new_e;
	} catch (DescriptorException &e) {
		AnnotatorException new_e(e);
		new_e.add_message("Annotator", "process_header_with_map()", __LINE__, 6, gwafile->get_descriptor()->get_name());
		throw new_e;
	}
}
예제 #2
0
void Formatter::process_header() throw (FormatterException) {
	Descriptor* descriptor = NULL;
	char header_separator = '\0';
	char* header = NULL;
	char* token = NULL;
	int column_position = 0;
	const char* column_name = NULL;
	const char* new_column_name = NULL;

	Column* column = NULL;

	if (gwafile == NULL) {
		return;
	}

	try {
		if (reader.read_line() <= 0) {
			throw FormatterException("Formatter", "process_header()", __LINE__, 5, gwafile->get_descriptor()->get_name());
		}

		descriptor = gwafile->get_descriptor();
		header_separator = gwafile->get_header_separator();
		header = *reader.line;

		token = auxiliary::strtok(&header, header_separator);
		while (token != NULL) {
			column = new Column();

			new_column_name = descriptor->get_renamed_column(token);
			if (new_column_name == NULL) {
				new_column_name = token;
			}

			column_name = descriptor->get_default_column(new_column_name, gwafile->is_case_sensitive());
			if (column_name != NULL) {
				if (strcmp(column_name, Descriptor::MARKER) == 0) {
				} else if (strcmp(column_name, Descriptor::CHR) == 0) {
				} else if (strcmp(column_name, Descriptor::POSITION) == 0) {
				} else if (strcmp(column_name, Descriptor::ALLELE1) == 0) {
				} else if (strcmp(column_name, Descriptor::ALLELE2) == 0) {
				} else if (strcmp(column_name, Descriptor::STRAND) == 0) {
				} else if (strcmp(column_name, Descriptor::EFFECT) == 0) {
				} else if (strcmp(column_name, Descriptor::STDERR) == 0) {
					stderr_column = column;
				} else if (strcmp(column_name, Descriptor::PVALUE) == 0) {
					pvalue_column = column;
					pvalue_column_pos = column_position;
				} else if (strcmp(column_name, Descriptor::FREQLABEL) == 0) {
					maf_column = column;
					maf_column_pos = column_position;
				} else if (strcmp(column_name, Descriptor::HWE_PVAL) == 0) {
				} else if (strcmp(column_name, Descriptor::CALLRATE) == 0) {
				} else if (strcmp(column_name, Descriptor::N_TOTAL) == 0) {
					n_total_column = column;
				} else if (strcmp(column_name, Descriptor::IMPUTED) == 0) {
				} else if (strcmp(column_name, Descriptor::USED_FOR_IMP) == 0) {
				} else if (strcmp(column_name, Descriptor::OEVAR_IMP) == 0) {
					oevar_imp_column = column;
					oevar_imp_column_pos = column_position;
				} else if (strcmp(column_name, Descriptor::AVPOSTPROB) == 0) {
				}
			}

			column->set_header(new_column_name);
			column->set_order(descriptor->get_column_order(new_column_name, gwafile->is_case_sensitive()));

			input_columns.push_back(column);

			token = auxiliary::strtok(&header, header_separator);
			column_position += 1;
		}
	} catch (ReaderException &e) {
		FormatterException new_e(e);
		new_e.add_message("Formatter", "process_header()", __LINE__, 6, gwafile->get_descriptor()->get_name());
		throw new_e;
	} catch (DescriptorException &e) {
		FormatterException new_e(e);
		new_e.add_message("Formatter", "process_header()", __LINE__, 6, gwafile->get_descriptor()->get_name());
		throw new_e;
	}
}