当前位置: 首页>>代码示例>>C++>>正文


C++ TextFile::addLine方法代码示例

本文整理汇总了C++中TextFile::addLine方法的典型用法代码示例。如果您正苦于以下问题:C++ TextFile::addLine方法的具体用法?C++ TextFile::addLine怎么用?C++ TextFile::addLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TextFile的用法示例。


在下文中一共展示了TextFile::addLine方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: store

  void EDTAFile::store(const String& filename, const FeatureMap& map) const
  {
    TextFile tf;
    tf.addLine("RT\tm/z\tintensity\tcharge");

    for (Size i = 0; i < map.size(); ++i)
    {
      const Feature& f = map[i];
      tf.addLine(String(f.getRT()) + "\t" + f.getMZ() + "\t" + f.getIntensity() + "\t" + f.getCharge());
    }

    tf.store(filename);

  }
开发者ID:BioinformaticsArchive,项目名称:OpenMS,代码行数:14,代码来源:EDTAFile.cpp

示例2: writeTermTree_

 void writeTermTree_(const String& accession, const ControlledVocabulary& cv, TextFile& file, UInt indent)
 {
   const ControlledVocabulary::CVTerm& term = cv.getTerm(accession);
   for (set<String>::const_iterator it = term.children.begin(); it != term.children.end(); ++it)
   {
     const ControlledVocabulary::CVTerm& child_term = cv.getTerm(*it);
     String subterm_line;
     for (Size i = 0; i < 4 * indent; ++i) subterm_line += "&nbsp;";
     String description = child_term.description;
     if (child_term.synonyms.size() != 0)
     {
       description += String(" -- Synonyms: '") + ListUtils::concatenate(child_term.synonyms, ", ") + "'";
     }
     subterm_line += "- <span title=\"" + description + "\">" + child_term.id + " ! " + child_term.name + "</span>";
     StringList tags;
     if (child_term.obsolete)
     {
       tags.push_back("<font color=darkred>obsolete</font>");
     }
     if (child_term.xref_type != ControlledVocabulary::CVTerm::NONE)
     {
       tags.push_back("value-type=" + ControlledVocabulary::CVTerm::getXRefTypeName(child_term.xref_type));
     }
     if (child_term.units.size() > 0)
     {
       StringList units;
       for (set<String>::const_iterator u_it = child_term.units.begin(); u_it != child_term.units.end(); ++u_it)
       {
         units.push_back(*u_it + "!" + cv.getTerm(*u_it).name);
       }
       tags.push_back(String("units=") + ListUtils::concatenate(units, ","));
     }
     if (child_term.xref_binary.size() > 0)
     {
       StringList types;
       for (StringList::const_iterator u_it = child_term.xref_binary.begin(); u_it != child_term.xref_binary.end(); ++u_it)
       {
         types.push_back(*u_it + "!" + cv.getTerm(*u_it).name);
       }
       tags.push_back(String("binary-array-types=") + ListUtils::concatenate(types, ","));
     }
     if (tags.size() != 0)
     {
       subterm_line += String("<FONT color=\"grey\"> (") + ListUtils::concatenate(tags, ", ") + ")</FONT>";
     }
     file.addLine(subterm_line + "<BR>");
     writeTermTree_(child_term.id, cv, file, indent + 1);
   }
 }
开发者ID:BioinformaticsArchive,项目名称:OpenMS,代码行数:49,代码来源:CVInspector.cpp

示例3: main_


//.........这里部分代码省略.........
        tf_single_header1 << "" << "";
        tf_single_header2 << "RT" << "mz";
      }

      // 5 entries for each input file
      tf_single_header0 << File::basename(in[fi]) << "" << "" << "" << "";
      tf_single_header1 << description << "" << "" << "" << "";
      tf_single_header2 << "RTobs" << "dRT" << "mzobs" << "dppm" << "intensity";

      for (Size i = 0; i < cm.size(); ++i)
      {
        //std::cerr << "Rt" << cm[i].getRT() << "  mz: " << cm[i].getMZ() << " R " <<  cm[i].getMetaValue("rank") << "\n";

        double mz_da = mztol * cm[i].getMZ() / 1e6; // mz tolerance in Dalton
        MSExperiment<>::ConstAreaIterator it = exp.areaBeginConst(cm[i].getRT() - rttol / 2,
                                                                  cm[i].getRT() + rttol / 2,
                                                                  cm[i].getMZ() - mz_da,
                                                                  cm[i].getMZ() + mz_da);
        Peak2D max_peak;
        max_peak.setIntensity(0);
        max_peak.setRT(cm[i].getRT());
        max_peak.setMZ(cm[i].getMZ());
        for (; it != exp.areaEndConst(); ++it)
        {
          if (max_peak.getIntensity() < it->getIntensity())
          {
            max_peak.setIntensity(it->getIntensity());
            max_peak.setRT(it.getRT());
            max_peak.setMZ(it->getMZ());
          }
        }
        double ppm = 0; // observed m/z offset

        if (max_peak.getIntensity() == 0)
        {
          ++not_found;
        }
        else
        {
          // take median for m/z found
          std::vector<double> mz;
          MSExperiment<>::Iterator itm = exp.RTBegin(max_peak.getRT());
          SignedSize low = std::min<SignedSize>(std::distance(exp.begin(), itm), rt_collect);
          SignedSize high = std::min<SignedSize>(std::distance(itm, exp.end()) - 1, rt_collect);
          MSExperiment<>::AreaIterator itt = exp.areaBegin((itm - low)->getRT() - 0.01, (itm + high)->getRT() + 0.01, cm[i].getMZ() - mz_da, cm[i].getMZ() + mz_da);
          for (; itt != exp.areaEnd(); ++itt)
          {
            mz.push_back(itt->getMZ());
            //std::cerr << "ppm: " << itt.getRT() << " " <<  itt->getMZ() << " " << itt->getIntensity() << std::endl;
          }

          if ((SignedSize)mz.size() > (low + high + 1)) LOG_WARN << "Compound " << i << " has overlapping peaks [" << mz.size() << "/" << low + high + 1 << "]" << std::endl;

          if (!mz.empty())
          {
            double avg_mz = std::accumulate(mz.begin(), mz.end(), 0.0) / double(mz.size());
            //std::cerr << "avg: " << avg_mz << "\n";
            ppm = (avg_mz - cm[i].getMZ()) / cm[i].getMZ() * 1e6;
          }

        }

        // appending the second column set requires separator
        String append_sep = (fi == 0 ? "" : out_sep);

        vec_single[i] += append_sep; // new line
        if (fi == 0)
        {
          vec_single[i] += String(cm[i].getRT()) + out_sep +
                           String(cm[i].getMZ()) + out_sep;
        }
        vec_single[i] += String(max_peak.getRT()) + out_sep +
                         String(max_peak.getRT() - cm[i].getRT()) + out_sep +
                         String(max_peak.getMZ()) + out_sep +
                         String(ppm)  + out_sep +
                         String(max_peak.getIntensity());
      }

      if (not_found) LOG_INFO << "Missing peaks for " << not_found << " compounds in file '" << in[fi] << "'.\n";
    }

    //-------------------------------------------------------------
    // create header
    //-------------------------------------------------------------
    vec_single.insert(vec_single.begin(), ListUtils::concatenate(tf_single_header2, out_sep));
    vec_single.insert(vec_single.begin(), ListUtils::concatenate(tf_single_header1, out_sep));
    vec_single.insert(vec_single.begin(), ListUtils::concatenate(tf_single_header0, out_sep));

    //-------------------------------------------------------------
    // writing output
    //-------------------------------------------------------------
    TextFile tf;
    for (std::vector<String>::iterator v_it = vec_single.begin(); v_it != vec_single.end(); ++v_it)
    {
      tf.addLine(*v_it);
    }
    tf.store(out);

    return EXECUTION_OK;
  }
开发者ID:BioinformaticsArchive,项目名称:OpenMS,代码行数:101,代码来源:EICExtractor.cpp

示例4: main_


//.........这里部分代码省略.........
    Size one_match = count(features_truth, "matches", "1");
    cout << "one match: " << one_match << percentage(one_match, features_truth.size()) << endl;
    Size charge_match = count(features_truth, "correct_charge", "true");
    cout << " - correct charge: " << charge_match << percentage(charge_match, features_truth.size()) << endl;
    Size centroid_match = count(features_truth, "exact_centroid_match", "true");
    cout << " - exact centroid match: " << centroid_match << percentage(centroid_match, features_truth.size()) << endl;
    Size multi_match = features_truth.size() - count(features_truth, "matches", "0") - count(features_truth, "matches", "1");
    cout << "multiple matches: " << multi_match << percentage(multi_match, features_truth.size()) << endl;
    Size incorrect_match = multi_match + one_match - charge_match;
    cout << "incorrect matches: " << incorrect_match << percentage(incorrect_match, features_truth.size()) << endl;
    if (abort_reasons.size())
    {
      cout << "reasons for unmatched features:" << endl;
      for (Map<String, UInt>::iterator it = abort_strings.begin(); it != abort_strings.end(); ++it)
      {
        cout << " - " << String(it->second).fillLeft(' ', 4) << ": " << it->first << endl;
      }
    }
    //------------------------ intensity ------------------------
    cout << endl;
    cout << "intensity statistics:" << endl;
    cout << "=====================" << endl;
    if (ints_i.empty())
    {
      cout << "correlation of found features: nan" << endl;
    }
    else
    {
      cout << "correlation of found features: " << pearsonCorrelationCoefficient(ints_i.begin(), ints_i.end(), ints_t.begin(), ints_t.end()) << endl;
    }
    if (ints_found.empty())
    {
      cout << "intensity distribution of found: 0.0 0.0 0.0 0.0 0.0" << endl;
    }
    else
    {
      cout << "intensity distribution of found: " << fiveNumbers(ints_found, 1) << endl;
    }
    if (ints_missed.empty())
    {
      cout << "intensity distribution of missed: 0.0 0.0 0.0 0.0 0.0" << endl;
    }
    else
    {
      cout << "intensity distribution of missed: " << fiveNumbers(ints_missed, 1) << endl;
    }

    //------------------------ charges ------------------------
    cout << endl;
    cout << "charge matches statistics:" << endl;
    cout << "===========================" << endl;
    Map<UInt, UInt> present_charges, found_charges;
    for (Size i = 0; i < features_truth.size(); ++i)
    {
      UInt charge = features_truth[i].getCharge();
      present_charges[charge]++;
      if (features_truth[i].getMetaValue("correct_charge").toString() == "true")
      {
        found_charges[charge]++;
      }
    }
    for (Map<UInt, UInt>::const_iterator it = present_charges.begin(); it != present_charges.end(); ++it)
    {
      cout << "charge " << it->first << ": " << found_charges[it->first] << "/" << it->second << percentage(found_charges[it->first], it->second) << endl;
    }

    //write output
    if (getStringOption_("out") != "")
    {
      FeatureXMLFile().store(getStringOption_("out"), features_truth);
    }

    //ROC curve
    if (getStringOption_("out_roc") != "")
    {
      TextFile tf;
      tf.addLine("false\tcorrect\tFDR\tTPR");

      features_in.sortByIntensity(true);
      UInt f_correct = 0;
      UInt f_false = 0;
      double found = features_in.size();
      double correct = features_truth.size();
      for (Size i = 0; i < features_in.size(); ++i)
      {
        if (features_in[i].metaValueExists("correct_hit"))
        {
          ++f_correct;
        }
        else
        {
          ++f_false;
        }
        tf.addLine(String(f_false) + "\t" + f_correct + "\t" + String::number(f_false / found, 3) + "\t" + String::number(f_correct / correct, 3));
      }
      tf.store(getStringOption_("out_roc"));
    }

    return EXECUTION_OK;
  }
开发者ID:grosenberger,项目名称:OpenMS,代码行数:101,代码来源:FFEval.cpp

示例5: main_

  ExitCodes main_(int, const char**)
  {
    //----------------------------------------------------------------
    // load data
    //----------------------------------------------------------------
    StringList in_list = getStringList_("in");
    String out = getStringOption_("out");
    String out_csv = getStringOption_("out_csv");
    String format = getStringOption_("out_type");

    if (out.empty() && out_csv.empty())
    {
      LOG_ERROR << "Neither 'out' nor 'out_csv' were provided. Please assign at least one of them." << std::endl;
      return ILLEGAL_PARAMETERS;
    }

    if (!out.empty() && format == "") // get from filename
    {
      try
      {
        format = out.suffix('.');
      }
      catch (Exception::ElementNotFound& /*e*/)
      {
        format = "nosuffix";
      }
      // check if format is valid:
      if (!ListUtils::contains(out_formats_, format.toLower()))
      {
        LOG_ERROR << "No explicit image output format was provided via 'out_type', and the suffix ('" << format << "') does not resemble a valid type. Please fix one of them." << std::endl;
        return ILLEGAL_PARAMETERS;
      }
    }

    double q_min = getDoubleOption_("q_min");
    double q_max = getDoubleOption_("q_max");
    if (q_min >= q_max)
    {
      LOG_ERROR << "The parameter 'q_min' must be smaller than 'q_max'. Quitting..." << std::endl;
      return ILLEGAL_PARAMETERS;
    }


    IDEvaluationBase* mw = new IDEvaluationBase();
    Param alg_param = mw->getParameters();
    alg_param.insert("", getParam_().copy("algorithm:", true));
    mw->setParameters(alg_param);

    if (!mw->loadFiles(in_list))
    {
      LOG_ERROR << "Tool failed. See above." << std::endl;
      return INCOMPATIBLE_INPUT_DATA;
    }
    mw->setVisibleArea(q_min, q_max);

    if (!out.empty()) // save as image and exit
    {
      String error;
      bool r = mw->exportAsImage(out.toQString(), error, format.toQString());
      if (r) return EXECUTION_OK;
      else
      {
        LOG_ERROR << error << std::endl;
        return ILLEGAL_PARAMETERS;
      }
    }

    if (!out_csv.empty())
    {
      TextFile tf;
      for (Size i = 0; i < mw->getPoints().size(); ++i)
      {
        MSSpectrum s = mw->getPoints()[i];
        StringList sl1;
        StringList sl2;
        for (Size j = 0; j < s.size(); ++j)
        {
          sl1.push_back(s[j].getMZ());
          sl2.push_back(s[j].getIntensity());
        }
        tf.addLine(String("# ") + String(s.getMetaValue("search_engine")));
        tf.addLine(ListUtils::concatenate(sl1, ","));
        tf.addLine(ListUtils::concatenate(sl2, ","));
      }
      tf.store(out_csv);
    }

    delete(mw);
    return EXECUTION_OK;
  }
开发者ID:FabianAicheler,项目名称:OpenMS,代码行数:90,代码来源:IDEvaluator.cpp

示例6: store

  void IBSpectraFile::store(const String& filename, const ConsensusMap& cm)
  {
    // typdefs for shorter code
    typedef std::vector<ProteinHit>::iterator ProtHitIt;

    // general settings .. do we need to expose these?
    // ----------------------------------------------------------------------
    /// Allow also non-unique peptides to be exported
    bool allow_non_unique = true;
    /// Intensities below this value will be set to 0.0 to avoid numerical problems when quantifying
    double intensity_threshold = 0.00001;
    // ----------------------------------------------------------------------


    // guess experiment type
    boost::shared_ptr<IsobaricQuantitationMethod> quantMethod = guessExperimentType_(cm);

    // we need the protein identifications to reference the protein names
    ProteinIdentification protIdent;
    bool has_proteinIdentifications = false;
    if (cm.getProteinIdentifications().size() > 0)
    {
      protIdent = cm.getProteinIdentifications()[0];
      has_proteinIdentifications = true;
    }

    // start the file by adding the tsv header
    TextFile textFile;
    textFile.addLine(ListUtils::concatenate(constructHeader_(*quantMethod), "\t"));

    for (ConsensusMap::ConstIterator cm_iter = cm.begin();
         cm_iter != cm.end();
         ++cm_iter)
    {
      const ConsensusFeature& cFeature = *cm_iter;
      std::vector<IdCSV> entries;

      /// 1st we extract the identification information from the consensus feature
      if (cFeature.getPeptideIdentifications().size() == 0 || !has_proteinIdentifications)
      {
        // we store unidentified hits anyway, because the iTRAQ quant is still helpful for normalization
        entries.push_back(IdCSV());
      }
      else
      {
        // protein name:
        const PeptideHit& peptide_hit = cFeature.getPeptideIdentifications()[0].getHits()[0];
        std::set<String> protein_accessions = peptide_hit.extractProteinAccessions();
        if (protein_accessions.size() != 1)
        {
          if (!allow_non_unique) continue; // we only want unique peptides
        }

        for (std::set<String>::const_iterator prot_ac = protein_accessions.begin(); prot_ac != protein_accessions.end(); ++prot_ac)
        {
          IdCSV entry;
          entry.charge = cFeature.getPeptideIdentifications()[0].getHits()[0].getCharge();
          entry.peptide = cFeature.getPeptideIdentifications()[0].getHits()[0].getSequence().toUnmodifiedString();
          entry.theo_mass = cFeature.getPeptideIdentifications()[0].getHits()[0].getSequence().getMonoWeight(Residue::Full, cFeature.getPeptideIdentifications()[0].getHits()[0].getCharge());

          // write modif
          entry.modif = getModifString_(cFeature.getPeptideIdentifications()[0].getHits()[0].getSequence());

          ProtHitIt proteinHit = protIdent.findHit(*prot_ac);
          if (proteinHit == protIdent.getHits().end())
          {
            std::cerr << "Protein referenced in peptide not found...\n";
            continue; // protein not found
          }

          entry.accession = proteinHit->getAccession();
          entries.push_back(entry);
        }
      }

      // 2nd we add the quantitative information of the channels

      // .. skip features with 0 intensity
      if (cFeature.getIntensity() == 0)
      {
        continue;
      }

      for (std::vector<IdCSV>::iterator entry = entries.begin();
           entry != entries.end();
           ++entry)
      {
        // set parent intensity
        entry->parent_intens = cFeature.getIntensity();
        entry->retention_time = cFeature.getRT();
        entry->spectrum = cFeature.getUniqueId();
        entry->exp_mass = cFeature.getMZ();

        // create output line
        StringList currentLine;

        // add entry to currentLine
        entry->toStringList(currentLine);

        // extract channel intensities and positions
//.........这里部分代码省略.........
开发者ID:chahuistle,项目名称:OpenMS,代码行数:101,代码来源:IBSpectraFile.cpp

示例7: main_

  ExitCodes main_(int, const char**)
  {
    StringList cv_files = getStringList_("cv_files");
    StringList cv_names = getStringList_("cv_names");
    if (cv_files.size() != cv_names.size())
    {
      cerr << "Error: You have to specify an identifier for each CV file. Aborting!" << endl;
      return ILLEGAL_PARAMETERS;
    }

    // load cv terms
    ControlledVocabulary cv;
    for (Size i = 0; i < cv_files.size(); ++i)
    {
      cv.loadFromOBO(cv_names[i], cv_files[i]);
    }
    Map<String, ControlledVocabulary::CVTerm> terms = cv.getTerms();

    // load mappings from mapping file
    String mapping_file = getStringOption_("mapping_file");
    CVMappings mappings;
    CVMappingFile().load(mapping_file, mappings);

    //store HTML version of mapping and CV
    if (getStringOption_("html") != "")
    {
      TextFile file;
      file.addLine("<HTML>");
      file.addLine("  <HEAD>");
      file.addLine("    <TITLE>CV mapping file</TITLE>");
      file.addLine("    <SCRIPT language=javascript type='text/javascript'>");
      file.addLine("      function toggleDiv(layer_ref,force_state) ");
      file.addLine("      {");
      file.addLine("        if (document.getElementById(layer_ref).style.display=='none' || force_state=='true')");
      file.addLine("        {");
      file.addLine("          document.getElementById(layer_ref).style.display = 'block';");
      file.addLine("        }");
      file.addLine("        else if (document.getElementById(layer_ref).style.display=='block' || force_state=='false')");
      file.addLine("        {");
      file.addLine("          document.getElementById(layer_ref).style.display = 'none';");
      file.addLine("        }");
      file.addLine("      }");
      file.addLine("    </SCRIPT>");
      file.addLine("  </HEAD>");
      file.addLine("  <BODY>");

      //count the number of terms and add button to expend/collaps all terms
      Int term_count = 0;
      for (vector<CVMappingRule>::const_iterator it = mappings.getMappingRules().begin(); it != mappings.getMappingRules().end(); ++it)
      {
        for (vector<CVMappingTerm>::const_iterator tit = it->getCVTerms().begin(); tit != it->getCVTerms().end(); ++tit)
        {
          ++term_count;
        }
      }
      String expand_all = "    <a href=\"javascript:toggleDiv('div0','true')";
      String collapse_all = "    <a href=\"javascript:toggleDiv('div0','false')";
      for (Int i = 1; i < term_count; ++i)
      {
        expand_all += String(";toggleDiv('div") + i + "','true')";
        collapse_all += String(";toggleDiv('div") + i + "','false')";
      }
      file.addLine(expand_all + "\">Expand all</a><BR>");
      file.addLine(collapse_all + "\">Collapse all</a>");
      file.addLine("    <TABLE width=100% border=0>");
      term_count = -1;
      for (vector<CVMappingRule>::const_iterator it = mappings.getMappingRules().begin(); it != mappings.getMappingRules().end(); ++it)
      {
        //create rule line
        file.addLine("      <TR><TD colspan=\"2\"><HR></TD></TR>");
        file.addLine(String("      <TR><TD>Identifier:</TD><TD><B>") + it->getIdentifier() + "</B></TD></TR>");
        file.addLine(String("      <TR><TD>Element:</TD><TD><B>") + it->getElementPath() + "</B></TD></TR>");
        if (it->getRequirementLevel() == CVMappingRule::MUST)
        {
          file.addLine("      <TR><TD>Requirement level:</TD><TD><FONT color=\"red\">MUST</FONT></TD></TR>");
        }
        else if (it->getRequirementLevel() == CVMappingRule::SHOULD)
        {
          file.addLine("      <TR><TD>Requirement level:</TD><TD><FONT color=\"orange\">SHOULD</FONT></TD></TR>");
        }
        else if (it->getRequirementLevel() == CVMappingRule::MAY)
        {
          file.addLine("      <TR><TD>Requirement level:</TD><TD><FONT color=\"green\">MAY</FONT></TD></TR>");
        }
        if (it->getCombinationsLogic() == CVMappingRule::AND)
        {
          file.addLine("      <TR><TD>Combination logic:</TD><TD><FONT color=\"red\">AND</FONT></TD></TR>");
        }
        else if (it->getCombinationsLogic() == CVMappingRule::XOR)
        {
          file.addLine("      <TR><TD>Combination logic:</TD><TD><FONT color=\"orange\">XOR</FONT></TD></TR>");
        }
        else if (it->getCombinationsLogic() == CVMappingRule::OR)
        {
          file.addLine("      <TR><TD>Combination logic:</TD><TD><FONT color=\"green\">OR</FONT></TD></TR>");
        }

        //create table with terms
        for (vector<CVMappingTerm>::const_iterator tit = it->getCVTerms().begin(); tit != it->getCVTerms().end(); ++tit)
        {
//.........这里部分代码省略.........
开发者ID:BioinformaticsArchive,项目名称:OpenMS,代码行数:101,代码来源:CVInspector.cpp


注:本文中的TextFile::addLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。