Esempio n. 1
0
void testSingleRateModel(Params &params, NGSAlignment &aln, NGSTree &tree, string model,
                         double *freq, DoubleVector &rate_info, StrVector &rate_name,
                         bool write_info, const char *report_file)
{
    char model_name[20];
    NGSAlignment sum_aln(aln.num_states, 1, freq);
    ModelsBlock *models_block = new ModelsBlock;

    NGSTree sum_tree(params, &sum_aln);
    sum_aln.tree = &sum_tree;

    if (model == "")
        sprintf(model_name, "GTR+F1");
    else
        sprintf(model_name, "%s+F1", model.c_str());
    try {
        params.model_name = model_name;
        sum_tree.setModelFactory(new ModelFactory(params, &sum_tree, models_block));
        sum_tree.setModel(sum_tree.getModelFactory()->model);
        sum_tree.setRate(sum_tree.getModelFactory()->site_rate);
        double bestTreeScore = sum_tree.getModelFactory()->optimizeParameters(false, write_info);
        cout << "LogL: " << bestTreeScore;
        cout << " / Rate: " << sum_tree.getRate()->getRate(0) << endl;
    } catch (...) {
        cout << "Skipped due to sparse matrix" << endl;
        //rate_info.push_back(MIN_SITE_RATE);
        rate_info.insert(rate_info.end(), rate_name.size(), MIN_SITE_RATE);
        return;
    }
    //return sum_tree.getRate()->getRate(0);
    rate_info.push_back(sum_tree.getRate()->getRate(0));

    double *rate_mat = new double[aln.num_states*aln.num_states];
    memset(rate_mat, 0, aln.num_states*aln.num_states*sizeof(double));
    sum_tree.getModel()->getRateMatrix(rate_mat);
    rate_info.insert(rate_info.end(), rate_mat, rate_mat+sum_tree.getModel()->getNumRateEntries());

    if (tree.getModel()->isReversible()) {
        sum_tree.getModel()->getStateFrequency(rate_mat);
        rate_info.insert(rate_info.end(), rate_mat, rate_mat+aln.num_states);
    }
	delete [] rate_mat;
	delete models_block;

    if (report_file) {
        DoubleMatrix tmp(1);
        tmp[0] = rate_info;
        reportNGSAnalysis(report_file, params, sum_aln, sum_tree, tmp, rate_name);
    }
}
Esempio n. 2
0
void runttgamma(TString sample="all", TString ExtraOpts= "", int workers=8)
{

  //TProof *proof = getProof("lite://",nwrks);
  TString proofOpt(Form("workers=%i",workers));
  //TProof *proof = TProof::Open(proofOpt);
  //if (!proof) {
  //  Printf("runProof: could not start/attach a PROOF session");
  //  return;
  //}

  //proof->SetLogLevel(2); // verbose

  TChain *chain = new TChain("ggNtuplizer/EventTree");
  StrVecMap::iterator ite;//
  bool foundSample = false;
  for ( ite = vsamples.begin(); ite != vsamples.end(); ++ite) {//
    
    std::string name(sample.Data());
    std::string tmpname = (*ite).first;
    if ( name != "all" && name != tmpname ) continue;
    foundSample = true;
    if ( name == "all" ) name = tmpname;
    StrVector location = vsamples[name];
    cout<< "Input sample: "<< name << endl;
    //StrVecMap::iterator ite;
    //for (ite = location.begin(); ite != location.end(); ++ite) {
    for ( size_t i=0; i < location.size(); ++i ) {
    
      //chain->Add(location.c_str());
      chain->Add( location[i].c_str() );
    }
    cout << "List of files:" << endl;
    chain->ls();
    cout << endl;
    //chain->SetProof(); // to run in PROOF mode
    TString opts(Form("sample=%s",name.c_str()));
    if (ExtraOpts != "" ) opts = ExtraOpts + " " + opts;

    ttgamma3 *myselector = new ttgamma3();

    //chain->Process("ttgamma3.C",opts.Data() );
    chain->Process(myselector, opts.Data() );
    cout << "Process: ttgamma.C done" << endl;

  }
  // logs
  
  //TList *logList = proof->GetManager()->GetSessionLogs()->GetListOfLogs();
  //for (int i=1; i< logList->GetSize(); ++i)
  //  {
  //    TProffLogElem *logElem = ( TProofLogElem* ) logList->At( i );
  //    macro = logElem->GetMacro();
  //    macro->SaveSource("data_muons_"+TString(Form("%i",i))+".stdout");
  //  }
  

  //chain->SetProof(0);
  //chain->Delete();
  //delete chain;
  //proof->ClearInput();
  //proof->ClearData();
  //proof->ClearInputData();
  //delete proof;
  if ( foundSample )
    cout << "runttgamma done"<<endl;
  else
    cout << "Error: No sample found with name: " << sample.Data() << endl;
}