Friday, January 9, 2015

DNA complementary sequence conversion C++

DNA is Deoxyribonucleic acid which encoding the genetic instructions including cell function and development of organisms.

DNA consist of 2 strands and each sequence is complementary. So, we can get a complementary sequence if we have a template sequence.
A - T (T - A)
G - C (C - G)


This is simple c++ programming code.
Input comes from user's input parameter in command.



If the program name is reverse, then ./reverse ACGT
The result will be like that.

./reverse ACGT
Input sequence: ACGT
Output sequence: TGCA





#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;

string convert(string str);

int main(int argc, char* argv[]){

    string str(argv[1]);
    string revcomp = convert(str);

    cout<<"Input  sequence: "<<str<<endl;
    cout<<"Output sequence: "<<revcomp<<endl;
}

string convert(string str){
    for(int i=0;i<str.length();i++){
        switch( str[i] ){
            case 'A':
                str[i] = 'T';
                break;
            case 'C':
                str[i] = 'G';
                break;
            case 'G':
                str[i] = 'C';
                break;
            case 'T':
                str[i] = 'A';
                break;
            default:
                cout<<"Argument error."<<endl;
                exit(-1);
        }
    }

    return str;
}




This is result figure.


No comments:

Post a Comment