structure.h 5.02 KB
#ifndef DEF_HSTR
#define DEF_HSTR

#include <utility>

#include "Motifs/motif.h"

// From RNAstructure
// New type defined to stock the motif helixs position of a secondary structure, its motif helix parent and its motif helix children
typedef struct helix{
        std::pair<int,int> pos_start;
        std::pair<int,int> pos_end;
        helix *parent;
        bool pseudo;
        std::vector<helix*> child;
        std::vector< helix * > crossingHelixs; //redundance in some other helixs DO NOT DELETE FROM HERE
} helix;

// From RNAstructure
// A stack useful for pseudoknot calculations. It stores intervals [i, j].
// An interval is pushed onto the stack with push(i', j')  (which does NOT affect the members i or j)
// An interval is popped off the stack with pop(), which sets the members i and j.
struct IntervalStack {
        std::vector<short> stack; unsigned short i, j; unsigned int pos;  /** i and j are the Current values */
        IntervalStack(int capacity = 8) :  stack(capacity), pos(0) {}
    void push(int i, int j) {
                if (stack.size() < pos+2) stack.resize(pos+2); // ensure there is room for two more elements.
        stack[pos++] = (short)i;
        stack[pos++] = (short)j;
    }
    bool pop() {
        if (pos==0) return false;
        j = stack[--pos]; // pop in reverse order or push (j, then i)
        i = stack[--pos];
        return true;
    }
};


class Structure
{
public:
    Structure();

    Structure (const int rna, const std::string &seq,
               const std::vector < std::pair < unsigned int, unsigned int > > &listBp,
               const int ct, const int nbCt, const int id, unsigned int energyModel, float energy,
               const std::vector < float > &probingData, float lowerThresProbing, float upperThresProbing);

    Structure(const Structure& that); //Copy

    ~Structure ();

    int get_rna_() const;

    std::string get_seq_() const;

    float get_obj1_() const;

    std::vector < std::pair < unsigned int, unsigned int > > get_listBp_() const;

    int get_ct_() const;

    float get_ic_() const;

    int get_nbCt_() const;

    int get_id_() const;

    float get_probing_() const;

    std::vector < Motif * > get_motifs_() const;

    void set_obj1_(float obj1);

    void set_id_(int id);

    void set_nbCt_(int nbCt);

    void set_ct_(int ct);

    void set_ic_(float ic);

    void set_probing_(float probing);

    std::string convToDP() const;

    std::string convToDP(char c1, std::vector<char> forbid, bool first) const;

    std::string convToDPonly() const;

    void getPseudoknotRanks(std::vector < uint > &ranks, std::vector < uint > basepr) const;

    bool hasPseudoknots(const std::vector < int > &pairs) const;

    void findPseudoknots(const std::vector < int > &currentPairs,
                         std::vector < int > *pseudoknotPairs = NULL,
                         std::vector < int > *normalPairs = NULL) const;

    std::string convToDPonly(char c1, std::vector<char> forbid, bool first) const;

    std::string to_string() const;

    std::string to_Json() const;

   // int find_bp(std::pair< unsigned int, unsigned int > p) const;

   // std::vector< unsigned int > find_bp_with_i(unsigned int i) const;

    Structure& operator=(const Structure& that); //Copy assigment helix

    bool operator<(const Structure &s);

    bool operator<(const Structure &s) const;

    bool operator>(const Structure &s);

    bool operator>(const Structure &s) const;

    bool operator<=(const Structure &s);

    bool operator<=(const Structure &s) const;

    bool operator>=(const Structure &s);

    bool operator>=(const Structure &s) const;

    bool operator==(const Structure &s);

    bool operator==(const Structure &s) const;

    static void makeListBp(std::string structureDP, std::vector < std::pair < unsigned int, unsigned int > > &listbp);

    static bool checkStructure(std::string structure);

    static bool checkListBp(std::string seq, std::vector < std::pair < unsigned int, unsigned int > > &listbp);

private:

    void print(helix *tmp);

    bool checkChildrenMulti(helix *child, helix *parent);

    bool checkChildrenIntern(helix *child, helix *parent);

    std::vector < Motif * > readTree(helix *tmp);

    void freeHelixSS(helix *val);

    void motifDetection();

    std::string convToNUPACK() const;

    void computeEnergyNUPACK();

    void computeEnergyVienna();

    void computeProbing(const std::vector < float > &probingData, float lowerThresProbing, float upperThresProbing);



    int rna_;

    std::string seq_;

    float obj1_;	//value of objective 1

    std::vector < std::pair < unsigned int, unsigned int > > listBp_;

    int ct_; // confidence Index of the complete Structure given in the structure file

    float ic_; // confidence Index containing ct_ and the constraint from the constraint file, used for clique problem

    unsigned int nbCt_; // Number of user constraint the solInteraction corresponds

    float probing_; // probing data score

    int id_; //id among the sub-optimal solution structure vector

    std::vector < Motif * > motifs_;
};

#endif