int NdbDictionary::Index::addIndexColumn(const char * name){ const Column c(name); return addColumn(c); }
void Migration_20100214140000_initial::up () { // The columns are created individually, not in the createTable statement. // This has the advantage that a table will have the required columns even // if it already existed with some or all of the columns missing. It has // the disadvantage that we have to create the users table with an id // column which is different from the legacy database where the users table // had no id column and the primary key was username. createTable ("person", true); // Creates the id column addColumn ("person", "nachname" , dataTypeString (), "", true); addColumn ("person", "vorname" , dataTypeString (), "", true); addColumn ("person", "verein" , dataTypeString (), "", true); addColumn ("person", "spitzname" , dataTypeString (), "", true); addColumn ("person", "vereins_id", dataTypeString (), "", true); addColumn ("person", "bemerkung" , dataTypeString (), "", true); createTableLike ("person", "person_temp", true); createTable ("flugzeug", true); // Creates the id column addColumn ("flugzeug", "kennzeichen", dataTypeString (), "", true); addColumn ("flugzeug", "verein", dataTypeString (), "", true); addColumn ("flugzeug", "sitze", dataTypeInteger (), "", true); addColumn ("flugzeug", "typ", dataTypeString (), "", true); addColumn ("flugzeug", "gattung", dataTypeCharacter (), "", true); addColumn ("flugzeug", "wettbewerbskennzeichen", dataTypeString (), "", true); addColumn ("flugzeug", "bemerkung", dataTypeString (), "", true); createTableLike ("flugzeug", "flugzeug_temp", true); createTable ("flug", true); // Creates the id column // Crew and plane addColumn ("flug", "flugzeug", dataTypeId (), "", true); addColumn ("flug", "pilot", dataTypeId (), "", true); addColumn ("flug", "begleiter", dataTypeId (), "", true); // Flight settings addColumn ("flug", "typ", dataTypeInteger (), "", true); addColumn ("flug", "modus", dataTypeCharacter (), "", true); // Departure and landing addColumn ("flug", "status", dataTypeInteger (), "", true); addColumn ("flug", "startart", dataTypeId (), "", true); addColumn ("flug", "startort", dataTypeString (), "", true); addColumn ("flug", "zielort", dataTypeString (), "", true); addColumn ("flug", "anzahl_landungen", dataTypeInteger (), "", true); addColumn ("flug", "startzeit", dataTypeDatetime (), "", true); addColumn ("flug", "landezeit", dataTypeDatetime (), "", true); // Towflight addColumn ("flug", "towplane", dataTypeId (), "", true); addColumn ("flug", "modus_sfz", dataTypeCharacter (), "", true); addColumn ("flug", "zielort_sfz", dataTypeString (), "", true); addColumn ("flug", "land_schlepp", dataTypeDatetime (), "", true); addColumn ("flug", "towpilot", dataTypeId (), "", true); // Incomplete names addColumn ("flug", "pnn", dataTypeString (), "", true); addColumn ("flug", "pvn", dataTypeString (), "", true); addColumn ("flug", "bnn", dataTypeString (), "", true); addColumn ("flug", "bvn", dataTypeString (), "", true); addColumn ("flug", "tpnn", dataTypeString (), "", true); addColumn ("flug", "tpvn", dataTypeString (), "", true); // Comments addColumn ("flug", "bemerkung", dataTypeString (), "", true); addColumn ("flug", "abrechnungshinweis", dataTypeString (), "", true); createTableLike ("flug", "flug_temp", true); // Creates the id column; note that the legacy database did not contain an // index column createTable ("user", true); addColumn ("user", "username", dataTypeString (), "NOT NULL", true); // TODO not null addColumn ("user", "password", dataTypeString (), "" , true); addColumn ("user", "perm_club_admin", dataTypeBoolean (), "" , true); addColumn ("user", "perm_read_flight_db", dataTypeBoolean (), "" , true); addColumn ("user", "club", dataTypeString (), "" , true); addColumn ("user", "person", dataTypeId (), "" , true); }
void MultiListBox::_addItem(const MyGUI::UString& _name) { addColumn(_name); setColumnResizingPolicyAt(getColumnCount() - 1, ResizingPolicy::Auto); }
void ColumnPreferencesFrame::on_newToolButton_clicked() { addColumn(true, "New Column", COL_NUMBER, NULL, 0); //TODO : Fix Translate }
toResultStorage::toResultStorage(bool available, QWidget *parent, const char *name) : toResultView(false, false, parent, name), AvailableGraph(available) { Unit = toConfigurationNewSingle::Instance().option(ToConfiguration::Global::SizeUnit).toString(); setAllColumnsShowFocus(true); setSortingEnabled(false); // enable it after data fetch setRootIsDecorated(true); addColumn(tr("Name")); addColumn(tr("Status")); addColumn(tr("Information")); addColumn(tr("Contents")); addColumn(tr("Logging")); addColumn(tr("Size (%1)").arg(Unit)); addColumn(tr("Free (%1)").arg(Unit)); addColumn(tr("Free (%)")); addColumn(tr("Autoextend (%1)").arg(Unit)); if (available) addColumn(tr("Used/Free/Autoextend")); else addColumn(tr("Available")); addColumn(tr("Coalesced")); addColumn(tr("Max free (%1)").arg(Unit)); addColumn(tr("Free fragments")); setSQLName(tr("toResultStorage")); setColumnAlignment(COL_SIZE, Qt::AlignRight); setColumnAlignment(COL_FREE_UNIT, Qt::AlignRight); setColumnAlignment(COL_FREE_PERCENT, Qt::AlignRight); setColumnAlignment(COL_AUTOEXT, Qt::AlignCenter); setColumnAlignment(COL_USED_FREE_AUTO, Qt::AlignCenter); setColumnAlignment(COL_COALESCED, Qt::AlignRight); setColumnAlignment(COL_MAX_FREE, Qt::AlignRight); setColumnAlignment(COL_FREE_FRAGMENTS, Qt::AlignRight); ShowCoalesced = false; OnlyFiles = false; Tablespaces = Files = NULL; setItemDelegate(new toResultStorageItemDelegate()); }
KFileDetailView::KFileDetailView(TQWidget *parent, const char *name) : TDEListView(parent, name), KFileView(), d(new KFileDetailViewPrivate()) { // this is always the static section, not the index depending on column order m_sortingCol = COL_NAME; m_blockSortingSignal = false; setViewName( i18n("Detailed View") ); addColumn( i18n( "Name" ) ); addColumn( i18n( "Size" ) ); addColumn( i18n( "Date" ) ); addColumn( i18n( "Permissions" ) ); addColumn( i18n( "Owner" ) ); addColumn( i18n( "Group" ) ); setShowSortIndicator( true ); setAllColumnsShowFocus( true ); setDragEnabled(true); connect( header(), TQT_SIGNAL( clicked(int)), TQT_SLOT(slotSortingChanged(int) )); connect( this, TQT_SIGNAL( returnPressed(TQListViewItem *) ), TQT_SLOT( slotActivate( TQListViewItem *) ) ); connect( this, TQT_SIGNAL( clicked(TQListViewItem *, const TQPoint&, int)), TQT_SLOT( selected( TQListViewItem *) ) ); connect( this, TQT_SIGNAL( doubleClicked(TQListViewItem *, const TQPoint&, int)), TQT_SLOT( slotActivate( TQListViewItem *) ) ); connect( this, TQT_SIGNAL(contextMenuRequested( TQListViewItem *, const TQPoint &, int )), this, TQT_SLOT( slotActivateMenu( TQListViewItem *, const TQPoint& ))); KFile::SelectionMode sm = KFileView::selectionMode(); switch ( sm ) { case KFile::Multi: TQListView::setSelectionMode( TQListView::Multi ); break; case KFile::Extended: TQListView::setSelectionMode( TQListView::Extended ); break; case KFile::NoSelection: TQListView::setSelectionMode( TQListView::NoSelection ); break; default: // fall through case KFile::Single: TQListView::setSelectionMode( TQListView::Single ); break; } // for highlighting if ( sm == KFile::Multi || sm == KFile::Extended ) connect( this, TQT_SIGNAL( selectionChanged() ), TQT_SLOT( slotSelectionChanged() )); else connect( this, TQT_SIGNAL( selectionChanged( TQListViewItem * ) ), TQT_SLOT( highlighted( TQListViewItem * ) )); // DND connect( &(d->autoOpenTimer), TQT_SIGNAL( timeout() ), this, TQT_SLOT( slotAutoOpen() )); setSorting( sorting() ); m_resolver = new KMimeTypeResolver<KFileListViewItem,KFileDetailView>( this ); }
KonqSidebarTree::KonqSidebarTree( KonqSidebarOldTreeModule *parent, QWidget *parentWidget, ModuleType moduleType, const QString& path ) : K3ListView( parentWidget ), m_currentTopLevelItem( 0 ), m_scrollingLocked( false ), m_collection( 0 ) { d = new KonqSidebarTree_Internal; d->m_dropMode = SidebarTreeMode; loadModuleFactories(); setAcceptDrops( true ); viewport()->setAcceptDrops( true ); installEventFilter(this); m_lstModules.setAutoDelete( true ); setSelectionMode( Q3ListView::Single ); setDragEnabled(true); m_sidebarModule = parent; m_animationTimer = new QTimer( this ); connect( m_animationTimer, SIGNAL(timeout()), this, SLOT(slotAnimation()) ); m_currentBeforeDropItem = 0; m_dropItem = 0; m_bOpeningFirstChild=false; addColumn( QString() ); header()->hide(); setTreeStepSize(15); m_autoOpenTimer = new QTimer( this ); connect( m_autoOpenTimer, SIGNAL(timeout()), this, SLOT(slotAutoOpenFolder()) ); connect( this, SIGNAL(doubleClicked(Q3ListViewItem*)), this, SLOT(slotDoubleClicked(Q3ListViewItem*)) ); connect( this, SIGNAL(mouseButtonPressed(int,Q3ListViewItem*,QPoint,int)), this, SLOT(slotMouseButtonPressed(int,Q3ListViewItem*,QPoint,int)) ); connect( this, SIGNAL(mouseButtonClicked(int,Q3ListViewItem*,QPoint,int)), this, SLOT(slotMouseButtonClicked(int,Q3ListViewItem*,QPoint,int)) ); connect( this, SIGNAL(returnPressed(Q3ListViewItem*)), this, SLOT(slotDoubleClicked(Q3ListViewItem*)) ); connect( this, SIGNAL(selectionChanged()), this, SLOT(slotSelectionChanged()) ); connect(qApp->clipboard(), SIGNAL(dataChanged()), this, SLOT(slotSelectionChanged())); // so that "paste" can be updated connect( this, SIGNAL(itemRenamed(Q3ListViewItem*,QString,int)), this, SLOT(slotItemRenamed(Q3ListViewItem*,QString,int))); if (moduleType == VIRT_Folder) { m_dirtreeDir.dir.setPath(KGlobal::dirs()->saveLocation("data","konqsidebartng/virtual_folders/"+path+'/')); m_dirtreeDir.relDir = path; } else { m_dirtreeDir.dir.setPath( path ); } kDebug(1201) << m_dirtreeDir.dir.path(); m_dirtreeDir.type = moduleType; // Initial parsing rescanConfiguration(); if (firstChild()) { m_bOpeningFirstChild = true; firstChild()->setOpen(true); m_bOpeningFirstChild = false; } OrgKdeKDirNotifyInterface *kdirnotify = new OrgKdeKDirNotifyInterface(QString(), QString(), QDBusConnection::sessionBus()); kdirnotify->setParent(this); connect(kdirnotify, SIGNAL(FilesAdded(QString)), SLOT(slotFilesAdded(QString))); connect(kdirnotify, SIGNAL(FilesChanged(QStringList)), SLOT(slotFilesChanged(QStringList))); connect(kdirnotify, SIGNAL(FilesRemoved(QStringList)), SLOT(slotFilesRemoved(QStringList))); m_collection = new KActionCollection(this); m_collection->addAssociatedWidget(this); m_collection->setObjectName( QLatin1String("bookmark actions" )); QAction *action = new KAction(KIcon("folder-new"), i18n("&Create New Folder..."), this); m_collection->addAction("create_folder", action); connect(action, SIGNAL(triggered(bool)), SLOT(slotCreateFolder())); action = new KAction(KIcon("edit-delete"), i18n("Delete Folder"), this); m_collection->addAction("delete", action); connect(action, SIGNAL(triggered(bool)), SLOT(slotDelete())); action = new KAction(KIcon("user-trash"), i18n("Move to Trash"), this); m_collection->addAction("trash", action); connect(action, SIGNAL(triggered(bool)), SLOT(slotTrash())); action = new KAction(i18n("Rename"), this); action->setIcon(KIcon("edit-rename")); m_collection->addAction("rename", action); connect(action, SIGNAL(triggered(bool)), SLOT(slotRename())); action = new KAction(KIcon("edit-delete"), i18n("Delete Link"), this); m_collection->addAction("delete_link", action); connect(action, SIGNAL(triggered(bool)), SLOT(slotDelete())); action = new KAction(KIcon("document-properties"), i18n("Properties"), this); m_collection->addAction("item_properties", action); connect(action, SIGNAL(triggered(bool)), SLOT(slotProperties())); action = new KAction(KIcon("window-new"), i18n("Open in New Window"), this); m_collection->addAction("open_window", action); connect(action, SIGNAL(triggered(bool)), SLOT(slotOpenNewWindow())); action = new KAction(KIcon("tab-new"), i18n("Open in New Tab"), this); m_collection->addAction("open_tab", action); connect(action, SIGNAL(triggered(bool)), SLOT(slotOpenTab())); action = new KAction(KIcon("edit-copy"), i18n("Copy Link Address"), this); m_collection->addAction("copy_location", action); connect(action, SIGNAL(triggered(bool)), SLOT(slotCopyLocation())); }
//---------------------------------------------------------------------------------------------- /// Examine the chi squared as a function of fitting parameters and estimate /// errors for each parameter. void CalculateChiSquared::estimateErrors() { // Number of fiting parameters auto nParams = m_function->nParams(); // Create an output table for displaying slices of the chi squared and // the probabilitydensity function auto pdfTable = API::WorkspaceFactory::Instance().createTable(); std::string baseName = getProperty("Output"); if (baseName.empty()) { baseName = "CalculateChiSquared"; } declareProperty(new API::WorkspaceProperty<API::ITableWorkspace>( "PDFs", "", Kernel::Direction::Output), "The name of the TableWorkspace in which to store the " "pdfs of fit parameters"); setPropertyValue("PDFs", baseName + "_pdf"); setProperty("PDFs", pdfTable); // Create an output table for displaying the parameter errors. auto errorsTable = API::WorkspaceFactory::Instance().createTable(); auto nameColumn = errorsTable->addColumn("str", "Parameter"); auto valueColumn = errorsTable->addColumn("double", "Value"); auto minValueColumn = errorsTable->addColumn("double", "Value at Min"); auto leftErrColumn = errorsTable->addColumn("double", "Left Error"); auto rightErrColumn = errorsTable->addColumn("double", "Right Error"); auto quadraticErrColumn = errorsTable->addColumn("double", "Quadratic Error"); auto chiMinColumn = errorsTable->addColumn("double", "Chi2 Min"); errorsTable->setRowCount(nParams); declareProperty(new API::WorkspaceProperty<API::ITableWorkspace>( "Errors", "", Kernel::Direction::Output), "The name of the TableWorkspace in which to store the " "values and errors of fit parameters"); setPropertyValue("Errors", baseName + "_errors"); setProperty("Errors", errorsTable); // Calculate initial values double chiSquared = 0.0; double chiSquaredWeighted = 0.0; double dof = 0; API::FunctionDomain_sptr domain; API::FunctionValues_sptr values; m_domainCreator->createDomain(domain, values); calcChiSquared(*m_function, nParams, *domain, *values, chiSquared, chiSquaredWeighted, dof); // Value of chi squared for current parameters in m_function double chi0 = chiSquared; // Fit data variance double sigma2 = chiSquared / dof; bool useWeighted = getProperty("Weighted"); if (useWeighted) { chi0 = chiSquaredWeighted; sigma2 = 0.0; } if (g_log.is(Kernel::Logger::Priority::PRIO_DEBUG)) { g_log.debug() << "chi0=" << chi0 << std::endl; g_log.debug() << "sigma2=" << sigma2 << std::endl; g_log.debug() << "dof=" << dof << std::endl; } // Parameter bounds that define a volume in the parameter // space within which the chi squared is being examined. GSLVector lBounds(nParams); GSLVector rBounds(nParams); // Number of points in lines for plotting size_t n = 100; pdfTable->setRowCount(n); const double fac = 1e-4; // Loop over each parameter for (size_t ip = 0; ip < nParams; ++ip) { // Add columns for the parameter to the pdf table. auto parName = m_function->parameterName(ip); nameColumn->read(ip, parName); // Parameter values auto col1 = pdfTable->addColumn("double", parName); col1->setPlotType(1); // Chi squared values auto col2 = pdfTable->addColumn("double", parName + "_chi2"); col2->setPlotType(2); // PDF values auto col3 = pdfTable->addColumn("double", parName + "_pdf"); col3->setPlotType(2); double par0 = m_function->getParameter(ip); double shift = fabs(par0 * fac); if (shift == 0.0) { shift = fac; } // Make a slice along this parameter GSLVector dir(nParams); dir.zero(); dir[ip] = 1.0; ChiSlice slice(*m_function, dir, *domain, *values, chi0, sigma2); // Find the bounds withn which the PDF is significantly above zero. // The bounds are defined relative to par0: // par0 + lBound is the lowest value of the parameter (lBound <= 0) // par0 + rBound is the highest value of the parameter (rBound >= 0) double lBound = slice.findBound(-shift); double rBound = slice.findBound(shift); lBounds[ip] = lBound; rBounds[ip] = rBound; // Approximate the slice with a polynomial. // P is a vector of values of the polynomial at special points. // A is a vector of Chebyshev expansion coefficients. // The polynomial is defined on interval [lBound, rBound] // The value of the polynomial at 0 == chi squared at par0 std::vector<double> P, A; bool ok = true; auto base = slice.makeApprox(lBound, rBound, P, A, ok); if (!ok) { g_log.warning() << "Approximation failed for parameter " << ip << std::endl; } if (g_log.is(Kernel::Logger::Priority::PRIO_DEBUG)) { g_log.debug() << "Parameter " << ip << std::endl; g_log.debug() << "Slice approximated by polynomial of order " << base->size() - 1; g_log.debug() << " between " << lBound << " and " << rBound << std::endl; } // Write n slice points into the output table. double dp = (rBound - lBound) / static_cast<double>(n); for (size_t i = 0; i < n; ++i) { double par = lBound + dp * static_cast<double>(i); double chi = base->eval(par, P); col1->fromDouble(i, par0 + par); col2->fromDouble(i, chi); } // Check if par0 is a minimum point of the chi squared std::vector<double> AD; // Calculate the derivative polynomial. // AD are the Chebyshev expansion of the derivative. base->derivative(A, AD); // Find the roots of the derivative polynomial std::vector<double> minima = base->roots(AD); if (minima.empty()) { minima.push_back(par0); } if (g_log.is(Kernel::Logger::Priority::PRIO_DEBUG)) { g_log.debug() << "Minima: "; } // If only 1 extremum is found assume (without checking) that it's a // minimum. // If there are more than 1, find the one with the smallest chi^2. double chiMin = std::numeric_limits<double>::max(); double parMin = par0; for (size_t i = 0; i < minima.size(); ++i) { double value = base->eval(minima[i], P); if (g_log.is(Kernel::Logger::Priority::PRIO_DEBUG)) { g_log.debug() << minima[i] << " (" << value << ") "; } if (value < chiMin) { chiMin = value; parMin = minima[i]; } } if (g_log.is(Kernel::Logger::Priority::PRIO_DEBUG)) { g_log.debug() << std::endl; g_log.debug() << "Smallest minimum at " << parMin << " is " << chiMin << std::endl; } // Points of intersections with line chi^2 = 1/2 give an estimate of // the standard deviation of this parameter if it's uncorrelated with the // others. A[0] -= 0.5; // Now A are the coefficients of the original polynomial // shifted down by 1/2. std::vector<double> roots = base->roots(A); std::sort(roots.begin(), roots.end()); if (roots.empty()) { // Something went wrong; use the whole interval. roots.resize(2); roots[0] = lBound; roots[1] = rBound; } else if (roots.size() == 1) { // Only one root found; use a bound for the other root. if (roots.front() < 0) { roots.push_back(rBound); } else { roots.insert(roots.begin(), lBound); } } else if (roots.size() > 2) { // More than 2 roots; use the smallest and the biggest auto smallest = roots.front(); auto biggest = roots.back(); roots.resize(2); roots[0] = smallest; roots[1] = biggest; } if (g_log.is(Kernel::Logger::Priority::PRIO_DEBUG)) { g_log.debug() << "Roots: "; for (size_t i = 0; i < roots.size(); ++i) { g_log.debug() << roots[i] << ' '; } g_log.debug() << std::endl; } // Output parameter info to the table. valueColumn->fromDouble(ip, par0); minValueColumn->fromDouble(ip, par0 + parMin); leftErrColumn->fromDouble(ip, roots[0] - parMin); rightErrColumn->fromDouble(ip, roots[1] - parMin); chiMinColumn->fromDouble(ip, chiMin); // Output the PDF for (size_t i = 0; i < n; ++i) { double chi = col2->toDouble(i); col3->fromDouble(i, exp(-chi + chiMin)); } // make sure function parameters don't change. m_function->setParameter(ip, par0); } // Improve estimates for standard deviations. // If parameters are correlated the found deviations // most likely underestimate the true values. unfixParameters(); GSLJacobian J(m_function, values->size()); m_function->functionDeriv(*domain, J); refixParameters(); // Calculate the hessian at the current point. GSLMatrix H; if (useWeighted) { H.resize(nParams, nParams); for (size_t i = 0; i < nParams; ++i) { for (size_t j = i; j < nParams; ++j) { double h = 0.0; for (size_t k = 0; k < values->size(); ++k) { double w = values->getFitWeight(k); h += J.get(k, i) * J.get(k, j) * w * w; } H.set(i, j, h); if (i != j) { H.set(j, i, h); } } } } else { H = Tr(J.matrix()) * J.matrix(); } // Square roots of the diagonals of the covariance matrix give // the standard deviations in the quadratic approximation of the chi^2. GSLMatrix V(H); if (!useWeighted) { V *= 1. / sigma2; } V.invert(); // In a non-quadratic asymmetric case the following procedure can give a // better result: // Find the direction in which the chi^2 changes slowest and the positive and // negative deviations in that direction. The change in a parameter at those // points can be a better estimate for the standard deviation. GSLVector v(nParams); GSLMatrix Q(nParams, nParams); // One of the eigenvectors of the hessian is the direction of the slowest // change. H.eigenSystem(v, Q); // Loop over the eigenvectors for (size_t i = 0; i < nParams; ++i) { auto dir = Q.copyColumn(i); if (g_log.is(Kernel::Logger::Priority::PRIO_DEBUG)) { g_log.debug() << "Direction " << i << std::endl; g_log.debug() << dir << std::endl; } // Make a slice in that direction ChiSlice slice(*m_function, dir, *domain, *values, chi0, sigma2); double rBound0 = dir.dot(rBounds); double lBound0 = dir.dot(lBounds); if (g_log.is(Kernel::Logger::Priority::PRIO_DEBUG)) { g_log.debug() << "lBound " << lBound0 << std::endl; g_log.debug() << "rBound " << rBound0 << std::endl; } double lBound = slice.findBound(lBound0); double rBound = slice.findBound(rBound0); std::vector<double> P, A; // Use a polynomial approximation bool ok = true; auto base = slice.makeApprox(lBound, rBound, P, A, ok); if (!ok) { g_log.warning() << "Approximation failed in direction " << i << std::endl; } // Find the deviation points where the chi^2 = 1/2 A[0] -= 0.5; std::vector<double> roots = base->roots(A); std::sort(roots.begin(), roots.end()); // Sort out the roots auto nRoots = roots.size(); if (nRoots == 0) { roots.resize(2, 0.0); } else if (nRoots == 1) { if (roots.front() > 0.0) { roots.insert(roots.begin(), 0.0); } else { roots.push_back(0.0); } } else if (nRoots > 2) { roots[1] = roots.back(); roots.resize(2); } if (g_log.is(Kernel::Logger::Priority::PRIO_DEBUG)) { g_log.debug() << "Roots " << roots[0] << " (" << slice(roots[0]) << ") " << roots[1] << " (" << slice(roots[1]) << ") " << std::endl; } // Loop over the parameters and see if there deviations along // this direction is greater than any previous value. for (size_t ip = 0; ip < nParams; ++ip) { auto lError = roots.front() * dir[ip]; auto rError = roots.back() * dir[ip]; if (lError > rError) { std::swap(lError, rError); } if (lError < leftErrColumn->toDouble(ip)) { if (g_log.is(Kernel::Logger::Priority::PRIO_DEBUG)) { g_log.debug() << " left for " << ip << ' ' << lError << ' ' << leftErrColumn->toDouble(ip) << std::endl; } leftErrColumn->fromDouble(ip, lError); } if (rError > rightErrColumn->toDouble(ip)) { if (g_log.is(Kernel::Logger::Priority::PRIO_DEBUG)) { g_log.debug() << " right for " << ip << ' ' << rError << ' ' << rightErrColumn->toDouble(ip) << std::endl; } rightErrColumn->fromDouble(ip, rError); } } // Output the quadratic estimate for comparrison. quadraticErrColumn->fromDouble(i, sqrt(V.get(i, i))); } }
void ConstraintWidget::setAttributes(DatabaseModel *model, BaseObject *parent_obj, OperationList *op_list, Constraint *constr) { ObjectType obj_type; unsigned count, i, row; Column *column=NULL; Table *ref_table=NULL; if(!parent_obj) throw Exception(ERR_ASG_NOT_ALOC_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); BaseObjectWidget::setAttributes(model, op_list, constr, parent_obj); info_frm->setVisible(this->table!=NULL); ref_table_sel->setModel(model); obj_type=parent_obj->getObjectType(); if(obj_type==OBJ_TABLE) count=table->getColumnCount(); else count=relationship->getAttributeCount(); columns_tab->blockSignals(true); for(i=0, row=0; i < count; i++) { if(obj_type==OBJ_TABLE) column=table->getColumn(i); else column=relationship->getAttribute(i); if(constr && constr->isColumnExists(column, Constraint::SOURCE_COLS)) { columns_tab->addRow(); addColumn(column, Constraint::SOURCE_COLS, row); row++; } } updateColumnsCombo(Constraint::SOURCE_COLS); columns_tab->setButtonsEnabled(ObjectTableWidget::ADD_BUTTON, (column_cmb->count()!=0)); columns_tab->blockSignals(false); if(constr) { constr_type_cmb->setCurrentIndex(constr_type_cmb->findText(~constr->getConstraintType())); constr_type_cmb->setEnabled(false); constr_type_lbl->setEnabled(false); check_expr_txt->setPlainText(Utf8String::create(constr->getCheckExpression())); deferrable_chk->setChecked(constr->isDeferrable()); deferral_cmb->setCurrentIndex(deferral_cmb->findText(~constr->getDeferralType())); match_cmb->setCurrentIndex(match_cmb->findText(~constr->getMatchType())); fill_factor_sb->setValue(constr->getFillFactor()); on_delete_cmb->setCurrentIndex(on_delete_cmb->findText(~constr->getActionType(false))); on_update_cmb->setCurrentIndex(on_update_cmb->findText(~constr->getActionType(true))); ref_table=dynamic_cast<Table *>(constr->getReferencedTable()); if(ref_table) { ref_columns_tab->blockSignals(true); ref_table_sel->setSelectedObject(ref_table); count=ref_table->getColumnCount(); for(i=0, row=0; i < count; i++) { column=ref_table->getColumn(i); if(constr->isColumnExists(column, Constraint::REFERENCED_COLS)) { ref_columns_tab->addRow(); addColumn(column, Constraint::REFERENCED_COLS, row); row++; } } updateColumnsCombo(Constraint::REFERENCED_COLS); ref_columns_tab->setButtonsEnabled(ObjectTableWidget::ADD_BUTTON, (column_cmb->count()!=0)); ref_columns_tab->blockSignals(false); } } }
/* This is the real constructor*/ ClpDynamicExampleMatrix::ClpDynamicExampleMatrix(ClpSimplex * model, int numberSets, int numberGubColumns, const int * starts, const double * lower, const double * upper, const CoinBigIndex * startColumn, const int * row, const double * element, const double * cost, const double * columnLower, const double * columnUpper, const unsigned char * status, const unsigned char * dynamicStatus, int numberIds, const int *ids) : ClpDynamicMatrix(model, numberSets, 0, NULL, lower, upper, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) { setType(25); numberColumns_ = numberGubColumns; // start with safe values - then experiment maximumGubColumns_ = numberColumns_; maximumElements_ = startColumn[numberColumns_]; // delete odd stuff created by ClpDynamicMatrix constructor delete [] startSet_; startSet_ = new int [numberSets_]; delete [] next_; next_ = new int [maximumGubColumns_]; delete [] row_; delete [] element_; delete [] startColumn_; delete [] cost_; delete [] columnLower_; delete [] columnUpper_; delete [] dynamicStatus_; delete [] status_; delete [] id_; // and size correctly row_ = new int [maximumElements_]; element_ = new double [maximumElements_]; startColumn_ = new CoinBigIndex [maximumGubColumns_+1]; // say no columns yet numberGubColumns_ = 0; startColumn_[0] = 0; cost_ = new double[maximumGubColumns_]; dynamicStatus_ = new unsigned char [maximumGubColumns_]; memset(dynamicStatus_, 0, maximumGubColumns_); id_ = new int[maximumGubColumns_]; if (columnLower) columnLower_ = new double[maximumGubColumns_]; else columnLower_ = NULL; if (columnUpper) columnUpper_ = new double[maximumGubColumns_]; else columnUpper_ = NULL; // space for ids idGen_ = new int [maximumGubColumns_]; int iSet; for (iSet = 0; iSet < numberSets_; iSet++) startSet_[iSet] = -1; // This starts code specific to this storage method CoinBigIndex i; fullStartGen_ = ClpCopyOfArray(starts, numberSets_ + 1); startColumnGen_ = ClpCopyOfArray(startColumn, numberColumns_ + 1); CoinBigIndex numberElements = startColumnGen_[numberColumns_]; rowGen_ = ClpCopyOfArray(row, numberElements); elementGen_ = new double[numberElements]; for (i = 0; i < numberElements; i++) elementGen_[i] = element[i]; costGen_ = new double[numberColumns_]; for (i = 0; i < numberColumns_; i++) { costGen_[i] = cost[i]; // I don't think I need sorted but ... CoinSort_2(rowGen_ + startColumnGen_[i], rowGen_ + startColumnGen_[i+1], elementGen_ + startColumnGen_[i]); } if (columnLower) { columnLowerGen_ = new double[numberColumns_]; for (i = 0; i < numberColumns_; i++) { columnLowerGen_[i] = columnLower[i]; if (columnLowerGen_[i]) { printf("Non-zero lower bounds not allowed - subtract from model\n"); abort(); } } } else { columnLowerGen_ = NULL; } if (columnUpper) { columnUpperGen_ = new double[numberColumns_]; for (i = 0; i < numberColumns_; i++) columnUpperGen_[i] = columnUpper[i]; } else { columnUpperGen_ = NULL; } // end specific coding if (columnUpper_) { // set all upper bounds so we have enough space double * columnUpper = model->columnUpper(); for(i = firstDynamic_; i < lastDynamic_; i++) columnUpper[i] = 1.0e10; } if (status) { status_ = ClpCopyOfArray(status, numberSets_); assert (dynamicStatus); CoinMemcpyN(dynamicStatus, numberIds, dynamicStatus_); assert (numberIds); } else { assert (!numberIds); status_ = new unsigned char [numberSets_]; memset(status_, 0, numberSets_); for (i = 0; i < numberSets_; i++) { // make slack key setStatus(i, ClpSimplex::basic); } } dynamicStatusGen_ = new unsigned char [numberColumns_]; memset(dynamicStatusGen_, 0, numberColumns_); // for clarity for (i = 0; i < numberColumns_; i++) setDynamicStatusGen(i, atLowerBound); // Populate with enough columns if (!numberIds) { // This could be made more sophisticated for (iSet = 0; iSet < numberSets_; iSet++) { int sequence = fullStartGen_[iSet]; CoinBigIndex start = startColumnGen_[sequence]; addColumn(startColumnGen_[sequence+1] - start, rowGen_ + start, elementGen_ + start, costGen_[sequence], columnLowerGen_ ? columnLowerGen_[sequence] : 0, columnUpperGen_ ? columnUpperGen_[sequence] : 1.0e30, iSet, getDynamicStatusGen(sequence)); idGen_[iSet] = sequence; // say which one in setDynamicStatusGen(sequence, inSmall); } } else { // put back old ones int * set = new int[numberColumns_]; for (iSet = 0; iSet < numberSets_; iSet++) { for (CoinBigIndex j = fullStartGen_[iSet]; j < fullStartGen_[iSet+1]; j++) set[j] = iSet; } for (int i = 0; i < numberIds; i++) { int sequence = ids[i]; CoinBigIndex start = startColumnGen_[sequence]; addColumn(startColumnGen_[sequence+1] - start, rowGen_ + start, elementGen_ + start, costGen_[sequence], columnLowerGen_ ? columnLowerGen_[sequence] : 0, columnUpperGen_ ? columnUpperGen_[sequence] : 1.0e30, set[sequence], getDynamicStatus(i)); idGen_[iSet] = sequence; // say which one in setDynamicStatusGen(sequence, inSmall); } delete [] set; } if (!status) { gubCrash(); } else { initialProblem(); } }
void NGSD::annotateSomatic(VariantList& variants, QString filename) { //get sample ids QStringList samples = filename.split('-'); QString ts_id = sampleId(samples[0], false); //check if we could determine the sample if (ts_id=="") { Log::warn("Could not find processed sample in NGSD from name '" + QFileInfo(filename).baseName() + "'. Annotation will be incomplete because processing system could not be determined!"); } //remove all NGSD-specific columns QList<VariantAnnotationHeader> headers = variants.annotations(); foreach(const VariantAnnotationHeader& header, headers) { if (header.name().startsWith("som_ihdb")) { removeColumnIfPresent(variants, header.name(), true); } } //get required column indices int som_ihdb_c_idx = addColumn(variants, "som_ihdb_c", "Somatic variant count within NGSD."); int som_ihdb_p_idx = addColumn(variants, "som_ihdb_p", "Projects with somatic variant in NGSD."); //(re-)annotate the variants for (int i=0; i<variants.count(); ++i) { Variant& v = variants[i]; SqlQuery query = getQuery(); query.exec("SELECT s.id, dsv.processed_sample_id_tumor, p.name FROM detected_somatic_variant as dsv, variant as v, processed_sample ps, sample as s, project as p WHERE ps.project_id=p.id AND dsv.processed_sample_id_tumor=ps.id and dsv.variant_id=v.id AND ps.sample_id=s.id AND s.tumor='1' AND v.chr='"+v.chr().str()+"' AND v.start='"+QString::number(v.start())+"' AND v.end='"+QString::number(v.end())+"' AND v.ref='"+v.ref()+"' AND v.obs='"+v.obs()+"'"); //process variants QMap<QByteArray, int> project_map; QSet<QByteArray> processed_ps_ids; QSet<QByteArray> processed_s_ids; while(query.next()) { QByteArray current_sample = query.value(0).toByteArray(); QByteArray current_ps_id = query.value(1).toByteArray(); QByteArray current_project = query.value(2).toByteArray(); //skip already seen processed samples (there could be several variants because of indel window, but we want to process only one) if (processed_ps_ids.contains(current_ps_id)) continue; processed_ps_ids.insert(current_ps_id); //skip the current sample for general statistics if (current_sample==ts_id) continue; //skip already seen samples for general statistics (there could be several processings of the same sample because of different processing systems or because of experment repeats due to quality issues) if (processed_s_ids.contains(current_sample)) continue; processed_s_ids.insert(current_sample); // count if(!project_map.contains(current_project)) project_map.insert(current_project,0); ++project_map[current_project]; } QByteArray somatic_projects; int somatic_count = 0; QMap<QByteArray, int>::const_iterator j = project_map.constBegin(); while(j!=project_map.constEnd()) { somatic_count += j.value(); somatic_projects += j.key() + ","; ++j; } v.annotations()[som_ihdb_c_idx] = QByteArray::number(somatic_count); v.annotations()[som_ihdb_p_idx] = somatic_projects; } }
void NGSD::annotate(VariantList& variants, QString filename) { initProgress("NGSD annotation", true); //get sample ids QString s_id = sampleId(filename, false); QString ps_id = processedSampleId(filename, false); QString sys_id = getValue("SELECT processing_system_id FROM processed_sample WHERE id='" + processedSampleId(filename, false) + "'").toString(); //check if we could determine the sample bool found_in_db = true; if (s_id=="" || ps_id=="" || sys_id=="") { Log::warn("Could not find processed sample in NGSD by name '" + filename + "'. Annotation will be incomplete because processing system could not be determined!"); found_in_db = false; } //get sample ids that have processed samples with the same processing system (not same sample, variants imported, same processing system, good quality of sample, not tumor) QSet<int> sys_sample_ids; SqlQuery tmp = getQuery(); tmp.exec("SELECT DISTINCT s.id FROM processed_sample as ps, sample s WHERE ps.processing_system_id='" + sys_id + "' AND ps.sample_id=s.id AND s.tumor='0' AND s.quality='good' AND s.id!='" + s_id + "' AND (SELECT count(id) FROM detected_variant as dv WHERE dv.processed_sample_id = ps.id)>0"); while(tmp.next()) { sys_sample_ids.insert(tmp.value(0).toInt()); } //remove all NGSD-specific columns QList<VariantAnnotationHeader> headers = variants.annotations(); foreach(const VariantAnnotationHeader& header, headers) { if (header.name().startsWith("ihdb_")) { removeColumnIfPresent(variants, header.name(), true); } } removeColumnIfPresent(variants, "classification", true); removeColumnIfPresent(variants, "classification_comment", true); removeColumnIfPresent(variants, "validated", true); removeColumnIfPresent(variants, "comment", true); //get required column indices QString num_samples = QString::number(sys_sample_ids.count()); int ihdb_hom_idx = addColumn(variants, "ihdb_hom", "Homozygous variant counts in NGSD for the same processing system (" + num_samples + " samples)."); int ihdb_het_idx = addColumn(variants, "ihdb_het", "Heterozyous variant counts in NGSD for the same processing system (" + num_samples + " samples)."); int ihdb_wt_idx = addColumn(variants, "ihdb_wt", "Wildtype variant counts in NGSD for the same processing system (" + num_samples + " samples)."); int ihdb_all_hom_idx = addColumn(variants, "ihdb_allsys_hom", "Homozygous variant counts in NGSD independent of the processing system."); int ihdb_all_het_idx = addColumn(variants, "ihdb_allsys_het", "Heterozygous variant counts in NGSD independent of the processing system."); int class_idx = addColumn(variants, "classification", "Classification from the NGSD."); int clacom_idx = addColumn(variants, "classification_comment", "Classification comment from the NGSD."); int valid_idx = addColumn(variants, "validated", "Validation information from the NGSD. Validation results of other samples are listed in brackets!"); if (variants.annotationIndexByName("comment", true, false)==-1) addColumn(variants, "comment", "Comments from the NGSD. Comments of other samples are listed in brackets!"); int comment_idx = variants.annotationIndexByName("comment", true, false); //(re-)annotate the variants SqlQuery query = getQuery(); for (int i=0; i<variants.count(); ++i) { //QTime timer; //timer.start(); //variant id Variant& v = variants[i]; QByteArray v_id = variantId(v, false).toLatin1(); //variant classification QVariant classification = getValue("SELECT class FROM variant_classification WHERE variant_id='" + v_id + "'", true); if (!classification.isNull()) { v.annotations()[class_idx] = classification.toByteArray().replace("n/a", ""); v.annotations()[clacom_idx] = getValue("SELECT comment FROM variant_classification WHERE variant_id='" + v_id + "'", true).toByteArray().replace("\n", " ").replace("\t", " "); } //int t_v = timer.elapsed(); //timer.restart(); //detected variant infos int dv_id = -1; QByteArray comment = ""; if (found_in_db) { query.exec("SELECT id, comment FROM detected_variant WHERE processed_sample_id='" + ps_id + "' AND variant_id='" + v_id + "'"); if (query.size()==1) { query.next(); dv_id = query.value(0).toInt(); comment = query.value(1).toByteArray(); } } //validation info int vv_id = -1; QByteArray val_status = ""; if (found_in_db) { query.exec("SELECT id, status FROM variant_validation WHERE sample_id='" + s_id + "' AND variant_id='" + v_id + "'"); if (query.size()==1) { query.next(); vv_id = query.value(0).toInt(); val_status = query.value(1).toByteArray().replace("n/a", ""); } } //int t_dv = timer.elapsed(); //timer.restart(); //validation info other samples int tps = 0; int fps = 0; query.exec("SELECT id, status FROM variant_validation WHERE variant_id='"+v_id+"' AND status!='n/a'"); while(query.next()) { if (query.value(0).toInt()==vv_id) continue; if (query.value(1).toByteArray()=="true positive") ++tps; else if (query.value(1).toByteArray()=="false positive") ++fps; } if (tps>0 || fps>0) { if (val_status=="") val_status = "n/a"; val_status += " (" + QByteArray::number(tps) + "xTP, " + QByteArray::number(fps) + "xFP)"; } //int t_val = timer.elapsed(); //timer.restart(); //comments other samples QList<QByteArray> comments; query.exec("SELECT id, comment FROM detected_variant WHERE variant_id='"+v_id+"' AND comment IS NOT NULL"); while(query.next()) { if (query.value(0).toInt()==dv_id) continue; QByteArray tmp = query.value(1).toByteArray().trimmed(); if (tmp!="") comments.append(tmp); } if (comments.size()>0) { if (comment=="") comment = "n/a"; comment += " ("; for (int i=0; i<comments.count(); ++i) { if (i>0) { comment += ", "; } comment += comments[i]; } comment += ")"; } //int t_com = timer.elapsed(); //timer.restart(); //genotype counts int allsys_hom_count = 0; int allsys_het_count = 0; int sys_hom_count = 0; int sys_het_count = 0; QSet<int> s_ids_done; int s_id_int = s_id.toInt(); query.exec("SELECT dv.genotype, ps.sample_id FROM detected_variant as dv, processed_sample ps WHERE dv.processed_sample_id=ps.id AND dv.variant_id='" + v_id + "'"); while(query.next()) { //skip this sample id int current_sample = query.value(1).toInt(); if (current_sample==s_id_int) continue; //skip already seen samples (there could be several processings of the same sample because of different processing systems or because of experment repeats due to quality issues) if (s_ids_done.contains(current_sample)) continue; s_ids_done.insert(current_sample); QByteArray current_geno = query.value(0).toByteArray(); if (current_geno=="hom") { ++allsys_hom_count; if (sys_sample_ids.contains(current_sample)) { ++sys_hom_count; } } else if (current_geno=="het") { ++allsys_het_count; if (sys_sample_ids.contains(current_sample)) { ++sys_het_count; } } } //qDebug() << (v.isSNV() ? "S" : "I") << query.size() << t_v << t_dv << t_val << t_com << timer.elapsed(); v.annotations()[ihdb_all_hom_idx] = QByteArray::number(allsys_hom_count); v.annotations()[ihdb_all_het_idx] = QByteArray::number(allsys_het_count); if (found_in_db) { v.annotations()[ihdb_hom_idx] = QByteArray::number((double)sys_hom_count / sys_sample_ids.count(), 'f', 4); v.annotations()[ihdb_het_idx] = QByteArray::number((double)sys_het_count / sys_sample_ids.count(), 'f', 4); v.annotations()[ihdb_wt_idx] = QByteArray::number((double)(sys_sample_ids.count() - sys_hom_count - sys_het_count) / sys_sample_ids.count(), 'f', 4); v.annotations()[valid_idx] = val_status; v.annotations()[comment_idx] = comment.replace("\n", " ").replace("\t", " "); } else { v.annotations()[ihdb_hom_idx] = "n/a"; v.annotations()[ihdb_het_idx] = "n/a"; v.annotations()[ihdb_wt_idx] = "n/a"; v.annotations()[valid_idx] = "n/a"; v.annotations()[comment_idx] = "n/a"; } emit updateProgress(100*i/variants.count()); } }