1. Definition:
Palindrome is defined as the word, phrase or any biological sequence etc. which is same word, phrase or sequence either we read or write if from forward or reverse direction.
For example, wow, dad, mom, madam, noun, 1991, 272, 555, 606, AACTAGGT, ACTAGT, etc. all are palindromes.
2. Explanation:
3. Methods:
3.1. By Manual / Algorithm:
3.2. By Programming:
Code:
#include <iostream>
#include <string>
#include <string.h>
#include <stdlib.h>
using namespace std;
int main()
{
/// Assignment Title Page
cout << "\n\n\t\t\t\t\t Bio-informatics Lab ";
cout << "\n\n\n\t\t\t\t\t Assignment # 02 ";
cout << "\n\n Date : 18/10/2021 \t\t\t\t\t\t\t\t\t\t Day: Monday";
cout << "\n\n\n\n Name ----> Muhammad Usman";
cout << "\n\n Roll No. ----> FA20-BCS-010";
cout << "\n\n Class ----> BCS";
cout << "\n\n Semester ----> 3rd";
cout << "\n\n Section ----> A1";
cout << "\n\n Submitted To ----> Merry Aksa";
/// Solution
cout << "\n\n\n\n ----------";
cout << "\n |Solution| ";
cout << "\n ----------\n\n";
/// Variables
char orgnl[15];
char revrs[15];
char cmplmtry[15];
cout<<"\n\t Enter DNA Sequence (Capital Letters without Spaces) = ";
cin>>orgnl; /// user input , ACTAGT or put ATGC
int leng = strlen(orgnl);
/// Complementary sequence
for (int i=0; i<=leng-1; i++)
{
if(orgnl[i]=='A')
{
cmplmtry[i] = 'T';
}
else if(orgnl[i]=='T')
{
cmplmtry[i] = 'A';
}
else if(orgnl[i]=='G')
{
cmplmtry[i] = 'C';
}
else if(orgnl[i]=='C')
{
cmplmtry[i] = 'G';
}
else
{
cout<<"\n\t Invalid sequence !!! Enter valid nucleotides A,T,G,C in Capital Letters. \n\n";
exit(0);
}
}
/// Display
cout<<"\n\t Complementary Sequence of "<<orgnl<<" = ";
for (int i=0; i<=leng-1; i++)
{
cout<<cmplmtry[i];
}
/// Reverse Sequence
for (int i=0; i<=leng-1; i++)
{
revrs[i]=orgnl[i]; /// ACTAGT
}
for (int i=0; i<(leng/2); i++)
{
swap(revrs[i],revrs[leng-i-1]); /// swaping pairs values on its index
}
/// Display
cout<<"\n\n\t Reverse Sequence of "<<orgnl<<" = ";
for (int i=0; i<=leng-1; i++)
{
cout<<revrs[i];
}
/// Checking Palindrome
string color="green";
for (int i=0; i<=leng-1; i++)
{
if(cmplmtry[i] == revrs[i])
{
color="green";
}
if(cmplmtry[i] != revrs[i])
{
color="red";
break;
}
}
/// Result Light
if(color == "green")
{
cout<<"\n\n\t Sequence ["<<orgnl<<"] is 'Palindromic Sequence' \n\n";
}
if(color == "red")
{
cout<<"\n\n\t Sequence ["<<orgnl<<"] is 'Not Palindromic Sequence' \n\n";
}
/// End Line
cout << "\n\n\n\t\t\t\t\t ---------- T H E E N D ---------- \n\n";
return 0;
}
No comments:
Post a Comment