void TranslationUnit::printResourceUsage(std::ostream& ostr, bool detailed) const { CXTUResourceUsage usage = clang().getCXTUResourceUsage(tu_); unsigned long totalBytes = 0; for (unsigned i = 0; i < usage.numEntries; i++) { CXTUResourceUsageEntry entry = usage.entries[i]; if (detailed) { ostr << clang().getTUResourceUsageName(entry.kind) << ": " << formatBytes(entry.amount) << std::endl; } if (entry.kind >= CXTUResourceUsage_MEMORY_IN_BYTES_BEGIN && entry.kind <= CXTUResourceUsage_MEMORY_IN_BYTES_END) { totalBytes += entry.amount; } } ostr << "TOTAL MEMORY: " << formatBytes(totalBytes) << " (" << FilePath(getSpelling()).filename() << ")" << std::endl; clang().disposeCXTUResourceUsage(usage); }
void MainWindow::on_recoverThread_updateStatus(const DdrescueStatus &status, DdrescueLog const &log) { ui->lblRescuedValue->setText(formatBytes(status.rescued())); ui->lblIposValue->setText(formatBytes(status.ipos())); ui->lblOposValue->setText(formatBytes(status.opos())); ui->lblErrsizeValue->setText(formatBytes(status.errsize())); ui->lblErrorsValue->setText(QString::number(status.errors())); ui->lblAvgRateValue->setText(formatBytes(status.averageRate()) + "/s"); ui->lblCurrRateValue->setText(formatBytes(status.currentRate()) + "/s"); ui->lblTimeFrom->setText(QString::number(status.timeFromLastSuccessfulRead()) + " s"); ui->lblStatus->setText(status.status()); QGraphicsScene *scene = ui->graph->scene(); if (!scene) { scene = new QGraphicsScene(); ui->graph->setScene(scene); } scene->clear(); qreal width = ui->graph->width()-5; qreal height = ui->graph->height()-5; scene->addRect(0,0,width,height,QPen(QColor(Qt::blue)), QBrush(QColor(Qt::blue))); long long sizeTotal = 0; for (int i = 0; i < log.blocks().size(); i++) { sizeTotal += log.blocks().at(i).size; } qreal wfactor = sizeTotal / width; if (sizeTotal > 0) { for (int i = 0; i < log.blocks().size(); i++) { qreal x = log.blocks().at(i).pos/wfactor; qreal w = log.blocks().at(i).size/wfactor; scene->addRect(x,0 ,w,height ,QPen(statusBlock2QColor(log.blocks().at(i).status)) , QBrush(statusBlock2QColor(log.blocks().at(i).status))); } } scene->addText(formatBytes(sizeTotal)); }
void DATVDemodGUI::on_StreamDataAvailable(int *intPackets, int *intBytes, int *intPercent, qint64 *intTotalReceived) { (void) intPackets; ui->lblStatus->setText(QString("Data: %1B").arg(formatBytes(*intTotalReceived))); m_intLastDecodedData = *intTotalReceived; if((*intPercent)<100) { ui->prgSynchro->setValue(*intPercent); } else { ui->prgSynchro->setValue(100); } m_intReadyDecodedData = *intBytes; }
void DATVDemodGUI::tick() { if (m_objDATVDemod) { m_objMagSqAverage(m_objDATVDemod->getMagSq()); double magSqDB = CalcDb::dbPower(m_objMagSqAverage / (SDR_RX_SCALED*SDR_RX_SCALED)); ui->channePowerText->setText(tr("%1 dB").arg(magSqDB, 0, 'f', 1)); } if((m_intLastDecodedData-m_intPreviousDecodedData)>=0) { m_intLastSpeed = 8*(m_intLastDecodedData-m_intPreviousDecodedData); ui->lblRate->setText(QString("Speed: %1b/s").arg(formatBytes(m_intLastSpeed))); } m_intPreviousDecodedData = m_intLastDecodedData; //Try to start video rendering m_objDATVDemod->PlayVideo(false); return; }
void RRFs::handleFileList() { if(!server->hasArg("dir")) {server->send(500, "text/plain", "BAD ARGS"); return;} String path = server->arg("dir"); DEBUGPRINT.println("handleFileList: " + path); Dir dir = SPIFFS.openDir(path); path = String(); String output = "["; while(dir.next()){ if (output != "[") output += ','; output += "{"; //output+="\"type\":\""; // output += (dir.isDir())?"dir":"file"; output += "\"name\":\""; output += String(dir.fileName()).substring(1); output += "\",\"size\":\""; output += formatBytes(dir.fileSize()); output += "\"}"; } output += "]"; server->send(200, "text/json", output); }
int CmdStatistics::execute (std::string& output) { int rc = 0; std::stringstream out; std::string dateformat = context.config.get ("dateformat"); // Go get the file sizes. size_t dataSize = context.tdb2.pending._file.size () + context.tdb2.completed._file.size () + context.tdb2.undo._file.size () /* // TODO Re-enable this once 2.1 has taskd support. + context.tdb2.backlog._file.size () + context.tdb2.synch_key._file.size () */ ; // Count the undo transactions. std::vector <std::string> undoTxns = context.tdb2.undo.get_lines (); int undoCount = 0; std::vector <std::string>::iterator tx; for (tx = undoTxns.begin (); tx != undoTxns.end (); ++tx) if (*tx == "---") ++undoCount; // Get all the tasks. std::vector <Task> all = context.tdb2.all_tasks (); std::vector <Task> filtered; filter (all, filtered); Date now; time_t earliest = time (NULL); time_t latest = 1; int totalT = 0; int deletedT = 0; int pendingT = 0; int completedT = 0; int waitingT = 0; int taggedT = 0; int annotationsT = 0; int recurringT = 0; float daysPending = 0.0; int descLength = 0; std::map <std::string, int> allTags; std::map <std::string, int> allProjects; std::vector <Task>::iterator task; for (task = filtered.begin (); task != filtered.end (); ++task) { ++totalT; Task::status status = task->getStatus (); switch (status) { case Task::deleted: ++deletedT; break; case Task::pending: ++pendingT; break; case Task::completed: ++completedT; break; case Task::recurring: ++recurringT; break; case Task::waiting: ++waitingT; break; } time_t entry = strtol (task->get ("entry").c_str (), NULL, 10); if (entry < earliest) earliest = entry; if (entry > latest) latest = entry; if (status == Task::completed) { time_t end = strtol (task->get ("end").c_str (), NULL, 10); daysPending += (end - entry) / 86400.0; } if (status == Task::pending) daysPending += (now.toEpoch () - entry) / 86400.0; descLength += task->get ("description").length (); std::map <std::string, std::string> annotations; task->getAnnotations (annotations); annotationsT += annotations.size (); std::vector <std::string> tags; task->getTags (tags); if (tags.size ()) ++taggedT; std::vector <std::string>::iterator t; for (t = tags.begin (); t != tags.end (); ++t) allTags[*t] = 0; std::string project = task->get ("project"); if (project != "") allProjects[project] = 0; } // Create a table for output. ViewText view; view.width (context.getWidth ()); view.intraPadding (2); view.add (Column::factory ("string", STRING_CMD_STATS_CATEGORY)); view.add (Column::factory ("string", STRING_CMD_STATS_DATA)); int row = view.addRow (); view.set (row, 0, STRING_COLUMN_LABEL_STAT_PE); view.set (row, 1, pendingT); row = view.addRow (); view.set (row, 0, STRING_COLUMN_LABEL_STAT_WA); view.set (row, 1, waitingT); row = view.addRow (); view.set (row, 0, STRING_COLUMN_LABEL_STAT_RE); view.set (row, 1, recurringT); row = view.addRow (); view.set (row, 0, STRING_COLUMN_LABEL_STAT_CO); view.set (row, 1, completedT); row = view.addRow (); view.set (row, 0, STRING_COLUMN_LABEL_STAT_DE); view.set (row, 1, deletedT); row = view.addRow (); view.set (row, 0, STRING_CMD_STATS_TOTAL); view.set (row, 1, totalT); row = view.addRow (); view.set (row, 0, STRING_CMD_STATS_ANNOTATIONS); view.set (row, 1, annotationsT); row = view.addRow (); view.set (row, 0, STRING_CMD_STATS_UNIQUE_TAGS); view.set (row, 1, (int)allTags.size ()); row = view.addRow (); view.set (row, 0, STRING_CMD_STATS_PROJECTS); view.set (row, 1, (int)allProjects.size ()); row = view.addRow (); view.set (row, 0, STRING_CMD_STATS_DATA_SIZE); view.set (row, 1, formatBytes (dataSize)); row = view.addRow (); view.set (row, 0, STRING_CMD_STATS_UNDO_TXNS); view.set (row, 1, undoCount); if (totalT) { row = view.addRow (); view.set (row, 0, STRING_CMD_STATS_TAGGED); std::stringstream value; value << std::setprecision (3) << (100.0 * taggedT / totalT) << "%"; view.set (row, 1, value.str ()); } if (filtered.size ()) { Date e (earliest); row = view.addRow (); view.set (row, 0, STRING_CMD_STATS_OLDEST); view.set (row, 1, e.toString (dateformat)); Date l (latest); row = view.addRow (); view.set (row, 0, STRING_CMD_STATS_NEWEST); view.set (row, 1, l.toString (dateformat)); row = view.addRow (); view.set (row, 0, STRING_CMD_STATS_USED_FOR); view.set (row, 1, Duration (latest - earliest).format ()); } if (totalT) { row = view.addRow (); view.set (row, 0, STRING_CMD_STATS_ADD_EVERY); view.set (row, 1, Duration (((latest - earliest) / totalT)).format ()); } if (completedT) { row = view.addRow (); view.set (row, 0, STRING_CMD_STATS_COMP_EVERY); view.set (row, 1, Duration ((latest - earliest) / completedT).format ()); } if (deletedT) { row = view.addRow (); view.set (row, 0, STRING_CMD_STATS_DEL_EVERY); view.set (row, 1, Duration ((latest - earliest) / deletedT).format ()); } if (pendingT || completedT) { row = view.addRow (); view.set (row, 0, STRING_CMD_STATS_AVG_PEND); view.set (row, 1, Duration ((int) ((daysPending / (pendingT + completedT)) * 86400)).format ()); } if (totalT) { row = view.addRow (); view.set (row, 0, STRING_CMD_STATS_DESC_LEN); view.set (row, 1, format (STRING_CMD_STATS_CHARS, (int) (descLength / totalT))); } /* // TODO Re-enable this when 2.1 has taskd support. Until then, it makes no // sense to include this. row = view.addRow (); view.set (row, 0, STRING_CMD_STATS_LAST_SYNCH); if (context.tdb2.synch_key._file.exists ()) view.set (row, 1, Date (context.tdb2.synch_key._file.mtime ()).toISO ()); else view.set (row, 1, "-"); */ // If an alternating row color is specified, notify the table. if (context.color ()) { Color alternate (context.config.get ("color.alternate")); if (alternate.nontrivial ()) { view.colorOdd (alternate); view.intraColorOdd (alternate); view.extraColorOdd (alternate); } } out << optionalBlankLine () << view.render () << optionalBlankLine (); output = out.str (); return rc; }
///Button clicked. void XTailForm::buttonClicked(int id) { swprintf_s(tbuffer, L"XTailForm button clicked: %i\n", id); logger->debug(tbuffer); if (id == 99) { if (chunkCount < 1) return; current = -1; id = BTN_NEXT; } if (id == 98) { if (chunkCount < 1) return; current = chunkCount-1; id = BTN_NEXT; } if (id == BTN_PREV || id == BTN_NEXT) { if (id == BTN_PREV) { current -= 1; if (current < 0) current = 0L; } if (id == BTN_NEXT) { current += 1; if (current > chunkCount) current = chunkCount; } //Set the start/end chunks. __int64 len = getXTail()->len; __int64 startXX = (len/chunkCount) * current; __int64 endXX = startXX + MAX_FILE_BUFFER; if (startXX > len) startXX = len; if (endXX > len) endXX = len; swprintf_s(tbuffer, L"Current: %I64i, Start: %I64i, End: %I64i\n", current, startXX, endXX); logger->debug(tbuffer); swprintf_s(tbuffer, L"%I64i", startXX); SendMessageW(getHWND(TXT_BYTE_START), WM_SETTEXT, 2048, (LPARAM) tbuffer); swprintf_s(tbuffer, L"%I64i", endXX); SendMessageW(getHWND(TXT_BYTE_END), WM_SETTEXT, 2048, (LPARAM) tbuffer); id = BTN_LOAD; } if (id == BTN_LOAD) { chunkCount = 0l; ZeroMemory(tmp, sizeof(wchar_t) * 2048); getText(TXT_FILENAME, tmp, 2048); swprintf_s(tbuffer, L"Attempting to load file: %s\n", tmp); logger->debug(tbuffer); wchar_t fileName[2048]; wcscpy_s(fileName, tmp); if (wcslen(tmp) < 1) { MessageBoxExW(hwnd, L"Please enter a valid filename.", L"Invalid Input", MB_OK, NULL); return; } ZeroMemory(tmp, sizeof(wchar_t) * 2048); getText(TXT_BYTE_START, tmp, 2048); swprintf_s(tbuffer, L"Start Pos: %s\n", tmp); logger->debug(tbuffer); if (wcslen(tmp) < 1) { MessageBoxExW(hwnd, L"Please enter a valid file start position.", L"Invalid Input", MB_OK, NULL); return; } wchar_t *tmpX; __int64 start = _wcstoi64(tmp, &tmpX, 10); swprintf_s(tbuffer, L"Got the start pos: %I64i\n", start); logger->debug(tbuffer); ZeroMemory(tmp, sizeof(wchar_t) * 2048); getText(TXT_BYTE_END, tmp, 2048); swprintf_s(tbuffer, L"End Pos: %s\n", tmp); logger->debug(tbuffer); if (wcslen(tmp) < 1) { MessageBoxExW(hwnd, L"Please enter a valid file end position.", L"Invalid Input", MB_OK, NULL); return; } __int64 end = _wcstoi64(tmp, &tmpX, 10); swprintf_s(tbuffer, L"Got the end pos: %I64i\n", end); logger->debug(tbuffer); if (start < 0 || end < 1 || (end < start)) { swprintf_s(tbuffer, L"Invalid start(%I64i) and end(%I64i) pos", start, end); MessageBoxExW(hwnd, tbuffer, L"Invalid Input", MB_OK, NULL); return; } //Get the file/length. __int64 fileLength = getXTail()->getFileLength(fileName); swprintf_s(tbuffer, L"Got the file length: %I64i\n", fileLength); logger->debug(tbuffer); if (fileLength < 1) { swprintf_s(tbuffer, L"File (%s) is not valid.", fileName); MessageBoxExW(hwnd, tbuffer, L"Invalid Input", MB_OK, NULL); return; } if (start > fileLength) { swprintf_s(tbuffer, L"Start(%I64i) is > file length", start); MessageBoxExW(hwnd, tbuffer, L"Invalid Input", MB_OK, NULL); return; } if (end > fileLength) end = fileLength; //Update window caption. char fileNamea[2048]; SendMessageA(getHWND(TXT_FILENAME), WM_GETTEXT, 2048, (LPARAM) fileNamea); wchar_t fmtFileLength[128]; formatBytes(fileLength, fmtFileLength, 128); chunkCount = (fileLength / MAX_FILE_BUFFER); swprintf_s(tbuffer, L"Len(%s) - 63Kb Chunks(%I64i), Current: %I64i", fmtFileLength, chunkCount, current); logger->debug(tbuffer); SendMessageW(getHWND(LBL_CHUNKS), WM_SETTEXT, 2048, (LPARAM) tbuffer); //Attempt to load and display file. ZeroMemory(file_buffer, sizeof(wchar_t) * MAX_FILE_BUFFER); swprintf_s(tbuffer, L"going to call readChunk Start: %I64i, End: %I64i\n", start, end); logger->debug(tbuffer); if (!getXTail()->readChunk(start, end, file_buffer, MAX_FILE_BUFFER)) return; setText(TXT_OUTPUT, file_buffer, MAX_FILE_BUFFER); } }
int main (int argc, char** argv) { UnitTest t (19); // TODO bool confirm (const std::string&); // TODO int confirm3 (const std::string&); // TODO int confirm4 (const std::string&); // TODO void delay (float); // std::string formatBytes (size_t); t.is (formatBytes (0), "0 B", "0 -> 0 B"); t.is (formatBytes (994), "994 B", "994 -> 994 B"); t.is (formatBytes (995), "1.0 KiB", "995 -> 1.0 KiB"); t.is (formatBytes (999), "1.0 KiB", "999 -> 1.0 KiB"); t.is (formatBytes (1000), "1.0 KiB", "1000 -> 1.0 KiB"); t.is (formatBytes (1001), "1.0 KiB", "1001 -> 1.0 KiB"); t.is (formatBytes (999999), "1.0 MiB", "999999 -> 1.0 MiB"); t.is (formatBytes (1000000), "1.0 MiB", "1000000 -> 1.0 MiB"); t.is (formatBytes (1000001), "1.0 MiB", "1000001 -> 1.0 MiB"); t.is (formatBytes (999999999), "1.0 GiB", "999999999 -> 1.0 GiB"); t.is (formatBytes (1000000000), "1.0 GiB", "1000000000 -> 1.0 GiB"); t.is (formatBytes (1000000001), "1.0 GiB", "1000000001 -> 1.0 GiB"); // TODO const std::string uuid (); // std::string taskDiff (const Task&, const Task&); Task left; left.set ("zero", "0"); left.set ("one", 1); left.set ("two", 2); Task right; right.set ("zero", "00"); right.set ("two", 2); right.set ("three", 3); Task rightAgain (right); std::string output = taskDifferences (left, right); t.ok (taskDiff (left, right), "Detected changes"); t.ok (output.find ("zero will be changed from '0' to '00'") != std::string::npos, "Detected change zero:0 -> zero:00"); t.ok (output.find ("one will be deleted") != std::string::npos, "Detected deletion one:1 ->"); t.ok (output.find ("two") == std::string::npos, "Detected no change two:2 -> two:2"); t.ok (output.find ("three will be set to '3'") != std::string::npos, "Detected addition -> three:3"); t.notok (taskDiff (right, rightAgain), "No changes detected"); output = taskDifferences (right, rightAgain); t.ok (output.find ("No changes will be made") != std::string::npos, "No changes detected"); return 0; }
int main (int argc, char** argv) { UnitTest t (12); // std::string formatBytes (size_t); t.is (formatBytes (0), "0 B", "0 -> 0 B"); t.is (formatBytes (994), "994 B", "994 -> 994 B"); t.is (formatBytes (995), "1.0 KiB", "995 -> 1.0 KiB"); t.is (formatBytes (999), "1.0 KiB", "999 -> 1.0 KiB"); t.is (formatBytes (1000), "1.0 KiB", "1000 -> 1.0 KiB"); t.is (formatBytes (1001), "1.0 KiB", "1001 -> 1.0 KiB"); t.is (formatBytes (999999), "1.0 MiB", "999999 -> 1.0 MiB"); t.is (formatBytes (1000000), "1.0 MiB", "1000000 -> 1.0 MiB"); t.is (formatBytes (1000001), "1.0 MiB", "1000001 -> 1.0 MiB"); t.is (formatBytes (999999999), "1.0 GiB", "999999999 -> 1.0 GiB"); t.is (formatBytes (1000000000), "1.0 GiB", "1000000000 -> 1.0 GiB"); t.is (formatBytes (1000000001), "1.0 GiB", "1000000001 -> 1.0 GiB"); // TODO const std::string uuid (); // TODO const std::string encode (const std::string& value); // TODO const std::string decode (const std::string& value); return 0; }
Installer::Installer(QWidget *parent) : QDialog(parent), ui(new Ui::Installer) { setAttribute(Qt::WA_DeleteOnClose, true); ui->setupUi(this); QProgressDialog wait(this); wait.setLabelText("Checking for new Required Core Tools ..."); wait.show(); if (qnam.networkAccessible() != QNetworkAccessManager::Accessible) { wait.hide(); QMessageBox::critical(this, "Network Inaccessible", "Can't check for updates as you appear to be offline."); return; } QSettings conf; QWidget *w = new QWidget; QGridLayout *g = new QGridLayout; QPushButton *b = 0; #if defined(Q_OS_WIN) #define OS_PATH "win32" #elif defined(Q_OS_MAC) #define OS_PATH "osx" #elif defined(Q_OS_LINUX) #define OS_PATH "osx" #else #error "Not yet specialized for other OSs" #endif int row = 0; g->addWidget(new QLabel("Name"), row, 0, 1, 1, Qt::AlignLeft); g->addWidget(new QLabel("Size"), row, 1, 1, 1, Qt::AlignHCenter); g->addWidget(new QLabel("Action"), row, 2, 1, 1, Qt::AlignRight); #if defined(Q_OS_WIN) || defined(Q_OS_MAC) { reply = qnam.head(QNetworkRequest(QUrl("http://apertium.projectjj.com/" OS_PATH "/nightly/apertium-all-dev.7z"))); QEventLoop loop; connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); QString lm = reply->rawHeader("Last-Modified"); QString cl = reply->rawHeader("Content-Length"); QString label("Install"); if (conf.contains("apertium-all-dev")) { label = "Reinstall"; if (conf.value("apertium-all-dev").toString() != lm) { label = "Update"; } } ++row; g->addWidget(new QLabel("Required Core Tools"), row, 0, 1, 1, Qt::AlignLeft); g->addWidget(new QLabel(formatBytes(cl.toUInt())), row, 1, 1, 1, Qt::AlignRight); g->addWidget(b = new QPushButton(label), row, 2, 1, 1, Qt::AlignRight); b->setProperty("name", "apertium-all-dev"); b->setProperty("url", QString("http://apertium.projectjj.com/" OS_PATH "/nightly/apertium-all-dev.7z")); b->setProperty("bsize", cl); b->setProperty("lm", lm); connect(b, SIGNAL(clicked()), this, SLOT(installpkg())); } #endif { wait.setLabelText("Checking for new language pairs ..."); reply = qnam.get(QNetworkRequest(QUrl("http://apertium.projectjj.com/" OS_PATH "/nightly/data.php"))); QEventLoop loop; connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); QString body = reply->readAll(); QRegularExpression rx("<tr><td>(apertium-\\w+-\\w+)</td><td>[^<]+</td><td>(\\d+)</td><td>([^<]+)</td>.*?</tr>"); QRegularExpressionMatchIterator it = rx.globalMatch(body); while (it.hasNext()) { QRegularExpressionMatch m = it.next(); QString name = m.captured(1); QString label("Install"); if (conf.contains(name)) { label = "Reinstall"; if (conf.value(name).toString() != m.captured(3)) { label = "Update"; } } ++row; g->addWidget(new QLabel(name), row, 0, 1, 1, Qt::AlignLeft); g->addWidget(new QLabel(formatBytes(m.captured(2).toUInt())), row, 1, 1, 1, Qt::AlignRight); g->addWidget(b = new QPushButton(label), row, 2, 1, 1, Qt::AlignRight); b->setProperty("name", name); b->setProperty("url", QString("http://apertium.projectjj.com/" OS_PATH "/nightly/data.php?deb=")+name); b->setProperty("bsize", m.captured(2)); b->setProperty("lm", m.captured(3)); connect(b, SIGNAL(clicked()), this, SLOT(installpkg())); } } w->setLayout(g); ui->scrollArea->setWidgetResizable(true); ui->scrollArea->setWidget(w); }
int main (int argc, char** argv) { UnitTest t (40); // TODO bool confirm (const std::string&); // TODO int confirm3 (const std::string&); // TODO int confirm4 (const std::string&); // TODO void delay (float); // std::string formatBytes (size_t); t.is (formatBytes (0), "0 B", "0 -> 0 B"); t.is (formatBytes (994), "994 B", "994 -> 994 B"); t.is (formatBytes (995), "1.0 KiB", "995 -> 1.0 KiB"); t.is (formatBytes (999), "1.0 KiB", "999 -> 1.0 KiB"); t.is (formatBytes (1000), "1.0 KiB", "1000 -> 1.0 KiB"); t.is (formatBytes (1001), "1.0 KiB", "1001 -> 1.0 KiB"); t.is (formatBytes (999999), "1.0 MiB", "999999 -> 1.0 MiB"); t.is (formatBytes (1000000), "1.0 MiB", "1000000 -> 1.0 MiB"); t.is (formatBytes (1000001), "1.0 MiB", "1000001 -> 1.0 MiB"); t.is (formatBytes (999999999), "1.0 GiB", "999999999 -> 1.0 GiB"); t.is (formatBytes (1000000000), "1.0 GiB", "1000000000 -> 1.0 GiB"); t.is (formatBytes (1000000001), "1.0 GiB", "1000000001 -> 1.0 GiB"); // TODO const std::string uuid (); // TODO These are in feedback.cpp, not util.cpp. // std::string taskDiff (const Task&, const Task&); Task left; left.set ("zero", "0"); left.set ("one", 1); left.set ("two", 2); Task right; right.set ("zero", "00"); right.set ("two", 2); right.set ("three", 3); Task rightAgain (right); std::string output = taskDifferences (left, right); t.ok (taskDiff (left, right), "Detected changes"); t.ok (output.find ("Zero will be changed from '0' to '00'") != std::string::npos, "Detected change zero:0 -> zero:00"); t.ok (output.find ("One will be deleted") != std::string::npos, "Detected deletion one:1 ->"); t.ok (output.find ("Two") == std::string::npos, "Detected no change two:2 -> two:2"); t.ok (output.find ("Three will be set to '3'") != std::string::npos, "Detected addition -> three:3"); t.notok (taskDiff (right, rightAgain), "No changes detected"); output = taskDifferences (right, rightAgain); t.ok (output.find ("No changes will be made") != std::string::npos, "No changes detected"); // void combine (std::vector <int>&, const std::vector <int>&); std::vector <int> vleft; vleft.push_back (1); vleft.push_back (2); vleft.push_back (3); std::vector <int> vright; vright.push_back (4); combine (vleft, vright); t.is (vleft.size (), (size_t)4, "1,2,3 + 4 -> [4]"); t.is (vleft[0], 1, "1,2,3 + 4 -> 1,2,3,4"); t.is (vleft[1], 2, "1,2,3 + 4 -> 1,2,3,4"); t.is (vleft[2], 3, "1,2,3 + 4 -> 1,2,3,4"); t.is (vleft[3], 4, "1,2,3 + 4 -> 1,2,3,4"); vright.push_back (3); vright.push_back (5); combine (vleft, vright); t.is (vleft.size (), (size_t)5, "1,2,3,4 + 3,4,5 -> [5]"); t.is (vleft[0], 1, "1,2,3,4 + 3,4,5 -> 1,2,3,4,5"); t.is (vleft[1], 2, "1,2,3,4 + 3,4,5 -> 1,2,3,4,5"); t.is (vleft[2], 3, "1,2,3,4 + 3,4,5 -> 1,2,3,4,5"); t.is (vleft[3], 4, "1,2,3,4 + 3,4,5 -> 1,2,3,4,5"); t.is (vleft[4], 5, "1,2,3,4 + 3,4,5 -> 1,2,3,4,5"); // std::vector<std::string> indentTree (const std::vector<std::string>&, const std::string whitespace=" ", char delimiter='.'); std::vector <std::string> flat; flat.push_back ("one"); flat.push_back ("one.two"); flat.push_back ("one.two.three"); flat.push_back ("one.four"); flat.push_back ("two"); std::vector <std::string> structured = indentTree (flat, " ", '.'); t.is (structured.size (), (size_t) 5, "indentTree yields 5 strings"); t.is (structured[0], "one", "indentTree 'one' -> 'one'"); t.is (structured[1], " one.two", "indentTree 'one.two' -> ' one.two'"); t.is (structured[2], " one.two.three", "indentTree 'one.two.three' -> ' one.two.three'"); t.is (structured[3], " one.four", "indentTree 'one.four' -> ' one.four'"); t.is (structured[4], "two", "indentTree 'two' -> 'two'"); // std::vector<std::string> indentProject (const std::string&, const std::string whitespace=" ", char delimiter='.'); t.is (indentProject (""), "", "indentProject '' -> ''"); t.is (indentProject ("one"), "one", "indentProject 'one' -> 'one'"); t.is (indentProject ("one.two"), " one.two", "indentProject 'one.two' -> ' one.two'"); t.is (indentProject ("one.two.three"), " one.two.three", "indentProject 'one.two.three' -> ' one.two.three'"); // TODO const std::string encode (const std::string& value); // TODO const std::string decode (const std::string& value); return 0; }
int fagzToCompact4(libmaus2::util::ArgInfo const & arginfo) { bool const rc = arginfo.getValue<unsigned int>("rc",1); bool const gz = arginfo.getValue<unsigned int>("gz",1); std::vector<std::string> inputfilenames; inputfilenames = arginfo.restargs; if ( arginfo.hasArg("inputfilenames") ) { std::string const inf = arginfo.getUnparsedValue("inputfilenames",std::string()); libmaus2::aio::InputStream::unique_ptr_type Pinf(libmaus2::aio::InputStreamFactoryContainer::constructUnique(inf)); while ( *Pinf ) { std::string line; std::getline(*Pinf,line); if ( line.size() ) inputfilenames.push_back(line); } } std::string const inlcp = libmaus2::util::OutputFileNameTools::lcp(inputfilenames); std::string defout = inlcp; defout = libmaus2::util::OutputFileNameTools::clipOff(defout,".gz"); defout = libmaus2::util::OutputFileNameTools::clipOff(defout,".fasta"); defout = libmaus2::util::OutputFileNameTools::clipOff(defout,".fa"); std::string const outputfilename = arginfo.getUnparsedValue("outputfilename",defout + ".compact"); std::string const metaoutputfilename = outputfilename + ".meta"; int const verbose = arginfo.getValue<int>("verbose",1); libmaus2::autoarray::AutoArray<char> B(8*1024,false); libmaus2::bitio::CompactArrayWriterFile compactout(outputfilename,2 /* bits per symbol */); if ( ! rc ) std::cerr << "[V] not storing reverse complements" << std::endl; // forward mapping table libmaus2::autoarray::AutoArray<uint8_t> ftable(256,false); // rc mapping for mapped symbols libmaus2::autoarray::AutoArray<uint8_t> ctable(256,false); std::fill(ftable.begin(),ftable.end(),4); std::fill(ctable.begin(),ctable.end(),4); ftable['a'] = ftable['A'] = 0; ftable['c'] = ftable['C'] = 1; ftable['g'] = ftable['G'] = 2; ftable['t'] = ftable['T'] = 3; uint64_t insize = 0; ctable[0] = 3; // A->T ctable[1] = 2; // C->G ctable[2] = 1; // G->C ctable[3] = 0; // T->A libmaus2::aio::OutputStreamInstance::unique_ptr_type metaOut(new libmaus2::aio::OutputStreamInstance(metaoutputfilename)); libmaus2::util::NumberSerialisation::serialiseNumber(*metaOut,0); uint64_t nseq = 0; std::vector<uint64_t> lvec; for ( uint64_t i = 0; i < inputfilenames.size(); ++i ) { std::string const fn = inputfilenames[i]; libmaus2::aio::InputStreamInstance CIS(fn); libmaus2::lz::BufferedGzipStream::unique_ptr_type BGS; std::istream * istr = 0; if ( gz ) { libmaus2::lz::BufferedGzipStream::unique_ptr_type tBGS( new libmaus2::lz::BufferedGzipStream(CIS)); BGS = UNIQUE_PTR_MOVE(tBGS); istr = BGS.get(); } else { istr = &CIS; } libmaus2::fastx::StreamFastAReaderWrapper fain(*istr); libmaus2::fastx::StreamFastAReaderWrapper::pattern_type pattern; while ( fain.getNextPatternUnlocked(pattern) ) { if ( verbose ) std::cerr << (i+1) << " " << stripAfterDot(basename(fn)) << " " << pattern.sid << "..."; libmaus2::util::NumberSerialisation::serialiseNumber(*metaOut,pattern.spattern.size()); lvec.push_back(pattern.spattern.size()); libmaus2::util::NumberSerialisation::serialiseNumber(*metaOut,0); // map symbols for ( uint64_t j = 0; j < pattern.spattern.size(); ++j ) pattern.spattern[j] = ftable[static_cast<uint8_t>(pattern.spattern[j])]; // replace blocks of N symbols by random bases uint64_t l = 0; // number of replaced blocks uint64_t nr = 0; while ( l < pattern.spattern.size() ) { // skip regular bases while ( l < pattern.spattern.size() && pattern.spattern[l] < 4 ) ++l; assert ( l == pattern.spattern.size() || pattern.spattern[l] == 4 ); // go to end of non regular bases block uint64_t h = l; while ( h < pattern.spattern.size() && pattern.spattern[h] == 4 ) ++h; // if non regular block is not empty if ( h-l ) { // replace by random bases for ( uint64_t j = l; j < h; ++j ) pattern.spattern[j] = (libmaus2::random::Random::rand8() & 3); // write bounds libmaus2::util::NumberSerialisation::serialiseNumber(*metaOut,l); libmaus2::util::NumberSerialisation::serialiseNumber(*metaOut,h); // add to interval counter nr += 1; } l = h; } // make sure there are no more irregular bases for ( uint64_t j = 0; j < pattern.spattern.size(); ++j ) assert ( pattern.spattern[j] < 4 ); // go back to start of meta data metaOut->seekp( - static_cast<int64_t>(2*nr+1)*sizeof(uint64_t), std::ios::cur ); // write number of intervals replaced libmaus2::util::NumberSerialisation::serialiseNumber(*metaOut,nr); // skip interval bounds already written metaOut->seekp( static_cast<int64_t>(2*nr )*sizeof(uint64_t), std::ios::cur ); // write bases compactout.write(pattern.spattern.c_str(),pattern.spattern.size()); // write reverse complement if requested if ( rc ) { // reverse complement std::reverse(pattern.spattern.begin(),pattern.spattern.end()); for ( uint64_t j = 0; j < pattern.spattern.size(); ++j ) pattern.spattern[j] = ctable[static_cast<uint8_t>(pattern.spattern[j])]; // write compactout.write(pattern.spattern.c_str(),pattern.spattern.size()); } insize += pattern.spattern.size()+1; nseq += 1; if ( verbose ) std::cerr << "done, input size " << formatBytes(pattern.spattern.size()+1) << " acc " << formatBytes(insize) << std::endl; } } metaOut->seekp(0); libmaus2::util::NumberSerialisation::serialiseNumber(*metaOut,nseq); metaOut->flush(); metaOut.reset(); libmaus2::aio::InputStreamInstance::unique_ptr_type metaISI(new libmaus2::aio::InputStreamInstance(metaoutputfilename)); // number of sequences uint64_t const rnseq = libmaus2::util::NumberSerialisation::deserialiseNumber(*metaISI); assert ( nseq == rnseq ); for ( uint64_t i = 0; i < nseq; ++i ) { // length of sequence uint64_t const l = libmaus2::util::NumberSerialisation::deserialiseNumber(*metaISI); assert ( l == lvec[i] ); uint64_t const nr = libmaus2::util::NumberSerialisation::deserialiseNumber(*metaISI); // skip replaced intervals metaISI->ignore(2*nr*sizeof(uint64_t)); } assert ( metaISI->peek() == std::istream::traits_type::eof() ); std::cerr << "Done, total input size " << insize << std::endl; compactout.flush(); return EXIT_SUCCESS; }