<
classType>
67 template<
classType>
85 template<
classType>
91 returnleft > right ? left : right;
101 template<
classType>
107 returnleft < right ? left : right;
120 template<
typenameCntType>
167 template<
typenameCntType>
170 return TSeqPos(GetPosition() * m_Window + 0.5) + m_Start;
173 template<
typenameCntType>
176 return TSeqPos((GetPosition() + GetRunLength()) * m_Window + 0.5) + m_Start;
180 template<
typenameCntType>
183 return TSeqPos(GetRunLength() * m_Window + 0.5);
187 template<
typenameCntType>
191 if(m_Pos >= 0 && m_Pos < m_Bins.size()) {
192CntType this_value = m_Bins[m_Pos];
195 i< m_Bins.size() && m_Bins[
i] == this_value;
203 template<
typenameCntType>
206m_Pos += m_RunLength;
207m_RunLength = x_CalcRunLength();
221 template<
typenameCntType>
227 typedef typenamecontainer_type::iterator
iterator;
234 CDensityMap(
constobjects::CBioseq_Handle& handle,
doublewindow = 1,
244CntType score = 1,
boolexpand =
false);
252objects::SAnnotSelector sel);
256objects::SAnnotSelector sel);
260 constobjects::CSeq_annot& seq_annot);
305objects::SAnnotSelector sel,
306vector<TSeqPos>& density);
352 template<
typenameCntType>
358: m_Range(start, stop)
363, m_Bins(x_CalcNbins(), def)
364, m_AccumFunc(func ? func : new
plus_func<CntType>)
369 template<
typenameCntType>
374: m_Range(0, handle.GetSeqVector().
size())
379, m_Bins(x_CalcNbins(), def)
380, m_AccumFunc(func ? func : new
plus_func<CntType>)
385 template<
typenameCntType>
387: m_Range(
map.m_Range)
388, m_Window(
map.m_Window)
389, m_DefVal(
map.m_DefVal)
392, m_Bins(
map.m_Bins)
393, m_AccumFunc(
map.m_AccumFunc->clone())
398 template<
typenameCntType>
405m_Range =
map.m_Range;
406m_Window =
map.m_Window;
407m_DefVal =
map.m_DefVal;
410m_Bins =
map.m_Bins;
411m_AccumFunc.reset(
map.m_AccumFunc->clone());
416 template<
typenameCntType>
421m_Bins.resize(x_CalcNbins(), m_DefVal);
426 template<
typenameCntType>
435ExtendTo( range.
GetTo());
438 TSeqRangeusable_range(m_Range.IntersectionWith(range));
439 if(usable_range.
Empty()) {
443m_Max =
max(m_Max, score);
444m_Min =
min(m_Min, score);
446 size_tbegin_bin = x_BinN(usable_range.
GetFrom());
447 size_tend_bin = begin_bin;
448 if(m_Window > 1.0) {
449end_bin = x_BinN(usable_range.
GetTo()) + 1;
451end_bin = x_BinN(usable_range.
GetToOpen());
453end_bin =
min(end_bin, m_Bins.size());
455 for(
size_t i= begin_bin;
i< end_bin ; ++
i) {
456CntType& new_val = m_Bins[
i];
457new_val = (*m_AccumFunc)(new_val, score);
458m_Max =
max(m_Max, new_val);
459m_Min =
min(m_Min, new_val);
464 template<
typenameCntType>
466CntType score,
boolexpand)
469ExtendTo( ranges.
GetTo());
473 if(ranges.
Empty()) {
476m_Max =
max(m_Max, score);
477m_Min =
min(m_Min, score);
479 size_tprevious_end_bin = 0;
481 size_tbegin_bin = x_BinN(range_it->GetFrom());
482 size_tend_bin = begin_bin;
483 if(m_Window > 1.0) {
484end_bin = x_BinN(range_it->GetTo()) + 1;
486end_bin = x_BinN(range_it->GetToOpen());
489begin_bin =
max(begin_bin, previous_end_bin);
490end_bin =
min(end_bin, m_Bins.size());
491previous_end_bin = end_bin;
492 for(
size_t i= begin_bin;
i< end_bin ; ++
i) {
493CntType& new_val = m_Bins[
i];
494new_val = (*m_AccumFunc)(new_val, score);
495m_Max =
max(m_Max, new_val);
496m_Min =
min(m_Min, new_val);
502 template<
typenameCntType>
506 for( objects::CSeq_loc_CI it(loc); it; ++it) {
507ranges += it.GetRange();
509AddRanges(ranges, 1,
false);
514 template<
typenameCntType>
517 returnAddLocation(feature.GetLocation());
521 template<
typenameCntType>
523 constobjects::CBioseq_Handle& handle,
524objects::SAnnotSelector sel)
530sel.SetSortOrder(objects::SAnnotSelector::eSortOrder_None);
534objects::CFeat_CI feat_iter(handle.GetScope(), *loc, sel);
535 if(feat_iter.GetSize() == 0) {
539 for(; feat_iter; ++feat_iter) {
540objects::CMappedFeat feat = *feat_iter;
543AddLocation(feat.GetLocation());
549 template<
typenameCntType>
551 constobjects::CBioseq_Handle& handle,
552objects::SAnnotSelector sel)
558objects::CAlign_CI align_iter(handle, range, sel);
560 for(
size_tai = 0; align_iter; ++align_iter, ++ai) {
561 constobjects::CSeq_align& align = *align_iter;
563 if(! align.CanGetDim()) {
564 _TRACE(
"Dimension not set. "<< ai);
567 intdim = align.GetDim();
569 _TRACE(
"Dimension not 2. "<< ai);
582 if(align.GetSegs().IsStd()) {
583 _TRACE(ai <<
": Std seg");
585= align.CreateDensegFromStdseg();
586aln_map =
newobjects::CAlnMap( ds_align->GetSegs().GetDenseg());
588}
else if(align.GetSegs().IsDenseg()) {
589aln_map =
newobjects::CAlnMap(align.GetSegs().GetDenseg());
590 _TRACE(ai <<
": Dense seg");
595 stringall_ids =
": ";
598all_ids += aln_map->GetSeqId(di).AsFastaString() +
", ";
603 TSeqRangerange_final(aln_map->GetSeqStart(0), aln_map->GetSeqStop(0));
604AddRange(range_final, 1,
false);
613 template<
typenameCntType>
615 constobjects::CBioseq_Handle& handle,
616 constobjects::CSeq_annot& seq_annot)
620objects::SAnnotSelector sel;
621objects::CSeq_annot_Handle sah
622= handle.GetScope().GetSeq_annotHandle(seq_annot);
623sel.SetLimitSeqAnnot(sah)
624.SetSortOrder(objects::SAnnotSelector::eSortOrder_None);
627objects::CAlign_CI align_iter(handle, range, sel);
629objects::CAlnMix mix(handle.GetScope());
630 for(
intai = 0; align_iter; ++align_iter, ++ai) {
631 constobjects::CSeq_align& align = *align_iter;
634 if(! align.CanGetDim() || align.GetDim() != 2) {
641 if(align.GetSegs().IsStd()) {
646align.CreateDensegFromStdseg();
648 newobjects::CAlnMap(ds_align->GetSegs().GetDenseg());
650 stringall_ids =
": ";
652di < aln_map->GetNumRows(); ++di) {
653all_ids += aln_map->GetSeqId(di).AsFastaString() +
", ";
657}
catch(
constobjects::CSeqalignException&
) {
661}
else if(align.GetSegs().IsDenseg()) {
664aln_map =
newobjects::CAlnMap(mix.GetDenseg());
666 if(aln_map->GetNumSegs() < 2)
668 _TRACE(ai <<
": Dense seg");
673objects::CAlnMap::TNumrow
row= 0;
674 for(
row= 0;
row!= aln_map->GetNumRows(); ++
row) {
675 if( handle.IsSynonym(aln_map->GetSeqId(
row)) ) {
676aln_map->SetAnchor(
row);
680 if(
row== aln_map->GetNumRows()) {
732 template<
typenameCntType>
736objects::SAnnotSelector sel,
737vector<TSeqPos>& density)
740 if(stop == start && stop == 0) {
741objects::CSeqVector vec = handle.GetSeqVector();
746objects::CFeat_CI feat_iter(handle.GetScope(),
747*handle.GetRangeSeq_loc(start, stop),
749 if(feat_iter.GetSize() == 0) {
753 size_tbins = (stop - start) / window;
754 if(bins * window < stop - start) {
758density.resize(bins, 0);
764deque<objects::CMappedFeat> feats;
767 TSeqPosbin_start = start + bin_count * window;
768 TSeqPosbin_stop = bin_start + window;
772objects::CMappedFeat feat = *feat_iter;
773 TSeqRangerange = feat.GetLocation().GetTotalRange();
775 while(range.
GetFrom() < bin_stop) {
776feats.push_back(feat);
783range = feat.GetLocation().GetTotalRange();
788 while(feats.size()) {
789objects::CMappedFeat& feat = feats.front();
790 TSeqRangerange = feat.GetLocation().GetTotalRange();
792 if(range.
GetTo() < bin_start) {
800*bin_iter = feats.size();
801max_val =
max(*bin_iter, max_val);
Run iterator. iterate through runs of equal values in the bins.
class CDensityMap generates a low-resolution view of a set of features.
position_type GetTo() const
TThisType & IntersectWith(const TRange &r)
Include a standard set of the NCBI C++ Toolkit most basic headers.
unsigned int TSeqPos
Type for sequence locations and lengths.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
virtual ~binary_functor()
void ExtendTo(TSeqPos stop)
extend our density map to cover the sequence position stop.
virtual Type operator()(const Type &left, const Type &right) const
void SetMin(const CntType &min)
CntType AddAlignments(const objects::CBioseq_Handle &handle, const objects::CSeq_annot &seq_annot)
All alignments in a given annotation on this bioseq within the range of this.
const accum_functor * GetAccum() const
CntType m_Min
Smallest count in a bin.
CntType m_DefVal
Default value.
vector< size_t > TDataPoints
CntType m_Max
maximum Count accumulated in the bins so far.
const_iterator end() const
TSeqPos GetSeqPosition() const
Type operator()(const Type &left, const Type &right) const
position_type m_RunLength
virtual binary_functor< Type > * clone() const
container_type::const_iterator const_iterator
CntType operator[](typename container_type::size_type n) const
TSeqRange m_Range
closed range on a sequence this covers.
const_iterator begin() const
void SetMax(const CntType &max)
container_type::iterator iterator
runlen_iterator RunLenBegin() const
size_t x_BinN(TSeqPos p)
convert from sequence coords to a bin number.
static TSeqPos GetDensityMap(const objects::CBioseq_Handle &handle, TSeqPos start, TSeqPos stop, TSeqPos window, objects::SAnnotSelector sel, vector< TSeqPos > &density)
OLD static method.
bool operator==(const CDenMapRunIterator< CntType > &rhs) const
TSeqPos GetSeqRunEndPosition() const
CntType AddAlignments(const objects::CBioseq_Handle &handle, objects::SAnnotSelector sel)
All alignments on this bioseq selected by sel in the range of this.
virtual void AddRanges(CRangeCollection< TSeqPos > ranges, CntType score=1, bool expand=false)
position_type GetRunLength() const
CDenMapRunIterator(position_type here, const container_type &bins, TSeqPos start, double window)
double m_Window
coordinates per bin.
const container_type & m_Bins
size_t x_CalcNbins()
given the range and window size, how many bins should there be?
CDensityMap< CntType > & operator=(const CDensityMap< CntType > &map)
CDenMapRunIterator< CntType > runlen_iterator
CDensityMap(TSeqPos start=0, TSeqPos stop=0, double window=1, accum_functor *func=NULL, CntType def=(CntType) 0)
vector< CntType > container_type
virtual binary_functor< Type > * clone() const =0
virtual void AddRange(TSeqRange range, CntType score=1, bool expand=false)
runlen_iterator RunLenIterator(typename container_type::size_type n) const
CntType GetDefVal() const
CDensityMap(const CDensityMap< CntType > &map)
CntType & operator[](typename container_type::size_type n)
CntType AddLocation(const objects::CSeq_loc &loc)
virtual Type operator()(const Type &left, const Type &right) const
CntType AddFeature(const objects::CSeq_feat &feature)
vector< CntType > container_type
position_type x_CalcRunLength() const
CDensityMap(const objects::CBioseq_Handle &handle, double window=1, accum_functor *func=NULL, CntType def=(CntType) 0)
CntType AddFeatures(const objects::CBioseq_Handle &handle, objects::SAnnotSelector sel)
All features on this bioseq selected by sel in the range of this.
container_type m_Bins
Where we actually keep the accumulated counts/scores/whatever.
TSeqPos GetSeqRunLength() const
TSeqRange GetRange() const
virtual binary_functor< Type > * clone() const
DECLARE_OPERATOR_BOOL(Valid())
unique_ptr< accum_functor > m_AccumFunc
position_type GetPosition() const
binary_functor< CntType > accum_functor
virtual Type operator()(const Type &left, const Type &right) const =0
virtual binary_functor< Type > * clone() const
container_type::size_type position_type
TSeqPos GetStop(const CSeq_loc &loc, CScope *scope, ESeqLocExtremes ext=eExtreme_Positional)
If only one CBioseq is represented by CSeq_loc, returns the position at the stop of the location.
TSeqPos GetStart(const CSeq_loc &loc, CScope *scope, ESeqLocExtremes ext=eExtreme_Positional)
If only one CBioseq is represented by CSeq_loc, returns the position at the start of the location.
position_type GetToOpen(void) const
CRange< TSeqPos > TSeqRange
typedefs for sequence ranges
#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 struct ncbi::grid::netcache::search::fields::SIZE size
#define row(bind, expected)
TEMPLATE binary functor base struct.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4