1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
/* The MIT License
Copyright (c) 2014 Adrian Tan <atks@umich.edu>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "vntr_annotator.h"
/**
* Constructor.
*/
VNTRAnnotator::VNTRAnnotator(std::string& ref_fasta_file, bool debug)
{
vm = new VariantManip(ref_fasta_file.c_str());
fai = fai_load(ref_fasta_file.c_str());
if (fai==NULL)
{
fprintf(stderr, "[%s:%d %s] Cannot load genome index: %s\n", __FILE__, __LINE__, __FUNCTION__, ref_fasta_file.c_str());
exit(1);
}
cre = new CandidateRegionExtractor(ref_fasta_file, debug);
cmp = new CandidateMotifPicker(debug);
fd = new FlankDetector(ref_fasta_file, debug);
this->debug = debug;
};
/**
* Destructor.
*/
VNTRAnnotator::~VNTRAnnotator()
{
delete vm;
fai_destroy(fai);
}
/**
* Annotates VNTR characteristics.
* @mode - e for exact alignment annotation
* - f for fuzzy alignment annotation
* -
*/
void VNTRAnnotator::annotate(Variant& variant, int32_t amode)
{
VNTR& vntr = variant.vntr;
bcf_hdr_t* h = variant.h;
bcf1_t* v = variant.v;
//update chromosome and position
variant.rid = bcf_get_rid(v);
variant.pos1 = bcf_get_pos1(v);
//this is for reannotating an VNTR record
//this is more for the purpose of evaluation to
//check if vt's algorithm is concordant with
//VNTRs from other sources.
if (variant.type==VT_VNTR)
{
if (debug) std::cerr << "============================================\n";
if (debug) std::cerr << "ANNOTATING VNTR/STR \n";
//1. pick candidate region
cre->pick_candidate_region(variant, REFERENCE, FINAL);
//2. set motifs from info field
cmp->set_motif_from_info_field(variant);
//3. compute purity scores
fd->compute_purity_score(variant, FINAL);
//4. compute composition and sequence statistics
fd->compute_composition_and_entropy(variant, FINAL);
}
//main purpose - annotation of Indels.
else if (variant.type&VT_INDEL)
{
//the basic steps in annotating a TR
//
//1. extract a region that has a chance of containing the repeat units
//2. choose a set of candidate motifs and pick motif
//3. detect repeat region and evaluate
//4. iterate 2 and 3
if (debug) std::cerr << "============================================\n";
if (debug) std::cerr << "ANNOTATING INDEL\n";
//1. selects candidate region by fuzzy left and right alignment
cre->pick_candidate_region(variant, EXACT_LEFT_RIGHT_ALIGNMENT, EXACT);
cmp->update_exact_repeat_unit(variant);
//2. detect candidate motifs from a reference sequence
cmp->generate_candidate_motifs(variant);
//this cannot possibly fail as next_motif() guarantees it
if (!cmp->next_motif(variant, CHECK_MOTIF_PRESENCE_IN_ALLELE))
{
//fall back on exact motif chosen.
VNTR& vntr = variant.vntr;
vntr.fuzzy_motif = vntr.exact_motif;
vntr.fuzzy_ru = vntr.exact_ru;
vntr.fuzzy_basis = vntr.exact_basis;
vntr.fuzzy_mlen = vntr.exact_mlen;
vntr.fuzzy_blen = vntr.exact_blen;;
if (debug) std::cerr << "updating fuzzy motif with exact motifs\n";
}
fd->detect_flanks(variant, EXACT);
fd->compute_purity_score(variant, EXACT);
fd->compute_composition_and_entropy(variant, EXACT);
fd->detect_flanks(variant, FUZZY);
fd->compute_purity_score(variant, FUZZY);
fd->compute_composition_and_entropy(variant, FUZZY);
//introduce reiteration based on concordance and exact concordance.
if (debug)
{
std::cerr << "\n";
vntr.print();
std::cerr << "\n";
}
if (debug) std::cerr << "============================================\n";
return;
}
}
|