folly::Future<int32_t> service_with_special_namesSvIf::future_annotations() {
  return apache::thrift::detail::si::future([&] { return annotations(); });
}
Beispiel #2
0
// perform classification in separate threads
void Classifier::runThread(FastaReader &reader)
{
    DnaSequence seq;
    boost::mt19937 randGen(0);
    RandomGen generator(randGen);

    while(seq = reader.readSequence())
    {
        // reproducible randomness
        randGen.seed(reader.numRead());

        // get a query sequence and convert to kmers
        KmerSequence fwdSeq = kmerizer_.kmerize(seq);
        
        // and the reverse complement
        KmerSequence revSeq = kmerizer_.revComp(fwdSeq);
        
        // search against database using both forward and reverse sequences
        searchHit fwdHit = referenceData_.search(fwdSeq);
        searchHit revHit = referenceData_.search(revSeq);

        // use the direction which gave the highest scoring hit
        KmerSequence &querySeq = fwdHit.score > revHit.score ? fwdSeq : revSeq;
        searchHit &hit = fwdHit.score > revHit.score ? fwdHit : revHit;

        std::vector<float> bootstraps(referenceData_.numLevels(), 0.f);
        std::vector<std::string> annotations(referenceData_.numLevels(), "AMBIGUOUS");
       
        // make each level annotations into a list of uniques
        for (unsigned int i=0; i< hit.annotationIds.size(); i++)
        {
            std::sort(hit.annotationIds[i].begin(), hit.annotationIds[i].end());
            std::vector<unsigned int>::iterator it;
            it = std::unique(hit.annotationIds[i].begin(), hit.annotationIds[i].end());
            hit.annotationIds[i].resize(std::distance(hit.annotationIds[i].begin(), it));
            if (hit.annotationIds[i].size() == 1)
                annotations[i] = referenceData_.annotationFromId(*hit.annotationIds[i].begin());
        }

        // bootstrap
        if(numBootstrap_ > 0)
            bootstraps = getBootstrap(querySeq, generator, hit);
       
        // output        
        std::stringstream s;
        s << std::setprecision(2) << std::fixed;
        s << querySeq.header.substr(0, querySeq.header.find("\t")) << "\t";
        s << hit.score << "\t";

        //for(unsigned int i=0; i<bootstraps.size(); i++)
        unsigned int i=bootstraps.size();
        while(i--)
        {
            s << annotations[i] << "\t";
            s << bootstraps[i];
            if(i>0)
            {
                s <<  "\t";
            }
            else
            {
                // dump ambiguous species
                if (hit.annotationIds[i].size() > 1 && outputAmbiguous_)
                { 
                    s << "\t";
                    for(std::vector<unsigned int>::iterator it = hit.annotationIds[i].begin(); it != hit.annotationIds[i].end(); ++it)
                    {
                        if (it != hit.annotationIds[i].begin())
                            s << ",";
            
                        s << referenceData_.annotationFromId(*it);
                    }
                }
            
                s << std::endl;
            }
        }
      
        boost::mutex::scoped_lock lock(mutex_);
        std::cout << s.str();
    }
}