我在谷歌中尝试了所有这些错误的解决方案,但没有找到解决这个问题的方法。
这个项目真的很大,但这里是其中一个文件:
cpp文件:
#include"Cluster.h"
Cluster::Cluster()
{}
Cluster::~Cluster() //close files and reomve dynamically-allocated memory
{
Splittedfile.close();
clustring.close();
Linefile.close();
delete[] protein;
delete[] NextProtein;
}
void spllitFile()
{
// check length of the file, and set length of NumOfSeq
Linefile.seekg(0, Linefile.end);
long sizeOfFile = Linefile.tellg();
NumOfProteins = sizeOfFile - 20;
//from the begining of LineFile:
//read 1 protein from LineFile & write it to Splittedfile.
//Each loop is advaced with:
// /n to Splittedfile & another 1 character "slide" in LineFile.
Linefile.seekg(ios_base::beg);
char* CopyProtein = new char[20]; // allocate buffer for reading 1 protein
long startPlaceOfRead = 0;
while (!(Linefile.eof()))
{
if ((startPlaceOfRead != 0) || (((sizeOfFile - startPlaceOfRead) < 20.0)))
Splittedfile << "\n";
Linefile.seekg(startPlaceOfRead);//to next protein - one for enter. one for back
if ((sizeOfFile - startPlaceOfRead) < 20.0) break;//if not enough for 1 protein
Linefile.read(CopyProtein, 20); // read 1 protein from infile
Splittedfile.write(CopyProtein, 20);// write to outfile
startPlaceOfRead++;
}
delete[] CopyProtein; // release dynamically-allocated memory
}
void buildClustrs()
{
Form Form;
char X[] = "XXXXXXXXXXXXXXXXXXXX««««««««";
int removed = 0;
for (int first = 0; first <= NumOfProteins; first++)//for the 1st
{
Splittedfile.seekg(0);
Splittedfile.seekg(first * 20 + 2 * first, ios_base::beg);
//int ThisPlace = Splittedfile.tellg();
Splittedfile.read(protein, 20);
if (strcmp(X, protein) == 0) continue; // 0= EQUAL
clustring << "\n\n\n";
clustring.write(protein, 20);
cout << "protein number " << first << " written as a lonely cluster " << endl; // WHEN FOUND belonging only-printing!
//remove this protein
Splittedfile.seekg(-20, Splittedfile.cur);
Splittedfile << "XXXXXXXXXXXXXXXXXXXX";
removed++;
for (int Allother = first + 1; Allother <= NumOfProteins; Allother++) //the following protein
{
Splittedfile.seekg(Allother * 20 + 2 * Allother);
Splittedfile.read(NextProtein, 20); // READ next protein, -read -go on automaticly-
if (strcmp(X, NextProtein) == 0) continue;
if ( (Form.Compare2Proteins (protein, NextProtein) ) !=-1)//>=60%
{
clustring << "\n";
clustring.write(NextProtein, 20);// write to clustring second protein in cluster
cout << "protein number " << Allother << " written to cluster " << first << endl; // WHEN FOUND belonging only-printing!
//remove this protein
Splittedfile.seekg(-20, Splittedfile.cur);//to next protein
Splittedfile << "XXXXXXXXXXXXXXXXXXXX";
removed++;
}
}
}
}
头文件:
#pragma once
#include <iostream>
#include <string.h>
#include <fstream>
#include <sstream>
#include <tchar.h>
#include <string.h>
#include "Main.h"
#include "Form.h"
using namespace std;
class Cluster
{
public:
Cluster();
~Cluster();
void spllitFile();
void buildClustrs();
};