Commit 3733a294 authored by Benoit Valot's avatar Benoit Valot
Browse files

Add new tsv monitor for comparison

Work only on peptide for now

git-svn-id: https://subversion.renater.fr/masschroq/trunk@2272 e4b6dbb4-9209-464b-83f7-6257456c460c
parent 926153e4
......@@ -72,6 +72,7 @@ SET(MASSCHROQ_LIB_SRCS
./lib/monitors/mcq_qxmlstreamwriter.cpp
./lib/monitors/quantifResultsBase.cpp
./lib/monitors/tsv_quantif_results.cpp
./lib/monitors/comparTsvQuantifResults.cpp
./lib/monitors/xhtmltable_quantif_results.cpp
./lib/monitors/gnumeric_quantif_results.cpp
./lib/monitors/xicTracesBase.cpp
......
/**
* \file comparTsvQuantifResults.h
* \date January 25, 2012
* \author Benoit Valot
*/
#include "comparTsvQuantifResults.h"
comparTsvQuantifResults::comparTsvQuantifResults()
: QuantifResultsBase()
{
_compar_output_stream = 0;
}
comparTsvQuantifResults::comparTsvQuantifResults(const QString & filename)
: QuantifResultsBase(filename)
{
setOutputFilesAndStreams(filename);
}
comparTsvQuantifResults::~comparTsvQuantifResults() {
if (_compar_output_stream != 0) {
delete _compar_output_stream;
_compar_output_stream = 0;
}
if (_compar_output_file != 0) {
_compar_output_file->close();
delete _compar_output_file;
_compar_output_file = 0;
}
}
void
comparTsvQuantifResults::setOutputFilesAndStreams(const QString & filename) {
QString compar_filename = filename;
compar_filename.append("_compar").append(".tsv");
_compar_output_file = new QFile(compar_filename);
const QString compar_file = _compar_output_file->fileName();
if (_compar_output_file->exists()) {
cout << "WARNING : Compar TSV output file '"
<< compar_file.toStdString()
<< "' already exists, it will be overwrited."
<< endl;
}
if (_compar_output_file->open(QIODevice::WriteOnly)) {
_compar_output_stream = new QTextStream(_compar_output_file);
} else {
throw mcqError(QObject::tr("cannot open the compar output file '%1' \n").arg(compar_file));
}
cout << "Writing quantification results in TSV output files : '"
<< compar_file.toStdString()
<< "'" << endl;
setLocaleAndPrecisionForAllStreams();
}
void
comparTsvQuantifResults::setLocaleAndPrecisionForAllStreams() {
#if QT_VERSION >= QT_V_4_5
_tmp_element_stream.setLocale(QLocale::system());
_compar_output_stream->setLocale(QLocale::system());
#endif
_tmp_element_stream.setRealNumberPrecision(8);
_tmp_element_stream.setRealNumberNotation(QTextStream::SmartNotation);
_compar_output_stream->setRealNumberPrecision(8);
_compar_output_stream->setRealNumberNotation(QTextStream::SmartNotation);
}
void
comparTsvQuantifResults::setMatchedPeaks(const std::vector<xicPeak *> * p_v_peak_list) {
vector<xicPeak *>::const_iterator itp;
for (itp = p_v_peak_list->begin();
itp != p_v_peak_list->end();
++itp) {
const Peptide * p_peptide(_current_quanti_item->getPeptide());
QString pepId(""), isotope_label(""), sampleId(""), tempArea(""), currentZ;
///on n'imprime que les données peptides
if (p_peptide != NULL) {
currentZ.setNum(getCurrentZ());
pepId = p_peptide->getXmlId();
pepId.append("_").append(currentZ);
if (p_peptide->getIsotopeLabel() != NULL) {
isotope_label = p_peptide->getIsotopeLabel()->getXmlId();
}
///TODO ajouter le quantiID
sampleId = _current_group_id;
sampleId.append("_");
sampleId.append(((*itp)->getMsrun())->getXmlId());
sampleId.append("_");
sampleId.append(isotope_label);
//ajoute à la liste de sample
if(!_sampleIds.contains(sampleId)){
_sampleIds << sampleId;
}
if(_map_peptide_quantification[pepId][sampleId]!=NULL){
tempArea = _map_peptide_quantification[pepId][sampleId];
tempArea.append("|").append(formatCell((*itp)->get_area()));
_map_peptide_quantification[pepId][sampleId] = tempArea;
}else{
_map_peptide_quantification[pepId][sampleId] = formatCell((*itp)->get_area());
}
QStringList list;
list << formatCell(p_peptide->getXmlId());
list << formatCell(_current_quanti_item->get_mz());
list << formatCell(currentZ);
list << p_peptide->getSequence();
vector <const Protein *> prots = p_peptide->getProteinList();
unsigned int prot_size = prots.size();
QString protIds("");
if (prot_size > 0) {
vector <const Protein *>::iterator it;
for (it = prots.begin();
it != prots.end();
++it) {
protIds.append((*it)->getXmlId()).append(" ");
}
}
list << protIds;
_map_peptide_description[pepId]=list;
}
}
}
void
comparTsvQuantifResults::debriefing() {
///print stored value
// liste samples
printHeaders();
QString sampId , pepId,tmpArea;
std::map<QString, std::map<QString, QString> >::const_iterator itpep;
for (itpep = _map_peptide_quantification.begin();
itpep != _map_peptide_quantification.end();
++itpep) {
QStringList list;
pepId = itpep->first;
list << _map_peptide_description[pepId];
QStringList::const_iterator sampleIterator;
for (sampleIterator = _sampleIds.constBegin(); sampleIterator != _sampleIds.constEnd();
++sampleIterator){
sampId = (*sampleIterator);
tmpArea = _map_peptide_quantification[pepId][sampId];
if(tmpArea!=NULL){
list << formatCell(tmpArea);
}else{
list << formatCell("");
}
}
printPepLine(list);
}
}
void
comparTsvQuantifResults::printHeaders() {
QStringList list;
list << formatCell("Peptide");
list << formatCell("m/z");
list << formatCell("z");
list << formatCell("Proteins");
list << _sampleIds;
printPepLine(list);
}
void
comparTsvQuantifResults::printPepLine(const QStringList & list) {
*_compar_output_stream << list.join(_sep) << _endl;
}
void
comparTsvQuantifResults::printLine(const QStringList & list) {
this->printPepLine(list);
}
/*
*
* MassChroQ: Mass Chromatogram Quantification software.
* Copyright (C) 2010 Olivier Langella, Edlira Nano, Benoit Valot, Michel Zivy.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* \file comparTsvQuantifResults.h
* \date January 25, 2012
* \author Benoit Valot
*/
#ifndef COMPAR_TSV_QUANTIF_RESULTS_H_
#define COMPAR_TSV_QUANTIF_RESULTS_H_ 1
#include "../msrun/ms_run_hash_group.h"
#include "../peptides/peptide_isotope.h"
#include "quantifResultsBase.h"
#include <iostream>
#include <QStringList>
#include <QFile>
#include <QTextStream>
#include <QTime>
/**
* \class TsvQuantifResults
* \brief Tab Separated Values type of peptide quantification results
*/
class comparTsvQuantifResults : public QuantifResultsBase {
public:
comparTsvQuantifResults();
comparTsvQuantifResults(const QString & filename);
virtual ~comparTsvQuantifResults();
virtual void debriefing();
protected:
virtual void setOutputFilesAndStreams(const QString & filename);
virtual void setLocaleAndPrecisionForAllStreams();
/// Override action on QuantifResultsBase for stored results
virtual void setMatchedPeaks(const std::vector<xicPeak *> * p_v_peak_list);
/// some printing and formating methods
virtual void printHeaders();
virtual void printPepLine(const QStringList & list);
virtual void printLine(const QStringList & list);
/// Output file for
QFile * _compar_output_file;
//stored data
/// hash map : peptide-z id -> map[sample id -> area]
std::map< QString, std::map<QString, QString> >_map_peptide_quantification;
/// hash map : peptide-z id -> list description
std::map< QString, QStringList >_map_peptide_description;
//list sampleID
QStringList _sampleIds;
private :
/// The streams corresponding to each output file
QTextStream * _compar_output_stream;
};
#endif /* COMPAR_TSV_QUANTIF_RESULTS_H_ */
......@@ -19,6 +19,7 @@
#include "../lib/monitors/tsv_all_xics.h"
#include "../lib/monitors/tsv_mzlist_xics.h"
#include "../lib/monitors/tsv_quantif_results.h"
#include "../lib/monitors/comparTsvQuantifResults.h"
#include "../lib/monitors/masschroqWriter.h"
#include "../lib/monitors/xhtmltable_quantif_results.h"
#include "../lib/monitors/gnumeric_quantif_results.h"
......@@ -976,14 +977,17 @@ bool
MasschroqmlParser::startTsvResult(const QString output_file) {
TsvQuantifResults * p_results;
comparTsvQuantifResults * compar_results;
try {
p_results = new TsvQuantifResults(output_file);
compar_results = new comparTsvQuantifResults(output_file);
} catch (mcqError error) {
_errorStr = QObject::tr("problem creating tsv output results :\n%1").arg(error.what());
return false;
}
_p_current_monitor_list->addMonitor(p_results);
_p_current_monitor_list->addMonitor(compar_results);
return true;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment