93 string prot_seq, trans_seq;
114 prot_seq = trans_seq;
122 TSeqPos ifrom = lit.GetRange().GetFrom();
123 TSeqPos ito = lit.GetRange().GetTo();
125 char basesIN[2], basesOUT[2];
130 for (
TSeqPos pos = neg ? ito : ifrom;
131 (neg ? (pos -
offset >= ifrom) : (pos +
offset <= ito)) &&
132 idx != prot_seq.length() && idx != trans_seq.length() ;
133 (neg ? pos -= 3 : pos += 3), ++idx)
135 bool mismatch = (prot_seq[idx] != trans_seq[idx]);
142 basesIN [0] = prot_seq[idx];
143 basesOUT[0] = trans_seq[idx];
156 seq_start + 0.5, trans_y,
true);
160 string main_seq, tmp_seq;
161 vec.
GetSeqData(seq_start - 1, seq_start + 2, tmp_seq);
165 0,
static_cast<TSeqPos>(tmp_seq.length()), main_seq);
171 reverse(main_seq.begin(), main_seq.end());
175 seq_start + 0.5, gen_y,
true);
185 int diff = neg ? seq_start - ifrom : ito - seq_start;
188 }
else if (diff == 1) {
190 }
else if (diff == 0) {
199 bool will_fit =
false;
202 int base_width = aln_mgr->
GetBaseWidth(aln_mgr->GetAnchor());
253 prot_len = prot_vec.
size();
255 gen_len = prot_len * 3;
274 if (cds_seq.empty()) {
278 &
GetFeature().GetData().GetCdregion().GetCode() :
nullptr;
282 if (cds_seq.empty()) {
288 gen_len =
GetLocation().GetTotalRange().GetLength();
289 prot_len = gen_len / 3 + 1;
292 #ifdef HIGHLIGHT_MISMATCHES
298 &
GetFeature().GetData().GetCdregion().GetCode() :
nullptr;
302 if (prot_seq.empty())
303 prot_seq = trans_seq;
311 int aligned_seq = aln_mgr->GetQuery();
312 int base_width = aln_mgr->GetBaseWidth(anchor);
313 int anchor_step = base_width == 3 ? 1 : 3;
319 static const CRgbaColor codon_mismatch_col(
"red");
320 static const CRgbaColor translated_col(
"dark blue");
324 bool aligned_neg = aln_mgr->IsNegativeStrand(aligned_seq);
325 bool anchor_neg = aln_mgr->IsNegativeStrand(anchor);
328 auto& anchor_range = map_it.m_AnchorRange;
332 auto& prod_int = *map_it.m_ProductInt;
333 auto& gen_int = *map_it.m_MappedInt;
334 auto& prod_range = map_it.m_MappedProdRange;
336 bool neg = gen_int.IsSetStrand() && gen_int.GetStrand() ==
eNa_strand_minus;
337 bool aln_strand = anchor_neg || aligned_neg;
338 int anchor_sign = (aln_strand && neg || !aln_strand && !neg) ? 1 : -1;
340 TSeqRange gen_range(gen_int.GetFrom(), gen_int.GetTo());
343 TSeqPos prod_pos = prod_int.GetFrom();
344 TSeqPos prod_stop = prod_int.GetTo() + 1;
346 prod_stop = min<int>(prod_stop, prod_pos +
round(
float(gen_range.
GetLength()) / base_width));
349 anchor_range.GetTo() : anchor_range.GetFrom();
355 int prod_from = prod_range.GetFrom();
356 int frame = prod_from > 0 ? prod_from % 3 : prot_offset;
357 TSeqPos prod_pos_f1 = (prod_from / 3) * 3 + 1;
358 pos += ((anchor_sign * anchor_step) / 3) * (prod_pos_f1 - prod_from);
360 pos += (anchor_sign * anchor_step);
362 while (prod_pos < prod_stop) {
363 if (prod_pos >= prot_seq.size())
366 if (anchor_sign > 0 && pos > (
TSignedSeqPos)anchor_range.GetTo())
368 if (anchor_sign < 0 && pos < (
TSignedSeqPos)anchor_range.GetFrom())
372 if (prod_pos < prot_seq.size())
373 prot_in[0] = prot_seq[prod_pos];
374 #ifdef HIGHLIGHT_MISMATCHES
376 if (prod_pos < trans_seq.size())
377 prot_out[0] = trans_seq[prod_pos];
378 bool mismatch = (prot_in[0] != prot_out[0]);
384 pos + 0.5, prot_y,
true);
387 TSeqPos p = prod_pos > 0 ? (prod_pos * 3) : 0;
388 string codon = cds_seq.substr(p, 3);
389 #ifdef HIGHLIGHT_MISMATCHES
390 string gen_codon = gen_seq.substr(p, 3);
396 x_PutCodon(codon, pos, gen_y, flip_strand != (anchor_sign < 0),
false);
399 gl.
ColorC(translated_col);
404 pos += anchor_sign * anchor_step;
436 prot_len = prot_vec.
size();
439 cerr <<
"prot_seq (obtained as feature product): " << endl << prot_seq << endl <<
"prot_seq.length(): " <<
440 prot_seq.length() <<
", * 3: " << prot_seq.length() * 3 << endl;
442 gen_len = prot_len * 3;
451 cerr <<
"sfp (cds feature obtained for the product): " << endl <<
MSerial_AsnText << *sfp << endl;
459 cerr <<
"cds_seq (obtained from product):" << endl << cds_seq << endl <<
"cds_seq.length(): " << cds_seq.length() <<
469 gen_len =
GetLocation().GetTotalRange().GetLength();
470 prot_len = gen_len / 3 + 1;
476 cerr <<
"gen_sec (parts of original seq obtained via intervals): " << endl;
478 gen_seq.reserve(gen_len);
483 TSeqPos f1 = iter.first->GetFrom();
484 TSeqPos f2 = iter.second->GetFrom();
485 TSeqPos t2 = iter.second->GetTo();
487 gen_seq.append(f1 - pre_t1,
'N');
489 cerr <<
string(f1 - pre_t1,
'N');
497 0,
static_cast<TSeqPos>(tmp_seq.length()), seq);
500 pre_t1 = iter.first->GetTo() + 1;
503 cerr << tmp_seq.length() <<
":\t" << tmp_seq << endl;
514 cerr <<
"trans_seq (translation from gen_seq): " << endl << trans_seq << endl <<
"trans_seq.length(): " <<
515 trans_seq.length() <<
", * 3: " << trans_seq.length() * 3 << endl;
519 if (prot_seq.empty())
520 prot_seq = trans_seq;
523 char prot_in[2], prot_out[2];
527 static const CRgbaColor codon_mismatch_col(
"red");
528 static const CRgbaColor translated_col(
"dark blue");
541 auto& prod_int = *map_it.first;
542 auto& gen_int = *map_it.second;
544 if (
nullptr != previous_prod_int) {
545 if (previous_prod_int->
GetTo() != (prod_int.GetFrom() - 1)) {
546 prev_frame += prod_int.
GetFrom() - previous_prod_int->
GetTo() - 1;
550 previous_prod_int = &prod_int;
553 cerr <<
"product range: (" << prod_int.
GetFrom() <<
", " << prod_int.GetTo() <<
")" << endl;
554 cerr <<
"general range: (" << gen_int.GetFrom() <<
", " << gen_int.GetTo() <<
")" << endl;
557 bool neg = gen_int.IsSetStrand() && gen_int.GetStrand() ==
eNa_strand_minus;
558 TSeqRange gen_range(gen_int.GetFrom(), gen_int.GetTo());
559 int step = neg ? -3 : 3;
561 while (current_exon !=
m_Intervals.end() && current_exon->GetFrom() > gen_range.
GetTo()) {
566 while (current_exon !=
m_Intervals.end() && current_exon->GetTo() < gen_range.
GetFrom()) {
572 int frame = (gen_range.
GetLength() + prev_frame) % 3;
584 TSeqPos prod_pos = prod_int.GetFrom();
590 switch (prev_frame) {
594 c_pos += (neg ? -1 : 1);
600 c_pos += (neg ? 1 : -1);
608 size_t prot_idx = (prod_pos > offs) ? (prod_pos - offs) / 3 : 0;
613 while (prod_pos <= prod_stop) {
618 prot_in[0] = prot_out[0] =
'X';
619 if (prot_idx < prot_seq.size())
620 prot_in[0] = prot_seq[prot_idx];
621 if (prot_idx < trans_seq.size())
622 prot_out[0] = trans_seq[prot_idx];
623 bool mismatch = (prot_in[0] != prot_out[0]);
630 if (prod_pos - 1 < gen_seq.size())
631 gen_codon = gen_seq.substr(prod_pos - 1, 3);
634 if (prot_idx * 3 < cds_seq.size())
635 codon = cds_seq.substr(prot_idx * 3 + offs, 3);
639 x_PutCodon(codon, c_pos, gen_y, flip_strand != neg,
false);
642 gl.
ColorC(translated_col);
651 if (prev_prod->GetTo() + 1 != prod_int.GetFrom()) {
652 c_pos = neg ? gen_int.GetTo() + 1 : gen_int.GetFrom();
654 x_DrawInsertion(c_pos, prot_y - (font_height + font_height), prot_y, prot_y - font_height);
658 if (prev_gen->GetFrom() - 1 != gen_int.GetTo()) {
659 c_pos = prev_gen->GetFrom() - 1;
663 if (prev_gen->GetTo() + 1 != gen_int.GetFrom()) {
664 c_pos = prev_gen->GetTo() + 1;
673 c_pos += (neg ? -1 : 1);
679 prev_gen.
Reset(&gen_int);
680 prev_prod.
Reset(&prod_int);
689 string new_codon = codon_str;
690 size_t len = codon_str.size();
693 if (
append) new_codon +=
" ";
694 else new_codon.insert(0,
" ");
696 if (neg) std::reverse(new_codon.begin(), new_codon.end());
User-defined methods of the data storage class.
static const int kVertSpace
CRgbaColor m_SeqProtMismatch
mismatched sequence color.
CGlTextureFont m_ProdFont
CRgbaColor m_SeqProtTrans
translated sequence color.
CGlTextureFont m_TransFont
CRef< CCdsConfig > m_CdsConfig
void x_DrawProtSeqWithMapping(TModelUnit trans_y, TModelUnit gen_y, TModelUnit prot_y) const
void x_DrawProjectedProtSeq(TModelUnit trans_y, TModelUnit gen_y, TModelUnit prot_y) const
void x_PutCodon(const string &codon_str, TSeqPos pos, TModelUnit y, bool neg, bool append) const
virtual void x_Draw() const
The default renderer for this layout object.
CCdsGlyph(const objects::CMappedFeat &feat)
virtual void x_UpdateBoundingBox()
Update the bounding box assuming children's sizes are fixed if any.
TSeqPos x_GetProtOffset() const
Returns protein translation offset.
virtual void x_Draw() const
The default renderer for this layout object.
void x_DrawInsertion(TModelUnit SeqPosTriangleMidPointX, TModelUnit BoundaryYLow, TModelUnit BoundaryYHigh, TModelUnit YCenterLine) const
TIntervals m_Intervals
intervals (like for features or alignments).
virtual void x_UpdateBoundingBox()
Update the bounding box assuming children's sizes are fixed if any.
CConstRef< CFeatureParams > m_Config
All the configs needed for rendering a feature.
CProjectedMappingInfo m_ProjectedMappingInfo
const TMappingInfo & GetMappingInfo() const
virtual const objects::CSeq_loc & GetLocation(void) const
access the position of this object.
bool x_IsProjected() const
const objects::CMappedFeat & GetMappedFeature(void) const
Access a new, fully remapped feature.
const objects::CSeq_feat & GetFeature(void) const
Access the original feature.
TModelUnit GetBarHeight(bool overview) const
void GetAnchorSequence(objects::CScope &scope, string &buffer) const
const IAlnGraphicDataSource * GetAlignmentDataSource() const
void TextOut(const CGlTextureFont *font, const char *text, TModelUnit x, TModelUnit y, bool center, bool adjust_flip=true) const
CRef< CSGSequenceDS > GetSeqDS() const
bool IsInVisibleRange(TSeqPos pos) const
TModelRange IntersectVisible(const CSeqGlyph *obj) const
const TModelUnit & GetScale() const
bool IsFlippedStrand() const
bool WillSeqLetterFit() const
is it enougth space to sequence letters.
class CRgbaColor provides a simple abstraction for managing colors.
objects::CScope & GetScope(void) const
Get the scope from the handle.
const objects::CSeqVector & GetSeqVector(void) const
CRenderingContext * m_Context
the rendering context
virtual void SetHeight(TModelUnit h)
virtual TModelUnit GetTop() const
virtual TModelUnit GetHeight() const
static SIZE_TYPE ReverseComplement(const string &src, TCoding src_coding, TSeqPos pos, TSeqPos length, string &dst)
static SIZE_TYPE Complement(const string &src, TCoding src_coding, TSeqPos pos, TSeqPos length, string &dst)
namespace ncbi::objects::
Seq-loc iterator class – iterates all intervals from a seq-loc in the correct order.
virtual TSeqPos GetBaseWidth(IAlnExplorer::TNumrow) const =0
virtual IAlnExplorer::TNumrow GetAnchor() const =0
static void DLIST_NAME() append(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
unsigned int TSeqPos
Type for sequence locations and lengths.
int TSignedSeqPos
Type for signed sequence position.
IRender & GetGl()
convenience function for getting current render manager
virtual TModelUnit TextHeight(const CGlTextureFont *font) const =0
virtual TModelUnit GetMetric(const CGlTextureFont *font, IGlFont::EMetric metric, const char *text=NULL, int len=-1) const =0
Calls the standard font metric functions except for pdf in which case it first replaces any bitmap fo...
virtual void ColorC(const CRgbaColor &c)=0
Set current color (glColor{3,4}{f,d}{v,})
#define MSerial_AsnText
I/O stream manipulators –.
TRange GetTotalRange(void) const
const CSeq_feat * GetCDSForProduct(const CBioseq &product, CScope *scope)
Get the encoding CDS feature of a given protein sequence.
static void Translate(const string &seq, string &prot, const CGenetic_code *code, bool include_stop=true, bool remove_trailing_X=false, bool *alt_start=NULL, bool is_5prime_complete=true, bool is_3prime_complete=true)
Translate a string using a specified genetic code.
@ fIs5PrimePartial
= 0x4 Translate first codon even if not start codon (because sequence is 5' partial)
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
@ eCoding_Iupac
Set coding to printable coding (Iupacna or Iupacaa)
void GetSeqData(TSeqPos start, TSeqPos stop, string &buffer) const
Fill the buffer string with the sequence data for the interval [start, stop).
void Reset(void)
Reset reference object.
position_type GetLength(void) const
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
TTo GetTo(void) const
Get the To member data.
TFrom GetFrom(void) const
Get the From member data.
const TLocation & GetLocation(void) const
Get the Location member data.
TFrame GetFrame(void) const
Get the Frame member data.
const TData & GetData(void) const
Get the Data member data.
const TCdregion & GetCdregion(void) const
Get the variant data.
bool IsSetFrame(void) const
Check if a value has been assigned to Frame data member.
TFrom GetFrom(void) const
Get the From member data.
TTo GetTo(void) const
Get the To member data.
bm::gap_word_t gap_length(const bm::gap_word_t *buf) noexcept
Returs GAP block length.
constexpr bool empty(list< Ts... >) noexcept
static const float kSequenceLevel
string GetProduct(const CProt_ref &prot_ref)