libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::FastaFileIndexer Class Reference

#include <fastafileindexer.h>

Inheritance diagram for pappso::FastaFileIndexer:
pappso::FastaFileIndexerInterface

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
std::size_t size () 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.

40 : m_fasta_file(fastaFile.absoluteFilePath())
41{
42
43 if(m_fasta_file.fileName().isEmpty())
44 {
45 throw PappsoException(QObject::tr("No FASTA file name specified"));
46 }
47 if(m_fasta_file.open(QIODevice::ReadOnly))
48 {
50 m_fasta_file.close();
51 }
52 else
53 {
54 throw PappsoException(
55 QObject::tr("ERROR opening FASTA file %1 for read").arg(fastaFile.fileName()));
56 }
57}

References m_fasta_file.

Referenced by FastaFileIndexer().

◆ FastaFileIndexer() [2/2]

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

Definition at line 59 of file fastafileindexer.cpp.

60 : m_fasta_file(other.m_fasta_file.fileName())
61{
62
63 m_indexArray = other.m_indexArray;
64 mpa_sequenceTxtIn = nullptr;
65}
std::vector< qint64 > m_indexArray

References FastaFileIndexer(), m_fasta_file, m_indexArray, and mpa_sequenceTxtIn.

◆ ~FastaFileIndexer()

pappso::FastaFileIndexer::~FastaFileIndexer ( )
virtual

Definition at line 66 of file fastafileindexer.cpp.

67{
68 close();
69}

References close().

Member Function Documentation

◆ close()

void pappso::FastaFileIndexer::close ( )
overridevirtual

Implements pappso::FastaFileIndexerInterface.

Definition at line 138 of file fastafileindexer.cpp.

139{
140 if(mpa_sequenceTxtIn != nullptr)
141 {
142 delete mpa_sequenceTxtIn;
143 mpa_sequenceTxtIn = nullptr;
144 m_fasta_file.close();
145 }
146}

References m_fasta_file, and mpa_sequenceTxtIn.

Referenced by ~FastaFileIndexer().

◆ getSequenceByIndex()

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

Implements pappso::FastaFileIndexerInterface.

Definition at line 149 of file fastafileindexer.cpp.

150{
151 open();
152
153 qDebug() << " goto=" << index << " pos=" << m_indexArray[index];
154 bool seek_ok;
155 if((index < m_indexArray.size()) && (seek_ok = mpa_sequenceTxtIn->seek(m_indexArray[index])))
156 {
157
158 qDebug() << " realpos=" << mpa_sequenceTxtIn->pos();
159 ;
160 if(!seek_ok)
161 {
162
163 throw PappsoException(QObject::tr("ERROR FastaFileIndexer : seek to "
164 "sequence %1, position %2 failed")
165 .arg(index)
166 .arg(m_indexArray[index]));
167 }
168 FastaReader reader(fasta_handler);
169 reader.parseOnlyOne(*mpa_sequenceTxtIn);
170 }
171 else
172 {
173 throw ExceptionOutOfRange(QObject::tr("ERROR reading FASTA file %1 : sequence index %2 "
174 "unreachable, array size=%3")
175 .arg(m_fasta_file.fileName())
176 .arg(index)
177 .arg(m_indexArray.size()));
178 }
179}

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

◆ makeFastaFileIndexerSPtr()

FastaFileIndexerSPtr pappso::FastaFileIndexer::makeFastaFileIndexerSPtr ( ) const

Definition at line 183 of file fastafileindexer.cpp.

184{
185
186 return std::make_shared<FastaFileIndexer>(*this);
187}

◆ open()

void pappso::FastaFileIndexer::open ( )
overridevirtual

Implements pappso::FastaFileIndexerInterface.

Definition at line 122 of file fastafileindexer.cpp.

123{
124 if(mpa_sequenceTxtIn != nullptr)
125 return;
126 if(m_fasta_file.open(QIODevice::ReadOnly))
127 {
128 mpa_sequenceTxtIn = new QTextStream(&m_fasta_file);
129 }
130 else
131 {
132 throw PappsoException(
133 QObject::tr("ERROR opening FASTA file %1 for read").arg(m_fasta_file.fileName()));
134 }
135}

References m_fasta_file, and mpa_sequenceTxtIn.

Referenced by getSequenceByIndex().

◆ parseFastaFile()

void pappso::FastaFileIndexer::parseFastaFile ( )
private

Definition at line 73 of file fastafileindexer.cpp.

74{
75
76 qDebug();
77 QDataStream bin_in(&m_fasta_file);
78 qint64 position = 0;
79
80 // QChar first_char;
81 // txt_in >> first_char;
82 qint8 char_in;
83 bin_in >> char_in;
84 while(!bin_in.atEnd() && (char_in < (qint8)21))
85 { // eat Windows \r\n
86 position++;
87 bin_in >> char_in;
88 }
89 while(!bin_in.atEnd())
90 {
91 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
92 // << " first_char=" << first_char;
93 if(char_in == (qint8)'>')
94 {
95
96 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
97 // << " index=" << m_indexArray.size()
98 // << " position=" << position;
99 m_indexArray.push_back(position);
100 }
101 // eat line
102 position++;
103 bin_in >> char_in;
104 while(!bin_in.atEnd() && (char_in > (qint8)20))
105 {
106 position++;
107 bin_in >> char_in;
108 }
109 position++;
110 bin_in >> char_in;
111
112 if(!bin_in.atEnd() && (char_in < (qint8)21))
113 { // eat Windows \r\n
114 position++;
115 bin_in >> char_in;
116 }
117 }
118 qDebug();
119}

References m_fasta_file, and m_indexArray.

◆ size()

std::size_t pappso::FastaFileIndexer::size ( ) const

Definition at line 191 of file fastafileindexer.cpp.

192{
193 return m_indexArray.size();
194}

References m_indexArray.

Member Data Documentation

◆ m_fasta_file

QFile pappso::FastaFileIndexer::m_fasta_file
private

◆ m_indexArray

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

Definition at line 74 of file fastafileindexer.h.

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

◆ mpa_sequenceTxtIn

QTextStream* pappso::FastaFileIndexer::mpa_sequenceTxtIn = nullptr
private

Definition at line 75 of file fastafileindexer.h.

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


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