std::vector<std::vector< Pquery const* >> pqueries_per_edge( Sample const& sample, bool only_max_lwr_placements ) { auto result = std::vector<std::vector< Pquery const* >>(); result.resize( sample.tree().edge_count() ); for( auto const& pqry : sample.pqueries() ) { if( only_max_lwr_placements ) { // If we are only interested in the most probably placement, find it first. PqueryPlacement const* max_p = nullptr; double max_v = std::numeric_limits<double>::lowest(); for( auto const& place : pqry.placements() ) { if( max_p == nullptr || place.like_weight_ratio > max_v ) { max_v = place.like_weight_ratio; max_p = &place; } } // If there is one, add it to the list for its edge. if( max_p ) { result[ max_p->edge().index() ].push_back( &pqry ); } } else { // If we instead want all placement, simply add them. for( auto const& place : pqry.placements() ) { result[ place.edge().index() ].push_back( &pqry ); } } } return result; }
pair<float, bool> getMaxGenotypePosterior(Sample & sample) { if (sample.genotypeInfo().empty()) { assert(sample.ploidy() == Sample::Ploidy::Zeroploid); return make_pair(0, false); } assert(sample.ploidy() != Sample::Ploidy::Zeroploid); assert(sample.ploidy() != Sample::Ploidy::Polyploid); float max_gpp = 0; bool has_gpp = false; for (auto & info: sample.genotypeInfo()) { auto gpp_value = info.getValue<float>("GPP"); if (gpp_value.second) { max_gpp = max(max_gpp, gpp_value.first); has_gpp = true; } } assert((max_gpp > 0) or Utils::floatCompare(max_gpp, 0)); assert((max_gpp < 1) or Utils::floatCompare(max_gpp, 1)); return make_pair(max_gpp, has_gpp); }
ATHENAError Track::GetKeyLength(const SLong & k_id, ULong & length) { Float f_lgt(0.0F); SLong s_id; Sample * sample; if (ULong(k_id) >= key_c) return ATHENA_ERROR_HANDLE; s_id = GetSampleID(s_id); if (_sample.IsNotValid(s_id)) { length = 0; return ATHENA_OK; } sample = _sample[s_id]; TrackKey * key = &key_l[k_id]; if (key->pitch.interval) { Float min, max, cur; Float size; length = sample->length; size = Float(length) * (key->loop + 1); min = key->pitch.min * sample->format.frequency * key->pitch.interval * 0.001F; max = key->pitch.max * sample->format.frequency * key->pitch.interval * 0.001F; cur = max; while (size > 0.0F) { f_lgt += key->pitch.interval; size -= cur = cur == min ? max : min; } if (size < 0.0F) f_lgt += key->pitch.interval * (size / cur); f_lgt *= 0.5F; } else { ULong size, loop; sample->GetLength(size); loop = (key->loop + 1) / 2; f_lgt = (size * loop) * (1.0F / key->pitch.max); loop = (key->loop + 1) - loop; f_lgt += (size * loop) * (1.0F / key->pitch.min); } length = key->start + (key->loop + 1) * key->delay_max; length += ULong(f_lgt); return ATHENA_OK; }
void Mixer::play(QString name) { Sample *sample; int offset; bool playing = false; QHash<QString, Sample*>::const_iterator i = samples.constBegin(); while (i != samples.constEnd()) { sample = (Sample *)i.value(); if (sample->playing && sample->loops!=0) { playing = true; break; } i++; } sample = samples[name]; if (playing) { offset = nframes % sample->size; } else { nframes = 0; offset = 0; } if (sample->loops && sample->playing) sample->pause(); else sample->play(offset); }
void SamplesWidget::getSamples() { bool ok; unsigned numSamples = sampleAmount->text().toUInt(&ok,10); if (ok) { Sample *sample; int numFree = 0; if (collection == NEW && sampleSet->getSize() > 1) { copySampleList(); } for (uint i = 0; i < numSamples; ++i) { sample = sampler->nextSample(); sample->setFree(!prob->wSpace()->collisionCheck(sample)); if (sample->isFree()) { ++numFree; sampleSet->add(sample); } else { delete sample; } } QString text = sampleAmount->text() + " samples were generated, " + QString::number(numFree) + " samples are free."; writeGUI(text.toUtf8().constData()); sampleAmount->setText(""); updateSampleList(); } else { writeGUI("Please, enter a valid amount of samples."); } }
void HsvFeatures::UpdateFeatureVector(const Sample &s) { IntRect rect = s.GetROI(); cv::Rect roi(rect.XMin(), rect.YMin(), rect.Width(), rect.Height()); m_featVec.setZero(); cv::Mat hsv_img = s.GetImage().GetHsvImage()(roi); int height = rect.Height(); int width = rect.Width(); // continuous? if(hsv_img.isContinuous()) { width *= height; height = 1; } int ix, iy; uchar *p; for(iy=0; iy < height; ++iy) { p = hsv_img.ptr<uchar>(iy); for(ix=0; ix < width; ++ix) { cv::Vec3b pixel(p[3*ix+0], p[3*ix+1], p[3*ix+2]); auto bin_idx = compBinIdx(pixel); m_featVec[bin_idx]++; } } m_featVec /= rect.Area(); }
RESULT PPRFA::ajoute_mots_associes (set <Word, ordre_mot> &W, const Word & v, const Sample & S, int maxmots) const { list < Word > L; // une liste de mot qui sert pour calculer W Alphabet::const_iterator b; // pour enumerer toutes les lettres Word w; // Le mot courant w.clear(); // on initialise avec w <-- epsilon // On ajoute tous les successeurs de v L.push_back (w); // et L = { eps } while ((!L.empty ()) && (maxmots != 0)) { // tant que L n'est pas vide w = L.front (); L.pop_front (); // w = min(L) et L=L\{w} if (W.find(w) == W.end()) { --maxmots; W.insert (w); } for (b = Sigma.begin (); b != Sigma.end (); b++) { w += *b; // w <-- wb //W.insert(w); if (S.find (v+w) != S.end ()) // si p_n(w)>0 { L.push_back (w); } w.erase (--w.end()); //w.pop_back (); // wb <-- w } } return VAL (0); }
int main(){ Sample s; s.a = 1; s.b =2; s.func1(); s.func2(); }
void SphereSampler::generateSamples(float, float) { clearSamples(); increaseSampleCount(); Sample tempSample; bool rejectionSampling = false; bool sampleFound = false; float x = 0.0f; float y = 0.0f; float z = 0.0f; float r = 0.0f; for (int i = 0; i < getCurrentSampleCount(); i++) { if (rejectionSampling) { while (true) { x = 2.0f * getRandomNumber(0,1) - 1.0f; y = 2.0f * getRandomNumber(0,1) - 1.0f; z = 2.0f * getRandomNumber(0,1) - 1.0f; if ((x*x + y*y + z*z) <= 1) break; } x *= radius; y *= radius; z *= radius; /*while (!sampleFound) { x = static_cast<float>(rand()) / static_cast<float>(RAND_MAX); y = static_cast<float>(rand()) / static_cast<float>(RAND_MAX); z = static_cast<float>(rand()) / static_cast<float>(RAND_MAX); if ((x*x + y*y + z*z) <= (radius *radius)) sampleFound = true;; } sampleFound = false;*/ tempSample.setOffset(Point3(x, y, z)); } /* ? = 2?r1 ? = acos(1 – 2r2) x = cx + 2Rcos(2?r1) r2(1 – r2) y = cy + 2Rsin(2?r1) r2(1 – r2) z = cz + R(1 – 2r2) */ else { float r1 = getRandomNumber(0, 1); float r2 = getRandomNumber(0, 1); /*float phi = 2 * M_PI * r1; float theta = acos(1 - (2 * r2));*/ Point3 offset; offset.x = 2 * radius * cos(2 * M_PI * r1) * sqrt(r2*(1 - r2)); offset.y = 2 * radius * sin(2 * M_PI * r1) * sqrt(r2*(1 - r2)); offset.z = radius * (1 - (2 * r2)); tempSample.setOffset(offset); } addSampleToList(tempSample); } }
void decomposeProperty(const Sample<T>& sample, PropertyBag& targetbag) { std::string tname = detail::DataSourceTypeInfo<T>::getType(); targetbag.setType("Sample"); //std::string str; assert( targetbag.empty() ); bool result =true; //std::stringstream out; //out << i+1; //str = out.str(); Property<PropertyBag>* el_bag = new Property<PropertyBag>("SampleValue", "Sample Value"); Property<T> el("SampleValue" , "Sample value ",sample.ValueGet()) ; if( el.getTypeInfo()->decomposeType(el.getDataSource(),el_bag->value()) ) { //log(Debug)<<"Element type "<<el.getType()<<" is a bag"<<endlog(); targetbag.add( el_bag ); // Put variables in the bag } else { //log(Debug)<<"Element type "<<el.getType()<<" is not a bag"<<endlog(); //For Property targetbag.add( new Property<T>("SampleValue" ,"Sample Value",sample.ValueGet() )); // Put variables in the bag } };
//! Retunrs an interpolated sample as a fraction of the distance to smp. //! Aditional, if the sample has a mapped configuration, it returns the //! interpolated configuration in the same proportion as the fraction. Sample* Sample::interpolate(Sample* smp, KthReal fraction){ Sample *tmp = new Sample(smp->getDim()); //Sample tmp(smp->getDim()); // Interpolation in sample space. vector<KthReal>& other = smp->getCoords(); for(unsigned int i = 0; i < _coords.size(); i++) tmp->_coords.at(i) = _coords.at(i) + fraction*(other.at(i) - _coords.at(i)); if(_config.size() > 0){ // Interpolation in configuration space if it exists. //RobConf tmpRobConf; vector<RobConf> tmpVec; for(unsigned int i = 0; i < _config.size(); i++){ //tmpRobConf = _config.at(i).interpolate(smp->getMappedConf().at(i)); tmpVec.push_back(_config.at(i).interpolate(smp->getMappedConf().at(i), fraction)); } tmp->setMappedConf(tmpVec); } return tmp; }
//-***************************************************************************** void OCurvesSchema::createWidthProperty( const Sample &iSamp ) { std::vector<float> emptyVals; std::vector<Util::uint32_t> emptyIndices; OFloatGeomParam::Sample empty; if ( iSamp.getWidths().getIndices() ) { empty = OFloatGeomParam::Sample( Abc::FloatArraySample( emptyVals ), Abc::UInt32ArraySample( emptyIndices ), iSamp.getWidths().getScope() ); // widths are indexed for some weird reason which is // technically ok, just wasteful m_widthsParam = OFloatGeomParam( this->getPtr(), "width", true, iSamp.getWidths().getScope(), 1, this->getTimeSampling() ); } else { empty = OFloatGeomParam::Sample( Abc::FloatArraySample( emptyVals ), iSamp.getWidths().getScope() ); // widths are not indexed m_widthsParam = OFloatGeomParam( this->getPtr(), "width", false, iSamp.getWidths().getScope(), 1, this->getTimeSampling() ); } // set all the missing samples for ( size_t i = 0; i < m_numSamples; ++i ) { m_widthsParam.set( empty ); } }
//////////////////////////////////////////////////////////////////////////////// // A helper function for loading an Allegro dat file where samples are // supposed to be stored. MAS::Error MAS::Skin::LoadSamples(ALLEGRO_PATH *dir) { if (!dir || !al_is_path_present(dir)) return Error(Error::NO_FILE); int i; const char *sampleName[] = { "SAMPLE_ACTIVATE", "SAMPLE_CLOSE", "SAMPLE_GOTFOCUS", "SAMPLE_KEY", "SAMPLE_LOSTFOCUS", "SAMPLE_OPEN", "SAMPLE_SCROLL" }; // Look for each sample inside the dat file and load it if it exists for (i=0; i<nSamples; i++) { al_set_path_filename(dir, sampleName[i]); al_set_path_extension(dir, ".wav"); const char *fullPath = al_path_cstr(dir, ALLEGRO_NATIVE_PATH_SEP); Sample spl; if (spl.Load(fullPath) == Error::NONE) { smpList[i]->Set(spl, true); } } al_set_path_filename(dir, ""); return Error(Error::NONE); }
bool Audio::Load(std::string filename, std::string name) { if (filename.length() == 0 || name.length() == 0) return false; Sample *sample = new Sample(); sample->setName(name); try { FMOD_RESULT res; res = FMOD_System_CreateSound( system, //FMOD system filename.c_str(), //filename FMOD_DEFAULT, //default audio NULL, //n/a &sample->sample); //pointer to sample if (res != FMOD_OK) { return false; } } catch (...) { return false; } samples.push_back(sample); return true; }
void FirstLayerNets::setResultExamples(std::vector<Sample> * samples) { Sample * resultSample = &(samples->at(samples->size() - 1)); for (int i = 0; i < resultSample->getExamplesCount(); i++ ) { int num = resultSample->getExamplesNum()[i]; int posInEnter = 0; int posInNeur = resultSample->enterCount; for (int j = 0; j < Nets.size(); j++) { Sample * sample = &samples->at(j); Perceptron * net = Nets[j]; double * exam = sample->examples[num]; for (int k = 0; k < net->getNeironsNum().size(); k++) { double value = net->getFunctionValue(k, exam); if (net->teachExamples.neironsToNextLevel[k]) { resultSample->setEnter(i, posInEnter, value); posInEnter ++; } else { resultSample->setEnter(i, posInNeur, value); } posInNeur ++; } } posInEnter = 0; } }
//-***************************************************************************** void OCurvesSchema::createNormalsProperty( const Sample &iSamp ) { std::vector<V3f> emptyVals; std::vector<Util::uint32_t> emptyIndices; ON3fGeomParam::Sample empty; if ( iSamp.getNormals().getIndices() ) { empty = ON3fGeomParam::Sample( Abc::V3fArraySample( emptyVals ), Abc::UInt32ArraySample( emptyIndices ), iSamp.getNormals().getScope() ); // normals are indexed m_normalsParam = ON3fGeomParam( this->getPtr(), "N", true, empty.getScope(), 1, this->getTimeSampling() ); } else { empty = ON3fGeomParam::Sample( Abc::V3fArraySample( emptyVals ), iSamp.getNormals().getScope() ); // normals are not indexed m_normalsParam = ON3fGeomParam( this->getPtr(), "N", false, empty.getScope(), 1, this->getTimeSampling() ); } // set all the missing samples for ( size_t i = 0; i < m_numSamples; ++i ) { m_normalsParam.set( empty ); } }
void Drumkit::dump() { DEBUGLOG( "Drumkit dump" ); DEBUGLOG( " |- Path = " + __path ); DEBUGLOG( " |- Name = " + __name ); DEBUGLOG( " |- Author = " + __author ); DEBUGLOG( " |- Info = " + __info ); DEBUGLOG( " |- Instrument list" ); for ( int i=0; i<__instruments->size(); i++ ) { Instrument* instrument = ( *__instruments )[i]; DEBUGLOG( QString( " |- (%1 of %2) Name = %3" ) .arg( i ) .arg( __instruments->size()-1 ) .arg( instrument->get_name() ) ); for (std::vector<InstrumentComponent*>::iterator it = instrument->get_components()->begin() ; it != instrument->get_components()->end(); ++it) { InstrumentComponent* component = *it; for ( int j=0; j<MAX_LAYERS; j++ ) { InstrumentLayer* layer = component->get_layer( j ); if ( layer ) { Sample* sample = layer->get_sample(); if ( sample ) { DEBUGLOG( QString( " |- %1 [%2]" ).arg( sample->get_filepath() ).arg( sample->is_empty() ) ); } else { DEBUGLOG( " |- NULL sample" ); } } } } } }
float Trio::maxAlleleValue(Sample & sample, const string & attribute) { auto value_1 = getFloatValue(sample.alleleInfo().at(sample.genotypeEstimate().front()), attribute); auto value_2 = getFloatValue(sample.alleleInfo().at(sample.genotypeEstimate().back()), attribute); return max(value_1, value_2); }
void SampleEditor::on_PlayOrigPushButton_clicked() { if (PlayOrigPushButton->text() == "Stop" ){ testpTimer(); return; } const int selectedlayer = InstrumentEditorPanel::get_instance()->getSelectedLayer(); Song *pSong = Hydrogen::get_instance()->getSong(); Instrument *pInstr = pSong->get_instrument_list()->get( Hydrogen::get_instance()->getSelectedInstrumentNumber() ); /* *preview_instrument deletes the last used preview instrument, therefore we have to construct a temporary *instrument. Otherwise pInstr would be deleted if consumed by preview_instrument. */ Instrument *tmpInstrument = Instrument::load_instrument( pInstr->get_drumkit_name(), pInstr->get_name() ); Sample *pNewSample = Sample::load( pInstr->get_layer( selectedlayer )->get_sample()->get_filepath() ); if ( pNewSample ){ int length = ( ( pNewSample->get_frames() / pNewSample->get_sample_rate() + 1) * 100 ); AudioEngine::get_instance()->get_sampler()->preview_instrument( tmpInstrument ); AudioEngine::get_instance()->get_sampler()->preview_sample( pNewSample, length ); m_pslframes = pNewSample->get_frames(); } m_pMainSampleWaveDisplay->paintLocatorEvent( StartFrameSpinBox->value() / m_divider + 24 , true); m_pSampleAdjustView->setDetailSamplePosition( __loops.start_frame, m_pZoomfactor , 0); m_pTimer->start(40); // update ruler at 25 fps m_pRealtimeFrameEnd = Hydrogen::get_instance()->getRealtimeFrames() + m_pslframes; PlayOrigPushButton->setText( QString( "Stop") ); }
std::vector<PqueryPlain> plain_queries( Sample const & smp ) { auto pqueries = std::vector<PqueryPlain>( smp.size() ); #pragma omp parallel for for (size_t i = 0; i < smp.size(); ++i) { const auto& opqry = smp.at(i); pqueries[i].index = i; pqueries[i].multiplicity = total_multiplicity( opqry ); pqueries[i].placements = std::vector<PqueryPlacementPlain>(opqry.placement_size()); for (size_t j = 0; j < opqry.placement_size(); ++j) { auto const& oplace = opqry.placement_at(j); auto& place = pqueries[i].placements[j]; place.edge_index = oplace.edge().index(); place.primary_node_index = oplace.edge().primary_node().index(); place.secondary_node_index = oplace.edge().secondary_node().index(); auto const& oplace_data = oplace.edge().data<PlacementEdgeData>(); place.branch_length = oplace_data.branch_length; place.pendant_length = oplace.pendant_length; place.proximal_length = oplace.proximal_length; place.like_weight_ratio = oplace.like_weight_ratio; } } return pqueries; }
void HistogramFeatures::UpdateFeatureVector(const Sample& s) { //IntRect rect = s.GetROI(); // note this truncates to integers //cv::Rect roi(rect.XMin(), rect.YMin(), rect.Width(), rect.Height()); //cv::resize(s.GetImage().GetImage(0)(roi), m_patchImage, m_patchImage.size()); m_featVec.setZero(); VectorXd hist(kNumBins); int histind = 0; for (int il = 0; il < kNumLevels; ++il) { int nc = il+1; float w = s.GetROI().Width()/nc; float h = s.GetROI().Height()/nc; FloatRect cell(0.f, 0.f, w, h); for (int iy = 0; iy < nc; ++iy) { cell.SetYMin(s.GetROI().YMin()+iy*h); for (int ix = 0; ix < nc; ++ix) { cell.SetXMin(s.GetROI().XMin()+ix*w); s.GetImage().Hist(cell, hist); m_featVec.segment(histind*kNumBins, kNumBins) = hist; ++histind; } } } m_featVec /= histind; }
void LRMachine::loadTestingSet(std::string filename) { // std::cout << "I'm loading testing set with the LRMachine from " << filename << std::endl; std::string line; std::ifstream testingFile(filename.c_str()); if(testingFile.is_open()){ while(std::getline(testingFile,line)) { Sample tmp; tmp.setInput(Utils::vStovD(Utils::split(line,';'))); std::getline(testingFile,line); std::vector<int> res; res.push_back(atoi(line.c_str())); tmp.setResult(res); C_testingSet.push_back(tmp); } testingFile.close(); } else{ std::cout << "Unable to open file" << std::endl; } }
double earth_movers_distance ( Sample const& lhs, Sample const& rhs, double const p, bool const with_pendant_length ) { // Get a tree with the average branch lengths of both provided trees. // This function also throws in case the trees have different topologies. tree::TreeSet tset; tset.add( lhs.tree(), "lhs" ); tset.add( rhs.tree(), "rhs" ); auto const avg_length_tree = tree::average_branch_length_tree( tset ); // Create an EMD tree from the average branch length tree, then calc the EMD. auto mass_tree = tree::convert_common_tree_to_mass_tree( avg_length_tree ); // Use the sum of masses as normalization factor for the masses. double totalmass_l = total_placement_mass_with_multiplicities( lhs ); double totalmass_r = total_placement_mass_with_multiplicities( rhs ); // Copy masses of both samples to the EMD tree, with different signs. double const pendant_work_l = add_sample_to_mass_tree( lhs, +1.0, totalmass_l, mass_tree ); double const pendant_work_r = add_sample_to_mass_tree( rhs, -1.0, totalmass_r, mass_tree ); // Calculate EMD. double work = tree::earth_movers_distance( mass_tree, p ).first; // If we also want the amount of work that was needed to move the placement masses from their // pendant position to the branch, we need to add those values. if( with_pendant_length ) { work += pendant_work_l + pendant_work_r; } return work; }
/* * Create file with the position of each line */ void DataSet::create_position_file(const string& file) { cout << endl; cout << "Trying to create file with all line positions ..." << endl; int pos = file.find("."); string file_tmp = file.substr(0, pos); string x_filename = file_tmp + ".pos_data"; string y_filename = file_tmp + ".pos_labels"; ofstream x_num_file(x_filename.c_str(), ios::binary); ofstream y_num_file(y_filename.c_str(), ios::binary); /* Try to open files */ ifstream xfp(x_filename_.c_str(), ios::binary); if (!xfp) { cout << "Could not open input file " << x_filename_ << endl; exit(EXIT_FAILURE); } ifstream yfp(y_filename_.c_str(), ios::binary); if (!yfp) { cout << "Could not open input file " << y_filename_ << endl; exit(EXIT_FAILURE); } /* Reading the header (first line of file)*/ int tmp; xfp >> num_samples_; xfp >> feature_dim_; yfp >> tmp; if (tmp != num_samples_) { cout << "Number of samples in data and labels file is different" << endl; exit(EXIT_FAILURE); } yfp >> tmp; x_num_file << xfp.tellg(); x_num_file << "\n"; y_num_file << yfp.tellg(); y_num_file << "\n"; /* Going through complete files */ for (int n_samp = 0; n_samp < num_samples_; n_samp++) { Sample sample; sample.x = arma::fvec(feature_dim_); yfp >> sample.y; y_num_file << yfp.tellg(); y_num_file << "\n"; for (int n_feat = 0; n_feat < feature_dim_; n_feat++) { xfp >> sample.x(n_feat); } x_num_file << xfp.tellg(); x_num_file << "\n"; } xfp.close(); yfp.close(); x_num_file.close(); y_num_file.close(); }
void Classifier::addSample(const Sample& sample, int label) { if (sample.empty()) { return; } const std::vector<float>& vector = sample.getData(); std::copy(vector.begin(), vector.end(), std::back_inserter(mData)); mLabelArray.push_back(label); }
std::vector<int> FirstLayerNets::getResultVectorIntersect(std::vector<Sample> samples) { std::vector<int> resultExamplesNum = ((Sample)samples[0]).getExamplesNum(); for (int i = 1; i < Nets.size(); i++) { Sample sample = samples[i]; resultExamplesNum = twoVectorIntersect(resultExamplesNum, sample.getExamplesNum()); } return resultExamplesNum; }
/** * @brief Main function that processes a jplace file and writes single jplace files for different * clades of the reference tree, each file containing the pqueries that fell into the clade with * more than a given threshold of accumulated likelihood weights. * * The program takes three input arguments in the following order: * * 1. A `jplace` input file. The pqueries in this file are then split into different samples. Each * such sample contains all pqueries whose placements are placed in a certain clade of the * reference tree with more than a cutoff threshold of their accumulated likelihood weight. * * According to the `jplace` standard, each pquery can have multiple possible placement positions. * Each position has a value `like_weight_ratio`, which can be interpreted as a measure of * probability of how likely the placement belongs to the branch that it is attached to. * The ratios for all branches of the tree thus sum up to 1.0. * If more of this placement mass than the threshold is placed on the branches of a single * clade of the tree, the according pquery is assigned to that clade. The threshold is * hardcoded in this demo and set to 0.95 (but can be changed if needed, of course). * * It is possible that the placement algorithm (e.g., EPA or pplacer) did not output placements * with low like_weight_ratios, depending on the selected options (see the respective manual * for more details on how to change this). This means that the provided sum might be lower * than 1.0 for some pqueries. In order to compensate for this (thus, to avoid classifying * those pqueries as uncertain), we normalize the like_weight_ratios first, so that their sum * is 1.0 again. This step thus ignores the uncertainties resulting from the placement * algorithm. * 2. A path to a file, which needs to contain a single line for each taxon of the reference tree. * Each line needs to contain a tab-separated entry that maps from a taxon of the tree to the * clade name that this taxon belongs to: * * Taxon_1 <tab> clade_a * * (where the " <tab> " of course is just a single tab character). * The taxa names need to be the same as the node names of the reference tree in the `jplace` * file. * * If a taxon in a clade file is not found on the tree, a warning is issued, and the taxon is * ignored. If the tree contains taxa which are not in any clade file, those branches are * assigned to a special clade "basal_branches". This is also the case for the inner branches * of the tree: all those branches which do not belong to one of the clades are collected in * this special clade. * * As a second special clade, the "uncertain" clade is used to collect all those pqueries * which did not fall into any clade with more than the threshold of accumulated likelihood * weights. * * The edges that belong to a clade are determined by finding the smalles subtree (split) of * the tree that contains all nodes of the clade. That means, the clades should be monophyletic * in order for this algorithm to work properly. Furthermore, the user needs to make sure that * each taxon is contained in at most one clade. Otherwise, the algorithm won't work properly. * * Remark: The rooting of the tree is insignificant for this program. Even if the root * coincidentally lies within one of the clades, the result is the same. The program does not * change the root; thus, when visualizing the clades, be aware that the tree might look * different depending on the rooting. * 3. An output directory path. For each clade (including the two special clades), a `jplace` file * named after the clade is written to that path. Each `jplace` file then contains all pqueries * that were assigned to that clade. * * A typical use case for this program is to extract pqueries that were placed in a particular * clade of interest in an evolutionary placement analysis. The extracted placements can then be * further examined in downstream analyses. * * It is also possible to do a second run of evolutionary placement with the original sequences of * the pqueries of one clade, using a refined reference tree for that clade with a higher resolution * (more reference taxa). This two-step placement approach allows for finely grained * placement positions while keeping the computational load relatively small. */ int main( int argc, char** argv ) { using namespace ::genesis::placement; // Threshold for how much placement mass needs to be in one clade // in order to assign a pquery to it. const double threshold = 0.95; // Activate logging, print genesis header. utils::Logging::log_to_stdout(); LOG_BOLD << genesis_header(); // Check if the command line contains the right number of arguments and store them. if (argc != 4) { throw std::runtime_error( "Need to provide three command line arguments:\n" " * An input jplace file path.\n" " * A clade file.\n" " * An output directory path." ); } auto jplace_filename = std::string( argv[1] ); auto clade_filename = std::string( argv[2] ); auto output_dir = utils::trim_right( std::string( argv[3] ), "/") + "/"; // Some user output. LOG_INFO << "Using jplace file " << jplace_filename; LOG_INFO << "Using clade file " << clade_filename; LOG_INFO << "Using output directory " << output_dir; // Read the taxa of all clades. auto clades = get_clade_taxa_lists( clade_filename ); LOG_INFO << "Found " << clades.size() << " clades"; // Read the Jplace file into a Sample object. Sample sample = JplaceReader().read( utils::from_file( jplace_filename )); // Normalize the like_weight_ratios. This step makes sure that missing placement weights do not // lead to a pquery being placed in the uncertain clade. That means, we only use the provided // placement masses as given in the jplace files, and scale them so that they sum up to 1.0. // In turn, this means that uncertainties resulting from the placement algorithm are ignored. normalize_weight_ratios( sample ); // Get a list of the edges per clade of the reference tree. auto clade_edges = get_clade_edges( clades, sample.tree() ); // Get a sample set that contains a sample per clade. // Each sample then has the pqueries from the original sample that fell into that clade. auto sample_set = extract_pqueries( clade_edges, sample, threshold ); // Write everything to jplace files. write_sample_set( sample_set, output_dir ); LOG_INFO << "Finished."; return 0; }
void useCase() { Sample s; Point p; Date d; //populate s p.x = 30; p.y = 60; d.d = 1; d.m = 5; d.y = 2012; d.place = p; s.setByValProp( d ); s.circularRef = &s; s.setDoubleProp( 344.23 ); s.setStdStringProp( "Hello!!!" ); //set the property intMember of s object to 15 jrtti::metatype< Sample >().property( "intMember" ).set( &s, 15 ); std::cout << s.intMember << " == " << 15 << std::endl; //retrieve the value of intMember from s object int i = jrtti::metatype< Sample >().property( "intMember" ).get<int>( &s ); std::cout << s.intMember << " == " << i << std::endl; //same as above using braket operator i = jrtti::metatype< Sample >()[ "intMember" ].get<int>( &s ); std::cout << s.intMember << " == " << i << std::endl; //getting a Metatype object jrtti::Metatype & mt = jrtti::metatype< Sample >(); //and working with it p.x = 23; mt[ "point" ].set( &s, &p ); std::cout << 23 << " == " << s.getByPtrProp()->x << std::endl; //call a method without parameters returning void mt.call<void>( "testMethod", &s ); //call a method returning int and having two parameters double f = mt.call<double,Sample,int,double>( "testSum", &s, 3, 8 ); std::cout << 3+8 << " == " << f << std::endl; //or f = mt.call<double>( "testSum", &s, 3, 8.0 ); std::cout << 3+8 << " == " << f << std::endl; //set value from a fully qualified path mt.apply( &s, "date.place.x", 25.0 ); //get value from a fully qualified path f = mt.eval<double>( &s, "date.place.x" ); std::cout << 25 << " == " << f << std::endl; //get a string representation of s object std::string contens = mt.toStr( &s ); //get a streamable string representation of s objecy contens = mt.toStr( &s, true ); //and set the s object from a string representation mt.fromStr( &s, contens ); std::cout << contens << std::endl; }
int main(int argc, const char** argv) { NVPWindow::System system(argv[0], PROJECT_NAME); Sample sample; return sample.run( PROJECT_NAME, argc, argv, 768, 512); }
//-***************************************************************************** void OCurvesSchema::calcBasisAndType(Alembic::Util::uint8_t (&basisAndType)[4], const Sample &iSamp) { basisAndType[0] = iSamp.getType(); basisAndType[1] = iSamp.getWrap(); basisAndType[2] = iSamp.getBasis(); // repeat so we don't have to change the data layout and bump up // the version number basisAndType[3] = basisAndType[2]; }