//--------------------------------------------------------------------------- void TEstimation::getPosteriorHDI(int param, float q, float* lower, float* upper){ //get shortest interval of fraction q //I assume an unimodal distribution, therefore, just adding bins from the largest to the smallest until q is reached //since two values have to be returned, the results are written to a passed variable ColumnVector d=posteriorMatrix.column(param).AsColumn(); SortDescending(d); float areaPosterior=getArea(posteriorMatrix.column(param), theta); float area=0; float criticalDensity=0; for(int k=1;k<=posteriorDensityPoints;++k){ criticalDensity=d(k); area+=step*d(k)/areaPosterior; if(area>q) break; } //now find coordinates float minK=0; for(int k=1;k<=posteriorDensityPoints;++k){ if(posteriorMatrix(k,param)>criticalDensity){ minK=k; break; } } float maxK=0; for(int k=posteriorDensityPoints;k>0;--k){ if(posteriorMatrix(k,param)>criticalDensity){ maxK=k; break; } } //now get area within interval if(minK==maxK){ cout << "\nWARNING: Problems calculating the HDI for parameter '" + mySimData->paramNames[param-1] + "'!"; *lower=0; *upper=0; } else { area=0; for(int k=(minK+1);k<maxK;++k) area+=step*posteriorMatrix(k,param); area=area/areaPosterior; float dif=area-q; //how much to add? float missing=dif/((posteriorMatrix(minK,param)+posteriorMatrix(maxK,param))/areaPosterior); *lower=theatParameterScale(param, minK)-missing*step; *upper=theatParameterScale(param, maxK)+missing*step; } }
int main(int argc, char *argv[]) { MyCmdLine(argc, argv); if (argc < 2) { Usage(); return 0; } if (opt_version) { printf("uchime v" MY_VERSION ".%s\n", SVN_VERSION); return 0; } printf("uchime v" MY_VERSION ".%s\n", SVN_VERSION); printf("by Robert C. Edgar\n"); printf("http://drive5.com/uchime\n"); printf("This code is donated to the public domain.\n"); printf("\n"); if (!optset_w) opt_w = 8; float MinFractId = 0.95f; if (optset_id) MinFractId = (float) opt_id; Log("%8.2f minh\n", opt_minh); Log("%8.2f xn\n", opt_xn); Log("%8.2f dn\n", opt_dn); Log("%8.2f xa\n", opt_xa); Log("%8.2f mindiv\n", opt_mindiv); Log("%8u maxp\n", opt_maxp); if (opt_input == "" && opt_uchime != "") opt_input = opt_uchime; if (opt_input == "") Die("Missing --input"); g_UchimeDeNovo = (opt_db == ""); if (opt_uchimeout != "") g_fUChime = CreateStdioFile(opt_uchimeout); if (opt_uchimealns != "") g_fUChimeAlns = CreateStdioFile(opt_uchimealns); SeqDB Input; SeqDB DB; Input.FromFasta(opt_input); if (!Input.IsNucleo()) Die("Input contains amino acid sequences"); const unsigned QuerySeqCount = Input.GetSeqCount(); vector<unsigned> Order; for (unsigned i = 0; i < QuerySeqCount; ++i) Order.push_back(i); if (g_UchimeDeNovo) { vector<float> Abs; for (unsigned i = 0; i < QuerySeqCount; ++i) { const char *Label = Input.GetLabel(i); float Ab = GetAbFromLabel(Label); Abs.push_back(Ab); } SortDescending(Abs, Order); DB.m_IsNucleoSet = true; DB.m_IsNucleo = true; } else { DB.FromFasta(opt_db); if (!DB.IsNucleo()) Die("Database contains amino acid sequences"); } vector<ChimeHit2> Hits; unsigned HitCount = 0; for (unsigned i = 0; i < QuerySeqCount; ++i) { unsigned QuerySeqIndex = Order[i]; SeqData QSD; Input.GetSeqData(QuerySeqIndex, QSD); float QAb = -1.0; if (g_UchimeDeNovo) QAb = GetAbFromLabel(QSD.Label); ChimeHit2 Hit; AlnParams &AP = *(AlnParams *) 0; AlnHeuristics &AH = *(AlnHeuristics *) 0; HSPFinder &HF = *(HSPFinder *) 0; bool Found = SearchChime(DB, QSD, QAb, AP, AH, HF, MinFractId, Hit); if (Found) ++HitCount; else { if (g_UchimeDeNovo) DB.AddSeq(QSD.Label, QSD.Seq, QSD.L); } WriteChimeHit(g_fUChime, Hit); ProgressStep(i, QuerySeqCount, "%u/%u chimeras found (%.1f%%)", HitCount, i, Pct(HitCount, i+1)); } Log("\n"); Log("%s: %u/%u chimeras found (%.1f%%)\n", opt_input.c_str(), HitCount, QuerySeqCount, Pct(HitCount, QuerySeqCount)); CloseStdioFile(g_fUChime); CloseStdioFile(g_fUChimeAlns); ProgressExit(); return 0; }
//----------------------------------------------------------------------- void MeshInfo::getMeshInformation( Ogre::MeshPtr mesh, const Vector3 &position, const Quaternion &orient, const Vector3 &scale) { size_t vertexCount = 0; size_t indexCount = 0; Vector3* vertices = 0; Vector3* normals; unsigned long* indices = 0; bool added_shared = false; size_t current_offset = 0; size_t shared_offset = 0; size_t next_offset = 0; size_t index_offset = 0; // Calculate how many vertices and indices we're going to need for ( unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i) { Ogre::SubMesh* submesh = mesh->getSubMesh( i ); // We only need to add the shared vertices once if(submesh->useSharedVertices) { if( !added_shared ) { vertexCount += mesh->sharedVertexData->vertexCount; added_shared = true; } } else { vertexCount += submesh->vertexData->vertexCount; } // Add the indices indexCount += submesh->indexData->indexCount; } // Allocate space for the vertices and indices vertices = new Vector3[vertexCount]; normals = new Vector3[vertexCount]; indices = new unsigned long[indexCount]; added_shared = false; // Run through the submeshes again, adding the data into the arrays for ( unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i) { Ogre::SubMesh* submesh = mesh->getSubMesh(i); Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData; if((!submesh->useSharedVertices)||(submesh->useSharedVertices && !added_shared)) { if(submesh->useSharedVertices) { added_shared = true; shared_offset = current_offset; } const Ogre::VertexElement* posElem = vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION); const Ogre::VertexElement* normalElem = vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_NORMAL); Ogre::HardwareVertexBufferSharedPtr vbuf = vertex_data->vertexBufferBinding->getBuffer(posElem->getSource()); unsigned char* vertex = static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY)); float* pReal; for( size_t j = 0; j < vertex_data->vertexCount; ++j, vertex += vbuf->getVertexSize()) { posElem->baseVertexPointerToElement(vertex, &pReal); Vector3 pt(pReal[0], pReal[1], pReal[2]); vertices[current_offset + j] = (orient * (pt * scale)) + position; normalElem->baseVertexPointerToElement(vertex, &pReal); Vector3 nt(pReal[0], pReal[1], pReal[2]); normals[current_offset + j] = nt; } vbuf->unlock(); next_offset += vertex_data->vertexCount; } Ogre::IndexData* index_data = submesh->indexData; size_t numTris = index_data->indexCount / 3; Ogre::HardwareIndexBufferSharedPtr ibuf = index_data->indexBuffer; bool use32bitindexes = (ibuf->getType() == Ogre::HardwareIndexBuffer::IT_32BIT); unsigned long* pLong = static_cast<unsigned long*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY)); unsigned short* pShort = reinterpret_cast<unsigned short*>(pLong); size_t offset = (submesh->useSharedVertices)? shared_offset : current_offset; size_t numTrisMultThree = numTris*3; if ( use32bitindexes ) { for ( size_t k = 0; k < numTrisMultThree; ++k) { indices[index_offset++] = pLong[k] + static_cast<unsigned long>(offset); } } else { for ( size_t k = 0; k < numTrisMultThree; ++k) { indices[index_offset++] = static_cast<unsigned long>(pShort[k]) + static_cast<unsigned long>(offset); } } ibuf->unlock(); current_offset = next_offset; } // Create triangles from the retrieved data for (size_t k = 0; k < indexCount-1; k+=3) { Triangle t; t.v1 = vertices [indices[k]]; t.vn1 = normals [indices[k]]; t.v2 = vertices [indices[k+1]]; t.vn2 = normals [indices[k+1]]; t.v3 = vertices [indices[k+2]]; t.vn3 = normals [indices[k+2]]; t.calculateSquareSurface(); t.calculateSurfaceNormal(); t.calculateEdgeNormals(); _triangles.push_back(t); } // Delete intermediate arrays delete [] indices; delete [] normals; delete [] vertices; // Sort the triangle on their size, if needed (only if a gaussian random number generator // function is used to perform a random lookup of a triangle) if (mDistribution == MSD_HOMOGENEOUS) sort(_triangles.begin(), _triangles.end(), SortDescending()); else if (mDistribution == MSD_HETEROGENEOUS_1) sort(_triangles.begin(), _triangles.end(), SortAscending()); }