Skip to content
Snippets Groups Projects
Select Git revision
  • b97a3c98e8c72a416de18b70b191109247c54b82
  • master default protected
  • develop protected
  • cmake_boost_refactor
  • ubuntu_ci
  • mmtf
  • non-orthogonal-maps
  • no_boost_filesystem
  • data_viewer
  • 2.11.1
  • 2.11.0
  • 2.10.0
  • 2.9.3
  • 2.9.2
  • 2.9.1
  • 2.9.0
  • 2.8.0
  • 2.7.0
  • 2.6.1
  • 2.6.0
  • 2.6.0-rc4
  • 2.6.0-rc3
  • 2.6.0-rc2
  • 2.6.0-rc
  • 2.5.0
  • 2.5.0-rc2
  • 2.5.0-rc
  • 2.4.0
  • 2.4.0-rc2
29 results

sec_structure_segments.cc

Blame
  • user avatar
    Marco Biasini authored
    970dff3c
    History
    sec_structure_segments.cc 4.14 KiB
    //------------------------------------------------------------------------------
    // This file is part of the OpenStructure project <www.openstructure.org>
    //
    // Copyright (C) 2008-2011 by the OpenStructure authors
    //
    // This library is free software; you can redistribute it and/or modify it under
    // the terms of the GNU Lesser General Public License as published by the Free
    // Software Foundation; either version 3.0 of the License, or (at your option)
    // any later version.
    // This library is distributed in the hope that it will be useful, but WITHOUT
    // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    // FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    // details.
    //
    // You should have received a copy of the GNU Lesser General Public License
    // along with this library; if not, write to the Free Software Foundation, Inc.,
    // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    //------------------------------------------------------------------------------
    #include <ost/mol/mol.hh>
    
    #include "sec_structure_segments.hh"
    
    /* 
      Author: Marco Biasini
     */
     
    namespace ost { namespace mol { namespace alg {
    
    
    namespace {
    
    class SecStrExtractor : public EntityVisitor {
    public:
      SecStrExtractor(): index_(0) {}
      virtual bool VisitResidue(const ResidueHandle& r)
      {
        if (sec_.empty()) {
          sec_.push_back(SecStructureSegment(index_, index_, r.GetSecStructure()));
        } else if (sec_.back().ss_type!=r.GetSecStructure()) {
          sec_.push_back(SecStructureSegment(index_, index_, r.GetSecStructure()));
        } else {
          sec_.back().last+=1;
        }    
        index_+=1;
        return false;
      }
      
      const SecStructureSegments& GetList() const { return sec_; }
    protected:
      SecStructureSegments  sec_;
      int                   index_;
    };
    
    
    // pretty bad case of code duplication.
    
    class HelicalExtractor : public SecStrExtractor {
    public:
      HelicalExtractor(): SecStrExtractor(), extend_(false)
      { }
      
      virtual bool VisitResidue(const ResidueHandle& r)
      {
        mol::SecStructure helical(mol::SecStructure::ALPHA_HELIX);
        if (r.GetSecStructure().IsHelical()) {
          if (sec_.empty()) {
            sec_.push_back(SecStructureSegment(index_, index_, helical));
            extend_=true;
          } else if (extend_) {
            sec_.back().last+=1;
          } else {
            sec_.push_back(SecStructureSegment(index_, index_, helical));
            extend_=true;        
          }
        } else {
          extend_=false;
        }    
        index_+=1;
        return false;
      }
    private:
      bool          extend_;
    };
    
    class ExtendedExtractor : public SecStrExtractor {
    public:
      ExtendedExtractor(): SecStrExtractor(), extend_(false)
      { }
      
      virtual bool VisitResidue(const ResidueHandle& r)
      {
        mol::SecStructure extended(mol::SecStructure::EXTENDED);
        if (r.GetSecStructure().IsExtended()) {
          if (sec_.empty()) {
            sec_.push_back(SecStructureSegment(index_, index_, extended));
            extend_=true;
          } else if (extend_) {
            sec_.back().last+=1;
          } else {
            sec_.push_back(SecStructureSegment(index_, index_, extended));
            extend_=true;        
          }
        } else {
          extend_=false;
        }        
        index_+=1;
        return false;
      }
    private:
      bool          extend_;
    };
    
    
    template <typename E, typename C>
    inline SecStructureSegments extract_ss(C c)
    {
      E extractor;
      c.Apply(extractor);
      return extractor.GetList();
    }
    
    }
    
    SecStructureSegments ExtractSecStructureSegments(const ChainHandle& chain)
    {
      return extract_ss<SecStrExtractor, ChainHandle>(chain);
    }
    
    SecStructureSegments ExtractSecStructureSegments(const ChainView& chain)
    {
      return extract_ss<SecStrExtractor, ChainView>(chain);
    }
      
    SecStructureSegments ExtractHelicalSegments(const ChainHandle& chain)
    {
      return extract_ss<HelicalExtractor, ChainHandle>(chain);
    }
    
    SecStructureSegments ExtractHelicalSegments(const ChainView& chain)
    {
      return extract_ss<HelicalExtractor, ChainView>(chain);
    }
    
    
    SecStructureSegments ExtractExtendedSegments(const ChainHandle& chain)
    {
      return extract_ss<ExtendedExtractor, ChainHandle>(chain);
    }
    
    SecStructureSegments ExtractExtendedSegments(const ChainView& chain)
    {
      return extract_ss<ExtendedExtractor, ChainView>(chain);
    }
    
    
    
    }}}