Skip to content
Snippets Groups Projects
Commit f72c1247 authored by Studer Gabriel's avatar Studer Gabriel
Browse files

Give more power to the RawModelingResult object.

It should not be possible for the user to mess around with the gaps
of the rawmodel object. Gaps can now only be accessed by their index,
bot not be modified. Only modification of gaps is possible with
the new functions ClearGaps, MergeGaps und RemoveTerminalGaps
parent 8083799d
No related branches found
No related tags found
No related merge requests found
......@@ -22,7 +22,11 @@ void export_model()
class_<RawModelingResult>("RawModelignResult", init<>())
.def_readwrite("model", &RawModelingResult::model)
.def_readwrite("gaps", &RawModelingResult::gaps)
.def_readwrite("seqres", &RawModelingResult::seqres);
.def_readwrite("seqres", &RawModelingResult::seqres)
.def("ClearGaps",&RawModelingResult::ClearGaps,(arg("gap")))
.def("MergeGaps",&RawModelingResult::MergeGaps,(arg("index")))
.def("RemoveTerminalGaps",&RawModelingResult::RemoveTerminalGaps)
;
def("BuildRawModel", BuildRawModelHandle,
(arg("aln"),
arg("include_ligands")=false,
......
......@@ -64,6 +64,214 @@ bool CheckCalphaAtom(ResidueView res)
}
int RawModelingResult::ClearGaps(const StructuralGap& gap){
String chain_name = gap.GetChainName();
int next_gap = -1;
if(gap.IsNTerminal()){
for(StructuralGapList::iterator i = gaps.begin(); i != gaps.end();){
if(i->GetChainName() != chain_name) continue;
if(i->IsCTerminal()){
if(gap.after.GetNumber() > i->before.GetNumber()){
if(gap.after.GetNumber() < i->before.GetNumber() + i->GetLength()){
std::stringstream ss;
ss << "Tried to clear gap "<<*i<<" but"<<gap;
ss << " is only overlapping not fully enclosing!";
throw promod3::Error(ss.str());
}
i = gaps.erase(i);
next_gap = i-gaps.begin();
continue;
}
}else if(i->IsNTerminal()){
if(i->after.GetNumber() <= gap.after.GetNumber()){
i = gaps.erase(i);
next_gap = i-gaps.begin();
continue;
}
}else{
if(gap.after.GetNumber() > i->before.GetNumber()){
if(gap.after.GetNumber() < i->after.GetNumber()){
std::stringstream ss;
ss << "Tried to clear gap "<<*i<<" but"<<gap;
ss << " is only overlapping not fully enclosing!";
throw promod3::Error(ss.str());
}
}
i = gaps.erase(i);
next_gap = i-gaps.begin();
continue;
}
++i;
}
return next_gap;
}
if(gap.IsCTerminal()){
for(StructuralGapList::iterator i = gaps.begin(); i != gaps.end();){
if(i->GetChainName() != chain_name) continue;
if(i->IsNTerminal()){
if(gap.before.GetNumber() < i->after.GetNumber()){
if(gap.before.GetNumber() > i->after.GetNumber() - i->GetLength()){
std::stringstream ss;
ss << "Tried to clear gap "<<*i<<" but"<<gap;
ss << " is only overlapping not fully enclosing!";
throw promod3::Error(ss.str());
}
i = gaps.erase(i);
next_gap = i-gaps.begin();
continue;
}
}else if(i->IsCTerminal()){
if(i->before.GetNumber() >= gap.before.GetNumber()){
i = gaps.erase(i);
next_gap = i-gaps.begin();
continue;
}
}else{
if(gap.before.GetNumber() < i->after.GetNumber()){
if(gap.before.GetNumber() > i->before.GetNumber()){
std::stringstream ss;
ss << "Tried to clear gap "<<*i<<" but"<<gap;
ss << " is only overlapping not fully enclosing!";
throw promod3::Error(ss.str());
}
}
i = gaps.erase(i);
next_gap = i-gaps.begin();
continue;
}
++i;
}
return next_gap;
}
for(StructuralGapList::iterator i = gaps.begin(); i != gaps.end();){
if(i->GetChainName() != chain_name) continue;
if(i->IsNTerminal()){
if(gap.before.GetNumber() < i->after.GetNumber()){
if(gap.after.GetNumber() < i->after.GetNumber()){
std::stringstream ss;
ss << "Tried to clear gap "<<*i<<" but"<<gap;
ss << " is only overlapping not fully enclosing!";
throw promod3::Error(ss.str());
}
if(gap.before.GetNumber() > i->after.GetNumber()-i->GetLength()){
std::stringstream ss;
ss << "Tried to clear gap "<<*i<<" but"<<gap;
ss << " is only overlapping not fully enclosing!";
throw promod3::Error(ss.str());
}
i = gaps.erase(i);
next_gap = i-gaps.begin();
continue;
}
}
else if(i->IsCTerminal()){
if(gap.after.GetNumber() > i->before.GetNumber()){
if(gap.before.GetNumber() > i->before.GetNumber()){
std::stringstream ss;
ss << "Tried to clear gap "<<*i<<" but"<<gap;
ss << " is only overlapping not fully enclosing!";
}
if(gap.after.GetNumber() < i->before.GetNumber() + i->GetLength()){
std::stringstream ss;
ss << "Tried to clear gap "<<*i<<" but"<<gap;
ss << " is only overlapping not fully enclosing!";
throw promod3::Error(ss.str());
}
i = gaps.erase(i);
next_gap = i-gaps.begin();
continue;
}
}else{
if(i->before.GetNumber() >= gap.before.GetNumber() &&
i->after.GetNumber() <= gap.after.GetNumber()){
i = gaps.erase(i);
next_gap = i-gaps.begin();
continue;
}
if(i->before.GetNumber() > gap.before.GetNumber() &&
i->before.GetNumber() < gap.after.GetNumber()){
std::stringstream ss;
ss << "Tried to clear gap "<<*i<<" but"<<gap;
ss << " is only overlapping not fully enclosing!";
throw promod3::Error(ss.str());
}
if(i->after.GetNumber() > gap.before.GetNumber() &&
i->after.GetNumber() < gap.after.GetNumber()){
std::stringstream ss;
ss << "Tried to clear gap "<<*i<<" but"<<gap;
ss << " is only overlapping not fully enclosing!";
throw promod3::Error(ss.str());
}
}
++i;
}
return next_gap;
}
void RawModelingResult::MergeGaps(uint index){
if(index >= gaps.size()-1){
throw promod3::Error("Invalid index provided when merging gaps!");
}
if(gaps[index].GetChain() != gaps[index+1].GetChain()){
throw promod3::Error("Subsequent gap must be of the same chain to be merged in!");
}
if(gaps[index].IsNTerminal() && gaps[index+1].IsCTerminal()){
std::stringstream ss;
ss << "You don't want to merge an NTerminal gap with a CTerminal Gap... ";
ss << "You might want to use the RemoveTerminalGaps function to get rid of them!";
throw promod3::Error(ss.str());
}
//assumes, that the gaps are sequential!
String full_seq = seqres[gaps[index].GetChainIndex()].GetGaplessString();
int before_number, after_number;
if(gaps[index].IsNTerminal()) before_number = 0;
else before_number = gaps[index].before.GetNumber().GetNum();
if(gaps[index+1].IsCTerminal()) after_number = full_seq.size()+1;
else after_number = gaps[index+1].after.GetNumber().GetNum();
String gap_seq = full_seq.substr(before_number,after_number-before_number-1);
//kill all residues in between the two new stems
ost::mol::XCSEditor ed = model.EditXCS(ost::mol::BUFFERED_EDIT);
ost::mol::ChainHandle chain = gaps[index].GetChain();
for(ost::mol::ResNum i = gaps[index].before.GetNumber() + 1;
i < gaps[index+1].after.GetNumber(); ++i){
ost::mol::ResidueHandle res = chain.FindResidue(i);
if(res.IsValid()) ed.DeleteResidue(res);
}
StructuralGap new_gap(gaps[index].before,
gaps[index+1].after,
gap_seq);
gaps[index] = new_gap;
gaps.erase(gaps.begin()+index+1);
}
int RawModelingResult::RemoveTerminalGaps(){
int removed_gaps = 0;
for(StructuralGapList::iterator i = gaps.begin(); i != gaps.end(); ){
if(i->IsNTerminal() || i->IsCTerminal()){
i = gaps.erase(i);
++removed_gaps;
}
else ++i;
}
return removed_gaps;
}
bool CopyConserved(ResidueView src_res, ResidueHandle dst_res, XCSEditor& edi,
bool& has_cbeta)
{
......
......@@ -26,6 +26,13 @@ struct RawModelingResult {
{
return !this->operator==(rhs);
}
int ClearGaps(const StructuralGap& gap);
void MergeGaps(uint index);
int RemoveTerminalGaps();
ost::mol::EntityHandle model;
StructuralGapList gaps;
ost::seq::SequenceList seqres;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment