From 7298954532521b9c7ec16c3f4f05c2318bdcb871 Mon Sep 17 00:00:00 2001 From: Valerio Mariani <valerio.mariani@unibas.ch> Date: Thu, 27 Jan 2011 21:57:30 +0100 Subject: [PATCH] Added GetCoverage function --- modules/seq/base/pymod/export_sequence.cc | 1 + modules/seq/base/src/alignment_handle.cc | 8 ++++++++ modules/seq/base/src/alignment_handle.hh | 7 +++++++ .../seq/base/src/impl/sequence_list_impl.cc | 18 ++++++++++++++++++ .../seq/base/src/impl/sequence_list_impl.hh | 2 +- 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/modules/seq/base/pymod/export_sequence.cc b/modules/seq/base/pymod/export_sequence.cc index ab36fdaed..b3632fc50 100644 --- a/modules/seq/base/pymod/export_sequence.cc +++ b/modules/seq/base/pymod/export_sequence.cc @@ -301,6 +301,7 @@ void export_sequence() .def("GetLength", &AlignmentHandle::GetLength) .def("__len__", &AlignmentHandle::GetLength) .def("GetSequences", &AlignmentHandle::GetSequences) + .def("GetCoverage", &AlignmentHandle::GetSequences) .def("AttachView", attach_view_a) .def("AttachView", attach_view_b) .def("Cut", &AlignmentHandle::Cut) diff --git a/modules/seq/base/src/alignment_handle.cc b/modules/seq/base/src/alignment_handle.cc index d2a7ab85d..bf2c12fdf 100644 --- a/modules/seq/base/src/alignment_handle.cc +++ b/modules/seq/base/src/alignment_handle.cc @@ -263,4 +263,12 @@ int AlignmentHandle::GetSequenceOffset(int seq_index) this->CheckValidity(); return impl_->GetSequence(seq_index)->GetOffset(); } + +Real AlignmentHandle::GetCoverage(int seq_index) const +{ + this->CheckValidity(); + return impl_->GetCoverage(seq_index); +} + + }} diff --git a/modules/seq/base/src/alignment_handle.hh b/modules/seq/base/src/alignment_handle.hh index bcba027d9..823e78be1 100644 --- a/modules/seq/base/src/alignment_handle.hh +++ b/modules/seq/base/src/alignment_handle.hh @@ -158,6 +158,13 @@ public: iterator end() const; bool IsValid() const { return impl_.get()!=0; } + + ///\brief get coverage of a specifi sequence + /// + /// returns a value representing how extensively the specified sequence + /// covers the first sequence (sequence 0). The function return a value + /// between 0 (no coverage) and 1 (full coverage) + Real GetCoverage(int seq_index) const; private: void CheckValidity() const; diff --git a/modules/seq/base/src/impl/sequence_list_impl.cc b/modules/seq/base/src/impl/sequence_list_impl.cc index b955d8b4c..16759dbcf 100644 --- a/modules/seq/base/src/impl/sequence_list_impl.cc +++ b/modules/seq/base/src/impl/sequence_list_impl.cc @@ -178,4 +178,22 @@ SequenceListImplPtr SequenceListImpl::Slice(int first, int n) const } } +Real SequenceListImpl::GetCoverage(int seq_index) const +{ + int a=0, b=0; + String seq_string_0 = GetSequence(0)->GetString(); + String seq_string_index = GetSequence(seq_index)->GetString(); + for (int i=0; i<GetSequence(0)->GetLength(); ++i) { + if (seq_string_0[i]!='-') { + a+=1; + if (seq_string_index[i]!='-') { + b+=1; + } + } + } + Real coverage=Real(b)/Real(a); + return coverage; +} + + }}} diff --git a/modules/seq/base/src/impl/sequence_list_impl.hh b/modules/seq/base/src/impl/sequence_list_impl.hh index 66bedd61f..ab382b8c8 100644 --- a/modules/seq/base/src/impl/sequence_list_impl.hh +++ b/modules/seq/base/src/impl/sequence_list_impl.hh @@ -78,7 +78,7 @@ public: return this->GetMaxLength()==this->GetMinLength(); } - + Real GetCoverage(int seq_index) const; SequenceListImplPtr Copy() const; -- GitLab