本文整理汇总了C++中DataSetList类的典型用法代码示例。如果您正苦于以下问题:C++ DataSetList类的具体用法?C++ DataSetList怎么用?C++ DataSetList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DataSetList类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadCmatrix
/** Read cluster matrix file. Can only get here if file has already been
* determined to be in the proper format, so do no further error checking.
* Expected format:
* <int> <int> <name>
*/
int DataIO_Std::ReadCmatrix(FileName const& fname,
DataSetList& datasetlist, std::string const& dsname)
{
// Allocate output data set
DataSet* ds = datasetlist.AddSet( DataSet::CMATRIX, dsname );
if (ds == 0) return 1;
DataSet_Cmatrix_MEM& Mat = static_cast<DataSet_Cmatrix_MEM&>( *ds );
// Buffer file
BufferedLine buffer;
if (buffer.OpenFileRead( fname )) return 1;
// Read past title. See if optional 'nframes' key is there.
const char* ptr = buffer.Line();
ArgList header;
header.SetList(ptr+1, SEPARATORS );
int nframes = header.getKeyInt("nframes", -1);
// Need to keep track of frame indices so we can check for sieving.
std::vector<char> sieveStatus;
if (nframes > 0)
sieveStatus.assign(nframes, 'T');
// Keep track of matrix values.
std::vector<float> Vals;
// Read file
bool checkSieve = true;
int f1 = -1, f2 = -1, firstf1 = -1;
float val = 0;
while ( (ptr = buffer.Line()) != 0 )
{
if (checkSieve) {
sscanf(ptr, "%i %i %f", &f1, &f2, &val);
if (f2 > (int)sieveStatus.size())
sieveStatus.resize(f2, 'T');
if (firstf1 == -1) {
// First values.
sieveStatus[f1-1] = 'F';
sieveStatus[f2-1] = 'F';
firstf1 = f1;
} else if (f1 > firstf1) {
checkSieve = false;
} else {
sieveStatus[f2-1] = 'F';
}
} else {
sscanf(ptr, "%*i %*i %f", &val);
}
Vals.push_back( val );
}
// DEBUG
//mprintf("Sieved array:\n");
//for (unsigned int i = 0; i < sieveStatus.size(); i++)
// mprintf("\t%6u %c\n", i+1, sieveStatus[i]);
// Try to determine if sieve is random or not.
int sieveDelta = 1;
f1 = -1;
f2 = -1;
int actual_nrows = 0;
for (int i = 0; i < (int)sieveStatus.size(); i++) {
if (sieveStatus[i] == 'F') {
actual_nrows++;
if (sieveDelta != -2) {
if (f1 == -1) {
f1 = i;
} else if (f2 == -1) {
sieveDelta = i - f1;
f1 = i;
f2 = i;
} else {
int newDelta = i - f1;
if (newDelta != sieveDelta) {
// Random. No need to calculate sieveDelta anymore.
sieveDelta = -2;
}
f1 = i;
}
}
}
}
if (sieveDelta == -2) {
// Random sieve. Try to figure out original sieve value.
int o_frames = (int)sieveStatus.size();
int o_sieve_value = o_frames / actual_nrows;
if ( (o_frames % actual_nrows) != 0 )
o_sieve_value++;
sieveDelta = -o_sieve_value;
}
if (debug_ > 0)
mprintf("DEBUG: sieve %i, actual_nrows= %i\n", sieveDelta, actual_nrows);
if (sieveDelta != 1 && nframes == -1)
mprintf("Warning: Pairwise distance matrix file contains sieved frames but\n"
"Warning: number of original frames is not present in file - this\n"
"Warning: may lead to ignored frames in cluster output. Please add\n"
"Warning: 'nframes <# original frames>' to the pairwise distance\n"
"Warning: matrix file header, e.g. '#F1 F2 pw.dat nframes 1000'.\n");
// Save cluster matrix
if (Mat.Allocate( DataSet::SizeArray(1, actual_nrows) )) return 1;
//.........这里部分代码省略.........
示例2: mprinterr
// DataIO_Std::Read_1D()
int DataIO_Std::Read_1D(std::string const& fname,
DataSetList& datasetlist, std::string const& dsname)
{
ArgList labels;
bool hasLabels = false;
// Buffer file
BufferedLine buffer;
if (buffer.OpenFileRead( fname )) return 1;
// Read the first line. Attempt to determine the number of columns
const char* linebuffer = buffer.Line();
if (linebuffer == 0) return 1;
int ntoken = buffer.TokenizeLine( SEPARATORS );
if ( ntoken == 0 ) {
mprinterr("Error: No columns detected in %s\n", buffer.Filename().full());
return 1;
}
// Try to skip past any comments. If line begins with a '#', assume it
// contains labels.
bool isCommentLine = true;
const char* ptr = linebuffer;
while (isCommentLine) {
// Skip past any whitespace
while ( *ptr != '\0' && isspace(*ptr) ) ++ptr;
// Assume these are column labels until proven otherwise.
if (*ptr == '#') {
labels.SetList(ptr+1, SEPARATORS );
if (!labels.empty()) {
hasLabels = true;
// If first label is Frame assume it is the index column
if (labels[0] == "Frame" && indexcol_ == -1)
indexcol_ = 0;
}
linebuffer = buffer.Line();
ptr = linebuffer;
if (ptr == 0) {
mprinterr("Error: No data found in file.\n");
return 1;
}
} else
// Not a recognized comment character, assume data.
isCommentLine = false;
}
// Special case: check if labels are '#F1 F2 <name> [nframes <#>]'. If so, assume
// this is a cluster matrix file.
if ((labels.Nargs() == 3 || labels.Nargs() == 5) && labels[0] == "F1" && labels[1] == "F2")
{
mprintf("Warning: Header format '#F1 F2 <name>' detected, assuming cluster pairwise matrix.\n");
return IS_ASCII_CMATRIX;
}
// Column user args start from 1
if (indexcol_ > -1)
mprintf("\tUsing column %i as index column.\n", indexcol_ + 1);
// Should be at first data line. Tokenize the line.
ntoken = buffer.TokenizeLine( SEPARATORS );
// If # of data columns does not match # labels, clear labels.
if ( !labels.empty() && ntoken != labels.Nargs() ) {
labels.ClearList();
hasLabels = false;
}
// Index column checks
if (indexcol_ != -1 ) {
if (indexcol_ >= ntoken) {
mprinterr("Error: Specified index column %i is out of range (%i columns).\n",
indexcol_+1, ntoken);
return 1;
}
if (!onlycols_.Empty() && !onlycols_.InRange(indexcol_)) {
mprinterr("Error: Index column %i specified, but not in given column range '%s'\n",
indexcol_+1, onlycols_.RangeArg());
return 1;
}
}
// Determine the type of data stored in each column. Assume numbers should
// be read with double precision.
MetaData md( dsname );
DataSetList::DataListType inputSets;
unsigned int nsets = 0;
for (int col = 0; col != ntoken; ++col) {
std::string token( buffer.NextToken() );
if (!onlycols_.Empty() && !onlycols_.InRange( col )) {
mprintf("\tSkipping column %i\n", col+1);
inputSets.push_back( 0 );
} else {
md.SetIdx( col+1 );
if (hasLabels) md.SetLegend( labels[col] );
if ( col == indexcol_ ) {
// Always save the index column as floating point
inputSets.push_back( new DataSet_double() );
} else if (validInteger(token)) {
// Integer number
inputSets.push_back( datasetlist.Allocate(DataSet::INTEGER) );
} else if (validDouble(token)) {
// Floating point number
inputSets.push_back( new DataSet_double() );
} else {
//.........这里部分代码省略.........