motif.cpp 2.5 KB
#include <iostream>
#include <sstream>

#include "motif.h"

Motif::Motif ()
{
}

Motif::Motif (int rna, std::string seq) : rna_(rna), seq_(seq)
{
    listBp_ = std::vector < std::pair < unsigned int, unsigned int > > ();
}

Motif::Motif (int rna, std::string seq, uint ic) : rna_(rna), seq_(seq), ic_(ic)
{
    listBp_ = std::vector < std::pair < unsigned int, unsigned int > > ();
}

Motif::Motif (const Motif& that) :
    rna_(that.rna_), seq_(that.seq_), listBp_(that.listBp_), ic_(that.ic_)
{
}

Motif::~Motif ()
{
}

int Motif::getRna_() const
{
	return rna_;
}

std::string Motif::getSeq_() const
{
    return seq_;
}

unsigned int Motif::getIc_() const
{
    return ic_;
}

std::vector < std::pair < unsigned int, unsigned int > > Motif::getListBp_() const
{
    return listBp_;
}

void Motif::setRna_(int rna)
{
	rna_ = rna;
}

void Motif::setSeq_(std::string seq)
{
    seq_ = seq;
}

void Motif::setIc_(unsigned int ic)
{
    ic_ = ic;
}

void Motif::setListBp_(std::vector < std::pair < unsigned int, unsigned int > > listBp)
{
    listBp_ = listBp;
}

Motif& Motif::operator=(const Motif& that)
{
    if(&that == this)
        return *this;

    rna_ = that.rna_;
    seq_ = that.seq_;
    ic_ = that.ic_;
    listBp_ = that.listBp_;
    return *this;
}

std::string Motif::convToDP() const
{
    std::cout << "debut convToDP" << std::endl;
    std::string res(uint(seq_.size()), '.');

    char  c1 = '(', c2 = ')';
    for (int i = 0; i < int(listBp_.size()); i++)
    {
        res[listBp_[i].first] = c1;
        res[listBp_[i].second] = c2;
    }
    std::cout << "fin convToDP" << std::endl;
    return res;
}

void Motif::checkListBp_() const
{
    for(size_t i = 0, size = listBp_.size(); i != size; i++)
    {
        if(!app(seq_[listBp_[i].first], seq_[listBp_[i].second])) {
            std::string s = std::string(1, seq_[listBp_[i].first]);
            std::string s2 = std::string(1, seq_[listBp_[i].second]);
            throw (std::string("Error in the motif or constraint, base pair " + s
                + "-" + s2 + " (" + std::to_string(listBp_[i].first+1) + "," +
                    std::to_string(listBp_[i].second+1) + ") isn't allow."));
        }
    }
}

bool Motif::app(const char c1, const char c2) const
{
    std::stringstream ss;
    ss << c1 << c2;
    std::string bp;
    ss >> bp;
    if (bp.compare("AU") != 0 and bp.compare("UA") != 0 and
            bp.compare("UG") != 0 and bp.compare("GU") != 0 and
            bp.compare("GC") != 0 and bp.compare("CG") != 0)
        return false;
    return true;
}