C++ code for graduate project

I need help in my code ,I hope reply to help me
thanks

Dear @Ghadeer_Ghazi_Qasem,
Kindly share your code and problem you are facing, so that I can help you.

We will be glad to help you @Ghadeer_Ghazi_Qasem just drop your code or issue in which you need help.

#include // std::cin, std::cout
#include // std::ifstream
#include
#include <time.h>
#include
#include
using namespace std;
int main()
{
char str[256];
string seq[200];//the initial seq
string random[200];//seq after cut
string reminder[200];//the reminder of seq
string x;
int cut;
cout << “This project for applied Gibbs algorithm on sequences to find motifs…” << endl;
cout<< “The maximum sequences can be entered are 200 sequences.” << endl;
std::cout << "Enter the name of an existing sequences file: "; //users/dell/desktop/graduate project/c++/sequances.txt
std::cin.get(str, 256);
std::ifstream in(str); // open file
////////////////cheak if file open or not
if (!in)
{
std::cerr << “error: can’t open file\n”;
return -1;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//initialization string each string have different line from file
int counter=0;
if(in.is_open())
{
while (getline(in, x))
{
seq[counter] = x;
reminder[counter] = x;
counter++;
}
counter = counter - 1;
};
in.close(); // close file
////////////////////////////////////////////////////////////////////////////////////////////////////
//print multi string each string have single line from file
cout << "please enter the length of motif nuclutide= ";
cin >> cut;
cout << "The initial sequences in strings " << endl;
for (int j = 0;seq[j] != “\0”;j++)
cout << seq[j] << endl;
/////////////////////////////////////////////////////////////////////////////
//the new strings with random cut
cout << “The motifs with random cut from original sequences.” << endl;
for (int o = 1;reminder[o] != “\0”;o++)
{
if (reminder[o].length() - cut - 1 <= 0)////////////////////the if to cheak if randoms can applied on sequances or not
{
cout << “the sequance equal or less the the cut random”;
return 1;
}
srand(time(NULL));
int ran = (rand() % (reminder[o].length() - cut - 1) + 0);//randome function give me from (0-(length-cut-1))
random[o] = reminder[o].substr(ran, cut);
//remover randome from all sequences
reminder[o].erase(ran, cut);
cout << random[o] << endl;
};
///////////////////////////////////////////////////
//the remainder of seq after cuting
cout << "The Remainder of nucleotides after extracting motiefs " << endl;
for (int t = 1;reminder[t] != “\0”;t++)
cout << reminder[t] << endl;
///////////////////////////////////////the code for save reminder string in new integer string by
///////////// location and counting the frequancy for each character
cout << “The background frequency of nucleotide” << endl;//wit static first sequances
string temp;
for (int i = 1;reminder[i] != “\0”;i++)
{
temp.append(reminder[i]);
}

size_t count[256];
int y=0;
int background[4] = {0};
std::fill_n(count, 256, 0);
for (int i = 0; i < temp.length();i++)
{
	char t = temp[i];
	int ind = uint8_t(t);
	++count[ind];
};//character to index and adding value 1 
for (int index = 0; index < 256;index++)
{
	if (count[index] && isgraph(index)) // non-zero counts of printable characters
	{
		std::cout << char(index) << " = " << count[index] << '\n';
		if (count[index] != 0) {
		background[y] = count[index];
		y++;}
	}
}
/////////////////////////////////////////////
//cout << "counter= " << counter << endl;
//cout << "motife= " << cut << endl;
//for (int i = 0;i < 4;i++)
	//cout << background[i]<<endl;
//cout << "the matrix of freqancay character" << endl;
cout << "\\\\\\\\\\\\\\\\\\\\\\" << endl;
	vector < vector<int> >matrix1(4, cut+1);
	for (int i = 0;i < 1;i++)
	{
		for (int j = 0;j < 4;j++)
		{
			matrix1[j][i] = background[j];
			cout << matrix1[j][i] << " ";cout << endl;
		}
	}
	cout << "//////////////////" << endl;
int A=0 , C=0, G=0, T=0;
for (int i = 0;i < cut;i++)
{
	for (int j = 1;j < counter;j++)
	{
		if (random[j][i] == 'A')
			A++;
		if (random[j][i] == 'C')
			C++;
		if (random[j][i] == 'G')
			G++;
		if (random[j][i] == 'T')
			T++;
		cout << random[j][i] ;cout << endl;
	}	
	cout << "A=" << A << " C=" << C << " G=" << G << " T=" << T << endl;
	/*for (int i = 1;i < cut;i++)
	{
		for (int j = 0;j < counter;j++)
		{
			matrix1[j][i] = A, C, G, T;
			cout << matrix1[j][i] << " ";cout << "\n";
		}
	}*/
	A = 0;C = 0;G = 0;T = 0;
}

return 0;
}

gibbs sampling for motif dection
This video shows what is required to write C ++ code, there are 4 parts to explain enough to understand the code.

I stopped writing the code when I was asked a complete matrix for motifs and in the top the code that I wrote.

I hope to help and thank you very much.

please see my reply in previous comment

Dear @Ghadeer_Ghazi_Qasem, can you please tell, actually what you want to do with this code?
I mean what this code will do?

1 Like

This code explain gibbs sampling fot motifs dection like video in the top

https://youtu.be/JCk0PJL6bCY and this video show final result of code

I hope you understand me

Thanks a lot

Do you have any idea about this code?
thanks