Loading...
Searching...
No Matches
pappso::MsFileAccessor Class Reference

`#include <msfileaccessor.h>`

## Public Member Functions

| MsFileAccessor (const QString &file_name, const QString &xml_prefix)
| MsFileAccessor (const MsFileAccessor &other)
virtual | ~MsFileAccessor ()
const QString & | getFileName () const
MzFormat | getFileFormat () const
| get the raw format of mz data
FileReaderType | getFileReaderType () const
| get the file reader type
void | setPreferredFileReaderType (MzFormat format, FileReaderType reader_type)
| given an mz format, explicitly set the preferred reader
FileReaderType | getpreferredFileReaderType (MzFormat format)
std::vector< MsRunIdCstSPtr > | getMsRunIds ()
void | setSelectedMsRunIdIndex (std::size_t index)
std::size_t | getSelectedMsRunIdIndex () const
MsRunIdCstSPtr | getSelectedMsRunId ()
MsRunReaderSPtr | msRunReaderSPtr (MsRunIdCstSPtr ms_run_id)
MsRunReaderSPtr | msRunReaderSPtr (std::size_t ms_run_id_index)
MsRunReaderSPtr | msRunReaderSPtrForSelectedMsRunIdIndex ()
MsRunReaderSPtr | getMsRunReaderSPtrByRunId (const QString &run_id, const QString &xml_id)
| get an msrun reader by finding the run_id in file
TimsMsRunReaderMs2SPtr | buildTimsMsRunReaderMs2SPtr ()
| if possible, builds directly a dedicated Tims TOF tdf file reader

## Static Public Member Functions

static MsRunReaderSPtr | buildMsRunReaderSPtr (MsRunIdCstSPtr ms_run_id)
| get an MsRunReader directly from a valid MsRun ID
static MsRunReaderSPtr | buildMsRunReaderSPtr (MsRunIdCstSPtr ms_run_id, pappso::FileReaderType preferred_file_reader_type)
| get an MsRunReader directly from a valid MsRun ID

## Private Attributes

QString | m_fileName
const QString | m_xmlPrefix
MzFormat | m_fileFormat = MzFormat::unknown
FileReaderType | m_fileReaderType
std::map< MzFormat, FileReaderType > | m_preferredFileReaderTypeMap
std::size_t | m_selectedMsRunIdIndex

## Detailed Description

Definition at line 26 of file msfileaccessor.h.

## Constructor & Destructor Documentation

## MsFileAccessor() [1/2]

pappso::MsFileAccessor::MsFileAccessor | ( | const QString & | file_name,
|  | const QString & | xml_prefix
| ) |  |

Definition at line 31 of file msfileaccessor.cpp.

: m_fileName(file_name), m_xmlPrefix(xml_prefix)
{
QFile file(file_name);
if(!file.exists())
throw(ExceptionNotFound(QObject::tr("File %1 not found.")
.arg(QFileInfo(file_name).absoluteFilePath())));
}
pappso::MsFileAccessor::m_xmlPrefix
const QString m_xmlPrefix
Definition msfileaccessor.h:100
pappso::MsFileAccessor::m_fileName
QString m_fileName
Definition msfileaccessor.h:96

## MsFileAccessor() [2/2]

pappso::MsFileAccessor::MsFileAccessor | ( | const MsFileAccessor & | other | ) |

Definition at line 42 of file msfileaccessor.cpp.

: m_fileName(other.m_fileName),
m_xmlPrefix(other.m_xmlPrefix),
m_fileFormat(other.m_fileFormat),
m_fileReaderType(other.m_fileReaderType)
{
}
pappso::MsFileAccessor::m_fileFormat
MzFormat m_fileFormat
Definition msfileaccessor.h:102
pappso::MsFileAccessor::m_fileReaderType
FileReaderType m_fileReaderType
Definition msfileaccessor.h:105

## ~MsFileAccessor()

pappso::MsFileAccessor::~MsFileAccessor | ( |  | ) |

virtual

Definition at line 50 of file msfileaccessor.cpp.

{
}

## Member Function Documentation

## buildMsRunReaderSPtr() [1/2]

MsRunReaderSPtr pappso::MsFileAccessor::buildMsRunReaderSPtr | ( | MsRunIdCstSPtr | ms_run_id | ) |

static

get an MsRunReader directly from a valid MsRun ID

no need to check the file format or filename : all is already part of the msrunid

Parameters

  ms_run_id | msrun identifier

Returns
  msrun reader shared pointer

Definition at line 332 of file msfileaccessor.cpp.

{
return buildMsRunReaderSPtr(ms_run_id, pappso::FileReaderType::tims);
}
pappso::MsFileAccessor::buildMsRunReaderSPtr
static MsRunReaderSPtr buildMsRunReaderSPtr(MsRunIdCstSPtr ms_run_id)
get an MsRunReader directly from a valid MsRun ID
Definition msfileaccessor.cpp:332
pappso::FileReaderType::tims
@ tims

References buildMsRunReaderSPtr(), and pappso::tims.

Referenced by buildMsRunReaderSPtr().

## buildMsRunReaderSPtr() [2/2]

MsRunReaderSPtr pappso::MsFileAccessor::buildMsRunReaderSPtr | ( | MsRunIdCstSPtr | ms_run_id,
|  | pappso::FileReaderType | preferred_file_reader_type
| ) |  |

static

get an MsRunReader directly from a valid MsRun ID

no need to check the file format or filename : all is already part of the msrunid

Parameters

  ms_run_id | msrun identifier
  preferred_file_reader_type | the preferred file reader type to use (depending on the mz format)

Returns
  msrun reader shared pointer

Definition at line 338 of file msfileaccessor.cpp.

{
QFile file(ms_run_id.get()->getFileName());
if(!file.exists())
throw(ExceptionNotFound(
QObject::tr("unable to build a reader : file %1 not found.")
.arg(QFileInfo(ms_run_id.get()->getFileName()).absoluteFilePath())));
MzFormat file_format = ms_run_id.get()->getMzFormat();
if(file_format == MzFormat::xy)
{
// qDebug() << "Returning a XyMsRunReader.";
return std::make_shared<XyMsRunReader>(ms_run_id);
}
else if(file_format == MzFormat::unknown)
{
throw(PappsoException(
QObject::tr("unable to build a reader for %1 : unknown file format")
.arg(QFileInfo(ms_run_id.get()->getFileName()).absoluteFilePath())));
}
else if(file_format == MzFormat::brukerTims)
{
if(preferred_file_reader_type == pappso::FileReaderType::tims)
{
return std::make_shared<TimsMsRunReader>(ms_run_id);
}
else if(preferred_file_reader_type == pappso::FileReaderType::tims_ms2)
{
return std::make_shared<TimsMsRunReaderMs2>(ms_run_id);
}
// qDebug() << "by default, build a TimsMsRunReader.";
return std::make_shared<TimsMsRunReader>(ms_run_id);
}
else
{
// qDebug() << "Returning a PwizMsRunReader .";
return std::make_shared<PwizMsRunReader>(ms_run_id);
}
}
pappso::MzFormat
MzFormat
Definition types.h:120
pappso::MzFormat::brukerTims
@ brukerTims
pappso::MzFormat::xy
@ xy
(x,y) format
pappso::MzFormat::unknown
@ unknown
unknown format
pappso::FileReaderType::tims_ms2
@ tims_ms2

References pappso::brukerTims, pappso::tims, pappso::tims_ms2, pappso::unknown, and pappso::xy.

## buildTimsMsRunReaderMs2SPtr()

TimsMsRunReaderMs2SPtr pappso::MsFileAccessor::buildTimsMsRunReaderMs2SPtr | ( |  | ) |

if possible, builds directly a dedicated Tims TOF tdf file reader

Definition at line 216 of file msfileaccessor.cpp.

{
// try TimsData reader
QString tims_dir = m_fileName;
if(!QFileInfo(tims_dir).isDir())
{
tims_dir = QFileInfo(m_fileName).absolutePath();
}
TimsMsFileReader tims_file_reader(tims_dir);
std::vector<MsRunIdCstSPtr> ms_run_ids =
tims_file_reader.getMsRunIds(m_xmlPrefix);
if(ms_run_ids.size())
{
// qDebug() << "Might well be handled using the Bruker code";
m_fileReaderType = FileReaderType::tims_ms2;
m_fileFormat = tims_file_reader.getFileFormat();
m_fileName = tims_dir;
return std::make_shared<TimsMsRunReaderMs2>(ms_run_ids.front());
}
else
{
throw(ExceptionNotPossible(
QObject::tr("Unable to read mz data directory %1 with TimsTOF reader.")
.arg(tims_dir)));
}
}

References pappso::TimsMsFileReader::getFileFormat(), pappso::TimsMsFileReader::getMsRunIds(), m_fileFormat, m_fileName, m_fileReaderType, m_xmlPrefix, and pappso::tims_ms2.

## getFileFormat()

MzFormat pappso::MsFileAccessor::getFileFormat | ( |  | ) | const

get the raw format of mz data

Definition at line 63 of file msfileaccessor.cpp.

{
return m_fileFormat;
}

References m_fileFormat.

Referenced by pappso::TandemWrapperRun::convertOrginalMsData2mzXmlData().

## getFileName()

const QString & pappso::MsFileAccessor::getFileName | ( |  | ) | const

Definition at line 56 of file msfileaccessor.cpp.

{
return m_fileName;
}

References m_fileName.

## getFileReaderType()

FileReaderType pappso::MsFileAccessor::getFileReaderType | ( |  | ) | const

get the file reader type

Definition at line 186 of file msfileaccessor.cpp.

{
return m_fileReaderType;
}

References m_fileReaderType.

## getMsRunIds()

std::vector< MsRunIdCstSPtr > pappso::MsFileAccessor::getMsRunIds | ( |  | ) |

Definition at line 70 of file msfileaccessor.cpp.

{
// qDebug();
// Try the PwizMsFileReader
PwizMsFileReader pwiz_ms_file_reader(m_fileName);
std::vector<MsRunIdCstSPtr> ms_run_ids =
pwiz_ms_file_reader.getMsRunIds(m_xmlPrefix);
if(ms_run_ids.size())
{
// qDebug() << "Might well be handled using the Pwiz code.";
m_fileFormat = pwiz_ms_file_reader.getFileFormat();
m_fileReaderType = FileReaderType::pwiz;
// But the user might have configured one preferred reader type.
auto pref = m_preferredFileReaderTypeMap.find(m_fileFormat);
if(pref != m_preferredFileReaderTypeMap.end())
{
m_fileReaderType = pref->second;
}
return ms_run_ids;
}
// qDebug() << "The Pwiz reader did not work.";
// Try the TimsData reader
QString tims_dir = m_fileName;
if(!QFileInfo(tims_dir).isDir())
{
tims_dir = QFileInfo(m_fileName).absolutePath();
}
TimsMsFileReader tims_file_reader(tims_dir);
ms_run_ids = tims_file_reader.getMsRunIds(m_xmlPrefix);
if(ms_run_ids.size())
{
// qDebug() << "Might well be handled using the Bruker code";
m_fileName = tims_dir;
m_fileFormat = tims_file_reader.getFileFormat();
m_fileReaderType = FileReaderType::tims;
auto pref = m_preferredFileReaderTypeMap.find(m_fileFormat);
if(pref != m_preferredFileReaderTypeMap.end())
{
m_fileReaderType = pref->second;
}
// qDebug() << "Returning Bruker::tims ms run(s)."
// << "with preferred reader type:"
// << Utils::fileReaderTypeAsString(m_fileReaderType);
return ms_run_ids;
}
// qDebug() << "The Tims reader did not work.";
// At this point try the XyMsFileReader
XyMsFileReader xy_ms_file_reader(m_fileName);
ms_run_ids = xy_ms_file_reader.getMsRunIds(m_xmlPrefix);
if(ms_run_ids.size())
{
// qDebug() << "Might well be handled using the XY code";
m_fileReaderType = FileReaderType::xy;
m_fileFormat = xy_ms_file_reader.getFileFormat();
return ms_run_ids;
}
// qDebug() << "The XY reader did not work.";
return ms_run_ids;
}
pappso::MsFileAccessor::m_preferredFileReaderTypeMap
std::map< MzFormat, FileReaderType > m_preferredFileReaderTypeMap
Definition msfileaccessor.h:107
pappso::FileReaderType::pwiz
@ pwiz
pappso::FileReaderType::xy
@ xy

References pappso::PwizMsFileReader::getFileFormat(), pappso::TimsMsFileReader::getFileFormat(), pappso::XyMsFileReader::getFileFormat(), pappso::PwizMsFileReader::getMsRunIds(), pappso::TimsMsFileReader::getMsRunIds(), pappso::XyMsFileReader::getMsRunIds(), m_fileFormat, m_fileName, m_fileReaderType, m_preferredFileReaderTypeMap, m_xmlPrefix, pappso::pwiz, pappso::tims, and pappso::xy.

Referenced by pappso::TandemWrapperRun::convertOrginalMsData2mzXmlData(), getMsRunReaderSPtrByRunId(), getSelectedMsRunId(), msRunReaderSPtr(), and msRunReaderSPtrForSelectedMsRunIdIndex().

## getMsRunReaderSPtrByRunId()

MsRunReaderSPtr pappso::MsFileAccessor::getMsRunReaderSPtrByRunId | ( | const QString & | run_id,
|  | const QString & | xml_id
| ) |  |

get an msrun reader by finding the run_id in file

Parameters

  run_id | identifier within file of the MSrun
  xml_id | XML identifier given by the user to identify this MSrun in our experiment (not in the file)

Definition at line 386 of file msfileaccessor.cpp.

{
std::vector<MsRunIdCstSPtr> run_list = getMsRunIds();
MsRunReaderSPtr reader_sp;
for(MsRunIdCstSPtr &original_run_id : run_list)
{
if(original_run_id.get()->getRunId() == run_id)
{
MsRunId new_run_id(*original_run_id.get());
new_run_id.setXmlId(xml_id);
return msRunReaderSPtr(std::make_shared<MsRunId>(new_run_id));
}
}
if((run_id.isEmpty()) && (run_list.size() == 1))
{
MsRunId new_run_id(*run_list[0].get());
new_run_id.setXmlId(xml_id);
return msRunReaderSPtr(std::make_shared<MsRunId>(new_run_id));
}
if(reader_sp == nullptr)
{
throw(
ExceptionNotFound(QObject::tr("run id %1 not found in file %2")
.arg(run_id)
.arg(QFileInfo(m_fileName).absoluteFilePath())));
}
return reader_sp;
}
pappso::MsFileAccessor::msRunReaderSPtr
MsRunReaderSPtr msRunReaderSPtr(MsRunIdCstSPtr ms_run_id)
Definition msfileaccessor.cpp:248
pappso::MsFileAccessor::getMsRunIds
std::vector< MsRunIdCstSPtr > getMsRunIds()
Definition msfileaccessor.cpp:70
pappso::MsRunReaderSPtr
std::shared_ptr< MsRunReader > MsRunReaderSPtr
Definition msrunreader.h:56
pappso::MsRunIdCstSPtr
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
Definition msrunid.h:46

References getMsRunIds(), m_fileName, msRunReaderSPtr(), and pappso::MsRunId::setXmlId().

## getpreferredFileReaderType()

FileReaderType pappso::MsFileAccessor::getpreferredFileReaderType | ( | MzFormat | format | ) |

Definition at line 172 of file msfileaccessor.cpp.

{
auto ret = m_preferredFileReaderTypeMap.find(format);
if(ret != m_preferredFileReaderTypeMap.end())
{
return ret->second;
}
return m_fileReaderType;
}

References m_fileReaderType, and m_preferredFileReaderTypeMap.

Referenced by msRunReaderSPtr().

## getSelectedMsRunId()

MsRunIdCstSPtr pappso::MsFileAccessor::getSelectedMsRunId | ( |  | ) |

Definition at line 207 of file msfileaccessor.cpp.

{
if(m_selectedMsRunIdIndex >= getMsRunIds().size())
throw PappsoException(QObject::tr("MsRunId request out-of-bound error."));
return getMsRunIds().at(m_selectedMsRunIdIndex);
}
pappso::MsFileAccessor::m_selectedMsRunIdIndex
std::size_t m_selectedMsRunIdIndex
Definition msfileaccessor.h:109

References getMsRunIds(), and m_selectedMsRunIdIndex.

## getSelectedMsRunIdIndex()

std::size_t pappso::MsFileAccessor::getSelectedMsRunIdIndex | ( |  | ) | const

Definition at line 200 of file msfileaccessor.cpp.

{
return m_selectedMsRunIdIndex;
}

References m_selectedMsRunIdIndex.

## msRunReaderSPtr() [1/2]

MsRunReaderSPtr pappso::MsFileAccessor::msRunReaderSPtr | ( | MsRunIdCstSPtr | ms_run_id | ) |

Definition at line 248 of file msfileaccessor.cpp.

{
// We want to return a MsRunReader that accounts for the configuration that
// the user might have set.
if(m_fileName != ms_run_id->getFileName())
throw(ExceptionNotPossible(
QObject::tr("The MsRunId instance must have the name file name as the "
"MsFileAccessor.")));
if(getpreferredFileReaderType(m_fileFormat) == FileReaderType::pwiz)
{
// qDebug() << "Returning a PwizMsRunReader.";
return std::make_shared<PwizMsRunReader>(ms_run_id);
}
else if(getpreferredFileReaderType(m_fileFormat) == FileReaderType::xy)
{
// qDebug() << "Returning a XyMsRunReader.";
return std::make_shared<XyMsRunReader>(ms_run_id);
}
else if(getpreferredFileReaderType(m_fileFormat) == FileReaderType::tims)
{
// qDebug() << "Returning a TimsMsRunReader.";
return std::make_shared<TimsMsRunReader>(ms_run_id);
}
else if(getpreferredFileReaderType(m_fileFormat) ==
FileReaderType::tims_frames)
{
// qDebug() << "Returning a TimsFramesMsRunReader.";
return std::make_shared<TimsFramesMsRunReader>(ms_run_id);
}
else if(getpreferredFileReaderType(m_fileFormat) == FileReaderType::tims_ms2)
{
// qDebug() << "Returning a TimsMsRunReaderMs2.";
return std::make_shared<TimsMsRunReaderMs2>(ms_run_id);
}
if(m_fileFormat == MzFormat::unknown)
{
if(ms_run_id.get()->getMzFormat() == MzFormat::xy)
{
return std::make_shared<XyMsRunReader>(ms_run_id);
}
else
{
return std::make_shared<PwizMsRunReader>(ms_run_id);
}
}
else
{
throw PappsoException(QObject::tr("No file format was found."));
}
return nullptr;
}
pappso::MsFileAccessor::getpreferredFileReaderType
FileReaderType getpreferredFileReaderType(MzFormat format)
Definition msfileaccessor.cpp:172
pappso::FileReaderType::tims_frames
@ tims_frames

References getpreferredFileReaderType(), m_fileFormat, m_fileName, pappso::pwiz, pappso::tims, pappso::tims_frames, pappso::tims_ms2, pappso::unknown, and pappso::xy.

Referenced by pappso::TandemWrapperRun::convertOrginalMsData2mzXmlData(), getMsRunReaderSPtrByRunId(), msRunReaderSPtr(), and msRunReaderSPtrForSelectedMsRunIdIndex().

## msRunReaderSPtr() [2/2]

MsRunReaderSPtr pappso::MsFileAccessor::msRunReaderSPtr | ( | std::size_t | ms_run_id_index | ) |

Definition at line 310 of file msfileaccessor.cpp.

{
std::vector<MsRunIdCstSPtr> ms_run_ids = getMsRunIds();
if(ms_run_id_index >= ms_run_ids.size())
throw PappsoException(QObject::tr("MsRunId request out-of-bound error."));
return msRunReaderSPtr(ms_run_ids.at(ms_run_id_index));
}

References getMsRunIds(), and msRunReaderSPtr().

## msRunReaderSPtrForSelectedMsRunIdIndex()

MsRunReaderSPtr pappso::MsFileAccessor::msRunReaderSPtrForSelectedMsRunIdIndex | ( |  | ) |

Definition at line 321 of file msfileaccessor.cpp.

{
std::vector<MsRunIdCstSPtr> ms_run_ids = getMsRunIds();
if(m_selectedMsRunIdIndex >= ms_run_ids.size())
throw PappsoException(QObject::tr("MsRunId request out-of-bound error."));
return msRunReaderSPtr(ms_run_ids.at(m_selectedMsRunIdIndex));
}

References getMsRunIds(), m_selectedMsRunIdIndex, and msRunReaderSPtr().

## setPreferredFileReaderType()

void pappso::MsFileAccessor::setPreferredFileReaderType | ( | MzFormat | format,
|  | FileReaderType | reader_type
| ) |  |

given an mz format, explicitly set the preferred reader

Definition at line 157 of file msfileaccessor.cpp.

{
auto ret = m_preferredFileReaderTypeMap.insert(
std::pair<MzFormat, FileReaderType>(format, reader_type));
if(!ret.second)
{
// replace
ret.first->second = reader_type;
}
}

References m_preferredFileReaderTypeMap.

Referenced by pappso::TandemWrapperRun::convertOrginalMsData2mzXmlData().

## setSelectedMsRunIdIndex()

void pappso::MsFileAccessor::setSelectedMsRunIdIndex | ( | std::size_t | index | ) |

Definition at line 193 of file msfileaccessor.cpp.

{
m_selectedMsRunIdIndex = index;
}

References m_selectedMsRunIdIndex.

## Member Data Documentation

## m_fileFormat

MzFormat pappso::MsFileAccessor::m_fileFormat = MzFormat::unknown

private

Definition at line 102 of file msfileaccessor.h.

Referenced by buildTimsMsRunReaderMs2SPtr(), getFileFormat(), getMsRunIds(), and msRunReaderSPtr().

## m_fileName

QString pappso::MsFileAccessor::m_fileName

private

Definition at line 96 of file msfileaccessor.h.

Referenced by buildTimsMsRunReaderMs2SPtr(), getFileName(), getMsRunIds(), getMsRunReaderSPtrByRunId(), and msRunReaderSPtr().

## m_fileReaderType

FileReaderType pappso::MsFileAccessor::m_fileReaderType

private

Definition at line 105 of file msfileaccessor.h.

Referenced by buildTimsMsRunReaderMs2SPtr(), getFileReaderType(), getMsRunIds(), and getpreferredFileReaderType().

## m_preferredFileReaderTypeMap

std::map<MzFormat, FileReaderType> pappso::MsFileAccessor::m_preferredFileReaderTypeMap

private

Definition at line 107 of file msfileaccessor.h.

Referenced by getMsRunIds(), getpreferredFileReaderType(), and setPreferredFileReaderType().

## m_selectedMsRunIdIndex

std::size_t pappso::MsFileAccessor::m_selectedMsRunIdIndex

private

Definition at line 109 of file msfileaccessor.h.

Referenced by getSelectedMsRunId(), getSelectedMsRunIdIndex(), msRunReaderSPtrForSelectedMsRunIdIndex(), and setSelectedMsRunIdIndex().

## m_xmlPrefix

const QString pappso::MsFileAccessor::m_xmlPrefix

private

Definition at line 100 of file msfileaccessor.h.

Referenced by buildTimsMsRunReaderMs2SPtr(), and getMsRunIds().

The documentation for this class was generated from the following files:

- pappsomspp/msfile/msfileaccessor.h
- pappsomspp/msfile/msfileaccessor.cpp