ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I call a function and when it returns a vector of int, it crash. The line where the execution stops is this, which we can found it in satDNA.cgi and calls a function of sample.cgi
int Ejecutar (){
/**
* Abrimos el fichero "datos.txt" en se han almacenado los datos de entrada de la
* aplicación para realizar la ejecución.
*/
ifstream datos;
ofstream parFiles("/opt/lampp/tmp/parejas.txt");
datos.open("/opt/lampp/tmp/datos.txt");
//Modificamos los permisos para que podamos escribir las parejas analizadas en el fichero.
string pr = "/opt/lampp/tmp/parejas.txt";
if (chmod(pr.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IWOTH | S_IROTH | S_IXOTH) == -1) {
perror("chmod");
}
string line;
getline(datos,line);
string argv[6];
int i=0;
do{
argv[i] = line;
i++;
getline(datos,line);
}while(!line.empty() && !line.find_first_of("\n\t\r ")== 0 && i<6);
datos.close();
// En este caso nuestro número de argumentos será el total -1 ya que empezamos
// la cuenta en 0. Los argumentos posibles serán : Tiempo de divergencia (opcional),
// Exclude Polimorphic Positions/Otherwise y Pairwise/Complete Deletion.
if ((i != 6))
{
exit(1);
}
// LECTURA ---------------------------------------------------------
char* fc = &argv[0][0];
SEQFILE *insfp;
if ((insfp = seqfopen(fc, "r", NULL)) == NULL) {
cerr<<"There was an error opening "<<argv[0]<<". Aborting."<<endl;
exit(1);
}
int nf = atoi(argv[5].c_str());
string format = string(seqfformat(insfp, 0));
sample theSample(insfp,nf);
cerr << "** Read "<< format;
cerr << " file with " << theSample.noSpecies() <<
" species containing ";
int pol, comD;
if (atoi(argv[2].c_str())!=0)
{
pol = atoi(argv[3].c_str());
comD = atoi(argv[4].c_str());
theSample.set_lT((double)atof(argv[2].c_str()));
}
else if (atoi(argv[2].c_str()) == 0)
{
pol = atoi(argv[3].c_str());
comD = atoi(argv[4].c_str());
theSample.set_lT(-1);
}
if ((pol != 0) && (pol != 1) )
{
// help();
exit(1);
}
if ((comD != 0) && (comD != 1) )
{
//help();
exit(1);
}
int sequenceSize = theSample.lengthOfSequences();
cerr << sequenceSize << " nucleotids each."<<endl;
// CALCULAR RESÚMENES ----------------------------------------------
/** SÓLO DOS ESPECIES, SP1 y SP2, de momento */
/* vector< vector<int> > resumenSP1 = theSample[0].summarise();
vector< vector<int> > resumenSP2 = theSample[1].summarise();*/
//AMPLIAMOS A MÁS DE DOS ESPECIES, COMPARACIONES 2 a 2
for(int i =0;i<nf;i++){
vector< vector<int> > resumen = theSample[i].summarise();
}
// SALIDA ----------------------------------------------------------
//SE CREAN X FICHEROS DE SALIDA (1 POR CADA COMPARACIÓN REALIZADA)
int fout = 0;
for(int x=nf-1;x>0;x--){ fout+=x;}
int fmt=0;
for(int j=0;j<nf;j++)
{
for(int k=j+1;k<nf;k++)
{
if(j!=k){
std::stringstream out ;
//out.flush();
//out.clear();
out<<"/opt/lampp/htdocs/proyecto/AnalisisPareja"<<fmt<<".html";
string fil = out.str();
ofstream outFile(fil.c_str());
//ofstream outputFile("/opt/lampp/htdocs/proyecto/resultado.html");//argv[1].c_str());
//outFiles[fmt].open(nomFiles[fmt].c_str());
if (chmod(fil.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IWOTH | S_IROTH | S_IXOTH) == -1) {
perror("chmod");
}
if(!outFile) {
cerr << "Cannot open " << outFile << " for input";
exit(1);
}
// En esta llamada vamos a tener que incluir un bucle para poder comparar los distintos formatos entre sí
// de modo que los indices que ahora son 0 y 1, pasarán a cambiar según los formatos que deseemos
// comparar. Así también quedará modificado el fichero de salida, ya que se creará uno por comparación.
parFiles<<theSample[j].speciesId()<<" - "<< theSample[k].speciesId()<<endl;
cerr<<"PRE Classify SATDNA.CPP:"<<j<<" Y "<<k<<" "<<endl;
vector <int> typeOfPosition;
typeOfPosition = theSample.classifyPositionsHTML(j,k, outFile);
cout<<"ANTES DE LA LLAMADA"<<endl;
//typeOfPosition = theSample.classifyPositionsHTML(j,k, outFile);
cerr<<"PASA classify de "<<j<<" Y "<<k<<" "<<endl;
//vector <int> typeOfPosition = theSample.classifyPositionsHTML(0,1, outputFile);
if (comD == 0)
{
theSample.stats(pol, typeOfPosition,j,k);
if (pol == 0)
outFile << "Shared polymorphisms not excluded<br/>Pairwise option<br/>"<< endl;
else
outFile << "Shared polymorphisms excluded<br/>Pairwise option<br/>"<< endl;
theSample.writeHTMLStats(typeOfPosition, outFile, pol,j,k);
theSample.writeHTMLfooter(outFile);
}
else
{
sample comDSample = theSample;
comDSample.stats(pol, typeOfPosition,j,k);
if (pol == 0)
outFile << "Shared polymorphisms not excluded<br/>Complete deletion option<br/>"<< endl;
else
outFile << "Shared polymorphisms excluded<br/>Complete deletion option<br/>"<< endl;
comDSample.writeHTMLStats(typeOfPosition, outFile, pol,j,k);
comDSample.writeHTMLfooter(outFile);
}
// Text file with the shared polymorphisms -----------------------
//char* tmp2;
string name, newname;
string argv1(argv[0]);
int pos = argv1.find_first_of('.', 1);
if (pos == -1) { // no dot in filename (yeah, just in case)
std::stringstream out;
out << argv[0].c_str()<<"_noSP"<<fmt;
newname = out.str();
// out.flush();
// out.clear();
}
else {
string filename = argv1.substr(0, pos);
string extension = argv1.substr(pos, argv1.length());
std::stringstream out;
out << filename<<"_noSP"<<fmt<<extension;
newname = out.str();//filename + "_noSP" + s.c_str() + extension;
}
cerr<<"antes de crear objeto"<<endl;
sample theSample_noPol(theSample, typeOfPosition);
cerr<<"despues de crear objeto"<<endl;
theSample_noPol.write(newname.c_str(), format,j,k);
cerr << "** Output in files " << fil << " and " << newname.c_str() << endl;
//outFile.flush();
//outFile.close();
//typeOfPosition.clear();
//typeOfPosition.~vector();
fmt++;
}
}
}
// }
parFiles.close();
return fout;
}
Function Being Called
Quote:
Code:
vector < int >
sample::classifyPositionsHTML(int indexA, int indexB, ostream & oFile)
{
vector< int > typeOfPosition((*this).lengthOfSequences(), -1);
// Stores the type of each position as defined in enum at util.h
vector<float> percent((*this).lengthOfSequences(), 0.0);
(*this)[indexA].classifyPositions((*this)[indexB].summarise(),
typeOfPosition, percent);
//percent.clear();
(*this).writeHTMLheader(oFile);
(*this).writeHTMLsummary(indexA, indexB, typeOfPosition, oFile);
(*this).writeHTMLlegend(oFile);
(*this).writeHTMLrichnessAT(indexA, indexB, oFile);
(*this).writeHTMLconsensus(LINE_LENGTH_INTERLEAVED,
indexA, indexB, oFile);
(*this).writeHTMLnucleotids(LINE_LENGTH_INTERLEAVED,
indexA, indexB, typeOfPosition, oFile);
(*this).writeHTMLlegend(oFile);
(*this).writeHTMLpositions(LINE_LENGTH_INTERLEAVED,
indexA, indexB, typeOfPosition, oFile);
cerr<<"ANTES DEL RETURN DE CLASSIFY POSITIONS HTML DE SAMPLE.CPP: "<<indexA <<" Y " <<indexB<<" "<<endl;
return typeOfPosition;
}
Please translate the comments into English and change the tabs to, say, three spaces. This is one of the reasons I never use tabs, spaces never go crazy.
Also cleanup the useless "(*iter)." dereferences. There are reasons why you would have to do that (local vars with the same name as members), but iter-> is preferable.
Is classifypositionsHTML really supposed to change the sample? It should be const if it's not supposed to.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.