C++ Bioinformatics

Computer Science | Artificial Intelligence | Computational Biology | Chess | Blender

C++ Bioinformatics

This is a simple console-based program that analyzes DNA strands in C++. The program reads a DNA strand and provides insights into the genetic code of organisms. The program is used to demonstrate the syntax and structure of a C++ program.

I am doing this because the C++ programming language is efficient and enhances performance. I aim to apply C++ in computational biology for faster computations and accurate results.

C++ Bioinformatics Project

#include <iostream>
#include <ctime>

char Nucleotides[] = {'A','C','G','T'};
std::string DNA = "";
void makeDNA(){
    srand(time(NULL));
    for(int i = 0;i < 50;i++){
        int randDNA = rand() % 4;
        DNA += Nucleotides[randDNA];
    }
}
void makeRNA(){
    for(int i = 0;i < 50;i++){
        if(DNA[i] == 'T'){
            DNA[i] = 'U';
        }
    }
}
void countDNA(){
    int aCount = 0;
    int tCount = 0;
    int gCount = 0;
    int cCount = 0;
    for(int i = 0;i < 50;i++){
        if(DNA[i] == 'U'){
            tCount += 1;
        }
        else if(DNA[i] == 'G'){
            gCount += 1;
        }
        else if(DNA[i] == 'A'){
            aCount += 1;
        }
        else if(DNA[i] == 'C'){
            cCount += 1;
        }
    }
    std::cout << "{A: " << aCount << ", T: " << tCount << ", G: "
                     << gCount << ", C: " << cCount << "}";
}
double GCpercent(std::string &DNA,int size){
    int content = 0;
    for(int i = 0;i < size;i++){
        if(DNA[i] == 'G' || DNA[i] == 'C'){
            content += 1;
        }
    }
    double results = (content / (double) size) * 100.0;
    return results;
}
void mutations(std::string &DNA,int size){
    for(int i = 0;i < size;i++){
        if(DNA[i] == 'G' && DNA[i+1] == 'U' && DNA[i+2] == 'G'){
            std::cout << "[5] Mutations - ";
            std::cout << "GTG True\n";
        }
    }  
}
void GCperSeg(const std::string &DNA,int size,int seg = 5){
    std::string seq = "";
    std::cout << "[ ";
    for(int i = 0;i < size;i+=seg){
        seq += DNA.substr(i,seg);
        std::cout << (int) GCpercent(seq,seq.length()) << '%' << ' ';
        seq.clear();
    }
    std::cout << ']';
}

// Now I use my functions in my big function "the main function"
int main() {
    system("clear");
    // Make the DNA
    makeDNA();
    std::cout << "[1] Sequence - ";
    std::cout << DNA << "\n\n";
    // Make the RNA for proteinsynthesis
    makeRNA();
    std::cout << "[2] RNA - ";
    std::cout << DNA << "\n\n";
    // Count every appearence of a nucleotide
    std::cout << "[3] Count DNA - ";
    countDNA();
    std::cout << "\n\n";
    // Calculate the GC percentage
    std::cout << "[4] GC percentage - ";
    std::cout << GCpercent(DNA,DNA.length()) << "%\n\n";
    // GTG Mutation
    mutations(DNA,DNA.length());
    std::cout << "\n";
    // GC percentage per section
    std::cout << "[6] GC per section - ";
    GCperSeg(DNA,DNA.length());
    std::cout << std::endl;
    return 0;
}