Commit a57b45b1 authored by Edlira Nano's avatar Edlira Nano
Browse files

corrected compar results

git-svn-id: https://subversion.renater.fr/masschroq/trunk@2275 e4b6dbb4-9209-464b-83f7-6257456c460c
parent 0c1ae59b
......@@ -6,193 +6,212 @@
#include "comparTsvQuantifResults.h"
comparTsvQuantifResults::comparTsvQuantifResults()
: QuantifResultsBase()
ComparTsvQuantifResults::ComparTsvQuantifResults()
:
QuantifResultsBase()
{
_compar_output_stream = 0;
_compar_output_stream = 0;
}
comparTsvQuantifResults::comparTsvQuantifResults(const QString & filename)
: QuantifResultsBase(filename)
ComparTsvQuantifResults::ComparTsvQuantifResults(const QString & filename)
: QuantifResultsBase(filename)
{
setOutputFilesAndStreams(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;
}
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();
ComparTsvQuantifResults::setOutputFilesAndStreams(const QString & filename)
{
QString compar_filename = filename;
compar_filename.append("_compar").append(".tsv");
if (_compar_output_file->exists()) {
cout << "WARNING : Compar TSV output file '"
<< compar_file.toStdString()
<< "' already exists, it will be overwrited."
<< endl;
}
_compar_output_file = new QFile(compar_filename);
const QString compar_file = _compar_output_file->fileName();
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));
}
if (_compar_output_file->exists())
{
cout << "WARNING : Compar TSV output file '"
<< compar_file.toStdString()
<< "' already exists, it will be overwrited."
<< endl;
}
cout << "Writing quantification results in TSV output files : '"
<< compar_file.toStdString()
<< "'" << 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));
}
setLocaleAndPrecisionForAllStreams();
cout << "Writing comparision quantification results in TSV output file : '"
<< compar_file.toStdString()
<< "'" << endl;
setLocaleAndPrecisionForAllStreams();
}
void
comparTsvQuantifResults::setLocaleAndPrecisionForAllStreams() {
ComparTsvQuantifResults::setLocaleAndPrecisionForAllStreams()
{
#if QT_VERSION >= QT_V_4_5
_tmp_element_stream.setLocale(QLocale::system());
_compar_output_stream->setLocale(QLocale::system());
_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);
_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;
}
}
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, pepSequence("");
// we only print peptide data
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_quantify_id;
sampleId.append("_");
sampleId.append(_current_group_id);
sampleId.append("_");
sampleId.append(((*itp)->getMsrun())->getXmlId());
sampleId.append("_");
sampleId.append(isotope_label);
// adding to the sample map
if (!_sampleIds.contains(sampleId))
{
_sampleIds << sampleId;
}
mcq_double area((*itp)->get_area());
tempArea = _map_peptide_quantification[pepId][sampleId];
if ( ! tempArea.isEmpty())
{
tempArea.append("|").append(formatCell(area));
}
else
{
tempArea = formatCell(area);
}
_map_peptide_quantification[pepId][sampleId] = tempArea;
QStringList list;
list << formatCell(p_peptide->getXmlId());
list << formatCell(_current_quanti_item->get_mz());
list << formatCell(currentZ);
pepSequence = p_peptide->getSequence();
list << formatCell(pepSequence);
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 << formatCell(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);
}
ComparTsvQuantifResults::debriefing()
{
/// print results
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 << formatCell(_map_peptide_description[pepId]);
QStringList::const_iterator sampleIterator;
for (sampleIterator = _sampleIds.constBegin();
sampleIterator != _sampleIds.constEnd();
++sampleIterator)
{
sampId = (*sampleIterator);
tmpArea = _map_peptide_quantification[pepId][sampId];
list << formatCell(tmpArea);
}
printPepLine(list);
}
}
void
comparTsvQuantifResults::printHeaders() {
ComparTsvQuantifResults::printHeaders()
{
QStringList list;
list << formatCell("Peptide");
list << formatCell("peptide");
list << formatCell("m/z");
list << formatCell("z");
list << formatCell("Sequence");
list << formatCell("Proteins");
list << formatCell("sequence");
list << formatCell("proteins");
list << _sampleIds;
printPepLine(list);
}
void
comparTsvQuantifResults::printPepLine(const QStringList & list) {
*_compar_output_stream << list.join(_sep) << _endl;
ComparTsvQuantifResults::printPepLine(const QStringList & list)
{
*_compar_output_stream << list.join(_sep) << _endl;
}
void
comparTsvQuantifResults::printLine(const QStringList & list) {
this->printPepLine(list);
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/>.
*
*/
*
* 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
......@@ -34,57 +35,57 @@
#include <QStringList>
#include <QFile>
#include <QTextStream>
#include <QTime>
//#include <QTime>
/**
* \class TsvQuantifResults
* \brief Tab Separated Values type of peptide quantification results
* \class ComparTsvQuantifResults
* \brief Tab Separated Values type of peptide quantification results well suited for result
* comparison
*/
class comparTsvQuantifResults : public QuantifResultsBase {
public:
comparTsvQuantifResults();
comparTsvQuantifResults(const QString & filename);
class ComparTsvQuantifResults : public QuantifResultsBase {
virtual ~comparTsvQuantifResults();
public:
virtual void debriefing();
ComparTsvQuantifResults();
ComparTsvQuantifResults(const QString & filename);
protected:
virtual ~ComparTsvQuantifResults();
virtual void setOutputFilesAndStreams(const QString & filename);
virtual void debriefing();
virtual void setLocaleAndPrecisionForAllStreams();
protected:
/// Override action on QuantifResultsBase for stored results
virtual void setMatchedPeaks(const std::vector<xicPeak *> * p_v_peak_list);
virtual void setOutputFilesAndStreams(const QString & filename);
/// some printing and formating methods
virtual void setLocaleAndPrecisionForAllStreams();
virtual void printHeaders();
/// override action on QuantifResultsBase for stored results
virtual void setMatchedPeaks(const std::vector<xicPeak *> * p_v_peak_list);
virtual void printPepLine(const QStringList & list);
/// some printing and formating methods
virtual void printLine(const QStringList & list);
virtual void printHeaders();
/// Output file for
QFile * _compar_output_file;
virtual void printPepLine(const QStringList & list);
//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;
virtual void printLine(const QStringList & list);
private :
/// Output file for compar results
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 -> protein id's list
std::map< QString, QStringList > _map_peptide_description;
//list sampleID
QStringList _sampleIds;
/// The streams corresponding to each output file
QTextStream * _compar_output_stream;
private :
/// The streams corresponding to each output file
QTextStream * _compar_output_stream;
};
#endif /* COMPAR_TSV_QUANTIF_RESULTS_H_ */
......@@ -10,198 +10,231 @@
QuantifResultsBase::QuantifResultsBase()
:
_tmp_element_stream(&_tmp_element),
_sep("\t"),
_endl("\n")
:
_tmp_element_stream(&_tmp_element),
_sep("\t"),
_endl("\n")
{
}
QuantifResultsBase::QuantifResultsBase(const QString & filename)
:
_tmp_element_stream(&_tmp_element),
_sep ("\t"),
_endl("\n")
:
_tmp_element_stream(&_tmp_element),
_sep ("\t"),
_endl("\n")
{
QFileInfo outFileInfo(filename);
QString outDir(outFileInfo.path());
QFileInfo outDirInfo(outDir);
if (! outDirInfo.exists()) {
throw mcqError(QObject::tr("cannot find the output directory '%1' of output file '%2' \n").arg(outDir, filename));
}
QFileInfo outFileInfo(filename);
QString outDir(outFileInfo.path());
QFileInfo outDirInfo(outDir);
if (! outDirInfo.exists())
{
throw mcqError(QObject::tr("cannot find the output directory '%1' of output file '%2' \n").arg(outDir, filename));
}
}
QuantifResultsBase::~QuantifResultsBase(){
QuantifResultsBase::~QuantifResultsBase()
{
}
const QStringList
QuantifResultsBase::getPepHeaders() const {
QStringList tmp_list;
tmp_list << "group";
tmp_list << "msrun";
tmp_list << "msrunfile";
tmp_list << "mz" << "rt" << "maxintensity"
<< "area" << "rtbegin" << "rtend";
tmp_list << "peptide";
tmp_list << "isotope";
tmp_list << "sequence" ;
tmp_list << "z";
tmp_list << "mods";
return (tmp_list);
QuantifResultsBase::getPepHeaders() const
{
QStringList tmp_list;
tmp_list << "group";
tmp_list << "msrun";
tmp_list << "msrunfile";
tmp_list << "mz" << "rt" << "maxintensity"
<< "area" << "rtbegin" << "rtend";
tmp_list << "peptide";
tmp_list << "isotope";
tmp_list << "sequence" ;
tmp_list << "z";
tmp_list << "mods";
return (tmp_list);
}
const QStringList
QuantifResultsBase::getProtHeaders() const {
QStringList tmp_list;
tmp_list << "peptide";
tmp_list << "protein";
tmp_list << "protein_description";
return (tmp_list);
QuantifResultsBase::getProtHeaders() const
{
QStringList tmp_list;
tmp_list << "peptide";
tmp_list << "protein";
tmp_list << "protein_description";
return (tmp_list);
}
const QString &
QuantifResultsBase::formatCell(const mcq_double d) {
_tmp_element = "";
_tmp_element_stream << d;
return (this->formatCell(_tmp_element));
QuantifResultsBase::formatCell(const mcq_double d)
{
_tmp_element = "";
_tmp_element_stream << d;
return (this->formatCell(_tmp_element));
}