/* * bcf_entry_setters.cpp * * Created on: Sep 20, 2012 * Author: Anthony Marcketta * ($Revision: 1 $) */ #include "bcf_entry.h" void bcf_entry::set_ALT(const int n_allele) { ALT.resize(n_allele-1); unsigned int pos = ALT_pos; string allele; for (int ui=0; ui<(n_allele-1); ui++) { allele = get_typed_string( &pos, line ); std::transform(allele.begin(), allele.end(), allele.begin(), ::toupper); ALT[ui] = allele; } parsed_ALT = true; } void bcf_entry::set_ALT(const string &in) { istringstream ss(in); string tmpstr; ALT.resize(0); while(!ss.eof()) { getline(ss, tmpstr, ','); add_ALT_allele(tmpstr); } parsed_ALT = true; } void bcf_entry::set_INFO() { int key; unsigned int size, type, i = INFO_pos; string data_type; INFO.resize(N_info); bool miss = true; for (unsigned int ui=0; ui INFO_entry(entry_header.INFO_map[key].ID, "."); data_type = entry_header.INFO_map[key].Type_str; ostringstream ss(ostringstream::out); for (unsigned int uj=0; uj(&line[cur_pos]); if ( tmp == (int8_t)0x81 ) break; ploidy[indv]++; cur_pos += sizeof(int8_t); } if (ploidy[indv] == 0) { set_indv_GENOTYPE_alleles(indv, make_pair(-2, -2)); } else if (ploidy[indv] == 1) { set_indv_PHASE(indv, '|'); tmp = *reinterpret_cast(&line[pos]); if (tmp == (int8_t)0x80) tmp = -1; else tmp = (tmp >> 1) - 1; set_indv_GENOTYPE_alleles(indv, make_pair(tmp, -2)); } else if (ploidy[indv] == 2) { tmp = *reinterpret_cast(&line[pos]); tmp2 = *reinterpret_cast(&line[pos+sizeof(int8_t)]); if (tmp == (int8_t)0x80) tmp = -1; else tmp = (tmp >> 1) - 1; if (tmp2 == (int8_t)0x80) { tmp2 = -1; set_indv_PHASE(indv, '/'); } else { char phase = phased[ tmp2 & (int8_t)1 ]; tmp2 = (tmp2 >> 1) - 1; set_indv_PHASE(indv, phase); } set_indv_GENOTYPE_alleles(indv, make_pair((int)tmp, (int)tmp2)); } else if (ploidy[indv] > 2) LOG.error("Polyploidy found, and is not supported by vcftools: " + CHROM + ":" + header::int2str(POS)); parsed_GT[indv] = true; } void bcf_entry::set_indv_GENOTYPE_and_PHASE(unsigned int indv, const pair &genotype, char phase) { set_indv_GENOTYPE_ids(indv, genotype); set_indv_PHASE(indv, phase); parsed_GT[indv] = true; } void bcf_entry::set_indv_GENOTYPE_and_PHASE(unsigned int indv, const pair &genotype, char phase) { pair a(-1,-1); if (genotype.first != ".") a.first = header::str2int(genotype.first); if (genotype.second != ".") a.second = header::str2int(genotype.second); set_indv_GENOTYPE_alleles(indv, a); set_indv_PHASE(indv, phase); parsed_GT[indv] = true; } void bcf_entry::set_indv_GENOTYPE_alleles(unsigned int indv, const pair &in) { if (GENOTYPE.size() == 0) GENOTYPE.resize(N_indv, make_pair(-1,-1)); pair a(-1,-1); if (in.first == 0x81) a.first = -2; else if (in.first != 0x80) a.first = in.first; if (in.second == 0x81) a.second = -2; else if (in.second != 0x80) a.second = in.second; GENOTYPE[indv] = in; parsed_GT[indv] = true; } void bcf_entry::set_indv_GENOTYPE_ids(unsigned int indv, const pair &in) { if (GENOTYPE.size() == 0) GENOTYPE.resize(N_indv, make_pair(-2,-2)); GENOTYPE[indv] = in; } void bcf_entry::set_indv_PHASE(unsigned int indv, char in) { if (PHASE.size() == 0) PHASE.resize(N_indv, '/'); PHASE[indv] = in; parsed_GT[indv] = true; } void bcf_entry::set_indv_GQUALITY(unsigned int indv, const vector &in) { float tmp; memcpy(&tmp, &in[0], sizeof(tmp)); parsed_GQ[indv] = true; if (tmp == 0x7F800001) { if (GQUALITY.size() > 0) GQUALITY[indv] = -1; return; } if (GQUALITY.size() == 0) GQUALITY.resize(N_indv, -1); if (tmp > 99.0) tmp = 99; GQUALITY[indv] = tmp; } void bcf_entry::set_indv_GQUALITY(unsigned int indv, const float &in) { parsed_GQ[indv] = true; if ( (in == -1) or (in == 0x7F800001) ) { if (GQUALITY.size() > 0) GQUALITY[indv] = -1; return; } if (GQUALITY.size() == 0) GQUALITY.resize(N_indv, -1); if (in > 99) GQUALITY[indv] = 99; else GQUALITY[indv] = in; } void bcf_entry::set_indv_GFILTER(unsigned int indv, const vector &in) { parsed_FT[indv] = true; if (GFILTER.size() == 0) GFILTER.resize(N_indv); GFILTER[indv].resize(0); if (in.empty()) return; else if ((in.size() == 1) and (in[0] == '\0') ) return; ostringstream ss; string ith_FILTER; ss.clear(); for (unsigned int ui=0; ui