Skip to content
Snippets Groups Projects
Commit 336f5fa9 authored by stefan's avatar stefan
Browse files

Fixed, alignment and sequence impls (added more bounds checks)

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2203 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 0cfc7f46
No related branches found
No related tags found
No related merge requests found
......@@ -62,9 +62,9 @@ int AlignmentHandle::GetResidueIndex(int seq_index, int pos) const
void AlignmentHandle::AddSequence(const ConstSequenceHandle& sequence)
{
this->CheckValidity();
if (impl_->GetCount()>0 &&
impl_->GetSequence(0)->GetLength()!=sequence.GetLength()) {
throw InvalidAlignment();
if (!sequence.IsValid() || (impl_->GetCount()>0 &&
impl_->GetSequence(0)->GetLength()!=sequence.GetLength())) {
throw InvalidSequence();
}
return impl_->AddSequence(sequence.Impl());
}
......@@ -124,7 +124,7 @@ int AlignmentHandle::GetCount() const
AlignmentHandle AlignmentFromSequenceList(const SequenceList& seq_list)
{
if (seq_list.SequencesHaveEqualLength()) {
if (seq_list.IsValid() && seq_list.SequencesHaveEqualLength()) {
return AlignmentHandle(seq_list.Impl());
}
throw InvalidAlignment();
......@@ -188,10 +188,14 @@ void AlignmentHandle::ShiftRegion(int start, int end, int amount,
{
this->CheckValidity();
int cnt=0;
for (impl::SequenceListImpl::Iterator i=impl_->Begin(),
e=impl_->End(); i!=e; ++i, ++cnt) {
if (master==-1 || cnt==master) {
(*i)->ShiftRegion(start, end, amount);
if(master!=-1){
impl::SequenceImplPtr handle = this->GetSequence(master).Impl();
handle->ShiftRegion(start, end, amount);
}
else{
for (impl::SequenceListImpl::Iterator i=impl_->Begin(),
e=impl_->End(); i!=e; ++i, ++cnt) {
(*i)->ShiftRegion(start, end, amount);
}
}
}
......@@ -199,6 +203,9 @@ void AlignmentHandle::ShiftRegion(int start, int end, int amount,
AlignedRegion AlignmentHandle::MakeRegion(int start, int n, int master) const
{
this->CheckValidity();
if(start<0 || n < 0 || start >= n || start + n >= this->GetLength()){
throw std::out_of_range("Region not valid");
}
return AlignedRegion(*this, start, start+n, master);
}
......
......@@ -121,8 +121,7 @@ public:
/// If set to -1, no master sequence is defined and the operations will
/// affect all sequences
///
/// This method does not throw any exceptions, even if the aligned region is
/// out of bounds.
/// If the aligned region is out of bounds, a std::out_of_bounds exeception will be thrown.
AlignedRegion MakeRegion(int start, int n, int master=-1) const;
/// \brief get number of sequences in alignment
......
......@@ -280,6 +280,9 @@ void SequenceImpl::Replace(const String& str,int start, int end)
void SequenceImpl::ShiftRegion(int start, int end, int amount)
{
if(start <= end && end + amount > this->GetLength() || start + amount <= 0){
throw std::out_of_range("Region not valid");
}
String str1=seq_string_.substr(start, end-start);
if (amount<0) {
String str2=seq_string_.substr(start+amount, -amount);
......
......@@ -41,12 +41,21 @@ public:
/// \brief get number of sequences in list
int GetCount() const { return list_.size(); }
SequenceImplPtr& GetSequence(int i)
{
return list_[i];
SequenceImplPtr& GetSequence(int i) {
unsigned int index = static_cast<unsigned int>(i);
if (index<list_.size()) {
return list_[index];
}
throw Error("Index not covered SequenceList");
}
const SequenceImplPtr& GetSequence(int i) const { return list_[i]; }
const SequenceImplPtr& GetSequence(unsigned int i) const {
unsigned int index = static_cast<unsigned int>(i);
if (index<list_.size()) {
return list_[index];
}
throw Error("Index not covered SequenceList");
}
int GetPos(int seq_index, int residue_index) const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment