50 typedef pair<objects::ENa_strand, objects::ENa_strand> TStrands;
53 TStrands RetrieveStdStrands(
const objects::CSeq_align& seq_align)
58 const CStd_seg & stdseg (*(std_list.front()));
69 if (seq_align.CheckNumRows() != 2) {
71 "Pairwise seq-align required to init align-shadow");
74 const bool is_denseg (seq_align.GetSegs().IsDenseg());
75 const bool is_stdseg (seq_align.GetSegs().IsStd());
76 if(!is_denseg && !is_stdseg) {
78 "Must be a dense-seg or std_seg to init align-shadow");
81 m_Id.first.Reset(&seq_align.GetSeq_id(0));
82 m_Id.second.Reset(&seq_align.GetSeq_id(1));
88 qstrand = seq_align.GetSeqStrand(0);
89 sstrand = seq_align.GetSeqStrand(1);
92 const TStrands strands (RetrieveStdStrands(seq_align));
93 qstrand = strands.first;
94 sstrand = strands.second;
98 m_Box[1] = seq_align.GetSeqStart(0);
99 m_Box[0] = seq_align.GetSeqStop(0);
102 m_Box[0] = seq_align.GetSeqStart(0);
103 m_Box[1] = seq_align.GetSeqStop(0);
107 m_Box[3] = seq_align.GetSeqStart(1);
108 m_Box[2] = seq_align.GetSeqStop(1);
111 m_Box[2] = seq_align.GetSeqStart(1);
112 m_Box[3] = seq_align.GetSeqStop(1);
120 const CDense_seg & ds (seq_align.GetSegs().GetDenseg());
125 const char indel[2] = {
'D',
'I'};
128 for (
size_t j: {0,1}) {
130 while(
i < starts.size() && starts[
i]==-1)
i += 2;
133 next[j] += lens[
i/2];
139 for (
size_t ii_lens = 0; ii_lens < lens.size(); ++ii_lens) {
142 for (
size_t j: {0,1}) {
143 if (starts[
i+j] != -1) {
145 if (
next[j] != starts[
i+j]+lens[ii_lens]) {
149 next[j] = starts[
i+j];
151 if (
next[j] != starts[
i+j]) {
155 next[j] = starts[
i+j] + lens[ii_lens];
163 else if(starts[
i+1] < 0) {
170 if(lens[ii_lens] > 1) {
179 "CAlignShadow(): save_xcript mode not supported "
180 "for seq-align segments other than dense-seg.");
193 const TId& idsubj,
TCoord sstart,
bool sstrand,
194 const string& xcript)
196 m_Id.first = idquery;
197 m_Id.second = idsubj;
202 TCoord q = qstart, q0 = q, s = sstart, s0 = s;
203 const int qinc (qstrand? 1: -1), sinc (sstrand? 1: -1);
228 "CAlignShadow()::CAlignShadow(): "
229 "Unexpected transcript symbol found");
244 os << align_shadow.
GetId(0)->AsFastaString() <<
'\t'
245 << align_shadow.
GetId(1)->AsFastaString() <<
'\t';
260 case 0:
return m_Id.first;
261 case 1:
return m_Id.second;
264 "CAlignShadow::GetId() - argument out of range");
285 case 0:
m_Id.first = id;
break;
286 case 1:
m_Id.second = id;
break;
289 "CAlignShadow::SetId() - argument out of range");
310 if(0 != where && where != 1) {
312 "CAlignShadow::GetStrand() - argument out of range");
336 if(0 != where && where != 1) {
338 "CAlignShadow::SetStrand() - argument out of range");
342 const Uint1 i1 (where << 1), i2 (i1 + 1);
344 if(
m_Box[i1] == g_UndefCoord ||
m_Box[i2] == g_UndefCoord) {
346 "CAlignShadow::SetStrand() -start and/or stop not yet set");
349 const bool cur_strand (
GetStrand(where));
350 if(strand != cur_strand) {
408 if(0 != where && where != 1) {
410 "CAlignShadow::GetStart() - argument out of range");
414 return m_Box[where << 1];
421 if(0 != where && where != 1) {
423 "CAlignShadow::GetStop() - argument out of range");
427 return m_Box[(where << 1) | 1];
458 if(0 != where && where != 1) {
460 "CAlignShadow::GetStart() - argument out of range");
471 if(0 != where && where != 1) {
473 "CAlignShadow::GetStop() - argument out of range");
511 if(0 != where && where != 1) {
513 "CAlignShadow::GetMin() - argument out of range");
517 Uint1 i1 = where << 1, i2 = i1 + 1;
525 if(0 != where && where != 1) {
527 "CAlignShadow::GetMax() - argument out of range");
531 Uint1 i1 = where << 1, i2 = i1 + 1;
539 if(0 != where && where != 1) {
541 "CAlignShadow::SetMin() - argument out of range");
545 const Uint1 i1 (where << 1), i2 (i1 + 1);
547 if(
m_Box[i1] == g_UndefCoord ||
m_Box[i2] == g_UndefCoord) {
549 "CAlignShadow::SetMin() - start and/or stop not yet set");
561 "CAlignShadow::SetMin() - new position is invalid");
571 if(0 != where && where != 1) {
573 "CAlignShadow::SetMax() - argument out of range");
577 const Uint1 i1 (where << 1), i2 (i1 + 1);
579 if(
m_Box[i1] == g_UndefCoord ||
m_Box[i2] == g_UndefCoord) {
581 "CAlignShadow::SetMax() - start and/or stop not yet set");
593 "CAlignShadow::SetMax() - new position is invalid");
680 m_Box[0] += shift_query;
681 m_Box[1] += shift_query;
682 m_Box[2] += shift_subj;
683 m_Box[3] += shift_subj;
715 bool newpos_invalid =
false;
717 if(new_pos < qmin || new_pos > qmax) {
718 newpos_invalid =
true;
722 if(new_pos < smin || new_pos > smax) {
723 newpos_invalid =
true;
729 "CAlignShadow::Modify(): requested new position invalid");
732 const bool same_strands = qstrand == sstrand;
740 Int1 dq = (qstrand? +1: -1), ds = (sstrand? +1: -1);
744 bool need_trace =
true;
746 if(q == new_pos) need_trace =
false;
749 if(s == new_pos) need_trace =
false;
752 const bool point_is_start((point%2) ^ (
GetStrand(point/2)? 1: 0));
760 case 'M':
case 'R': q += dq; s += ds;
break;
761 case 'D': q += dq;
break;
762 case 'I': s += ds;
break;
765 "CAlignShadow::Modify(): unexpected transcript symbol");
771 if(q == new_pos)
break;
774 if(s == new_pos)
break;
779 if(q == new_pos + dq)
break;
782 if(s == new_pos + ds)
break;
787 if(!point_is_start && n1 > 0) {
789 case 'M':
case 'R': q -= dq; s -= ds;
break;
790 case 'D': q -= dq;
break;
791 case 'I': s -= ds;
break;
816 "CAlignShadow::Modify(): Invalid end point requested.");
820 if( point_is_start ) {
821 xcript = xcript.substr(n1, xcript.size() - n1);
836 TCoord qlen = 1 + qmax - qmin, slen = 1 + smax - smin;
837 double k = double(qlen) / slen;
838 Int4 delta_q, delta_s;
843 delta_q = new_pos - qmin;
845 if( smin + delta_s > smax ) {
846 delta_s = smax - smin;
861 delta_q = qmax - new_pos;
863 if( smin + delta_s > smax ) {
864 delta_s = smax - smin;
879 delta_s = new_pos - smin;
881 if( qmin + delta_q > qmax ) {
882 delta_q = qmax - qmin;
897 delta_s = smax - new_pos;
899 if( qmin + delta_q > qmax ) {
900 delta_q = qmax - qmin;
915 "CAlignShadow::Modify(): invalid end requested");
924 const size_t dim (
in.size());
929 const char* p (
in.data());
933 for(
size_t k (1); k < dim; ++k) {
969 if(
'0' <= c && c <=
'9') {
970 N =
N * 10 + c -
'0';
974 out.append(
N - 1,
C);
977 out.push_back(
C = c);
981 out.append(
N - 1,
C);
CNcbiOstream & operator<<(CNcbiOstream &os, const CAlignShadow &align_shadow)
void SetId(Uint1 where, const TId &id)
bool GetQueryStrand(void) const
void SetQueryMax(TCoord pos)
TCoord GetQueryStart(void) const
void SetQueryMin(TCoord pos)
TCoord GetSubjStop(void) const
void SetStop(Uint1 where, TCoord pos)
std::pair< TId, TId > m_Id
const TCoord * GetBox(void) const
static string s_RunLengthDecode(const string &in)
TCoord GetMin(Uint1 where) const
virtual void Modify(Uint1 point, TCoord new_pos)
const TId & GetSubjId(void) const
void SetMax(Uint1 where, TCoord pos)
void SetSubjStrand(bool strand)
void SetQueryStrand(bool strand)
void Shift(Int4 shift_query, Int4 shift_subj)
TCoord GetQueryMin(void) const
void SetSubjId(const TId &id)
TCoord GetSubjStart(void) const
bool GetSubjStrand(void) const
void SetSubjStart(TCoord pos)
void SetSubjMin(TCoord pos)
void SetMin(Uint1 where, TCoord pos)
TCoord GetMax(Uint1 where) const
void SetStart(Uint1 where, TCoord pos)
TCoord GetStop(Uint1 where) const
const TId & GetId(Uint1 where) const
TCoord GetQueryStop(void) const
void SetQueryStart(TCoord pos)
virtual void x_PartialSerialize(CNcbiOstream &os) const
const TId & GetQueryId(void) const
TCoord GetSubjMin(void) const
static string s_RunLengthEncode(const string &in)
void SetSubjStop(TCoord pos)
TCoord GetQueryMax(void) const
TCoord GetQuerySpan(void) const
void SetBox(const TCoord box[4])
void SetQueryId(const TId &id)
void SetStrand(Uint1 where, bool strand)
void SetSubjMax(TCoord pos)
TCoord GetSubjMax(void) const
const TTranscript & GetTranscript(void) const
TCoord GetSubjSpan(void) const
TCoord GetStart(Uint1 where) const
void SetQueryStop(TCoord pos)
bool GetStrand(Uint1 where) const
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
std::ofstream out("events_result.xml")
main entry point for tests
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
int TSignedSeqPos
Type for signed sequence position.
void swap(NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair1, NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair2)
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
ENa_strand GetStrand(const CSeq_loc &loc, CScope *scope=0)
Returns eNa_strand_unknown if multiple Bioseqs in loc Returns eNa_strand_other if multiple strands in...
uint8_t Uint1
1-byte (8-bit) unsigned integer
int32_t Int4
4-byte (32-bit) signed integer
uint32_t Uint4
4-byte (32-bit) unsigned integer
int8_t Int1
1-byte (8-bit) signed integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define USING_SCOPE(ns)
Use the specified namespace.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
vector< CRef< CSeq_loc > > TLoc
list< CRef< CStd_seg > > TStd
const TStarts & GetStarts(void) const
Get the Starts member data.
vector< ENa_strand > TStrands
const TLens & GetLens(void) const
Get the Lens member data.
vector< TSignedSeqPos > TStarts
const TStrands & GetStrands(void) const
Get the Strands member data.
ENa_strand
strand of nucleic acid
std::istream & in(std::istream &in_, double &x_)
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)