10 #include <GL/freeglut.h>
15 #define STB_IMAGE_IMPLEMENTATION
16 #include "stb_image.h"
21 "ACA box 91 (SNORA91)";
34 void drawText(
const char* text,
float x,
float y) {
36 for (
const char* c = text; *c !=
'\0'; c++) {
37 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *c);
57 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
60 glBindTexture(GL_TEXTURE_2D,
texture);
62 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
63 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
65 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
66 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
68 int width, height, nrChannels;
69 unsigned char* data = stbi_load(filename, &width, &height, &nrChannels, 0);
72 Logger::trace(
"Trying to load texture of size: {}x{}", width, height);
74 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
75 GL_UNSIGNED_BYTE, data);
76 glGenerateMipmap(GL_TEXTURE_2D);
80 stbi_image_free(data);
103 float halfWidth = aspectRatio / 2.0f;
106 glTexCoord2f(0.0f, 1.0f);
107 glVertex2f(-halfWidth, -0.5f);
108 glTexCoord2f(1.0f, 1.0f);
109 glVertex2f(halfWidth, -0.5f);
110 glTexCoord2f(1.0f, 0.0f);
111 glVertex2f(halfWidth, 0.5f);
112 glTexCoord2f(0.0f, 0.0f);
113 glVertex2f(-halfWidth, 0.5f);
151 if (
keys[27]) glutLeaveMainLoop();
163 glViewport(0, 0, width, height);
165 float aspect = (float)width / (
float)height;
167 glMatrixMode(GL_PROJECTION);
169 if (width >= height) {
170 gluOrtho2D(-1.0 * aspect, 1.0 * aspect, -1.0, 1.0);
172 gluOrtho2D(-1.0, 1.0, -1.0 / aspect, 1.0 / aspect);
175 glMatrixMode(GL_MODELVIEW);
183 glClear(GL_COLOR_BUFFER_BIT);
184 glEnable(GL_TEXTURE_2D);
185 glBindTexture(GL_TEXTURE_2D,
texture);
189 glDisable(GL_TEXTURE_2D);
190 glColor3f(1.0f, 1.0f, 1.0f);
191 drawText((
"Current RNA: " +
rna_name).c_str(), -1.0f, 0.9f);
195 drawText((
"Number of bonds: " + std::to_string(
number_of_bonds)).c_str(),
198 drawText(
"Controls:", -1.0f, 0.7f);
199 drawText((
"(x, y): " + std::to_string(
pan_x) +
", " + std::to_string(
pan_y))
202 drawText((
"Zoom: " + std::to_string(
zoom)).c_str(), -1.0f, 0.6f);
204 glDisable(GL_TEXTURE_2D);
208 int main(
int argc,
char** argv) {
214 file.open(
"rna/" +
rna_name +
".rna");
221 std::string rna_sequence;
222 std::getline(file, rna_sequence);
224 const int minimal_loop_length = 5;
226 std::vector<std::pair<int, int>> fold;
228 fold, 0, rna_sequence.size() - 1);
230 std::string dot_notation =
dot_write(rna_sequence, fold);
235 Logger::info(
"Total number of nucleotides: {}", rna_sequence.size());
242 glutInit(&argc, argv);
243 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
244 glutInitWindowSize(800, 600);
245 glutCreateWindow(
"OpenGL Image Display");
248 GLenum err = glewInit();
249 if (err != GLEW_OK) {
250 Logger::error(
"Failed to initialize GLEW: {}", glewGetErrorString(err));
262 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
263 glClear(GL_COLOR_BUFFER_BIT);
static void info(const char *format, Args... args)
Logs messages of type info.
static void trace(const char *format, Args... args)
Logs messages of type trace.
static void error(const char *format, Args... args)
Logs messages of type error. Furthermore closes the output file and exits the program.
static void warn(const char *format, Args... args)
Logs messages of type warning. Doesn't exit the program, just notifies the issue.
Header file logging library.
GLuint texture
OpenGL reference to the RNA structure image.
float pan_x
Pan along the x-axis.
void display()
Callback function for displaying the image and the text.
bool keys[256]
Keeps track of which key was pressed on the keyboard.
int textureHeight
Global variables to keep track of RNA structure image width.
int number_of_bonds
Number of bonds in input.
float pan_y
Pan along the y-axis.
int textureWidth
Global variables to keep track of RNA structure image width.
void loadTexture(const char *filename)
Loads an RGBA image.
void keyboardUp(unsigned char key, int x, int y)
Callback function for keyboard events (Up press)
void reshape(int width, int height)
Callback function called when reshaping window.
std::string rna_name
Global variable to store rna name.
void drawTexturedQuad()
Draws a textured quad on the screen. Keeps the aspect ratio of the image intact.
int number_of_nucleotides
Number of nucleotides in input.
void update()
Callback function for updating the keyboard input.
void keyboardDown(unsigned char key, int x, int y)
Callback function for keyboard events (Down press)
RNA folding algorithm implementation.
std::vector< std::vector< int > > create_matrix(const std::string &rna_sequence, const int &minimal_loop_length=0)
Function to create the DP matrix for RNA folding.
std::string dot_write(const std::string &rna, const std::vector< std::pair< int, int >> &fold)
Function to create the dot-bracket notation from the bonds.
void traceback(const std::vector< std::vector< int >> &nm, const std::string &rna, std::vector< std::pair< int, int >> &fold, int i, int j)
Function to traceback DP and get the bonds structure.
void dot_bracket_to_dot(const std::string &sequence, const std::string &structure)
Creates a DOT script from the RNA sequence and structure and calls graphviz.
int rna_score(const std::string &rna_sequence, const int &minimal_loop_length=0)
Function to calculate number of bonds (theoretical) in the RNA.