本文整理汇总了C++中PeakMap::size方法的典型用法代码示例。如果您正苦于以下问题:C++ PeakMap::size方法的具体用法?C++ PeakMap::size怎么用?C++ PeakMap::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PeakMap
的用法示例。
在下文中一共展示了PeakMap::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
vector<vector<Size> > PScore::calculateRankMap(const PeakMap& peak_map, double mz_window)
{
vector<std::vector<Size> > rank_map; // note: ranks are zero based
rank_map.reserve(peak_map.size());
for (Size i = 0; i != peak_map.size(); ++i)
{
const PeakSpectrum& spec = peak_map[i];
vector<double> mz;
vector<double> intensities;
for (Size j = 0; j != spec.size(); ++j)
{
mz.push_back(spec[j].getMZ());
intensities.push_back(spec[j].getIntensity());
}
rank_map.push_back(calculateIntensityRankInMZWindow(mz, intensities, mz_window));
}
return rank_map;
}
示例2: writeXQuestXMLSpec
// version for label-free linkers
void XQuestResultXMLFile::writeXQuestXMLSpec(String out_file, String base_name, const std::vector< std::vector< OPXLDataStructs::CrossLinkSpectrumMatch > >& all_top_csms, const PeakMap& spectra)
{
// String spec_xml_filename = base_name + "_matched.spec.xml";
// XML Header
std::ofstream spec_xml_file;
std::cout << "Writing spec.xml to " << out_file << std::endl;
spec_xml_file.open(out_file.c_str(), std::ios::trunc); // ios::app = append to file, ios::trunc = overwrites file
// TODO write actual data
spec_xml_file << "<?xml version=\"1.0\" encoding=\"UTF-8\"?><xquest_spectra compare_peaks_version=\"3.4\" date=\"Tue Nov 24 12:41:18 2015\" author=\"Thomas Walzthoeni,Oliver Rinner\" homepage=\"http://proteomics.ethz.ch\" resultdir=\"aleitner_M1012_004_matched\" deffile=\"xquest.def\" >" << std::endl;
// collect indices of spectra, that need to be written out
std::vector <Size> spectrum_indices;
for (Size i = 0; i < all_top_csms.size(); ++i)
{
if (!all_top_csms[i].empty())
{
if (all_top_csms[i][0].scan_index_light < spectra.size())
{
spectrum_indices.push_back(all_top_csms[i][0].scan_index_light);
}
}
}
// loop over list of indices and write out spectra
for (Size i = 0; i < spectrum_indices.size(); ++i)
{
String spectrum_light_name = base_name + ".light." + spectrum_indices[i];
String spectrum_heavy_name = base_name + ".heavy." + spectrum_indices[i];
String spectrum_name = spectrum_light_name + String("_") + spectrum_heavy_name;
// 4 Spectra resulting from a light/heavy spectra pair. Write for each spectrum, that is written to xquest.xml (should be all considered pairs, or better only those with at least one sensible Hit, meaning a score was computed)
spec_xml_file << "<spectrum filename=\"" << spectrum_light_name << ".dta" << "\" type=\"light\">" << std::endl;
spec_xml_file << getxQuestBase64EncodedSpectrum_(spectra[spectrum_indices[i]], String(""));
spec_xml_file << "</spectrum>" << std::endl;
spec_xml_file << "<spectrum filename=\"" << spectrum_heavy_name << ".dta" << "\" type=\"heavy\">" << std::endl;
spec_xml_file << getxQuestBase64EncodedSpectrum_(spectra[spectrum_indices[i]], String(""));
spec_xml_file << "</spectrum>" << std::endl;
String spectrum_common_name = spectrum_name + String("_common.txt");
spec_xml_file << "<spectrum filename=\"" << spectrum_common_name << "\" type=\"common\">" << std::endl;
spec_xml_file << getxQuestBase64EncodedSpectrum_(spectra[spectrum_indices[i]], spectrum_light_name + ".dta," + spectrum_heavy_name + ".dta");
spec_xml_file << "</spectrum>" << std::endl;
String spectrum_xlink_name = spectrum_name + String("_xlinker.txt");
spec_xml_file << "<spectrum filename=\"" << spectrum_xlink_name << "\" type=\"xlinker\">" << std::endl;
spec_xml_file << getxQuestBase64EncodedSpectrum_(spectra[spectrum_indices[i]], spectrum_light_name + ".dta," + spectrum_heavy_name + ".dta");
spec_xml_file << "</spectrum>" << std::endl;
}
spec_xml_file << "</xquest_spectra>" << std::endl;
spec_xml_file.close();
return;
}
示例3: getPrecursors_
void getPrecursors_(const PeakMap & exp, vector<Precursor> & precursors, vector<double> & precursors_rt)
{
for (Size i = 0; i != exp.size(); ++i)
{
vector<Precursor> pcs = exp[i].getPrecursors();
if (pcs.empty())
{
continue;
}
vector<double> pcs_rt(pcs.size(), exp[i].getRT());
copy(pcs.begin(), pcs.end(), back_inserter(precursors));
copy(pcs_rt.begin(), pcs_rt.end(), back_inserter(precursors_rt));
}
}
示例4: run
void FeatureFinder::run(const String& algorithm_name, PeakMap& input_map, FeatureMap& features, const Param& param, const FeatureMap& seeds)
{
// Nothing to do if there is no data
if ((algorithm_name != "mrm" && input_map.empty()) || (algorithm_name == "mrm" && input_map.getChromatograms().empty()))
{
features.clear(true);
return;
}
// check input
{
// We need updated ranges => check number of peaks
if (algorithm_name != "mrm" && input_map.getSize() == 0)
{
throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "FeatureFinder needs updated ranges on input map. Aborting.");
}
// We need MS1 data only => check levels
if (algorithm_name != "mrm" && (input_map.getMSLevels().size() != 1 || input_map.getMSLevels()[0] != 1))
{
throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "FeatureFinder can only operate on MS level 1 data. Please do not use MS/MS data. Aborting.");
}
//Check if the peaks are sorted according to m/z
if (!input_map.isSorted(true))
{
LOG_WARN << "Input map is not sorted by RT and m/z! This is done now, before applying the algorithm!" << std::endl;
input_map.sortSpectra(true);
input_map.sortChromatograms(true);
}
for (Size s = 0; s < input_map.size(); ++s)
{
if (input_map[s].empty())
continue;
if (input_map[s][0].getMZ() < 0)
{
throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "FeatureFinder can only operate on spectra that contain peaks with positive m/z values. Filter the data accordingly beforehand! Aborting.");
}
}
}
// initialize
if (algorithm_name != "mrm" && algorithm_name != "centroided")
{
// Resize peak flag vector
flags_.resize(input_map.size());
for (Size i = 0; i < input_map.size(); ++i)
{
flags_[i].assign(input_map[i].size(), UNUSED);
}
}
// do the work
if (algorithm_name != "none")
{
FeatureFinderAlgorithm* algorithm = Factory<FeatureFinderAlgorithm>::create(algorithm_name);
algorithm->setParameters(param);
algorithm->setData(input_map, features, *this);
algorithm->setSeeds(seeds);
algorithm->run();
delete(algorithm);
}
if (algorithm_name != "mrm") // mrm works on chromatograms; the next section is only for conventional data
{
//report RT apex spectrum index and native ID for each feature
for (Size i = 0; i < features.size(); ++i)
{
//index
Size spectrum_index = input_map.RTBegin(features[i].getRT()) - input_map.begin();
features[i].setMetaValue("spectrum_index", spectrum_index);
//native id
if (spectrum_index < input_map.size())
{
String native_id = input_map[spectrum_index].getNativeID();
features[i].setMetaValue("spectrum_native_id", native_id);
}
else
{
/// @todo that happens sometimes using IsotopeWaveletFeatureFinder (Rene, Marc, Andreas, Clemens)
std::cerr << "FeatureFinderAlgorithm_impl, line=" << __LINE__ << "; FixMe this cannot be, but happens" << std::endl;
}
}
}
}
示例5: main_
ExitCodes main_(int, const char **)
{
//-------------------------------------------------------------
// parsing parameters
//-------------------------------------------------------------
String in(getStringOption_("in"));
String out(getStringOption_("out"));
Size num_spots_per_row(getIntOption_("num_spots_per_row"));
double RT_distance(getDoubleOption_("RT_distance"));
//-------------------------------------------------------------
// reading input
//-------------------------------------------------------------
PeakMap exp;
MzMLFile f;
f.setLogType(log_type_);
f.load(in, exp);
//-------------------------------------------------------------
// calculations
//-------------------------------------------------------------
ProgressLogger pl;
pl.setLogType(log_type_);
pl.startProgress(0, exp.size(), "Assigning pseudo RTs.");
Size num_ms1(0), num_ms1_base(0), row_counter(0);
bool row_to_reverse(false);
double actual_RT(0);
for (Size i = 0; i != exp.size(); ++i)
{
pl.setProgress(i);
if (row_to_reverse)
{
actual_RT = (double)(num_ms1_base + (num_spots_per_row - row_counter)) * RT_distance;
writeDebug_("RT=" + String(actual_RT) + " (modified, row_counter=" + String(row_counter) + ")", 1);
}
else
{
actual_RT = (double)num_ms1 * RT_distance;
writeDebug_("RT=" + String(actual_RT), 1);
}
exp[i].setRT(actual_RT);
if (exp[i].getMSLevel() == 1)
{
if (++row_counter >= num_spots_per_row)
{
row_counter = 0;
if (row_to_reverse)
{
row_to_reverse = false;
}
else
{
row_to_reverse = true;
}
}
++num_ms1;
if (!row_to_reverse)
{
num_ms1_base = num_ms1;
}
}
}
pl.endProgress();
// sort the spectra according to their new RT
exp.sortSpectra();
//-------------------------------------------------------------
// writing output
//-------------------------------------------------------------
f.store(out, exp);
return EXECUTION_OK;
}
示例6: pickExperiment
/**
* @brief Applies the peak-picking algorithm to a map (MSExperiment). This
* method picks peaks for each scan in the map consecutively. The resulting
* picked peaks are written to the output map.
*
* @param input input map in profile mode
* @param output output map with picked peaks
* @param boundaries_spec boundaries of the picked peaks in spectra
* @param boundaries_chrom boundaries of the picked peaks in chromatograms
* @param check_spectrum_type if set, checks spectrum type and throws an exception if a centroided spectrum is passed
*/
void PeakPickerHiRes::pickExperiment(const PeakMap& input, PeakMap& output,
std::vector<std::vector<PeakBoundary> >& boundaries_spec,
std::vector<std::vector<PeakBoundary> >& boundaries_chrom,
const bool check_spectrum_type) const
{
// make sure that output is clear
output.clear(true);
// copy experimental settings
static_cast<ExperimentalSettings &>(output) = input;
// resize output with respect to input
output.resize(input.size());
Size progress = 0;
startProgress(0, input.size() + input.getChromatograms().size(), "picking peaks");
if (input.getNrSpectra() > 0)
{
for (Size scan_idx = 0; scan_idx != input.size(); ++scan_idx)
{
if (ms_levels_.empty()) // auto mode
{
SpectrumSettings::SpectrumType spectrum_type = input[scan_idx].getType();
if (spectrum_type == SpectrumSettings::CENTROID)
{
output[scan_idx] = input[scan_idx];
}
else
{
std::vector<PeakBoundary> boundaries_s; // peak boundaries of a single spectrum
pick(input[scan_idx], output[scan_idx], boundaries_s);
boundaries_spec.push_back(boundaries_s);
}
}
else if (!ListUtils::contains(ms_levels_, input[scan_idx].getMSLevel())) // manual mode
{
output[scan_idx] = input[scan_idx];
}
else
{
std::vector<PeakBoundary> boundaries_s; // peak boundaries of a single spectrum
// determine type of spectral data (profile or centroided)
SpectrumSettings::SpectrumType spectrum_type = input[scan_idx].getType();
if (spectrum_type == SpectrumSettings::CENTROID && check_spectrum_type)
{
throw OpenMS::Exception::IllegalArgument(__FILE__, __LINE__, __FUNCTION__, "Error: Centroided data provided but profile spectra expected.");
}
pick(input[scan_idx], output[scan_idx], boundaries_s);
boundaries_spec.push_back(boundaries_s);
}
setProgress(++progress);
}
}
for (Size i = 0; i < input.getChromatograms().size(); ++i)
{
MSChromatogram chromatogram;
std::vector<PeakBoundary> boundaries_c; // peak boundaries of a single chromatogram
pick(input.getChromatograms()[i], chromatogram, boundaries_c);
output.addChromatogram(chromatogram);
boundaries_chrom.push_back(boundaries_c);
setProgress(++progress);
}
endProgress();
return;
}
示例7: main_
ExitCodes main_(int, const char **) override
{
//-------------------------------------------------------------
// parameter handling
//-------------------------------------------------------------
//input/output files
String in(getStringOption_("in"));
String out(getStringOption_("out"));
//-------------------------------------------------------------
// loading input
//-------------------------------------------------------------
PeakMap exp;
MzMLFile f;
f.setLogType(log_type_);
PeakFileOptions options;
options.clearMSLevels();
options.addMSLevel(2);
f.getOptions() = options;
f.load(in, exp);
writeDebug_("Data set contains " + String(exp.size()) + " spectra", 1);
//-------------------------------------------------------------
// calculations
//-------------------------------------------------------------
vector<PeptideIdentification> pep_ids;
CompNovoIdentificationCID comp_novo_id;
// set the options
Param algorithm_param = getParam_().copy("algorithm:", true);
comp_novo_id.setParameters(algorithm_param);
comp_novo_id.getIdentifications(pep_ids, exp);
algorithm_param = comp_novo_id.getParameters();
//-------------------------------------------------------------
// writing output
//-------------------------------------------------------------
DateTime now = DateTime::now();
String date_string = now.get();
String identifier("CompNovoCID_" + date_string);
for (vector<PeptideIdentification>::iterator it = pep_ids.begin(); it != pep_ids.end(); ++it)
{
it->assignRanks();
it->setIdentifier(identifier);
}
vector<ProteinIdentification> prot_ids;
ProteinIdentification prot_id;
prot_id.setIdentifier(identifier);
prot_id.setDateTime(now);
StringList ms_runs;
exp.getPrimaryMSRunPath(ms_runs);
prot_id.setPrimaryMSRunPath(ms_runs);
ProteinIdentification::SearchParameters search_parameters;
search_parameters.charges = "+2-+3";
if (algorithm_param.getValue("tryptic_only").toBool())
{
search_parameters.digestion_enzyme = *(ProteaseDB::getInstance()->getEnzyme("Trypsin"));
}
else
{
search_parameters.digestion_enzyme = *(ProteaseDB::getInstance()->getEnzyme("no cleavage"));
}
search_parameters.mass_type = ProteinIdentification::MONOISOTOPIC;
search_parameters.fixed_modifications = algorithm_param.getValue("fixed_modifications");
search_parameters.variable_modifications = algorithm_param.getValue("variable_modifications");
search_parameters.missed_cleavages = (UInt)algorithm_param.getValue("missed_cleavages");
search_parameters.fragment_mass_tolerance = (double)algorithm_param.getValue("fragment_mass_tolerance");
search_parameters.precursor_mass_tolerance = (double)algorithm_param.getValue("precursor_mass_tolerance");
search_parameters.fragment_mass_tolerance_ppm = false;
search_parameters.precursor_mass_tolerance_ppm = false;
prot_id.setSearchParameters(search_parameters);
prot_id.setSearchEngineVersion("0.9beta");
prot_id.setSearchEngine("CompNovo");
prot_ids.push_back(prot_id);
IdXMLFile().store(out, prot_ids, pep_ids);
return EXECUTION_OK;
}
示例8: correctToNearestFeature
// Wrong assignment of the mono-isotopic mass for precursors are assumed:
// - if precursor_mz matches the mz of a non-monoisotopic feature mass trace
// - and in the case that believe_charge is true: if feature_charge matches the precursor_charge
// In the case of wrong mono-isotopic assignment several options for correction are available:
// keep_original will create a copy of the precursor and tandem spectrum for the new mono-isotopic mass trace and retain the original one
// all_matching_features does this not for only the closest feature but all features in a question
set<Size> correctToNearestFeature(const FeatureMap& features, PeakMap & exp, double rt_tolerance_s = 0.0, double mz_tolerance = 0.0, bool ppm = true, bool believe_charge = false, bool keep_original = false, bool all_matching_features = false, int max_trace = 2)
{
set<Size> corrected_precursors;
// for each precursor/MS2 find all features that are in the given tolerance window (bounding box + rt tolerances)
// if believe_charge is set, only add features that match the precursor charge
map<Size, set<Size> > scan_idx_to_feature_idx;
for (Size scan = 0; scan != exp.size(); ++scan)
{
// skip non-tandem mass spectra
if (exp[scan].getMSLevel() != 2 || exp[scan].getPrecursors().empty()) continue;
// extract precusor / MS2 information
const double pc_mz = exp[scan].getPrecursors()[0].getMZ();
const double rt = exp[scan].getRT();
const int pc_charge = exp[scan].getPrecursors()[0].getCharge();
for (Size f = 0; f != features.size(); ++f)
{
// feature is incompatible if believe_charge is set and charges don't match
if (believe_charge && features[f].getCharge() != pc_charge) continue;
// check if precursor/MS2 position overlap with feature
if (overlaps_(features[f], rt, pc_mz, rt_tolerance_s))
{
scan_idx_to_feature_idx[scan].insert(f);
}
}
}
// filter sets to retain compatible features:
// if precursor_mz = feature_mz + n * feature_charge (+/- mz_tolerance) a feature is compatible, others are removed from the set
for (map<Size, set<Size> >::iterator it = scan_idx_to_feature_idx.begin(); it != scan_idx_to_feature_idx.end(); ++it)
{
const Size scan = it->first;
const double pc_mz = exp[scan].getPrecursors()[0].getMZ();
const double mz_tolerance_da = ppm ? pc_mz * mz_tolerance * 1e-6 : mz_tolerance;
// Note: This is the "delete while iterating" pattern so mind the pre- and postincrement
for (set<Size>::iterator sit = it->second.begin(); sit != it->second.end(); )
{
if (!compatible_(features[*sit], pc_mz, mz_tolerance_da, max_trace))
{
it->second.erase(sit++);
}
else
{
++sit;
}
}
}
// remove entries with no compatible features (empty sets).
// Note: This is the "delete while iterating" pattern so mind the pre- and postincrement
for (map<Size, set<Size> >::iterator it = scan_idx_to_feature_idx.begin(); it != scan_idx_to_feature_idx.end(); )
{
if (it->second.empty())
{
scan_idx_to_feature_idx.erase(it++);
}
else
{
++it;
}
}
if (debug_level_ > 0)
{
LOG_INFO << "Number of precursors with compatible features: " << scan_idx_to_feature_idx.size() << endl;
}
if (!all_matching_features)
{
// keep only nearest features in set
for (map<Size, set<Size> >::iterator it = scan_idx_to_feature_idx.begin(); it != scan_idx_to_feature_idx.end(); ++it)
{
const Size scan = it->first;
const double pc_rt = exp[scan].getRT();
double min_distance = 1e16;
set<Size>::iterator best_feature = it->second.begin();
// determine nearest/best feature
for (set<Size>::iterator sit = it->second.begin(); sit != it->second.end(); ++sit)
{
const double current_distance = fabs(pc_rt - features[*sit].getRT());
if (current_distance < min_distance)
{
min_distance = current_distance;
best_feature = sit;
}
}
// delete all except the nearest/best feature
//.........这里部分代码省略.........
示例9: main_
ExitCodes main_(int argc, const char** argv)
{
//-------------------------------------------------------------
// parameter handling
//-------------------------------------------------------------
//input/output files
String in(getStringOption_("in")), out(getStringOption_("out"));
FileHandler fh;
FileTypes::Type in_type = fh.getType(in);
//-------------------------------------------------------------
// loading input
//-------------------------------------------------------------
PeakMap exp;
// keep only MS2 spectra
fh.getOptions().addMSLevel(2);
fh.loadExperiment(in, exp, in_type, log_type_);
writeDebug_(String("Spectra loaded: ") + exp.size(), 2);
if (exp.getSpectra().empty())
{
throw OpenMS::Exception::FileEmpty(__FILE__, __LINE__, __FUNCTION__, "Error: No MS2 spectra in input file.");
}
// determine type of spectral data (profile or centroided)
SpectrumSettings::SpectrumType spectrum_type = exp[0].getType();
if (spectrum_type == SpectrumSettings::RAWDATA)
{
if (!getFlag_("force"))
{
throw OpenMS::Exception::IllegalArgument(__FILE__, __LINE__, __FUNCTION__, "Error: Profile data provided but centroided MS2 spectra expected. To enforce processing of the data set the -force flag.");
}
}
//-------------------------------------------------------------
// calculations
//-------------------------------------------------------------
Param mascot_param = getParam_().copy("Mascot_parameters:", true);
MascotGenericFile mgf_file;
Param p;
// TODO: switch this to mzML (much smaller)
p.setValue("internal:format", "Mascot generic", "Sets the format type of the peak list, this should not be changed unless you write the header only.", ListUtils::create<String>("advanced"));
p.setValue("internal:HTTP_format", "true", "Write header with MIME boundaries instead of simple key-value pairs. For HTTP submission only.", ListUtils::create<String>("advanced"));
p.setValue("internal:content", "all", "Use parameter header + the peak lists with BEGIN IONS... or only one of them.", ListUtils::create<String>("advanced"));
mgf_file.setParameters(mascot_param);
// get the spectra into string stream
writeDebug_("Writing MGF file to stream", 1);
stringstream ss;
mgf_file.store(ss, in, exp, true); // write in compact format
// Usage of a QCoreApplication is overkill here (and ugly too), but we just use the
// QEventLoop to process the signals and slots and grab the results afterwards from
// the MascotRemotQuery instance
char** argv2 = const_cast<char**>(argv);
QCoreApplication event_loop(argc, argv2);
MascotRemoteQuery* mascot_query = new MascotRemoteQuery(&event_loop);
Param mascot_query_param = getParam_().copy("Mascot_server:", true);
writeDebug_("Setting parameters for Mascot query", 1);
mascot_query->setParameters(mascot_query_param);
writeDebug_("Setting spectra for Mascot query", 1);
mascot_query->setQuerySpectra(ss.str());
// remove unnecessary spectra
ss.clear();
QObject::connect(mascot_query, SIGNAL(done()), &event_loop, SLOT(quit()));
QTimer::singleShot(1000, mascot_query, SLOT(run()));
writeDebug_("Fire off Mascot query", 1);
event_loop.exec();
writeDebug_("Mascot query finished", 1);
if (mascot_query->hasError())
{
writeLog_("An error occurred during the query: " + mascot_query->getErrorMessage());
delete mascot_query;
return EXTERNAL_PROGRAM_ERROR;
}
// write Mascot response to file
String mascot_tmp_file_name(File::getTempDirectory() + "/" + File::getUniqueName() + "_Mascot_response");
QFile mascot_tmp_file(mascot_tmp_file_name.c_str());
mascot_tmp_file.open(QIODevice::WriteOnly);
mascot_tmp_file.write(mascot_query->getMascotXMLResponse());
mascot_tmp_file.close();
// clean up
delete mascot_query;
vector<PeptideIdentification> pep_ids;
ProteinIdentification prot_id;
// set up mapping between scan numbers and retention times:
MascotXMLFile::RTMapping rt_mapping;
MascotXMLFile::generateRTMapping(exp.begin(), exp.end(), rt_mapping);
//.........这里部分代码省略.........
示例10: if
ExitCodes
main_(int, const char**)
{
//-------------------------------------------------------------
// general variables and data
//-------------------------------------------------------------
FileHandler fh;
vector<PeptideIdentification> peptide_identifications;
vector<ProteinIdentification> protein_identifications;
//-------------------------------------------------------------
// reading input
//-------------------------------------------------------------
const String in = getStringOption_("in");
ProgressLogger logger;
logger.setLogType(ProgressLogger::CMD);
logger.startProgress(0, 1, "Loading...");
if (File::isDirectory(in))
{
const String in_directory = File::absolutePath(in).ensureLastChar('/');
const String mz_file = getStringOption_("mz_file");
const bool ignore_proteins_per_peptide = getFlag_("ignore_proteins_per_peptide");
UInt i = 0;
FileHandler fh;
FileTypes::Type type;
MSExperiment<Peak1D> msexperiment;
// Note: we had issues with leading zeroes, so let us represent scan numbers as Int (next line used to be map<String, float> num_and_rt;) However, now String::toInt() might throw.
map<Int, float> num_and_rt;
vector<String> NativeID;
// The mz-File (if given)
if (!mz_file.empty())
{
type = fh.getTypeByFileName(mz_file);
fh.loadExperiment(mz_file, msexperiment, type);
for (MSExperiment<Peak1D>::Iterator spectra_it = msexperiment.begin(); spectra_it != msexperiment.end(); ++spectra_it)
{
String(spectra_it->getNativeID()).split('=', NativeID);
try
{
num_and_rt[NativeID[1].toInt()] = spectra_it->getRT();
// cout << "num_and_rt: " << NativeID[1] << " = " << NativeID[1].toInt() << " : " << num_and_rt[NativeID[1].toInt()] << endl; // CG debuggging 2009-07-01
}
catch (Exception::ConversionError& e)
{
writeLog_(String("Error: Cannot read scan number as integer. '") + e.getMessage());
}
}
}
// Get list of the actual Sequest .out-Files
StringList in_files;
if (!File::fileList(in_directory, String("*.out"), in_files))
{
writeLog_(String("Error: No .out files found in '") + in_directory + "'. Aborting!");
}
// Now get to work ...
for (vector<String>::const_iterator in_files_it = in_files.begin(); in_files_it != in_files.end(); ++in_files_it)
{
vector<PeptideIdentification> peptide_ids_seq;
ProteinIdentification protein_id_seq;
vector<double> pvalues_seq;
vector<String> in_file_vec;
SequestOutfile sequest_outfile;
writeDebug_(String("Reading file ") + *in_files_it, 3);
try
{
sequest_outfile.load((String) (in_directory + *in_files_it), peptide_ids_seq, protein_id_seq, 1.0, pvalues_seq, "Sequest", ignore_proteins_per_peptide);
in_files_it->split('.', in_file_vec);
for (Size j = 0; j < peptide_ids_seq.size(); ++j)
{
// We have to explicitly set the identifiers, because the normal set ones are composed of search engine name and date, which is the same for a bunch of sequest out-files.
peptide_ids_seq[j].setIdentifier(*in_files_it + "_" + i);
Int scan_number = 0;
if (!mz_file.empty())
{
try
{
scan_number = in_file_vec[2].toInt();
peptide_ids_seq[j].setRT(num_and_rt[scan_number]);
}
catch (Exception::ConversionError& e)
{
writeLog_(String("Error: Cannot read scan number as integer. '") + e.getMessage());
}
catch (exception& e)
{
writeLog_(String("Error: Cannot read scan number as integer. '") + e.what());
//.........这里部分代码省略.........
示例11:
TOLERANCE_ABSOLUTE(0.01)
MzDataFile file;
PeakMap e;
// real test
file.load(OPENMS_GET_TEST_DATA_PATH("MzDataFile_1.mzData"), e);
//test DocumentIdentifier addition
TEST_STRING_EQUAL(e.getLoadedFilePath(), OPENMS_GET_TEST_DATA_PATH("MzDataFile_1.mzData"));
TEST_STRING_EQUAL(FileTypes::typeToName(e.getLoadedFileType()), "mzData");
//---------------------------------------------------------------------------
// ms-level, RT, native ID
//---------------------------------------------------------------------------
TEST_EQUAL(e.size(), 3)
TEST_EQUAL(e[0].getMSLevel(), 1)
TEST_EQUAL(e[1].getMSLevel(), 2)
TEST_EQUAL(e[2].getMSLevel(), 1)
TEST_REAL_SIMILAR(e[0].getRT(), 60)
TEST_REAL_SIMILAR(e[1].getRT(), 120)
TEST_REAL_SIMILAR(e[2].getRT(), 180)
TEST_STRING_EQUAL(e[0].getNativeID(), "spectrum=10")
TEST_STRING_EQUAL(e[1].getNativeID(), "spectrum=11")
TEST_STRING_EQUAL(e[2].getNativeID(), "spectrum=12")
TEST_EQUAL(e[0].getType(), SpectrumSettings::UNKNOWN)
//---------------------------------------------------------------------------
//meta data array meta data
//---------------------------------------------------------------------------
TEST_EQUAL(e[0].getFloatDataArrays()[0].getMetaValue("URL"), "www.open-ms.de")
示例12: it
TOLERANCE_ABSOLUTE(0.01)
PeakMap e;
DTA2DFile file;
//test exception
TEST_EXCEPTION( Exception::FileNotFound , file.load("dummy/dummy.dta2d",e) )
// real test
file.load(OPENMS_GET_TEST_DATA_PATH("DTA2DFile_test_1.dta2d"),e);
//test DocumentIdentifier addition
TEST_STRING_EQUAL(e.getLoadedFilePath(), OPENMS_GET_TEST_DATA_PATH("DTA2DFile_test_1.dta2d"));
TEST_STRING_EQUAL(FileTypes::typeToName(e.getLoadedFileType()),"dta2d");
TEST_EQUAL(e.size(), 9);
ABORT_IF(e.size() != 9)
TEST_STRING_EQUAL(e[0].getNativeID(),"index=0")
TEST_STRING_EQUAL(e[1].getNativeID(),"index=1")
TEST_STRING_EQUAL(e[2].getNativeID(),"index=2")
TEST_STRING_EQUAL(e[3].getNativeID(),"index=3")
TEST_STRING_EQUAL(e[4].getNativeID(),"index=4")
TEST_STRING_EQUAL(e[5].getNativeID(),"index=5")
TEST_STRING_EQUAL(e[6].getNativeID(),"index=6")
TEST_STRING_EQUAL(e[7].getNativeID(),"index=7")
TEST_STRING_EQUAL(e[8].getNativeID(),"index=8")
PeakMap::const_iterator it(e.begin());
TEST_REAL_SIMILAR((*it)[0].getPosition()[0], 230.02)
TEST_REAL_SIMILAR(it->getRT(), 4711.1)
示例13: convertSpectraToChromatograms
chrom2.setChromatogramType(ChromatogramSettings::SELECTED_REACTION_MONITORING_CHROMATOGRAM);
ChromatogramPeak peak1, peak2, peak3;
peak1.setRT(0.1);
peak2.setRT(0.2);
peak3.setRT(0.3);
chrom1.push_back(peak1);
chrom1.push_back(peak2);
chrom2.push_back(peak2);
chrom2.push_back(peak2);
exp.addChromatogram(chrom1);
exp.addChromatogram(chrom2);
TEST_EQUAL(exp.size(), 0)
TEST_EQUAL(exp.getChromatograms().size(), 2)
ChromatogramTools().convertChromatogramsToSpectra(exp);
TEST_EQUAL(exp.size(), 4)
TEST_EQUAL(exp.getChromatograms().size(), 0)
TEST_REAL_SIMILAR(exp[0][0].getMZ(), 200.1)
TEST_EQUAL(exp[0].getPrecursors().size(), 1)
TEST_REAL_SIMILAR(exp[0].getPrecursors().begin()->getMZ(), 100.1)
}
END_SECTION
START_SECTION(template <typename ExperimentType> void convertSpectraToChromatograms(ExperimentType& exp, bool remove_spectra = false))
{
示例14: main_
//.........这里部分代码省略.........
infile.write(input_filename);
//-------------------------------------------------------------
// calculations
//-------------------------------------------------------------
int status = QProcess::execute(xtandem_executable.toQString(), QStringList(input_filename.toQString())); // does automatic escaping etc...
if (status != 0)
{
writeLog_("XTandem problem. Aborting! Calling command was: '" + xtandem_executable + " \"" + input_filename + "\"'.\nDoes the !XTandem executable exist?");
// clean temporary files
if (this->debug_level_ < 2)
{
File::removeDirRecursively(temp_directory);
LOG_WARN << "Set debug level to >=2 to keep the temporary files at '" << temp_directory << "'" << std::endl;
}
else
{
LOG_WARN << "Keeping the temporary files at '" << temp_directory << "'. Set debug level to <2 to remove them." << std::endl;
}
return EXTERNAL_PROGRAM_ERROR;
}
vector<ProteinIdentification> protein_ids;
ProteinIdentification protein_id;
vector<PeptideIdentification> peptide_ids;
// read the output of X!Tandem and write it to idXML
XTandemXMLFile tandem_output;
tandem_output.setModificationDefinitionsSet(ModificationDefinitionsSet(getStringList_("fixed_modifications"), getStringList_("variable_modifications")));
// find the file, because XTandem extends the filename with a timestamp we do not know (exactly)
StringList files;
File::fileList(temp_directory, "_tandem_output_file*.xml", files);
if (files.size() != 1)
{
throw Exception::FileNotFound(__FILE__, __LINE__, __PRETTY_FUNCTION__, tandem_output_filename);
}
tandem_output.load(temp_directory + files[0], protein_id, peptide_ids);
// now put the RTs into the peptide_ids from the spectrum ids
for (vector<PeptideIdentification>::iterator it = peptide_ids.begin(); it != peptide_ids.end(); ++it)
{
UInt id = (Int)it->getMetaValue("spectrum_id");
--id; // native IDs were written 1-based
if (id < exp.size())
{
it->setRT(exp[id].getRT());
double pre_mz(0.0);
if (!exp[id].getPrecursors().empty()) pre_mz = exp[id].getPrecursors()[0].getMZ();
it->setMZ(pre_mz);
//it->removeMetaValue("spectrum_id");
}
else
{
LOG_ERROR << "XTandemAdapter: Error: id '" << id << "' not found in peak map!" << endl;
}
}
//-------------------------------------------------------------
// writing output
//-------------------------------------------------------------
// handle the search parameters
ProteinIdentification::SearchParameters search_parameters;
search_parameters.db = getStringOption_("database");
search_parameters.charges = "+" + String(getIntOption_("min_precursor_charge")) + "-+" + String(getIntOption_("max_precursor_charge"));
示例15: copy
START_SECTION((SpectraMerger(const SpectraMerger& source)))
SpectraMerger copy(*e_ptr);
TEST_EQUAL(copy.getParameters(), e_ptr->getParameters())
END_SECTION
START_SECTION((SpectraMerger& operator=(const SpectraMerger& source)))
SpectraMerger copy;
copy = *e_ptr;
TEST_EQUAL(copy.getParameters(), e_ptr->getParameters())
END_SECTION
START_SECTION((template < typename MapType > void mergeSpectraBlockWise(MapType &exp)))
PeakMap exp, exp2;
MzMLFile().load(OPENMS_GET_TEST_DATA_PATH("SpectraMerger_input_2.mzML"), exp);
TEST_EQUAL(exp.size(), 144)
exp2 = exp;
SpectraMerger merger;
Param p;
p.setValue("block_method:rt_block_size", 5);
p.setValue("block_method:ms_levels", IntList::create(StringList::create("1")));
merger.setParameters(p);
merger.mergeSpectraBlockWise(exp);
TEST_EQUAL(exp.size(), 130);
exp=exp2;
p.setValue("block_method:rt_block_size", 4);
p.setValue("block_method:ms_levels", IntList::create(StringList::create("2")));
merger.setParameters(p);