diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..6a45f3d8530f6e6313ca4f80ed570078fe4700e1 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,185 @@ +# CMake script for C++ X!TandemPipeline +# Author: Olivier Langella +# Created: 05/06/2015 + +# Global parameters +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(xtpcpp CXX) +IF(NOT CMAKE_BUILD_TYPE) +# SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING +# "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." +# FORCE) + SET(CMAKE_BUILD_TYPE Debug CACHE STRING + "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." + FORCE) +ENDIF(NOT CMAKE_BUILD_TYPE) + +MESSAGE("CMAKE_BUILD_TYPE : ${CMAKE_BUILD_TYPE}") + +IF(CMAKE_BUILD_TYPE MATCHES "Release") + MESSAGE("compiling as release version") + ADD_DEFINITIONS("-DQT_NO_DEBUG_OUTPUT") +ENDIF( CMAKE_BUILD_TYPE MATCHES "Release" ) + +IF(CMAKE_BUILD_TYPE MATCHES "Debug") + MESSAGE("compiling as debug version") +ENDIF( CMAKE_BUILD_TYPE MATCHES "Debug" ) + +IF(CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo") + MESSAGE("compiling as release with debug info version") +ENDIF( CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo" ) + +#SET(CMAKE_CXX_FLAGS "-Wall -Weffc++ -Wshadow -Wconversion") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + + + +SET(SOFTWARE_NAME "XTPcpp") + +SET(XTPCPP_VERSION_MAJOR "0") +SET(XTPCPP_VERSION_MINOR "2") +SET(XTPCPP_VERSION_PATCH "0") +SET(XTPCPP_VERSION "${XTPCPP_VERSION_MAJOR}.${XTPCPP_VERSION_MINOR}.${XTPCPP_VERSION_PATCH}") + +# Set the CMAKE_PREFIX_PATH for the find_library fonction when using non +# standard install location +IF(CMAKE_INSTALL_PREFIX) + SET(CMAKE_PREFIX_PATH "${CMAKE_INSTALL_PREFIX}" ${CMAKE_PREFIX_PATH}) +ENDIF(CMAKE_INSTALL_PREFIX) + +# Subdirectories +ADD_SUBDIRECTORY(src) + +# Doxygen +FIND_PACKAGE(Doxygen) +IF (DOXYGEN_FOUND) + ADD_CUSTOM_TARGET (apidoc cp Doxyfile ${CMAKE_BINARY_DIR}/Doxyfile-build + COMMAND echo "OUTPUT_DIRECTORY=${CMAKE_BINARY_DIR}" >> ${CMAKE_BINARY_DIR}/Doxyfile-build + COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile-build + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + ADD_CUSTOM_TARGET (apidoc-stable cp Doxyfile ${CMAKE_BINARY_DIR}/Doxyfile-stable + COMMAND echo "OUTPUT_DIRECTORY=${CMAKE_BINARY_DIR}" >> ${CMAKE_BINARY_DIR}/Doxyfile-stable + COMMAND echo "HTML_HEADER=header.html" >> ${CMAKE_BINARY_DIR}/Doxyfile-stable + COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile-stable + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) +ENDIF (DOXYGEN_FOUND) + +# Packager +SET(CPACK_PACKAGE_NAME "xtpcpp") +SET(CPACK_PACKAGE_VENDOR "PAPPSO Development Team") +SET(CPACK_PACKAGE_VERSION "${PAPPSOMSTOOLS_VERSION}") +SET(CPACK_PACKAGE_VERSION_MAJOR "${PAPPSOMSTOOLS_VERSION_MAJOR}") +SET(CPACK_PACKAGE_VERSION_MINOR "${PAPPSOMSTOOLS_VERSION_MINOR}") +SET(CPACK_PACKAGE_VERSION_PATCH "${PAPPSOMSTOOLS_VERSION_PATCH}") +SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "various mass spectrometry and proteomics tools") +SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING") +SET(CPACK_RESOURCE_FILE_AUTHORS "${CMAKE_SOURCE_DIR}/AUTHORS") +SET(CPACK_RESOURCE_FILE_INSTALL "${CMAKE_SOURCE_DIR}/INSTALL") +SET(CPACK_SOURCE_GENERATOR "TGZ") +SET(CPACK_SOURCE_IGNORE_FILES + "CMakeFiles" + "Makefile" + "_CPack_Packages" + "CMakeCache.txt" + ".*\\\\.git" + ".*\\\\.gz" + ".*\\\\.deb" + ".*\\\\.rpm" + ".*\\\\.dmg" + ".*\\\\..*\\\\.swp" + "src/\\\\..*" + "src/libbpp*" + "debian/tmp" + "debian/libbpp.*/" + "debian/libbpp.*\\\\.so.*" + "debian/libbpp.*\\\\.a" + "debian/libbpp.*\\\\.substvars" + "debian/libbpp.*\\\\.debhelper" + "debian/debhelper\\\\.log" + "build/" + "html" + "Core.tag" + "Testing" + "build-stamp" + "install_manifest.txt" + "DartConfiguration.tcl" + ${CPACK_SOURCE_IGNORE_FILES} +) + + + +#dch -Djessie "message" +#cmake .. +#make deb +# scp pappsoms-tools* proteus.moulon.inra.fr:/var/www/apt/incoming +# reprepro -Vb /var/www/apt processincoming default +# +# debuild -S -sa +# dput -f olivier-langella *changes + +IF (MACOS) + SET(CPACK_GENERATOR "Bundle") +ENDIF() + +SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") +SET(CPACK_DEBSOURCE_PACKAGE_FILE_NAME "lib${CMAKE_PROJECT_NAME}_${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}.orig") +INCLUDE(CPack) + +#This adds the 'dist' target +ADD_CUSTOM_TARGET(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source) +# 'clean' is not (yet) a first class target. However, we need to clean the directories before building the sources: +IF("${CMAKE_GENERATOR}" MATCHES "Make") + ADD_CUSTOM_TARGET(make_clean + COMMAND ${CMAKE_MAKE_PROGRAM} clean + WORKING_DIRECTORY ${CMAKE_CURRENT_DIR} + ) + ADD_DEPENDENCIES(dist make_clean) +ENDIF() + +IF (UNIX) +#This creates deb packages: + + + + add_custom_target(targz + cpack -G TGZ --config CPackSourceConfig.cmake && tar xvfz ${CPACK_PACKAGE_NAME}-${PAPPSOMSTOOLS_VERSION}.tar.gz + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Creating .tar.gz" VERBATIM + ) + + + add_custom_target(deb + cd ${CPACK_PACKAGE_NAME}-${PAPPSOMSTOOLS_VERSION} && dpkg-buildpackage + DEPENDS targz + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Creating Debian package" VERBATIM + ) + + file(GLOB changesdebs "${CMAKE_BINARY_DIR}/${CPACK_PACKAGE_NAME}_*.dsc") + + foreach(libfile ${changesdebs}) + SET(changesdeb "${libfile}") + endforeach(libfile) + + message ("changes debian file : ${changesdeb}") + #lintian -IEi --pedantic tandem-mass_2013.06.15-1_amd64.changes + add_custom_target(lintian + lintian -IEi --pedantic ${changesdeb} + DEPENDS deb + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "lintian check" VERBATIM + ) + +ENDIF() + +SET(CTEST_UPDATE_TYPE git) +SET(UPDATE_COMMAND "git") +SET(UPDATE_OPTIONS "") + +#ENABLE_TESTING() +#INCLUDE(CTest) +#IF (BUILD_TESTING) +# ADD_SUBDIRECTORY(test) +#ENDIF(BUILD_TESTING) + +INSTALL(PROGRAMS ${CMAKE_BINARY_DIR}/src/xtpcpp DESTINATION bin) \ No newline at end of file diff --git a/cmake_modules/FindPwiz.cmake b/cmake_modules/FindPwiz.cmake new file mode 100644 index 0000000000000000000000000000000000000000..578ee5176d3353f373c970e445d787beddf77d9a --- /dev/null +++ b/cmake_modules/FindPwiz.cmake @@ -0,0 +1,25 @@ +# Copyright : ETH Zurich +# License : three-clause BSD license +# Authors : Witold Wolski +# for full text refer to files: LICENSE, AUTHORS and COPYRIGHT +#FIND_PATH(Pwiz_INCLUDE_DIR pwiz/Version.hpp) + FIND_PATH( Pwiz_INCLUDE_DIR pwiz/Version.hpp + PATHS /usr/local/include /usr/include + PATH_SUFFIXES pwiz libpwiz ENV PATH) + +FIND_LIBRARY(Pwiz_LIBRARY NAMES pwiz) +IF (Pwiz_INCLUDE_DIR AND Pwiz_LIBRARY) +MESSAGE(STATUS "XXXXXXXXXXXXX ${Pwiz_LIBRARY} XXXXXXXXXXXXXXX") +SET(Pwiz_FOUND TRUE) +ENDIF (Pwiz_INCLUDE_DIR AND Pwiz_LIBRARY) +IF (Pwiz_FOUND) +# show which CppUnit was found only if not quiet +IF (NOT Pwiz_FIND_QUIETLY) +MESSAGE(STATUS "Found Pwiz: ${Pwiz_LIBRARY}") +ENDIF (NOT Pwiz_FIND_QUIETLY) +ELSE (Pwiz_FOUND) +# fatal error if CppUnit is required but not found +IF (Pwiz_FIND_REQUIRED) +MESSAGE(FATAL_ERROR "Could not find Pwiz please do specify the Pwiz_INCLUDE_DIR and the Pwiz_LIBRARY variables using ccmake!") +ENDIF (Pwiz_FIND_REQUIRED) +ENDIF (Pwiz_FOUND) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..dce53c9a5d40c88ddf999bb8875da1ab688894df --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,90 @@ +# CMake script for xtpcpp +# Author: Olivier Langella +# Created: 03/03/2015 + + +# Appeler automatique le moc quand nécessaire +#SET(CMAKE_AUTOMOC ON) +# Les fichiers générés par le moc sont générés dans le dossier bin, dire à CMake de toujours +# inclure les entêtes de ce dossier +#SET(CMAKE_INCLUDE_CURRENT_DIR ON) + +#FIND_PACKAGE(Boost REQUIRED) +#INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS}) + +FIND_PACKAGE( Qt4 COMPONENTS QTCORE QTGUI QTSVG REQUIRED ) + + +FIND_PACKAGE( Odsstream REQUIRED ) #ODSSTREAM_INCLUDE_DIR AND ODSSTREAM_LIBRARY +#SET (ODSSTREAM_DIR "/home/olivier/eclipse/git/cpp_libodsstream") +#SET (ODSSTREAM_INCLUDE_DIR "${ODSSTREAM_DIR}/src") +#SET (ODSSTREAM_QT5_LIBRARY "${ODSSTREAM_DIR}/build/src/libodsstream-qt5.so") +INCLUDE_DIRECTORIES(${ODSSTREAM_INCLUDE_DIR}) + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Xml_EXECUTABLE_COMPILE_FLAGS} ${Qt5Gui_EXECUTABLE_COMPILE_FLAGS} ${Qt5Svg_EXECUTABLE_COMPILE_FLAGS}") + + +#FIND_PACKAGE( Pappsomspp REQUIRED ) +SET (PAPPSOMSPP_DIR "/home/olivier/eclipse/git/pappsomspp") +#SET (PAPPSOMSPP_DIR "/home/langella/developpement/git/pappsomspp") +SET (PAPPSOMSPP_INCLUDE_DIR "${PAPPSOMSPP_DIR}/src") +SET (PAPPSOMSPP_QT4_LIBRARY "${PAPPSOMSPP_DIR}/build/src/libpappsomspp-qt4.so") + +INCLUDE_DIRECTORIES( ${PAPPSOMSPP_INCLUDE_DIR} ) + +set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules) + +FIND_PACKAGE(Pwiz REQUIRED) +INCLUDE_DIRECTORIES( ${Pwiz_INCLUDE_DIR}) +IF (Pwiz_FOUND) + INCLUDE_DIRECTORIES( ${Pwiz_INCLUDE_DIR}) + #FIND_PACKAGE(Boost REQUIRED) + #INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS}) +ELSE (Pwiz_FOUND) + MESSAGE("Proteowizard library not found") + MESSAGE("did you apt-get install libpwiz-dev libboost-dev ?") +ENDIF (Pwiz_FOUND) + +configure_file (${CMAKE_SOURCE_DIR}/src/config.h.cmake ${CMAKE_SOURCE_DIR}/src/config.h) + +# File list +SET(CPP_FILES + utils/readspectrum.cpp +) + +SET (GUI_UIS +) + +SET(XTPCPP_MOC_HDRS +) + + +# this will run uic on .ui files: +QT4_WRAP_UI( GUI_UI_HDRS ${GUI_UIS} ) + +QT4_WRAP_CPP( XTPCPP_MOC_SRCS ${XTPCPP_MOC_HDRS} ) + + + +set(QTLIBS ${Qt5Xml_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Svg_LIBRARIES}) + +# we need this to be able to include headers produced by uic in our code +# (CMAKE_BINARY_DIR holds a path to the build directory, while INCLUDE_DIRECTORIES() works just like INCLUDEPATH from qmake) +INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_BINARY_DIR} ) +INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ) + +ADD_EXECUTABLE(xtpcpp ${CPP_FILES} ${GUI_UI_HDRS} ${XTPCPP_MOC_SRCS}) +target_include_directories (xtpcpp PUBLIC ${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} ${QT_QTSVG_INCLUDE_DIR}) + SET_TARGET_PROPERTIES(xtpcpp + PROPERTIES OUTPUT_NAME xtpcpp + CLEAN_DIRECT_OUTPUT 1 + COMPILE_DEFINITIONS "${QT_DEFINITIONS}" + #INCLUDE_DIRECTORIES "${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR}" + ) +TARGET_LINK_LIBRARIES(xtpcpp ${PAPPSOMSPP_QT4_LIBRARY} ${Pwiz_LIBRARY} ${ODSSTREAM_QT4_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTSVG_LIBRARY}) + +INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/xtpcpp DESTINATION bin) + +#configure_file (${CMAKE_SOURCE_DIR}/templates/share/applications/pt-peptideviewer.desktop.cmake ${CMAKE_BINARY_DIR}/templates/share/applications/pt-peptideviewer.desktop) + + diff --git a/src/config.h.cmake b/src/config.h.cmake new file mode 100644 index 0000000000000000000000000000000000000000..02f0430420afff653cc5316049547f071271756d --- /dev/null +++ b/src/config.h.cmake @@ -0,0 +1,13 @@ +#ifndef _CONFIG_H +#define _CONFIG_H + +#cmakedefine XTPCPP_VERSION "@XTPCPP_VERSION@" + +#cmakedefine SOFTWARE_NAME "@SOFTWARE_NAME@" + +#include <QDebug> + + + + +#endif /* _CONFIG_H */ diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d6375538653e730f6e2f794b1d34e9a56ca39b85 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,58 @@ + +/******************************************************************************* +* Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>. +* +* This file is part of PAPPSOms-tools. +* +* PAPPSOms-tools 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. +* +* PAPPSOms-tools 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 PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>. +* +* Contributors: +* Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and implementation +******************************************************************************/ + +#include <QApplication> +#include <iostream> +#include "ptspectrumviewer.h" +#include "qspectrumwidget.h" + +using namespace std; + +int main(int argc, char *argv[]) +{ + QTextStream errorStream(stderr, QIODevice::WriteOnly); + QApplication app(argc, argv); + + try { + QCoreApplication::setOrganizationName("PAPPSO"); + QCoreApplication::setOrganizationDomain("pappso.inra.fr"); + QCoreApplication::setApplicationName("xtpcpp"); + PtSpectrumViewer window; + window.show(); + + return app.exec(); + } + catch (pappso::PappsoException& error) + { + errorStream << "Oops! an error occurred in XTPcpp. Dont Panic :" << endl; + errorStream << error.qwhat() << endl; + app.exit(1); + } + + catch (std::exception& error) + { + errorStream << "Oops! an error occurred in XTPcpp. Dont Panic :" << endl; + errorStream << error.what() << endl; + app.exit(1); + } +} diff --git a/src/utils/readspectrum.cpp b/src/utils/readspectrum.cpp new file mode 100644 index 0000000000000000000000000000000000000000..37944bff5bd92835584230f03bef88ef3da05fd9 --- /dev/null +++ b/src/utils/readspectrum.cpp @@ -0,0 +1,218 @@ + +/******************************************************************************* +* Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>. +* +* This file is part of PAPPSOms-tools. +* +* PAPPSOms-tools 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. +* +* PAPPSOms-tools 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 PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>. +* +* Contributors: +* Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and implementation +******************************************************************************/ + +#include "readspectrum.h" + +#include <QDebug> +#include <pappsomspp/spectrum/spectrum.h> +#include <pappsomspp/exception/exceptionnotfound.h> + +#include <pwiz/data/common/cv.hpp> +#include <pwiz_tools/common/FullReaderList.hpp> +//#include <pwiz/utility/misc/Std.hpp> +#include <pwiz/data/msdata/SpectrumInfo.hpp> +#include <pwiz/data/msdata/MSData.hpp> +#include <locale> + +//http://sourceforge.net/p/proteowizard/mailman/message/28245157/ + +using namespace pappso; + + +pwiz::msdata::MSDataFile * getPwizMSDataFile(const QString & filename) { + qDebug() << "getPwizMSDataFile opening file " << filename ; + std::string env; + env=setlocale(LC_ALL,""); + struct lconv * lc = localeconv (); + qDebug() << " env=" << env.c_str() << " lc->decimal_point " << lc->decimal_point; + setlocale(LC_ALL,"C"); + //lc = localeconv (); + //qDebug() << " env=" << localeconv () << " lc->decimal_point " << lc->decimal_point; + pwiz::msdata::MSDataFile * dataFile = new pwiz::msdata::MSDataFile(filename.toStdString()); + + setlocale(LC_ALL,env.c_str()); + + return dataFile; +} + + +SpectrumSp getSpectrumSpFromPwizMSDataFile(pwiz::msdata::MSDataFile * p_ms_data_file, unsigned int scan_num, unsigned int & precursor_charge_state) { + + if (p_ms_data_file == nullptr) { + SpectrumSp empty; + return (empty); + } + + const bool getBinaryData = true; + pwiz::msdata::SpectrumListPtr spectrum_list_ptr = p_ms_data_file->run.spectrumListPtr; + unsigned int spectrum_index = 0; + if (spectrum_list_ptr.get()->size() == 1) { + spectrum_index = 0; + } + else { + // turn our scan numbers into navtieId strings for pwiz + pwiz::msdata::CVID nativeIdFormat_ = pwiz::msdata::id::getDefaultNativeIDFormat(*p_ms_data_file); + string nativeScanId = pwiz::msdata::id::translateScanNumberToNativeID(nativeIdFormat_, QString("%1").arg(scan_num).toStdString()); + spectrum_index = spectrum_list_ptr.get()->find(nativeScanId); + } + qDebug() << "spectrum_index " << spectrum_index; + if (spectrum_index == spectrum_list_ptr.get()->size()) { + //pwiz::msdata::SpectrumPtr simple_spectrum_pwiz = spectrum_list_ptr.get()->spectrum(10, getBinaryData); + //qDebug() << "spectrum id 10 " << simple_spectrum_pwiz.get()->get; + throw ExceptionNotFound(QObject::tr("scan number %1 not found MS file").arg(scan_num)); + } + pwiz::msdata::SpectrumPtr simple_spectrum_pwiz = spectrum_list_ptr.get()->spectrum(spectrum_index, getBinaryData); + if (simple_spectrum_pwiz.get()->precursors.size() > 0) { + pwiz::msdata::Precursor & precursor = *(simple_spectrum_pwiz.get()->precursors.begin()); + if (precursor.selectedIons.size() > 0) { + pwiz::msdata::SelectedIon & ion = *(precursor.selectedIons.begin()); + + //selected ion m/z + mz selected_ion_mz = QString(ion.cvParam(pwiz::cv::MS_selected_ion_m_z).value.c_str()).toDouble(); + //peak intensity + pappso_double peak_intensity = QString(ion.cvParam(pwiz::cv::MS_peak_intensity).value.c_str()).toDouble(); + + // unsigned int test = QString(ion.cvParam(pwiz::cv::MS_1200_series_LC_MSD_SL).value.c_str()).toUInt(); + // qDebug() << " tes "<< test; + //charge state + unsigned int charge_state = QString(ion.cvParam(pwiz::cv::MS_charge_state).value.c_str()).toUInt(); + + qDebug() << " selected_ion_mz "<< selected_ion_mz ; + qDebug() << " peak_intensity "<< peak_intensity; + qDebug() << " charge_state "<< charge_state; + if (charge_state > 0) { + precursor_charge_state = charge_state; + } + } + } + + /* for (pwiz::data::CVParam cv_param :ion.cvParams) { + pwiz::msdata::CVID param_id = cv_param.cvid; + qDebug() << param_id ; + //qDebug() << cv_param.cvid.c_str(); + qDebug() << cv_param.name().c_str(); + qDebug() << cv_param.value.c_str(); + }*/ + // fill in MZIntensityPair vector for convenient access to binary data + vector<pwiz::msdata::MZIntensityPair> pairs; + simple_spectrum_pwiz->getMZIntensityPairs(pairs); + // cout << "spectrum_simple size:" << pairs.size() << endl; + + Spectrum spectrum; + + // iterate through the m/z-intensity pairs + for (vector<pwiz::msdata::MZIntensityPair>::const_iterator it=pairs.begin(), end=pairs.end(); it!=end; ++it) + { + //qDebug() << "it->mz " << it->mz << " it->intensity" << it->intensity; + spectrum.push_back(Peak(it->mz, it->intensity)); + } + qDebug() << "spectrum size " << spectrum.size(); + //cout << "spectrum_simple size " << spectrum_simple.getSpectrumSize()<< endl; + + // lc = localeconv (); + //qDebug() << " env=" << localeconv () << " lc->decimal_point " << lc->decimal_point; + return spectrum.makeSpectrumSp(); +} + +Spectrum readSpectrum(const QString & filename, unsigned int scan_num, unsigned int & precursor_charge_state) { + qDebug() << "opening file " << filename << " scan " << scan_num; + std::string env; + env=setlocale(LC_ALL,""); + struct lconv * lc = localeconv (); + qDebug() << " env=" << env.c_str() << " lc->decimal_point " << lc->decimal_point; + setlocale(LC_ALL,"C"); + //lc = localeconv (); + //qDebug() << " env=" << localeconv () << " lc->decimal_point " << lc->decimal_point; + pwiz::msdata::MSDataFile dataFile(filename.toStdString()); + + const bool getBinaryData = true; + pwiz::msdata::SpectrumListPtr spectrum_list_ptr = dataFile.run.spectrumListPtr; + unsigned int spectrum_index = 0; + if (spectrum_list_ptr.get()->size() == 1) { + spectrum_index = 0; + } + else { + // turn our scan numbers into navtieId strings for pwiz + pwiz::msdata::CVID nativeIdFormat_ = pwiz::msdata::id::getDefaultNativeIDFormat(dataFile); + string nativeScanId = pwiz::msdata::id::translateScanNumberToNativeID(nativeIdFormat_, QString("%1").arg(scan_num).toStdString()); + spectrum_index = spectrum_list_ptr.get()->find(nativeScanId); + } + qDebug() << "spectrum_index " << spectrum_index; + if (spectrum_index == spectrum_list_ptr.get()->size()) { + //pwiz::msdata::SpectrumPtr simple_spectrum_pwiz = spectrum_list_ptr.get()->spectrum(10, getBinaryData); + //qDebug() << "spectrum id 10 " << simple_spectrum_pwiz.get()->get; + throw ExceptionNotFound(QObject::tr("scan number %1 not found in %2").arg(scan_num).arg(filename)); + } + pwiz::msdata::SpectrumPtr simple_spectrum_pwiz = spectrum_list_ptr.get()->spectrum(spectrum_index, getBinaryData); + if (simple_spectrum_pwiz.get()->precursors.size() > 0) { + pwiz::msdata::Precursor & precursor = *(simple_spectrum_pwiz.get()->precursors.begin()); + if (precursor.selectedIons.size() > 0) { + pwiz::msdata::SelectedIon & ion = *(precursor.selectedIons.begin()); + + //selected ion m/z + mz selected_ion_mz = QString(ion.cvParam(pwiz::cv::MS_selected_ion_m_z).value.c_str()).toDouble(); + //peak intensity + pappso_double peak_intensity = QString(ion.cvParam(pwiz::cv::MS_peak_intensity).value.c_str()).toDouble(); + + // unsigned int test = QString(ion.cvParam(pwiz::cv::MS_1200_series_LC_MSD_SL).value.c_str()).toUInt(); + // qDebug() << " tes "<< test; + //charge state + unsigned int charge_state = QString(ion.cvParam(pwiz::cv::MS_charge_state).value.c_str()).toUInt(); + + qDebug() << " selected_ion_mz "<< selected_ion_mz ; + qDebug() << " peak_intensity "<< peak_intensity; + qDebug() << " charge_state "<< charge_state; + if (charge_state > 0) { + precursor_charge_state = charge_state; + } + } + } + + /* for (pwiz::data::CVParam cv_param :ion.cvParams) { + pwiz::msdata::CVID param_id = cv_param.cvid; + qDebug() << param_id ; + //qDebug() << cv_param.cvid.c_str(); + qDebug() << cv_param.name().c_str(); + qDebug() << cv_param.value.c_str(); + }*/ + // fill in MZIntensityPair vector for convenient access to binary data + vector<pwiz::msdata::MZIntensityPair> pairs; + simple_spectrum_pwiz->getMZIntensityPairs(pairs); + // cout << "spectrum_simple size:" << pairs.size() << endl; + + Spectrum spectrum; + + // iterate through the m/z-intensity pairs + for (vector<pwiz::msdata::MZIntensityPair>::const_iterator it=pairs.begin(), end=pairs.end(); it!=end; ++it) + { + //qDebug() << "it->mz " << it->mz << " it->intensity" << it->intensity; + spectrum.push_back(Peak(it->mz, it->intensity)); + } + qDebug() << "spectrum size " << spectrum.size(); + //cout << "spectrum_simple size " << spectrum_simple.getSpectrumSize()<< endl; + + setlocale(LC_ALL,env.c_str()); + // lc = localeconv (); + //qDebug() << " env=" << localeconv () << " lc->decimal_point " << lc->decimal_point; + return spectrum; +} diff --git a/src/utils/readspectrum.h b/src/utils/readspectrum.h new file mode 100644 index 0000000000000000000000000000000000000000..da0cfeb53aa89c0abf063cf774a9024b4b0f00c1 --- /dev/null +++ b/src/utils/readspectrum.h @@ -0,0 +1,40 @@ + +/******************************************************************************* +* Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>. +* +* This file is part of PAPPSOms-tools. +* +* PAPPSOms-tools 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. +* +* PAPPSOms-tools 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 PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>. +* +* Contributors: +* Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and implementation +******************************************************************************/ + +#ifndef READSPECTRUM_H +#define READSPECTRUM_H + +#include <QString> +#include <pappsomspp/spectrum/spectrum.h> + +#include <pwiz/data/msdata/MSDataFile.hpp> + +using namespace pappso; + +Spectrum readSpectrum(const QString & filename, unsigned int scan_num,unsigned int & precursor_charge_state); + +pwiz::msdata::MSDataFile * getPwizMSDataFile(const QString & filename); + +SpectrumSp getSpectrumSpFromPwizMSDataFile(pwiz::msdata::MSDataFile * p_ms_data_file, unsigned int scan_num, unsigned int & precursor_charge_state); + +#endif // READSPECTRUM_H