Skip to content
Snippets Groups Projects
Commit 3613ad2e authored by juergen's avatar juergen
Browse files

adding Replace to AlignmentHandle and AlignedRegion interface

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@1912 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent dce3d61e
No related branches found
No related tags found
No related merge requests found
...@@ -161,6 +161,8 @@ void export_sequence() ...@@ -161,6 +161,8 @@ void export_sequence()
.def("GetSequences", &AlignmentHandle::GetSequences) .def("GetSequences", &AlignmentHandle::GetSequences)
.def("AttachView", attach_view_a) .def("AttachView", attach_view_a)
.def("AttachView", attach_view_b) .def("AttachView", attach_view_b)
.def("Cut", &AlignmentHandle::Cut)
.def("Replace",&AlignmentHandle::Replace)
.def("__getitem__", &slice_aln) .def("__getitem__", &slice_aln)
.def("__getitem__", &AlignmentHandle::operator[]) .def("__getitem__", &AlignmentHandle::operator[])
.def("__iter__", iterator<AlignmentHandle>()) .def("__iter__", iterator<AlignmentHandle>())
...@@ -174,6 +176,7 @@ void export_sequence() ...@@ -174,6 +176,7 @@ void export_sequence()
; ;
class_<AlignedRegion>("AlignedRegion", no_init) class_<AlignedRegion>("AlignedRegion", no_init)
.def("Delete", &AlignedRegion::Delete) .def("Delete", &AlignedRegion::Delete)
.def("Replace", &AlignedRegion::Replace)
.def("ShiftLeft", &AlignedRegion::ShiftLeft) .def("ShiftLeft", &AlignedRegion::ShiftLeft)
.def("ShiftRight", &AlignedRegion::ShiftRight) .def("ShiftRight", &AlignedRegion::ShiftRight)
.def("GetStart", &AlignedRegion::GetStart) .def("GetStart", &AlignedRegion::GetStart)
...@@ -181,6 +184,7 @@ void export_sequence() ...@@ -181,6 +184,7 @@ void export_sequence()
.def("GetLength", &AlignedRegion::GetLength) .def("GetLength", &AlignedRegion::GetLength)
.def("SetMaster", &AlignedRegion::SetMaster) .def("SetMaster", &AlignedRegion::SetMaster)
.def("GetMaster", &AlignedRegion::GetMaster) .def("GetMaster", &AlignedRegion::GetMaster)
.def("GetAlignmentHandle",&AlignedRegion::GetAlignmentHandle)
.add_property("master", &AlignedRegion::GetMaster, .add_property("master", &AlignedRegion::GetMaster,
&AlignedRegion::SetMaster) &AlignedRegion::SetMaster)
.def("__getitem__", &AlignedRegion::operator[]) .def("__getitem__", &AlignedRegion::operator[])
......
...@@ -50,6 +50,11 @@ void AlignedRegion::Delete() ...@@ -50,6 +50,11 @@ void AlignedRegion::Delete()
end_=start_; end_=start_;
} }
void AlignedRegion::Replace(const AlignedRegion& aln_r)
{
aln_.Replace(aln_r,start_, end_);
end_=start_+end_;
}
void AlignedRegion::ShiftLeft(int n) void AlignedRegion::ShiftLeft(int n)
{ {
...@@ -118,4 +123,9 @@ int AlignedRegion::GetLength() const ...@@ -118,4 +123,9 @@ int AlignedRegion::GetLength() const
return end_-start_; return end_-start_;
} }
AlignmentHandle AlignedRegion::GetAlignmentHandle() const
{
return aln_;
}
}} }}
...@@ -47,9 +47,10 @@ public: ...@@ -47,9 +47,10 @@ public:
int GetStart() const; int GetStart() const;
int GetMaster() const; int GetMaster() const;
void SetMaster(int master); void SetMaster(int master);
/// \brief delete interval /// \brief delete interval and update length of AlignedRegion
void Delete(); void Delete();
///\brief replace region with content of AlignedRegion and set length to length of \p aln_r
void Replace(const AlignedRegion& aln_r);
/// \brief shift the aligned region of the master sequence to the left by /// \brief shift the aligned region of the master sequence to the left by
/// n characters. /// n characters.
void ShiftLeft(int n); void ShiftLeft(int n);
...@@ -64,6 +65,9 @@ public: ...@@ -64,6 +65,9 @@ public:
/// \sa AlignmentHandle::GetLength() /// \sa AlignmentHandle::GetLength()
int GetLength() const; int GetLength() const;
///\brief retrieve alignment handle for aligned region
AlignmentHandle GetAlignmentHandle() const;
/// \brief get aligned column at given index /// \brief get aligned column at given index
/// ///
/// The indices range from 0 to GetLength()-1. /// The indices range from 0 to GetLength()-1.
......
...@@ -23,9 +23,11 @@ ...@@ -23,9 +23,11 @@
#include <ost/invalid_handle.hh> #include <ost/invalid_handle.hh>
#include <ost/seq/alignment_handle.hh> #include <ost/seq/alignment_handle.hh>
#include <ost/seq/impl/sequence_list_impl.hh> #include <ost/seq/impl/sequence_list_impl.hh>
#include <ost/seq/impl/sequence_impl.hh>
#include <ost/seq/sequence_list.hh> #include <ost/seq/sequence_list.hh>
#include <ost/seq/aligned_region.hh> #include <ost/seq/aligned_region.hh>
#include <ost/seq/aligned_column_iterator.hh> #include <ost/seq/aligned_column_iterator.hh>
#include <ost/integrity_error.hh>
namespace ost { namespace seq { namespace ost { namespace seq {
...@@ -164,6 +166,22 @@ void AlignmentHandle::Cut(int start, int end) ...@@ -164,6 +166,22 @@ void AlignmentHandle::Cut(int start, int end)
} }
} }
void AlignmentHandle::Replace(const AlignedRegion& aln_r, int start, int end){
this->CheckValidity();
//check that alignment handle and aligned region contain same number of sequences
if (impl_->GetCount() != aln_r.GetAlignmentHandle().GetCount()) {
throw IntegrityError("alignment handle and aligned region are required "\
"to share the same number of sequences");
}
int aln_rStart=aln_r.GetStart();
int aln_rEnd=aln_r.GetEnd();
AlignmentHandle aln=aln_r.GetAlignmentHandle();
//iterate over sequences and replace part of sequences with the substrings
//from aligned region
for (int i=0;i<impl_->GetCount() ;++i) {
this->GetSequence(i).Impl()->Replace(aln.GetSequence(i).GetString().substr(aln_rStart,aln_rEnd), start, end);
}
}
void AlignmentHandle::ShiftRegion(int start, int end, int amount, void AlignmentHandle::ShiftRegion(int start, int end, int amount,
int master) int master)
......
...@@ -138,6 +138,8 @@ public: ...@@ -138,6 +138,8 @@ public:
/// \brief cut out half-closed interval start, end /// \brief cut out half-closed interval start, end
void Cut(int start, int end); void Cut(int start, int end);
///\brief Replace part of an alignment
void Replace(const AlignedRegion& rhs, int start, int end);
/// \brief shift half-closed interval by amount /// \brief shift half-closed interval by amount
/// ///
/// if master is -1, all sequences of the alignment will be shifted. Otherwise /// if master is -1, all sequences of the alignment will be shifted. Otherwise
......
...@@ -265,6 +265,12 @@ void SequenceImpl::Cut(int start, int n) ...@@ -265,6 +265,12 @@ void SequenceImpl::Cut(int start, int n)
this->ShiftsFromSequence(); this->ShiftsFromSequence();
} }
void SequenceImpl::Replace(const String& str,int start, int end)
{
seq_string_.replace(start, end-start, str);
this->ShiftsFromSequence();
}
void SequenceImpl::ShiftRegion(int start, int end, int amount) void SequenceImpl::ShiftRegion(int start, int end, int amount)
{ {
String str1=seq_string_.substr(start, end-start); String str1=seq_string_.substr(start, end-start);
......
...@@ -77,6 +77,9 @@ public: ...@@ -77,6 +77,9 @@ public:
/// \brief Set sequence String /// \brief Set sequence String
void SetString(const String& seq); void SetString(const String& seq);
/// \brief replace substring starting from start to end
void Replace(const String& str,int start, int end);
/// \brief Get sequence as String ignoring gaps /// \brief Get sequence as String ignoring gaps
String GetGaplessString() const; String GetGaplessString() const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment