Commit bf8c88e1 authored by Langella Olivier's avatar Langella Olivier
Browse files

WIP: using rocksdb to store peaks for postmatching mode

parent 810fc84d
......@@ -20,7 +20,8 @@ Build-Depends: debhelper (>= 5),
libodsstream-qt5-dev (>=0.4.4),
qtbase5-dev,
libqcustomplot-dev,
libqt5xmlpatterns5-dev
libqt5xmlpatterns5-dev,
librocksdb-dev
Build-Conflicts: qt3-dev-tools
Homepage: http://pappso.inra.fr/bioinfo/masschroq/
......@@ -32,7 +33,9 @@ Depends: ${shlibs:Depends},
libqt5core5a,
libqt5concurrent5,
libpappsomspp-qt5-0 (= @LIBPAPPSOMSPP_VERSION@),
libodsstream-qt5-0
libodsstream-qt5-0,
libgflags2v5,
librocksdb4.5
Replaces: masschroq (<< 1.5.0)
Conflicts: masschroq (<< 1.5.0)
Suggests: masschroq, masschroq-gui, masschroq-studio
......
# Try to find RocksDB headers and library.
#
# Usage of this module as follows:
#
# find_package(RocksDB)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# ROCKSDB_ROOT_DIR Set this variable to the root installation of
# RocksDB if the module has problems finding the
# proper installation path.
#
# Variables defined by this module:
#
# ROCKSDB_FOUND System has RocksDB library/headers.
# ROCKSDB_LIBRARIES The RocksDB library.
# ROCKSDB_INCLUDE_DIRS The location of RocksDB headers.
find_path(ROCKSDB_ROOT_DIR
NAMES include/rocksdb/db.h
)
find_library(ROCKSDB_LIBRARIES
NAMES rocksdb
HINTS ${ROCKSDB_ROOT_DIR}/lib
)
find_path(ROCKSDB_INCLUDE_DIRS
NAMES rocksdb/db.h
HINTS ${ROCKSDB_ROOT_DIR}/include
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(RocksDB DEFAULT_MSG
ROCKSDB_LIBRARIES
ROCKSDB_INCLUDE_DIRS
)
mark_as_advanced(
ROCKSDB_ROOT_DIR
ROCKSDB_LIBRARIES
ROCKSDB_INCLUDE_DIRS
)
......@@ -7,6 +7,14 @@ SET(masschroq_RCCS resources.qrc)
FIND_PACKAGE( Qt5 COMPONENTS Core Gui Xml XmlPatterns Widgets Concurrent PrintSupport REQUIRED )
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/modules)
if (RocksDB_FOUND)
else (RocksDB_FOUND)
FIND_PACKAGE( RocksDB REQUIRED )
endif (RocksDB_FOUND)
if (QCustomPlot_FOUND)
else (QCustomPlot_FOUND)
FIND_PACKAGE( QCustomPlot REQUIRED )
......@@ -42,8 +50,6 @@ ELSE (PAPPSOMSPP_WIDGET_QT5_FOUND)
ENDIF (PAPPSOMSPP_WIDGET_QT5_FOUND)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/modules)
SET (GUI_UIS
......@@ -52,6 +58,7 @@ SET (GUI_UIS
SET(MASSCHROQ_LIB_SRCS
./masschroq_cli.cpp
./mcqsession.cpp
./lib/consoleout.cpp
./lib/mcq_error.h
./lib/share/utilities.cpp
......@@ -206,11 +213,11 @@ ADD_LIBRARY(${MASSCHROQ_LIB_NAME} SHARED ${MASSCHROQ_LIB_SRCS} ${MASSCHROQ_LIB_
${SAXLIB_SRCS} ${OBIWARP_SRCS} ${MASSCHROQ_RCC_SRCS_QT5})
TARGET_LINK_LIBRARIES(${MASSCHROQ_LIB_NAME}
Qt5::Core Qt5::Gui Qt5::Xml Qt5::XmlPatterns Qt5::Concurrent
${PAPPSOMSPP_QT5_LIBRARY} ${ODSSTREAM_QT5_LIBRARY}
${PAPPSOMSPP_QT5_LIBRARY} ${ODSSTREAM_QT5_LIBRARY} ${ROCKSDB_LIBRARIES}
)
target_include_directories (${MASSCHROQ_LIB_NAME} PUBLIC ${Qt5Core_INCLUDES} ${Qt5Concurrent_INCLUDES} ${Qt5Gui_INCLUDES}
${Qt5Xml_INCLUDES} ${Qt5XmlPatterns_INCLUDES} ${PAPPSOMSPP_INCLUDE_DIR} ${ODSSTREAM_INCLUDE_DIR}
${QCustomPlot_INCLUDES} ${QUAZIP_INCLUDE_DIR}
${QCustomPlot_INCLUDES} ${QUAZIP_INCLUDE_DIR} ${ROCKSDB_INCLUDE_DIRS}
)
SET_TARGET_PROPERTIES(${MASSCHROQ_LIB_NAME} PROPERTIES
VERSION ${MASSCHROQ_LIB_VERSION}
......
......@@ -12,6 +12,7 @@
#include "../pepfileparser/masschroq_dom_engine.h"
#include "../lib/peptides/peptide_isotope.h"
#include "./consoleout.h"
#include "../mcqsession.h"
#include <math.h>
#include <QFileInfo>
......@@ -26,63 +27,23 @@
#include "share/utilities.h"
#endif
//static variable
QDir MassChroq::_tmp_dir;
std::shared_ptr<QTemporaryDir> MassChroq::_sp_session_tmp_dir=nullptr;
/**
* 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 mcqError(QObject::tr("error : cannot find the temporary directory : %1 \n").arg(dirName));
}
else
{
QFileInfo tmpDirInfo(_tmp_dir.absolutePath());
if (!tmpDirInfo.isWritable())
{
throw mcqError(QObject::tr("error : cannot write to the temporary directory : %1 \n").arg(dirName));
}
}
if (_sp_session_tmp_dir.get() != nullptr) {
_sp_session_tmp_dir = nullptr;
}
QString name = getSessionTmpDirName();
/*
QFile touch_file(QString("%1/touch_test").arg(name));
if (touch_file.open(QIODevice::WriteOnly)) {
}
else {
throw mcqError(QString("error in MassChroq::setTmpDir :\nunable to open file %1").arg(touch_file.fileName()));
}
touch_file.close();
*/
mcqout() << "MassChroQ temporary directory is set to : " << _tmp_dir.absolutePath() << endl;
McqSession::getInstance().setTmpDir(dirName);
mcqout() << "MassChroQ temporary directory is set to : " << McqSession::getInstance().getTmpDirName() << endl;
}
const QString
MassChroq::getTmpDirName()
{
return _tmp_dir.absolutePath();
return McqSession::getInstance().getTmpDirName();
}
const QString
MassChroq::getSessionTmpDirName()
{
if (_sp_session_tmp_dir.get() == nullptr) {
_sp_session_tmp_dir = std::make_shared<QTemporaryDir>(QString("%1/mcq_session_").arg(_tmp_dir.absolutePath()));
}
return _sp_session_tmp_dir.get()->path();
MassChroq::getSessionTmpDirName() {
return McqSession::getInstance().getSessionTmpDirName();
}
QDateTime MassChroq::begin_date_time;
......
......@@ -190,14 +190,6 @@ protected:
private:
/** @brief Temporary working directory static variable. it has to be set to use MassChroQ
*/
static QDir _tmp_dir;
/** @brief session temporary directory
*/
static std::shared_ptr<QTemporaryDir> _sp_session_tmp_dir;
/** @brief trace directory path */
QDir _traces_directory;
/** @brief traces output format */
......
......@@ -33,28 +33,17 @@
#include "../mass_chroq.h"
#include "../consoleout.h"
#include "../quanti_items/quantiItemBase.h"
#include <rocksdb/db.h>
#include "../../mcqsession.h"
AlignedPeakCollectionOnDisk::AlignedPeakCollectionOnDisk(const QuantiItemBase * p_quanti_item_base)
{
_peak_collection_file.setFileName(MassChroq::getSessionTmpDirName() + "/" + QString("peak_collection_%1").arg(p_quanti_item_base->getMzId()));
if (_peak_collection_file.exists()) {
throw mcqError(QString("error in AlignedPeakCollectionOnDisk::AlignedPeakCollectionOnDisk :\ntemporary file %1 already exists").arg(_peak_collection_file.fileName()));
}
if (_peak_collection_file.open(QIODevice::WriteOnly)) {
}
else {
throw mcqError(QString("error in AlignedPeakCollectionOnDisk::AlignedPeakCollectionOnDisk :\nunable to open file %1").arg(_peak_collection_file.fileName()));
}
_peak_collection_file.close();
_p_quanti_item_base = p_quanti_item_base;
}
AlignedPeakCollectionOnDisk::~AlignedPeakCollectionOnDisk()
{
if (_peak_collection_file.isOpen()) {
_peak_collection_file.close();
}
_peak_collection_file.remove();
}
void AlignedPeakCollectionOnDisk::add(const Msrun* p_current_msrun,AlignedXicPeakSp & xic_peak_sp) {
......@@ -79,6 +68,13 @@ void AlignedPeakCollectionOnDisk::add(const Msrun* p_current_msrun,AlignedXicPea
void AlignedPeakCollectionOnDisk::clear(const Msrun* p_current_msrun) {
_tmp_aligned_peak_list.clear();
QString key(QString("%1-%2").arg(_p_quanti_item_base->getMzId()).arg(p_current_msrun->getXmlId()));
std::string value;
rocksdb::Status s = McqSession::getInstance().getRocksDb()->Delete(rocksdb::WriteOptions(), key.toStdString());
if (!s.ok()) {
throw mcqError(QString("error in AlignedPeakCollectionOnDisk::clear :\nrocksdb::Status status=%1").arg(s.ToString().c_str()));
}
}
std::vector<const Msrun*> AlignedPeakCollectionOnDisk::getMsRunList() {
......@@ -88,8 +84,13 @@ std::vector<const Msrun*> AlignedPeakCollectionOnDisk::getMsRunList() {
std::vector<AlignedXicPeakSp> & AlignedPeakCollectionOnDisk::getMsRunAlignedPeakList(const Msrun* p_msrun) {
qDebug() << "AlignedPeakCollectionOnDisk::getMsRunAlignedPeakList begin" << endl;
_tmp_aligned_peak_list.clear();
_peak_collection_file.open(QIODevice::ReadOnly);
QDataStream instream(&_peak_collection_file);
QString key(QString("%1-%2").arg(_p_quanti_item_base->getMzId()).arg(p_msrun->getXmlId()));
std::string value;
rocksdb::Status s = McqSession::getInstance().getRocksDb()->Get(rocksdb::ReadOptions(), key.toStdString(), &value);
if (!s.ok()) {
throw mcqError(QString("error in AlignedPeakCollectionOnDisk::getMsRunAlignedPeakList :\nrocksdb::Status status=%1").arg(s.ToString().c_str()));
}
QDataStream instream(QByteArray(value.c_str()));
QString msrun_id;
quint32 vector_size;
......@@ -107,11 +108,10 @@ std::vector<AlignedXicPeakSp> & AlignedPeakCollectionOnDisk::getMsRunAlignedPeak
}
}
if (instream.status() != QDataStream::Ok) {
throw mcqError(QString("error in AlignedPeakCollectionOnDisk::getMsRunAlignedPeakList :\nread datastream failed on %1 with QDataStream status=%2").arg(_peak_collection_file.fileName()).arg(instream.status()));
throw mcqError(QString("error in AlignedPeakCollectionOnDisk::getMsRunAlignedPeakList :\nread datastream failed status=%1").arg(instream.status()));
}
}
_peak_collection_file.close();
qDebug() << "AlignedPeakCollectionOnDisk::getMsRunAlignedPeakList end _tmp_aligned_peak_list.size()=" << _tmp_aligned_peak_list.size()<< endl;
return _tmp_aligned_peak_list;
}
......@@ -123,17 +123,20 @@ void AlignedPeakCollectionOnDisk::endMsrunQuantification(const Msrun* p_current_
if (_p_msrun_list.back() != p_current_msrun) {
throw mcqError(QString("error in AlignedPeakCollectionOnDisk::endMsrunQuantification :\n_p_msrun_list.back() != p_current_msrun %1!=2").arg(_p_msrun_list.back()->getXmlId()).arg(p_current_msrun->getXmlId()));
}
if (!_peak_collection_file.exists()) {
throw mcqError(QString("error in AlignedPeakCollectionOnDisk::endMsrunQuantification :\ntemporary file %1 does not exists").arg(_peak_collection_file.fileName()));
}
_peak_collection_file.open(QIODevice::Append);
QDataStream outstream(&_peak_collection_file);
QByteArray buffer;
QDataStream outstream( &buffer, QIODevice::ReadWrite );
outstream << p_current_msrun->getXmlId();
outstream << (quint32) _tmp_aligned_peak_list.size();
for (AlignedXicPeakSp xic_peak_sp:_tmp_aligned_peak_list) {
xic_peak_sp->serialize(&outstream);
}
_peak_collection_file.close();
QString key(QString("%1-%2").arg(_p_quanti_item_base->getMzId()).arg(p_current_msrun->getXmlId()));
std::string value;
rocksdb::Status s = McqSession::getInstance().getRocksDb()->Put(rocksdb::WriteOptions(), key.toStdString(), buffer.data());
if (!s.ok()) {
throw mcqError(QString("error in AlignedPeakCollectionOnDisk::endMsrunQuantification :\nrocksdb::Status status=%1").arg(s.ToString().c_str()));
}
}
_tmp_aligned_peak_list.clear();
......
......@@ -53,7 +53,7 @@ public:
private :
std::vector<const Msrun*> _p_msrun_list;
QFile _peak_collection_file;
const QuantiItemBase * _p_quanti_item_base;
std::vector<AlignedXicPeakSp> _tmp_aligned_peak_list;
};
......
/*******************************************************************************
* Copyright (c) 2018 Olivier Langella <Olivier.Langella@u-psud.fr>.
*
* This file is part of the MassChroQ software.
*
* MassChroQ 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.
*
* MassChroQ 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 MassChroQ. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* Olivier Langella <Olivier.Langella@u-psud.fr> - initial API and implementation
******************************************************************************/
/**
* \file mcqsession.cpp
* \date April 28, 2018
* \author Olivier Langella
* \brief singleton to store general informations on the current MassChroQ session
*/
#include "mcqsession.h"
#include "lib/mcq_error.h"
McqSession McqSession::m_instance=McqSession();
McqSession::McqSession()
{
}
rocksdb::DB* McqSession::getRocksDb() {
if (m_p_db == nullptr) {
rocksdb::Options options;
options.create_if_missing = true;
rocksdb::Status status =
rocksdb::DB::Open(options, QString("%1/rocksdb").arg(getSessionTmpDirName()).toStdString(), &m_p_db);
assert(status.ok());
}
return m_p_db;
}
McqSession::~McqSession()
{
if (m_p_db != nullptr) delete m_p_db;
}
McqSession& McqSession::getInstance()
{
return m_instance;
}
void McqSession::setTmpDir(const QString & dir_name) {
_tmp_dir.setPath(dir_name);
if (!_tmp_dir.exists())
{
throw mcqError(QObject::tr("error : cannot find the temporary directory : %1 \n").arg(dir_name));
}
else
{
QFileInfo tmpDirInfo(_tmp_dir.absolutePath());
if (!tmpDirInfo.isWritable())
{
throw mcqError(QObject::tr("error : cannot write to the temporary directory : %1 \n").arg(dir_name));
}
}
if (_sp_session_tmp_dir.get() != nullptr) {
_sp_session_tmp_dir = nullptr;
}
QString name = getSessionTmpDirName();
}
const QString McqSession::getTmpDirName() {
return _tmp_dir.absolutePath();
}
const QString McqSession::getSessionTmpDirName() {
if (_sp_session_tmp_dir.get() == nullptr) {
_sp_session_tmp_dir = std::make_shared<QTemporaryDir>(QString("%1/mcq_session_").arg(_tmp_dir.absolutePath()));
}
return _sp_session_tmp_dir.get()->path();
}
/*******************************************************************************
* Copyright (c) 2018 Olivier Langella <Olivier.Langella@u-psud.fr>.
*
* This file is part of the MassChroQ software.
*
* MassChroQ 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.
*
* MassChroQ 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 MassChroQ. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* Olivier Langella <Olivier.Langella@u-psud.fr> - initial API and implementation
******************************************************************************/
/**
* \file mcqsession.h
* \date April 28, 2018
* \author Olivier Langella
* \brief singleton to store general informations on the current MassChroQ session
*/
#ifndef MCQSESSION_H
#define MCQSESSION_H
#include <QTemporaryDir>
#include <rocksdb/db.h>
class McqSession
{
public:
static McqSession& getInstance();
void setTmpDir(const QString & dir_name);
const QString getSessionTmpDirName();
const QString getTmpDirName();
rocksdb::DB* getRocksDb();
private:
McqSession();
~McqSession();
private:
static McqSession m_instance;
/** @brief Temporary working directory static variable. it has to be set to use MassChroQ
*/
QDir _tmp_dir;
/** @brief session temporary directory
*/
std::shared_ptr<QTemporaryDir> _sp_session_tmp_dir=nullptr;
rocksdb::DB* m_p_db = nullptr;
};
#endif // MCQSESSION_H
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