Commit 7003b1f9 authored by Edlira Nano's avatar Edlira Nano
Browse files

Changed names continue

git-svn-id: https://subversion.renater.fr/masschroq/trunk@1870 e4b6dbb4-9209-464b-83f7-6257456c460c
parent 3f0ab66e
This diff is collapsed.
/**
* \file mass_chroq.cpp
* \date September 18, 2009
* \author Olivier Langella
*/
#define QT_V_4_5 0x040500
#include "mass_chroq.h"
#include "mcq_error.h"
#include "../saxhandlers/mass_chroq_handler.h"
#include "monitors/monitorList.h"
#include <QFileInfo>
#if QT_VERSION > QT_V_4_5
#include <QUrl>
#include <QXmlSchemaValidator>
#include <QXmlSchema>
#include "messageHandler.h"
#endif
//static variable
QDir MassChroq::tmp_dir;
/**
* We set the temporary working directory to the one precised by the
* user if he did so (second parameter of masschroq); if not we set
* it to the system's temporary directory
*/
void
MassChroq::setTmpDir(QString dirName) {
tmp_dir.setPath(dirName);
if (!tmp_dir.exists()) {
throw qmsError(QObject::tr("error : cannot find the temporary directory : %1 \n").arg(dirName));
} else {
QFileInfo tmpDirInfo(tmp_dir.absolutePath());
if (!tmpDirInfo.isWritable()) {
throw qmsError(QObject::tr("error : cannot write to the temporary directory : %1 \n").arg(dirName));
}
}
}
MassChroq::MassChroq() {
qDebug() << "MassChroq::MassChroq begin";
_output_stream = new QTextStream(stdout, QIODevice::WriteOnly);
_p_quantif_results = new MonitorList();
}
MassChroq::~MassChroq() {
qDebug() << "MassChroq::~MassChroq begin";
//delete msruns
_ms_run_collection.free();
//delete peptides
_peptide_list.free();
delete (_output_stream);
qDebug() << "MassChroq::~MassChroq end";
}
/// Set the XML input filename and verify if it exists and if its readable
void
MassChroq::setXmlFilename(QString fileName) {
_param_file_info.setFile(fileName);
if (!_param_file_info.exists()) {
throw qmsError(QObject::tr("error : cannot find the xml input file : '%1' \n").arg(fileName));
} else if (!_param_file_info.isReadable()) {
throw qmsError(QObject::tr("error : cannot read the xml input file : '%1' \n").arg(fileName));
}
}
/**
* This method validates both XSD schema and XML input file against it
*/
void
MassChroq::validateXmlFile() {
qDebug() << "MassChroq::validateXmlFile begin : Qt local version "
<< QT_VERSION_STR << ", must be > than 4.5";
#if QT_VERSION > QT_V_4_5
QFile schema_file(MASSCHROQ_XSD);
if ( !schema_file.open(QIODevice::ReadOnly) ) {
throw
qmsError(QObject::tr("error opening the file of the XSD schema : %1 \n Try make install to install the schema file. \n").arg(schema_file.fileName()));
}
qDebug()
<< "MassChroq::validateXmlFile enter > 4.5";
QXmlSchema schema;
MessageHandler messHandler;
/// load verifies if the schema is valid before loading it
// attention : if schema is invalid the behaviour is undefined
// this is why we throw the error here
if ( schema.load(&schema_file, QUrl::fromLocalFile(schema_file.fileName())) ) {
schema.setMessageHandler(&messHandler);
QFile file(_param_file_info.filePath());
file.open(QIODevice::ReadOnly);
QXmlSchemaValidator validator(schema);
if (validator.validate(&file, QUrl::fromLocalFile(file.fileName()))) {
qDebug() << "MassChroq::validateXmlFile instance document is valid";
file.close();
} else {
qDebug() << "MassChroq::validateXmlFile instance document is invalid";
QString err_text = messHandler.description();
char err_line[50];
sprintf(err_line, "%d", messHandler.line());
char err_column[50];
sprintf(err_column, "%d", messHandler.column());
throw
qmsError(QObject::tr("error validation against XSD schema in file : %1, at line %2, column %3 : \n %4").arg
(_param_file_info.filePath(),
err_line,
err_column,
err_text
));
}
} else {
throw
qmsError(QObject::tr("error validating XSD schema : %1 : is invalid \n").arg(schema_file.fileName()));
}
#endif
}
/**
* this important method is the first one to be called in this class : it
* launches the parsing of the XML input file and it handles this
* parsing till it ends
*/
void
MassChroq::runXmlFile() {
validateXmlFile();
MassChroqHandler handler(this);
QXmlSimpleReader reader;
reader.setContentHandler(&handler);
reader.setErrorHandler(&handler);
*_output_stream << "Running MassChroq " << QMSCPP_VERSION
<< " with XML file '" << _param_file_info.filePath()
<< "'" << endl;
QFile file(_param_file_info.filePath());
QXmlInputSource xmlInputSource(&file);
if (reader.parse(xmlInputSource)) {
} else {
throw qmsError(QObject::tr("error reading MassChroq param file :\n").append(handler.errorString()));
}
*_output_stream << "MassChroq : DONE on file '"
<< _param_file_info.filePath()
<< "'" << endl;
}
void
MassChroq::addMsRun(msRun * p_msrun) {
p_msrun->sleepOnDisk();
_ms_run_collection.setMsRun(p_msrun);
*_output_stream << "MS run '" << p_msrun->getXmlId() << "' : added" << endl;
qDebug()
<< "MassChroq::addMsRun(const QString & idname, msRun * p_msrun) msrun nb of spectrum : "
<< p_msrun->get_nb_spectrum();
}
void
MassChroq::addAlignmentMethod(const QString & method_id,
AlignmentBase * alignment_method) {
_alignment_methods[method_id] = alignment_method;
*_output_stream << "Alignment method '" << method_id << "' : added" << endl;
}
void
MassChroq::addQuantificationMethod(QuantificationMethod * quantification_method) {
QString quantification_id = quantification_method->getXmlId();
_quantification_methods[quantification_id] = quantification_method;
*_output_stream << "Quantification method '" << quantification_id << "' : added" << endl;
}
void
MassChroq::addIsotopeLabel(const IsotopeLabel * p_isotope_label) {
_map_p_isotope_labels[p_isotope_label->getXmlId()] = p_isotope_label;
}
const IsotopeLabel *
MassChroq::getIsotopeLabel(const QString & label_id) {
return (_map_p_isotope_labels[label_id]);
}
void
MassChroq::newMsRunGroup(const QString & group_id,
const QStringList & list_msrun_ids) {
std::map<QString, msRunHashGroup *>::iterator it;
it = _groups.find(group_id);
if (it == _groups.end()) {
/// OK this key does not exist, we can create it
msRunHashGroup * newgroup = new msRunHashGroup(group_id);
_groups[group_id] = newgroup;
msRun * p_msrun;
QStringListIterator list_it(list_msrun_ids);
QString msrun_id;
while (list_it.hasNext()) {
msrun_id = list_it.next();
p_msrun = _ms_run_collection.getMsRun(msrun_id);
if (p_msrun == NULL) {
/// we have a problem
throw qmsError(QObject::tr("error in MassChroq::newMsRunGroup :\nthe msrun with id %1 does not exist").arg(msrun_id));
} else {
/// verify that this msrun is not already part of an existing group
std::map<QString, msRunHashGroup *>::iterator itverif;
for (itverif = _groups.begin();
itverif != _groups.end();
++itverif) {
if ( (itverif->second)->containsMsRun(p_msrun) ) {
*_output_stream << "WARNING : MS run group '"
<< group_id << "' : contains MS run '"
<< p_msrun->getXmlId()
<< "' which is already part of '"
<< itverif->first
<< "' group"
<< endl;
}
}
/// add this msrun to the new group
newgroup->setMsRun(p_msrun);
}
}
} else {
throw qmsError(QObject::tr("error in MassChroq::newMsRunGroup :\nthe group with id %1 already exists").arg(group_id));
}
QString coutList = list_msrun_ids.join(", ");
*_output_stream << "MS run group '" << group_id
<< "' = ("
<< coutList
<<") : defined" << endl;
}
msRun *
MassChroq::findMsRun(const QString & msrun_id) const {
return _ms_run_collection.getMsRun(msrun_id);
}
msRunHashGroup *
MassChroq::findGroup(const QString & group_id) const {
std::map<QString, msRunHashGroup *>::const_iterator it;
it = _groups.find(group_id);
if (it == _groups.end()) {
return (NULL);
}
return (it->second);
}
const Protein *
MassChroq::findProtein(const QString & protein_id) const {
std::map<QString, const Protein *>::const_iterator it;
it = _p_proteins.find(protein_id);
if (it == _p_proteins.end()) {
return (NULL);
}
return (it->second);
}
AlignmentBase *
MassChroq::findAlignmentMethod(const QString & method_id) const {
std::map<const QString, AlignmentBase *>::const_iterator it;
it = _alignment_methods.find(method_id);
if (it == _alignment_methods.end()) {
return (NULL);
}
return (it->second);
}
QuantificationMethod *
MassChroq::findQuantificationMethod(const QString & method_id) const {
std::map<const QString, QuantificationMethod *>::const_iterator it;
it = _quantification_methods.find(method_id);
if (it == _quantification_methods.end()) {
return (NULL);
}
return (it->second);
}
void
MassChroq::alignGroup(const QString & group_id,
const QString & method_id,
const QString & ref_msrun_id) {
*_output_stream << "MS run group '" << group_id
<< "': alignment method '" << method_id
<< "', reference msrun '" << ref_msrun_id
<< "': alignment begin" << endl;
msRunHashGroup * p_group;
AlignmentBase * p_method;
//find group
p_group = findGroup(group_id);
if (p_group == NULL) {
throw qmsError(QObject::tr("error in MassChroq::alignGroup :\nthe group with id %1 does not exist").arg(group_id));
}
p_method = findAlignmentMethod(method_id);
if (p_method == NULL) {
throw qmsError(QObject::tr("error in MassChroq::alignGroup :\nthe alignment method with id %1 does not exist").arg(method_id));
}
p_group->setReferenceMsrun(ref_msrun_id);
p_group->alignMsRuns(*p_method);
*_output_stream << "MS run group '" << group_id
<< "' : alignment method '" << method_id
<< "', reference msrun '" << ref_msrun_id
<< "' : alignment finished" << endl;
}
void
MassChroq::executeQuantifOnGroup(const vector<const LookForBase *>
v_p_current_mass_to_look_for,
const QString & group_id,
const QString & quantification_id) {
*_output_stream
<< "MS run group '" << group_id
<< "': quantification method '" << quantification_id
<< "': quantification begin" << endl;
msRunHashGroup * p_group;
// find group
p_group = findGroup(group_id);
if (p_group == NULL)
{
throw qmsError(QObject::tr("error in MassChroq::executeQuantifOnGroup :\nthe group with id %1 does not exist").arg(group_id));
}
QuantificationMethod * quanti_method;
// find quantification method
quanti_method = findQuantificationMethod(quantification_id);
if (quanti_method == NULL)
{
throw qmsError(QObject::tr("error in MassChroq::executeQuantifOnGroup :\nthe quantification method with id %1 does not exist").arg(quantification_id));
}
p_group->detectAndQuantify(quanti_method,
v_p_current_mass_to_look_for,
*_p_quantif_results);
*_output_stream
<< "MS run group '" << group_id
<< "': quantification method '" << quantification_id
<< "': quantification finished" << endl;
}
void
MassChroq::addProtein(const Protein * p_protein) {
_p_proteins[p_protein->getXmlId()] = p_protein;
}
void
MassChroq::addPeptideInPeptideList(Peptide * p_peptide) {
_peptide_list.push_back(p_peptide);
}
const Peptide *
MassChroq::getPeptide(const QString pepid) const {
return _peptide_list.getPeptide(pepid);
}
PeptideList *
MassChroq::newPeptideListInGroup(QString & group_xml_id) const {
const msRunHashGroup * group = findGroup(group_xml_id);
if (group == NULL) {
throw qmsError(QObject::tr("error in MassChroq::alignGroup :\nthe group with id %1 does not exist").arg(group_xml_id));
}
return _peptide_list.newPeptideListObservedInMsGroup(*group);
}
void
MassChroq::setPeptideListInMsruns() const {
msRunHashGroup::const_iterator it;
for (it = _ms_run_collection.begin();
it != _ms_run_collection.end();
++it) {
msRun * msrun = it->second;
msrun->setPeptideList( _peptide_list.newPeptideListObservedInMsrun(msrun) );
}
}
void
MassChroq::setResults(MonitorList * p_results) {
if (_p_quantif_results != NULL) {
delete (_p_quantif_results);
}
_p_quantif_results = p_results;
}
void
MassChroq::debriefing() {
_p_quantif_results->debriefing();
}
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