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 More...
FileReaderType | getFileReaderType () const
| get the file reader type More...
void | setPreferedFileReaderType (MzFormat format, FileReaderType reader_type)
| given an mz format, explicitly set the prefered reader More...
std::vector< MsRunIdCstSPtr > | getMsRunIds ()
MsRunReaderSPtr | msRunReaderSp (MsRunIdCstSPtr ms_run_id)
MsRunReaderSPtr | getMsRunReaderSPtrByRunId (const QString &run_id, const QString &xml_id)
| get an msrun reader by finding the run_id in file More...
TimsMsRunReaderMs2SPtr | buildTimsMsRunReaderMs2SPtr ()
| if possible, builds directly a dedicated Tims TOF tdf file reader More...

## Static Public Member Functions

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

## Private Attributes

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

## Detailed Description

Definition at line 34 of file msfileaccessor.h.

## Constructor & Destructor Documentation

## MsFileAccessor() [1/2]

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

Definition at line 28 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:101
pappso::MsFileAccessor::m_fileName
QString m_fileName
Definition: msfileaccessor.h:97

## MsFileAccessor() [2/2]

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

Definition at line 39 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:103
pappso::MsFileAccessor::m_fileReaderType
FileReaderType m_fileReaderType
Definition: msfileaccessor.h:106

## ~MsFileAccessor()

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

virtual

Definition at line 47 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 224 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:224
pappso::FileReaderType::tims
@ tims

References pappso::tims.

## buildMsRunReaderSPtr() [2/2]

MsRunReaderSPtr pappso::MsFileAccessor::buildMsRunReaderSPtr | ( | MsRunIdCstSPtr | ms_run_id,
|  | pappso::FileReaderType | prefered_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
  prefered_file_reader_type | the prefered file reader type to use (depending on the mz format)

Returns
  msrun reader shared pointer

Definition at line 230 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(prefered_file_reader_type == pappso::FileReaderType::tims)
{
return std::make_shared<TimsMsRunReader>(ms_run_id);
}
else if(prefered_file_reader_type == pappso::FileReaderType::tims_ms2)
{
qDebug();
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:107
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 143 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 60 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 53 of file msfileaccessor.cpp.

{
return m_fileName;
}

References m_fileName.

## getFileReaderType()

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

get the file reader type

Definition at line 329 of file msfileaccessor.cpp.

{
return m_fileReaderType;
}

References m_fileReaderType.

## getMsRunIds()

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

Definition at line 67 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_fileReaderType = FileReaderType::pwiz;
m_fileFormat = pwiz_ms_file_reader.getFileFormat();
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_fileReaderType = FileReaderType::tims;
m_fileFormat = tims_file_reader.getFileFormat();
m_fileName = tims_dir;
auto pref = m_preferedFileReaderTypeMap.find(m_fileFormat);
if(pref != m_preferedFileReaderTypeMap.end())
{
m_fileReaderType = pref->second;
}
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_preferedFileReaderTypeMap
std::map< MzFormat, FileReaderType > m_preferedFileReaderTypeMap
Definition: msfileaccessor.h:108
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_preferedFileReaderTypeMap, m_xmlPrefix, pappso::pwiz, pappso::tims, and pappso::xy.

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

## 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 278 of file msfileaccessor.cpp.

{
qDebug() << "GGGGGGGGG1";
std::vector<MsRunIdCstSPtr> run_list = getMsRunIds();
MsRunReaderSPtr reader_sp;
qDebug() << "GGGGGGGGG";
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 msRunReaderSp(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 msRunReaderSp(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::msRunReaderSp
MsRunReaderSPtr msRunReaderSp(MsRunIdCstSPtr ms_run_id)
Definition: msfileaccessor.cpp:175
pappso::MsFileAccessor::getMsRunIds
std::vector< MsRunIdCstSPtr > getMsRunIds()
Definition: msfileaccessor.cpp:67
pappso::MsRunReaderSPtr
std::shared_ptr< MsRunReader > MsRunReaderSPtr
Definition: msrunreader.h:184
pappso::MsRunIdCstSPtr
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
Definition: msrunid.h:44

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

## msRunReaderSp()

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

Definition at line 175 of file msfileaccessor.cpp.

{
if(m_fileName != ms_run_id->getFileName())
throw(ExceptionNotPossible(
QObject::tr("The MsRunId instance must have the name file name as the "
"MsFileAccessor.")));
if(m_fileReaderType == FileReaderType::pwiz)
{
qDebug() << "Returning a PwizMsRunReader.";
return std::make_shared<PwizMsRunReader>(ms_run_id);
}
else if(m_fileReaderType == FileReaderType::xy)
{
qDebug() << "Returning a XyMsRunReader.";
return std::make_shared<XyMsRunReader>(ms_run_id);
}
else if(m_fileReaderType == FileReaderType::tims)
{
qDebug() << "Returning a TimsMsRunReader.";
return std::make_shared<TimsMsRunReader>(ms_run_id);
}
else if(m_fileReaderType == 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);
}
}
return nullptr;
}

References m_fileFormat, m_fileName, m_fileReaderType, pappso::pwiz, pappso::tims, pappso::tims_ms2, pappso::unknown, and pappso::xy.

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

## setPreferedFileReaderType()

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

given an mz format, explicitly set the prefered reader

Definition at line 316 of file msfileaccessor.cpp.

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

References m_preferedFileReaderTypeMap.

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

## Member Data Documentation

## m_fileFormat

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

private

Definition at line 103 of file msfileaccessor.h.

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

## m_fileName

QString pappso::MsFileAccessor::m_fileName

private

Definition at line 97 of file msfileaccessor.h.

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

## m_fileReaderType

FileReaderType pappso::MsFileAccessor::m_fileReaderType

private

Definition at line 106 of file msfileaccessor.h.

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

## m_preferedFileReaderTypeMap

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

private

Definition at line 108 of file msfileaccessor.h.

Referenced by getMsRunIds(), and setPreferedFileReaderType().

## m_xmlPrefix

const QString pappso::MsFileAccessor::m_xmlPrefix

private

Definition at line 101 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