void fixEnsGtf(char *outName, int inCount, char *inFiles[]) /* fixEnsGtf - fix space vs. tab and start/stop codon problems in Ensemble .gtf file. */ { FILE *f = mustOpen(outName, "w"); struct lineFile *lf; int fileIx; int lineSize; char *line; for (fileIx = 0; fileIx < inCount; ++fileIx) { lf = lineFileOpen(inFiles[fileIx], TRUE); printf("Processing %s\n", lf->fileName); while (lineFileNext(lf, &line, &lineSize)) { fixLine(lf, line, f); } lineFileClose(&lf); } }
void printResult(QSqlQuery query) { int pos; QList<TfieldDef> fields; int ncols; ncols = 0; for (pos = 0; pos <= query.record().count()-1;pos++) { ncols++; TfieldDef field; field.fieldName = query.record().field(pos).name(); switch (query.record().field(pos).type()) { case QVariant::Bool: field.fieldType = "BOL"; break; case QVariant::Char: field.fieldType = "CHR"; break; case QVariant::Date: field.fieldType = "DAT"; break; case QVariant::DateTime: field.fieldType = "DTM"; break; case QVariant::Double: field.fieldType = "DBL"; break; case QVariant::Int: field.fieldType = "INT"; break; case QVariant::String: field.fieldType = "STR"; break; case QVariant::Time: field.fieldType = "TIM"; break; case QVariant::UInt: field.fieldType = "UIN"; break; default: field.fieldType = "NA"; } fields.append(field); } int nrows; nrows = 0; while (query.next()) { nrows++; } nrows++; //Heads QVector<QVector<QString> > grid; grid.resize(nrows); int r; for(r=0; r<nrows; r++) { grid[r].resize(ncols); } //Append the field names for (pos = 0; pos <= fields.count()-1;pos++) grid[0][pos] = fields[pos].fieldName; for (pos = 0; pos <= fields.count()-1;pos++) grid[0][pos] = fields[pos].fieldName; r = 1; query.first(); QString value; while (query.isValid()) { for (pos = 0; pos <= fields.count()-1;pos++) { if (fields[pos].fieldType == "DBL") value = QString::number(query.value(getFieldIndex(query,fields[pos].fieldName)).toDouble(),'f',3); else { if (fields[pos].fieldName != "ogc_geom") value = query.value(getFieldIndex(query,fields[pos].fieldName)).toString().simplified(); else value = "Geometry data"; } grid[r][pos] = value; } r++; query.next(); } QVector< int> colSizes; colSizes.resize(ncols); for (pos = 0; pos <= ncols-1;pos++) colSizes[pos] = 0; //Get the maximum size of each column for (pos = 0; pos <= ncols-1;pos++) { for(r=0; r<nrows; r++) { if (grid[r][pos].length() +2 > colSizes[pos]) { colSizes[pos] = grid[r][pos].length() +2; } } } //Print the table printf("\n"); //Print top line for (pos=0;pos<= ncols-1;pos++) { printf("+"); printf(fixLine("-",colSizes[pos]).toLocal8Bit().data()); } printf("+"); printf("\n"); //Print the columns headings for (pos=0;pos<= ncols-1;pos++) { printf("+"); printf(fixString(" " + grid[0][pos] + " ",colSizes[pos]).toLocal8Bit().data()); } printf("+"); printf("\n"); //Print separation for (pos=0;pos<= ncols-1;pos++) { printf("+"); printf(fixLine("-",colSizes[pos]).toLocal8Bit().data()); } printf("+"); printf("\n"); //Print the values for (r=1;r<=nrows-1;r++) { printf("|"); for (pos=0;pos<= ncols-1;pos++) { printf(fixString(" " + grid[r][pos] + " ",colSizes[pos]).toLocal8Bit().data()); printf("|"); } printf("\n"); } //Print the end //Print separation for (pos=0;pos<= ncols-1;pos++) { printf("+"); printf(fixLine("-",colSizes[pos]).toLocal8Bit().data()); } printf("+"); printf("\n"); }
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); //Command line arguments TCLAP::CmdLine cmd("GOBLET (c) 2012, International Livestock Research Institute (ILRI) \n Developed by Carlos Quiros ([email protected])", ' ', "1.0 (Beta 1)"); //Required arguments TCLAP::ValueArg<std::string> databaseArg("d","database","Database name",true,"","string"); TCLAP::ValueArg<std::string> calculationArg("c","calculation","Calculation to perform. For example: 'sum(DatasetA),sum(DatasetB)' ",true,"","string"); TCLAP::ValueArg<std::string> ouputArg("o","output","Output type: (h)uman readable or (c)omputer readable",true,"","string"); //Non required arguments TCLAP::ValueArg<std::string> pathArg("a","path","Path to database. Default .",false,".","string"); TCLAP::ValueArg<std::string> hostArg("H","host","Connect to host. Default localhost",false,"localhost","string"); TCLAP::ValueArg<std::string> portArg("P","port","Port number to use. Default 3306",false,"3306","string"); TCLAP::ValueArg<std::string> userArg("u","user","User. Default empty",false,"","string"); TCLAP::ValueArg<std::string> passArg("p","password","Passwork. Default no password",false,"","string"); TCLAP::ValueArg<std::string> descArg("s","descriptions","Descriptions for the calculations separated by coma. Default value is the calculation string",false,"","string"); //Switches TCLAP::SwitchArg remoteSwitch("r","remote","Connect to remote host", cmd, false); cmd.add(databaseArg); cmd.add(calculationArg); cmd.add(ouputArg); cmd.add(pathArg); cmd.add(hostArg); cmd.add(portArg); cmd.add(userArg); cmd.add(passArg); cmd.add(descArg); //Parsing the command lines cmd.parse( argc, argv ); //Getting the variables from the command bool remote = remoteSwitch.getValue(); QString path = QString::fromUtf8(pathArg.getValue().c_str()); QString dbName = QString::fromUtf8(databaseArg.getValue().c_str()); QString host = QString::fromUtf8(hostArg.getValue().c_str()); QString port = QString::fromUtf8(portArg.getValue().c_str()); QString userName = QString::fromUtf8(userArg.getValue().c_str()); QString password = QString::fromUtf8(passArg.getValue().c_str()); QString calculation = QString::fromUtf8(calculationArg.getValue().c_str()); QString format = QString::fromUtf8(ouputArg.getValue().c_str()); QString description = QString::fromUtf8(descArg.getValue().c_str()); myDBConn con; QSqlDatabase mydb; if (!remote) { QDir dir; dir.setPath(path); if (con.connectToDB(dir.absolutePath()) == 1) { if (!dir.cd(dbName)) { gbtLog(QObject::tr("The database does not exists")); con.closeConnection(); return 1; } mydb = QSqlDatabase::addDatabase(con.getDriver(),"connection1"); } } else { mydb = QSqlDatabase::addDatabase("QMYSQL","connection1"); mydb.setHostName(host); mydb.setPort(port.toInt()); if (!userName.isEmpty()) mydb.setUserName(userName); if (!password.isEmpty()) mydb.setPassword(password); } mydb.setDatabaseName(dbName); if (!mydb.open()) { gbtLog(QObject::tr("Cannot open database")); con.closeConnection(); return 1; } else { QTime procTime; procTime.start(); QString sql; QSqlQuery qry(mydb); QList <TdatasetInfo> datasets; if (constructSQL(calculation,sql,mydb,datasets)) { gbtLog(QObject::tr("Error in calculation.")); gbtLog(qry.lastError().databaseText()); mydb.close(); con.closeConnection(); return 1; } QDomDocument doc; QDomElement root; doc = QDomDocument("GOBLETXML"); root = doc.createElement("CalcXML"); root.setAttribute("version", "1.0"); doc.appendChild(root); QDomElement varName; QDomText varValue; QList<TfieldDef> fields; int ncols; ncols = 0; if (!qry.exec(sql)) { gbtLog(QObject::tr("Cannot reset dataset.")); gbtLog(qry.lastError().databaseText()); mydb.close(); con.closeConnection(); return 1; } int nfields; nfields = qry.record().count(); QString nfield; int pos; QStringList descriptions; descriptions = getDescriptions(description); if (descriptions.count() != nfields) { descriptions.clear(); descriptions.append("Class code"); for (pos = 1; pos <= nfields-1; pos++) { descriptions.append(qry.record().field(pos).name()); } } for (pos = 0; pos <= nfields-1;pos++) { ncols++; nfield = descriptions[pos]; nfield.replace("T" + datasets[pos].code + ".",datasets[pos].name + "."); nfield.replace(".cellvalue",""); TfieldDef field; field.fieldName = nfield; field.fieldDesc = nfield; //Change for description if (pos == 0) { field.fieldType = "CHAR"; } else field.fieldType = "DEC"; fields.append(field); } QDomElement shapevars; shapevars = doc.createElement("Values"); root.appendChild(shapevars); for (pos = 0; pos <= fields.count()-1;pos++) { varName = doc.createElement("Field"); shapevars.appendChild(varName); varValue = doc.createTextNode(fields[pos].fieldDesc); varName.appendChild(varValue); } int nrows; nrows = 0; while (qry.next()) { nrows++; } nrows++; QVector<QVector<QString> > grid; grid.resize(nrows); int r; for(r=0; r<nrows; r++) { grid[r].resize(ncols); } for (pos = 0; pos <= fields.count()-1;pos++) grid[0][pos] = fields[pos].fieldDesc; r = 1; qry.first(); QString value; while (qry.isValid()) { for (pos = 0; pos <= fields.count()-1;pos++) { if (fields[pos].fieldType == "DEC") value = QString::number(qry.value(pos).toDouble(),'f',3); else value = qry.value(pos).toString(); grid[r][pos] = value; } r++; qry.next(); } if (format == "h") { QVector< int> colSizes; colSizes.resize(ncols); for (pos = 0; pos <= ncols-1;pos++) colSizes[pos] = 0; //Get the maximum size of each column for (pos = 0; pos <= ncols-1;pos++) { for(r=0; r<nrows; r++) { if (grid[r][pos].length() +2 > colSizes[pos]) { colSizes[pos] = grid[r][pos].length() +2; } } } //Print the table printf("\n"); //Print top line for (pos=0;pos<= ncols-1;pos++) { printf("+"); printf(fixLine("-",colSizes[pos]).toLocal8Bit().data()); } printf("+"); printf("\n"); //Print the columns headings for (pos=0;pos<= ncols-1;pos++) { printf("+"); printf(fixString(" " + grid[0][pos] + " ",colSizes[pos]).toLocal8Bit().data()); } printf("+"); printf("\n"); //Print separation for (pos=0;pos<= ncols-1;pos++) { printf("+"); printf(fixLine("-",colSizes[pos]).toLocal8Bit().data()); } printf("+"); printf("\n"); //Print the values for (r=1;r<=nrows-1;r++) { printf("|"); for (pos=0;pos<= ncols-1;pos++) { printf(fixString(" " + grid[r][pos] + " ",colSizes[pos]).toLocal8Bit().data()); printf("|"); } printf("\n"); } //Print the end //Print separation for (pos=0;pos<= ncols-1;pos++) { printf("+"); printf(fixLine("-",colSizes[pos]).toLocal8Bit().data()); } printf("+"); printf("\n"); } else { QDomElement shapeData; shapeData = doc.createElement("CalcData"); root.appendChild(shapeData); QDomElement rowData; QDomElement fieldData; QDomText fieldValue; for (r=1;r<=nrows-1;r++) { rowData = doc.createElement("Row"); shapeData.appendChild(rowData); for (pos=0;pos<= ncols-1;pos++) { fieldData = doc.createElement("Field"); fieldData.setAttribute("Name",fields[pos].fieldDesc); rowData.appendChild(fieldData); fieldValue = doc.createTextNode(grid[r][pos]); fieldData.appendChild(fieldValue); } } QTextStream out(stdout); out.setCodec("UTF-8"); doc.save(out,1,QDomNode::EncodingFromTextStream); } int Hours; int Minutes; int Seconds; int Milliseconds; Milliseconds = procTime.elapsed(); Hours = Milliseconds / (1000*60*60); Minutes = (Milliseconds % (1000*60*60)) / (1000*60); Seconds = ((Milliseconds % (1000*60*60)) % (1000*60)) / 1000; if (format == "h") gbtLog("Finished in " + QString::number(Hours) + " Hours," + QString::number(Minutes) + " Minutes and " + QString::number(Seconds) + " Seconds."); mydb.close(); con.closeConnection(); return 0; } return 0; }