Nice try khkremer.
I tried dong it with adding up CStrings, too; but it turned out
to be much slower than the char* approach.
The process of loading, trimming and translating to Protein ;-)
is about 10 times faster when not done with cstring.
When I originally wrote this thing in JAVA it actually crashed all
the time when using operator += on strings.
Well, I would like to see the approach above working. I don't see
a flaw in it so it really bugs me that it doesn't do what I want it
to.
Do tellg() and seekg() have any problems or did I call the functions
at the wrong moment.
Another approach I could think of would be:
Readline(theHeader);
Use a function to get position of the following '>'
read anything in between into char *buffer.
Somehow the function crashed on reaching the end of the database.
bool CDna2Protein::GetNextPart(
{
bool done = false;
bool inRecord = false;
CString data;
if (!databasein.is_open())
{
databasein.open(_filePath)
}
while (!databasein.eof() && !done)
{
char buf[256];
char beginOfLine;
databasein >> beginOfLine;
databasein.putback(beginOf
if (beginOfLine == '>')
{
inRecord = !inRecord;
done = (!inRecord);
if (inRecord)
{
databasein.getline(buf, 256, '\n');
scaffold = new char[256];
sprintf(scaffold,"%s",buf)
//data.erase(); //Didn't know what this is good for.
}
}
else
{
if (inRecord)
{
databasein.getline(buf, 256, '\n');
data += buf;
}
}
}
code = data.GetBuffer(); //Conversion back to my charackter array
trim();
//Needs to return something
//false when done and true otherwise
}
Main Topics
Browse All Topics





by: khkremerPosted on 2004-04-05 at 11:19:16ID: 10759727
I don't have the rest of your class, so I rewrote this as just a function, you should be able to retrofit this into your class again. All member variables are globals in my example. I think I came up with a better way of handling this (no need to calculate the size of the buffer anymore, this is all done with a string):
;
"); "); ");
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
ifstream input;
string scaffold;
string data;
bool GetNextPart(const char * _filePath)
{
bool done = false;
bool inRecord = false;
if (!input.is_open())
{
input.open(_filePath);
}
while (!input.eof() && !done)
{
char buf[256];
char beginOfLine;
input >> beginOfLine;
input.putback(beginOfLine)
if (beginOfLine == '>')
{
inRecord = !inRecord;
done = (!inRecord);
if (inRecord)
{
input.getline(buf, 256, '\n');
scaffold = buf;
data.erase();
}
}
else
{
if (inRecord)
{
input.getline(buf, 256, '\n');
data += buf;
}
}
}
cout << "scaffold: " << scaffold << endl;
cout << "data: " << data << endl;
}
int main()
{
GetNextPart("./protein.txt
GetNextPart("./protein.txt
GetNextPart("./protein.txt
input.close();
return 0;
}