Commit 926153e4 authored by Edlira Nano's avatar Edlira Nano
Browse files

corrected bug of traces for all peptides in post_matching mode when asked for...

corrected bug of traces for all peptides in post_matching mode when asked for traces for some peptides only

git-svn-id: https://subversion.renater.fr/masschroq/trunk@2271 e4b6dbb4-9209-464b-83f7-6257456c460c
parent 38fc3f1e
......@@ -5,23 +5,26 @@
*/
#include "tsv_all_xics.h"
//#include "../msrun/ms_run_hash_group.h"
TsvAllXics::TsvAllXics(const QString output_dir) :
XicTracesBase(output_dir)
TsvAllXics::TsvAllXics(const QString output_dir)
:
XicTracesBase(output_dir)
{
/// all is to be traced
setToBeTraced(true);
/// all is to be traced
setToBeTraced(true);
}
TsvAllXics::~TsvAllXics() {
TsvAllXics::~TsvAllXics()
{
}
void
TsvAllXics::setTraceItem(QuantiItemBase * quanti_item) {
/// all is to be traced, nothing to do
TsvAllXics::setTraceItem(QuantiItemBase * quanti_item)
{
/// all is to be traced, nothing to do
}
void
TsvAllXics::privateEndCurrentSearchItem() {
TsvAllXics::privateUnsetTraceItem()
{
}
......@@ -51,7 +51,7 @@ class TsvAllXics : public XicTracesBase {
virtual void setTraceItem(QuantiItemBase * quanti_item);
virtual void privateEndCurrentSearchItem();
virtual void privateUnsetTraceItem();
};
......
......@@ -5,43 +5,48 @@
*/
#include "tsv_mzlist_xics.h"
//#include "../look_for/lookForBase.h"
TsvMzListXics::TsvMzListXics(const QString output_dir) :
XicTracesBase(output_dir)
TsvMzListXics::TsvMzListXics(const QString output_dir)
:
XicTracesBase(output_dir)
{
setToBeTraced(false);
setToBeTraced(false);
}
TsvMzListXics::~TsvMzListXics() {
TsvMzListXics::~TsvMzListXics()
{
}
void
TsvMzListXics::addMz(const mcq_double mz) {
_v_mz_values.push_back(mz);
TsvMzListXics::addMz(const mcq_double mz)
{
_v_mz_values.push_back(mz);
}
void
TsvMzListXics::setTraceItem(QuantiItemBase * quanti_item) {
if (quanti_item->getType() == MZ_QUANTI_ITEM) {
mcq_double current_mz(quanti_item->get_mz());
std::vector<mcq_double>::const_iterator it;
for (it = _v_mz_values.begin();
it != _v_mz_values.end();
++it) {
if (*it == current_mz) {
/// tracing flag becomes true
setToBeTraced(true);
return;
}
}
}
TsvMzListXics::setTraceItem(QuantiItemBase * quanti_item)
{
if (quanti_item->getType() == MZ_QUANTI_ITEM)
{
mcq_double current_mz(quanti_item->get_mz());
std::vector<mcq_double>::const_iterator it;
for (it = _v_mz_values.begin();
it != _v_mz_values.end();
++it)
{
if (*it == current_mz)
{
/// tracing flag becomes true
setToBeTraced(true);
return;
}
}
}
}
void
TsvMzListXics::privateEndCurrentSearchItem() {
setToBeTraced(false);
TsvMzListXics::privateUnsetTraceItem()
{
setToBeTraced(false);
}
......@@ -52,7 +52,7 @@ protected :
virtual void setTraceItem(QuantiItemBase * quanti_item);
virtual void privateEndCurrentSearchItem();
virtual void privateUnsetTraceItem();
private:
......
......@@ -8,41 +8,49 @@
#include "../quanti_items/quantiItemMzRt.h"
TsvMzRtXics::TsvMzRtXics(const QString output_dir) :
XicTracesBase(output_dir)
TsvMzRtXics::TsvMzRtXics(const QString output_dir)
:
XicTracesBase(output_dir)
{
setToBeTraced(false);
setToBeTraced(false);
}
TsvMzRtXics::~TsvMzRtXics() {
TsvMzRtXics::~TsvMzRtXics()
{
}
void
TsvMzRtXics::addMzRt(const mcq_double mz, const mcq_double rt) {
pair<mcq_double, mcq_double> elmt(mz, rt);
_v_mzrt_values.push_back(elmt);
TsvMzRtXics::addMzRt(const mcq_double mz, const mcq_double rt)
{
pair<mcq_double, mcq_double> elmt(mz, rt);
_v_mzrt_values.push_back(elmt);
}
void
TsvMzRtXics::setTraceItem(QuantiItemBase * quanti_item) {
if (quanti_item->getType() == MZRT_QUANTI_ITEM) {
const mcq_double current_mz(quanti_item->get_mz());
const mcq_double current_rt(quanti_item->getRt());
std::vector< pair<mcq_double, mcq_double> >::const_iterator it;
for (it = _v_mzrt_values.begin();
it != _v_mzrt_values.end();
++it) {
if ( (it->first == current_mz) &&
(it->second == current_rt) ) {
/// tracing flag becomes true
setToBeTraced(true);
return;
}
}
}
TsvMzRtXics::setTraceItem(QuantiItemBase * quanti_item)
{
if (quanti_item->getType() == MZRT_QUANTI_ITEM)
{
const mcq_double current_mz(quanti_item->get_mz());
const mcq_double current_rt(quanti_item->getRt());
std::vector< pair<mcq_double, mcq_double> >::const_iterator it;
for (it = _v_mzrt_values.begin();
it != _v_mzrt_values.end();
++it)
{
if ( (it->first == current_mz) &&
(it->second == current_rt) )
{
/// tracing flag becomes true
setToBeTraced(true);
return;
}
}
}
}
void
TsvMzRtXics::privateEndCurrentSearchItem() {
setToBeTraced(false);
TsvMzRtXics::privateUnsetTraceItem()
{
setToBeTraced(false);
}
......@@ -51,7 +51,7 @@ protected :
virtual void setTraceItem(QuantiItemBase * quanti_item);
virtual void privateEndCurrentSearchItem();
virtual void privateUnsetTraceItem();
private:
......
......@@ -8,49 +8,58 @@
#include "../peptides/peptide_list.h"
#include "algorithm"
TsvPepListXics::TsvPepListXics(const QString output_dir) :
XicTracesBase(output_dir)
TsvPepListXics::TsvPepListXics(const QString output_dir)
:
XicTracesBase(output_dir)
{
setToBeTraced(false);
setToBeTraced(false);
}
TsvPepListXics::~TsvPepListXics() {
_peptide_list.clear();
TsvPepListXics::~TsvPepListXics()
{
_peptide_list.clear();
}
void
TsvPepListXics::addPeptide(const QString & pepId) {
_peptide_list.push_back(pepId);
TsvPepListXics::addPeptide(const QString & pepId)
{
_peptide_list.push_back(pepId);
}
bool
TsvPepListXics::containsPeptide(const QString & pepId) const {
vector<QString>::const_iterator it;
it = find(_peptide_list.begin(), _peptide_list.end(), pepId);
if (it != _peptide_list.end())
return true;
else
return false;
TsvPepListXics::containsPeptide(const QString & pepId) const
{
vector<QString>::const_iterator it;
it = find(_peptide_list.begin(), _peptide_list.end(), pepId);
if (it != _peptide_list.end())
return true;
else
return false;
}
void
TsvPepListXics::setTraceItem(QuantiItemBase * quanti_item) {
if (quanti_item->getType() == PEPTIDE_QUANTI_ITEM) {
const Peptide * current_pep(quanti_item->getPeptide());
if (current_pep != NULL) {
QString current_pep_id = current_pep->getXmlId();
if ( containsPeptide(current_pep_id) ) {
/// tracing flag becomes true
setToBeTraced(true);
_current_pep_id = current_pep_id;
}
}
}
TsvPepListXics::setTraceItem(QuantiItemBase * quanti_item)
{
if (quanti_item->getType() == PEPTIDE_QUANTI_ITEM)
{
const Peptide * current_pep(quanti_item->getPeptide());
if (current_pep != NULL)
{
QString current_pep_id = current_pep->getXmlId();
if ( containsPeptide(current_pep_id) )
{
/// tracing flag becomes true
setToBeTraced(true);
_current_pep_id = current_pep_id;
}
}
}
}
void
TsvPepListXics::privateEndCurrentSearchItem() {
_current_pep_id.clear();
setToBeTraced(false);
TsvPepListXics::privateUnsetTraceItem()
{
_current_pep_id.clear();
setToBeTraced(false);
}
......@@ -53,7 +53,7 @@ class TsvPepListXics : public XicTracesBase {
virtual void setTraceItem(QuantiItemBase * quanti_item);
virtual void privateEndCurrentSearchItem();
virtual void privateUnsetTraceItem();
private:
......
......@@ -9,194 +9,194 @@
#include "../xic/xic_base.h"
XicTracesBase::XicTracesBase(const QString & output_dir)
:
_tmp_element_stream(&_tmp_element),
_sep("\t")
:
_tmp_element_stream(&_tmp_element),
_sep("\t")
{
/// verify and set the output directory
QFileInfo output_dir_info(output_dir);
if (! output_dir_info.exists()) {
QDir current_dir = QDir::current();
if (! current_dir.mkdir(output_dir)) {
QString new_name("xic_traces");
current_dir.mkdir(new_name);
output_dir_info.setFile(new_name);
}
/// verify and set the output directory
QFileInfo output_dir_info(output_dir);
if (! output_dir_info.exists()) {
QDir current_dir = QDir::current();
if (! current_dir.mkdir(output_dir)) {
QString new_name("xic_traces");
current_dir.mkdir(new_name);
output_dir_info.setFile(new_name);
}
cout << "WARNING : quantification traces directory '"
<< output_dir.toStdString()
<< "' does not exist, creating directory '"
<< output_dir_info.absoluteFilePath().toStdString() << "'" << endl;
}
cout << "WARNING : quantification traces directory '"
<< output_dir.toStdString()
<< "' does not exist, creating directory '"
<< output_dir_info.absoluteFilePath().toStdString() << "'" << endl;
}
_output_dir_name = output_dir_info.absoluteFilePath();
_output_dir_name = output_dir_info.absoluteFilePath();
_current_stream = new QTextStream();
setLocaleAndPrecisionForAllStreams();
cout << "Writing quantification traces in directory '"
<< (output_dir_info.absoluteFilePath()).toStdString()
<< "'" << endl;
_current_stream = new QTextStream();
setLocaleAndPrecisionForAllStreams();
cout << "Writing quantification traces in directory '"
<< (output_dir_info.absoluteFilePath()).toStdString()
<< "'" << endl;
}
XicTracesBase::~XicTracesBase(){
if (_current_stream != 0) {
_current_stream->flush();
delete _current_stream;
_current_stream = 0;
}
if (_current_stream != 0) {
_current_stream->flush();
delete _current_stream;
_current_stream = 0;
}
}
bool
XicTracesBase::isToBeTraced() const {
return _toBeTraced;
return _toBeTraced;
}
void
XicTracesBase::setToBeTraced(const bool b) {
_toBeTraced = b;
_toBeTraced = b;
}
const QString
XicTracesBase::setTraceFileName(QuantiItemBase * quanti_item) {
QString prefix(_current_quantify_id);
prefix.append("_").append(_current_group_id).append("_");
prefix.append(_current_msrun->getXmlId()).append("_");
prefix.append(quanti_item->getSimpleName(_current_msrun));
QString current_filename = _output_dir_name;
current_filename.append("/").append(prefix).append(".tsv");
return current_filename;
QString prefix(_current_quantify_id);
prefix.append("_").append(_current_group_id).append("_");
prefix.append(_current_msrun->getXmlId()).append("_");
prefix.append(quanti_item->getSimpleName(_current_msrun));
QString current_filename = _output_dir_name;
current_filename.append("/").append(prefix).append(".tsv");
return current_filename;
}
void
XicTracesBase::setLocaleAndPrecisionForStream(QTextStream * stream) {
#if QT_VERSION >= QT_V_4_5
stream->setLocale(QLocale::system());
stream->setLocale(QLocale::system());
#endif
stream->setRealNumberPrecision(8);
stream->setRealNumberNotation(QTextStream::SmartNotation);
stream->setRealNumberPrecision(8);
stream->setRealNumberNotation(QTextStream::SmartNotation);
}
void
XicTracesBase::setLocaleAndPrecisionForAllStreams() {
setLocaleAndPrecisionForStream(&_tmp_element_stream);
setLocaleAndPrecisionForStream(_current_stream);
setLocaleAndPrecisionForStream(&_tmp_element_stream);
setLocaleAndPrecisionForStream(_current_stream);
}
void
XicTracesBase::setCurrentQuantify(const QString & quantify_id) {
_current_quantify_id.clear();
_current_quantify_id = quantify_id;
_current_quantify_id.clear();
_current_quantify_id = quantify_id;
}
void
XicTracesBase::setCurrentGroup(const msRunHashGroup * group) {
_current_group_id.clear();
_current_group_id = group->getXmlId();
_current_group_id.clear();
_current_group_id = group->getXmlId();
}
void
XicTracesBase::setEndCurrentGroup() {
_current_group_id.clear();
_current_group_id.clear();
}
void
XicTracesBase::setCurrentMsrun(const Msrun * msrun) {
_current_msrun = msrun;
_current_msrun = msrun;
}
void
XicTracesBase::setEndCurrentMsrun() {
_current_msrun = 0;
_current_msrun = 0;
}
void
XicTracesBase::setCurrentSearchItem(QuantiItemBase * quanti_item) {
setTraceItem(quanti_item);
if ( isToBeTraced() ) {
const QString filename = setTraceFileName(quanti_item);
_current_file.setFileName(filename);
setTraceItem(quanti_item);
if ( isToBeTraced() ) {
const QString filename = setTraceFileName(quanti_item);
_current_file.setFileName(filename);
if (!_current_file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
_current_file.close();
delete _current_stream;
throw mcqError(QObject::tr("Cannot create file : '%1'.").arg(_current_file.fileName()));
}
if (!_current_file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
_current_file.close();
delete _current_stream;
throw mcqError(QObject::tr("Cannot create file : '%1'.").arg(_current_file.fileName()));
}
_current_stream->setDevice(&_current_file);
printCurrentTitle(quanti_item);
_current_header << "rt" << "intensities";
}
_current_stream->setDevice(&_current_file);
printCurrentTitle(quanti_item);
_current_header << "rt" << "intensities";
}
}
void
XicTracesBase::setEndCurrentSearchItem() {
if ( isToBeTraced() ) {
_current_header.clear();
_current_file.close();
_current_xic_v_int.clear();
_current_xic_v_rt.clear();
_current_filters_v_int.clear();
_current_allpeaks_v_maxintensity.clear();
privateEndCurrentSearchItem();
}
if ( isToBeTraced() ) {
_current_header.clear();
_current_file.close();
_current_xic_v_int.clear();
_current_xic_v_rt.clear();
_current_filters_v_int.clear();
_current_allpeaks_v_maxintensity.clear();
privateUnsetTraceItem();
}
}
void
XicTracesBase::setXic(const xicBase * xic) {
if ( isToBeTraced() ) {
_current_xic_v_rt = xic->getAlignedRetentionTimes();
_current_xic_v_int = *(xic->getConstIntensities());
}
if ( isToBeTraced() ) {
_current_xic_v_rt = xic->getAlignedRetentionTimes();
_current_xic_v_int = *(xic->getConstIntensities());
}
}
void
XicTracesBase::setFilteredXic(const xicBase * xic,
const QString & filterType,
const unsigned int filterNum) {
if ( isToBeTraced() ) {
QString filterInfo = QString("filter_%1").arg(filterType);
_current_header << filterInfo;
_current_filters_v_int.push_back(*(xic->getConstIntensities()));
}
const QString & filterType,
const unsigned int filterNum) {
if ( isToBeTraced() ) {
QString filterInfo = QString("filter_%1").arg(filterType);
_current_header << filterInfo;
_current_filters_v_int.push_back(*(xic->getConstIntensities()));
}
}
void
XicTracesBase::setAllPeaks(const std::vector<xicPeak *> * p_v_peak_list) {
if ( isToBeTraced() ) {
QString allpeaks = QString("all_peaks_max_intensity");
_current_header << allpeaks;
vector<mcq_double>::const_iterator it_xic_rt;
vector<xicPeak *>::const_iterator it_peaks;
for (it_xic_rt = _current_xic_v_rt.begin();
it_xic_rt != _current_xic_v_rt.end();
++it_xic_rt) {
bool found(false);
if ( isToBeTraced() ) {
QString allpeaks = QString("all_peaks_max_intensity");
_current_header << allpeaks;
vector<mcq_double>::const_iterator it_xic_rt;
vector<xicPeak *>::const_iterator it_peaks;
for (it_xic_rt = _current_xic_v_rt.begin();
it_xic_rt != _current_xic_v_rt.end();
++it_xic_rt) {
bool found(false);
for (it_peaks = p_v_peak_list->begin();
it_peaks != p_v_peak_list->end();
++it_peaks) {
if ( *it_xic_rt == (*it_peaks)->get_aligned_max_rt() ) {
found = true;
mcq_double max_int = (*it_peaks)->get_max_intensity();
_current_allpeaks_v_maxintensity.push_back(max_int);
for (it_peaks = p_v_peak_list->begin();
it_peaks != p_v_peak_list->end();
++it_peaks) {
if ( *it_xic_rt == (*it_peaks)->get_aligned_max_rt() ) {
found = true;
mcq_double max_int = (*it_peaks)->get_max_intensity();
_current_allpeaks_v_maxintensity.push_back(max_int);
}
}
if (! found) {
_current_allpeaks_v_maxintensity.push_back(-1);
}
}
}
}
if (! found) {
_current_allpeaks_v_maxintensity.push_back(-1);