pappso::FastaFileIndexer Class Reference

`#include <fastafileindexer.h>`

Inheritance diagram for pappso::FastaFileIndexer:

## Public Member Functions

| FastaFileIndexer (const QFileInfo &fastaFile)
| FastaFileIndexer (const FastaFileIndexer &other)
virtual | ~FastaFileIndexer ()
void | getSequenceByIndex (FastaHandlerInterface &fasta_handler, std::size_t index) override
void | open () override
void | close () override
FastaFileIndexerSPtr | makeFastaFileIndexerSPtr () const

## Private Member Functions

void | parseFastaFile ()

## Private Attributes

QFile | m_fasta_file
std::vector< qint64 > | m_indexArray
QTextStream * | mpa_sequenceTxtIn = nullptr

## Detailed Description

Definition at line 51 of file fastafileindexer.h.

## Constructor & Destructor Documentation

## FastaFileIndexer() [1/2]

pappso::FastaFileIndexer::FastaFileIndexer | ( | const QFileInfo & | fastaFile | ) |

Definition at line 39 of file fastafileindexer.cpp.

: m_fasta_file(fastaFile.absoluteFilePath())
{
if(m_fasta_file.fileName().isEmpty())
{
throw PappsoException(QObject::tr("No FASTA file name specified"));
}
if(m_fasta_file.open(QIODevice::ReadOnly))
{
parseFastaFile();
m_fasta_file.close();
}
else
{
throw PappsoException(QObject::tr("ERROR opening FASTA file %1 for read")
.arg(fastaFile.fileName()));
}
}
pappso::FastaFileIndexer::m_fasta_file
QFile m_fasta_file
Definition: fastafileindexer.h:71
pappso::FastaFileIndexer::parseFastaFile
void parseFastaFile()
Definition: fastafileindexer.cpp:73

References m_fasta_file, and parseFastaFile().

## FastaFileIndexer() [2/2]

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

Definition at line 59 of file fastafileindexer.cpp.

: m_fasta_file(other.m_fasta_file.fileName())
{
m_indexArray = other.m_indexArray;
mpa_sequenceTxtIn = nullptr;
}
pappso::FastaFileIndexer::mpa_sequenceTxtIn
QTextStream * mpa_sequenceTxtIn
Definition: fastafileindexer.h:73
pappso::FastaFileIndexer::m_indexArray
std::vector< qint64 > m_indexArray
Definition: fastafileindexer.h:72

References m_indexArray, and mpa_sequenceTxtIn.

## ~FastaFileIndexer()

pappso::FastaFileIndexer::~FastaFileIndexer | ( |  | ) |

virtual

Definition at line 66 of file fastafileindexer.cpp.

{
close();
}
pappso::FastaFileIndexer::close
void close() override
Definition: fastafileindexer.cpp:138

References close().

## Member Function Documentation

## close()

void pappso::FastaFileIndexer::close | ( |  | ) |

override virtual

Implements pappso::FastaFileIndexerInterface.

Definition at line 138 of file fastafileindexer.cpp.

{
if(mpa_sequenceTxtIn != nullptr)
{
delete mpa_sequenceTxtIn;
mpa_sequenceTxtIn = nullptr;
m_fasta_file.close();
}
}

References m_fasta_file, and mpa_sequenceTxtIn.

Referenced by ~FastaFileIndexer().

## getSequenceByIndex()

void pappso::FastaFileIndexer::getSequenceByIndex | ( | FastaHandlerInterface & | fasta_handler,
|  | std::size_t | index
| ) |  |

override virtual

Implements pappso::FastaFileIndexerInterface.

Definition at line 149 of file fastafileindexer.cpp.

{
open();
qDebug() << " goto=" << index << " pos=" << m_indexArray[index];
bool seek_ok;
if((index < m_indexArray.size()) &&
(seek_ok = mpa_sequenceTxtIn->seek(m_indexArray[index])))
{
qDebug() << " realpos=" << mpa_sequenceTxtIn->pos();
;
if(!seek_ok)
{
throw PappsoException(QObject::tr("ERROR FastaFileIndexer : seek to "
"sequence %1, position %2 failed")
.arg(index)
.arg(m_indexArray[index]));
}
FastaReader reader(fasta_handler);
reader.parseOnlyOne(*mpa_sequenceTxtIn);
}
else
{
throw ExceptionOutOfRange(
QObject::tr("ERROR reading FASTA file %1 : sequence index %2 "
"unreachable, array size=%3")
.arg(m_fasta_file.fileName())
.arg(index)
.arg(m_indexArray.size()));
}
}
pappso::FastaFileIndexer::open
void open() override
Definition: fastafileindexer.cpp:122

References m_fasta_file, m_indexArray, mpa_sequenceTxtIn, open(), and pappso::FastaReader::parseOnlyOne().

## makeFastaFileIndexerSPtr()

FastaFileIndexerSPtr pappso::FastaFileIndexer::makeFastaFileIndexerSPtr | ( |  | ) | const

Definition at line 186 of file fastafileindexer.cpp.

{
return std::make_shared<FastaFileIndexer>(*this);
}

## open()

void pappso::FastaFileIndexer::open | ( |  | ) |

override virtual

Implements pappso::FastaFileIndexerInterface.

Definition at line 122 of file fastafileindexer.cpp.

{
if(mpa_sequenceTxtIn != nullptr)
return;
if(m_fasta_file.open(QIODevice::ReadOnly))
{
mpa_sequenceTxtIn = new QTextStream(&m_fasta_file);
}
else
{
throw PappsoException(QObject::tr("ERROR opening FASTA file %1 for read")
.arg(m_fasta_file.fileName()));
}
}

References m_fasta_file, and mpa_sequenceTxtIn.

Referenced by getSequenceByIndex().

## parseFastaFile()

void pappso::FastaFileIndexer::parseFastaFile | ( |  | ) |

private

Definition at line 73 of file fastafileindexer.cpp.

{
qDebug();
QDataStream bin_in(&m_fasta_file);
qint64 position = 0;
// QChar first_char;
// txt_in >> first_char;
qint8 char_in;
bin_in >> char_in;
while(!bin_in.atEnd() && (char_in < (qint8)21))
{ // eat Windows \r\n
position++;
bin_in >> char_in;
}
while(!bin_in.atEnd())
{
// qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
// << " first_char=" << first_char;
if(char_in == (qint8)'>')
{
// qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
// << " index=" << m_indexArray.size()
// << " position=" << position;
m_indexArray.push_back(position);
}
// eat line
position++;
bin_in >> char_in;
while(!bin_in.atEnd() && (char_in > (qint8)20))
{
position++;
bin_in >> char_in;
}
position++;
bin_in >> char_in;
if(!bin_in.atEnd() && (char_in < (qint8)21))
{ // eat Windows \r\n
position++;
bin_in >> char_in;
}
}
qDebug();
}

References m_fasta_file, and m_indexArray.

Referenced by FastaFileIndexer().

## Member Data Documentation

## m_fasta_file

QFile pappso::FastaFileIndexer::m_fasta_file

private

Definition at line 71 of file fastafileindexer.h.

Referenced by FastaFileIndexer(), close(), getSequenceByIndex(), open(), and parseFastaFile().

## m_indexArray

std::vector<qint64> pappso::FastaFileIndexer::m_indexArray

private

Definition at line 72 of file fastafileindexer.h.

Referenced by FastaFileIndexer(), getSequenceByIndex(), and parseFastaFile().

## mpa_sequenceTxtIn

QTextStream* pappso::FastaFileIndexer::mpa_sequenceTxtIn = nullptr

private

Definition at line 73 of file fastafileindexer.h.

Referenced by FastaFileIndexer(), close(), getSequenceByIndex(), and open().

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

- pappsomspp/fasta/fastafileindexer.h
- pappsomspp/fasta/fastafileindexer.cpp