Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull request for pseudoknots #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/include/document_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ class document_writer
std::string get_rna_subtree_formatted(
rna_tree::iterator root) const;

std::string find_pseudoknots(
rna_tree::pre_post_order_iterator begin,
rna_tree::pre_post_order_iterator end) const;

public:
/**
* initialize new document_writer on document `filename`.`suffix`
Expand Down
6 changes: 5 additions & 1 deletion src/include/rna_tree_label.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct rna_label
std::string label;
std::string tmp_label; //label used in the template (can be used to store information about the mapped nodes label in the template)
point p;
size_t pseudoknot;
};

/**
Expand All @@ -63,6 +64,9 @@ class rna_pair_label : public node_base
rna_pair_label() = default;
rna_pair_label(
const std::string& s);

rna_pair_label(const std::string& s, size_t pseudoknot);

bool operator==(
const rna_pair_label& other) const;
rna_pair_label operator+(
Expand Down Expand Up @@ -138,9 +142,9 @@ class rna_pair_label : public node_base
public:
status_type status = untouched;
std::vector<size_t> remake_ids;
std::vector<rna_label> labels;

private:
std::vector<rna_label> labels;
point parent_center;
std::vector<rectangle> bounding_objects;

Expand Down
34 changes: 32 additions & 2 deletions src/tree/rna_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ using namespace std;
inline static std::vector<rna_pair_label> convert(
const std::string& labels);

inline static std::vector<rna_pair_label> convert(const std::string& labels, const std::string& brackets);


inline static std::string trim(
std::string s);

Expand All @@ -41,7 +44,7 @@ rna_tree::rna_tree(
const std::string& _labels,
const std::string& _name)
: tree_base<rna_pair_label>(
trim(_brackets), convert(trim(_labels))), _name(_name)
trim(_brackets), convert(trim(_labels), trim(_brackets))), _name(_name)
{
set_postorder_ids();
distances = {0xBADF00D, 0xBADF00D, 0xBADF00D};
Expand Down Expand Up @@ -82,7 +85,34 @@ void rna_tree::set_name(
return vec;
}


std::vector<rna_pair_label> convert(
const std::string& labels,
const std::string& brackets)
{
vector<rna_pair_label> vec;
vec.reserve(labels.size());
size_t pseudoknot = 1;

for (size_t i = 0; i < labels.size(); ++i)
{
if(brackets[i] == '[' || brackets[i] == '{')
{
vec.emplace_back(labels.substr(i, 1), pseudoknot);
pseudoknot++;
}
else if(brackets[i] == ']' || brackets[i] == '}')
{
--pseudoknot;
vec.emplace_back(labels.substr(i, 1), pseudoknot);
}
else
{
vec.emplace_back(labels.substr(i, 1));
}
}

return vec;
}


void rna_tree::update_points(
Expand Down
8 changes: 7 additions & 1 deletion src/tree/rna_tree_label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ bool rna_label::operator==(
rna_pair_label::rna_pair_label(
const std::string& s)
{
labels.push_back({s, "", point::bad_point()});
labels.push_back({s, "", point::bad_point(), 0});
}

rna_pair_label::rna_pair_label(const std::string& s, size_t pseudoknot)
{
labels.push_back({s, point::bad_point(), pseudoknot});
}


const rna_label& rna_pair_label::operator[](
size_t index) const
{
Expand Down
36 changes: 35 additions & 1 deletion src/utils/document_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,45 @@ std::string document_writer::get_rna_background_formatted(
return out.str();
}

std::string document_writer::find_pseudoknots(rna_tree::pre_post_order_iterator begin, rna_tree::pre_post_order_iterator end) const
{
ostringstream out;

while(begin != end)
{
for(auto&& l: begin->labels)
{
if(l.pseudoknot != 0)
{
auto rest = begin;
++rest;

while(rest != end)
{
for(auto&& ll: rest->labels)
{
if(ll.pseudoknot == l.pseudoknot)
{
out << get_line_formatted(l.p, ll.p, RGB::RED);
}
}
++rest;
}
}
}

++begin;
}

return out.str();
}

std::string document_writer::get_rna_formatted(
rna_tree rna) const
{
return get_rna_subtree_formatted(rna.begin())
+ get_rna_background_formatted(rna.begin_pre_post(), rna.end_pre_post());
+ get_rna_background_formatted(rna.begin_pre_post(), rna.end_pre_post())
+ find_pseudoknots(rna.begin_pre_post(), rna.end_pre_post());
}

void document_writer::init(
Expand Down