Skip to content

Commit

Permalink
Fix #38. Percent is now computed compressFile->pos() / compressFile->…
Browse files Browse the repository at this point in the history
…size()
  • Loading branch information
dridk committed Mar 14, 2017
1 parent 8393fa8 commit 7605421
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 60 deletions.
17 changes: 6 additions & 11 deletions analysis/analysisrunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,29 @@ AnalysisRunner::~AnalysisRunner()

void AnalysisRunner::run()
{
setStatus(Prepare);
setStatus(Running);

QFileInfo fileInfo(mFilename);

QFile * compressFile = new QFile(mFilename);
QIODevice * file = Q_NULLPTR;

file = new QFile(mFilename);
if (is_gz(file))
{
file = new KCompressionDevice(mFilename, KCompressionDevice::GZip);
file = new KCompressionDevice(compressFile,true,KCompressionDevice::GZip);
if (!is_fastq(file))
file = Q_NULLPTR;
}
else if (is_bz2(file))
{
file = new KCompressionDevice(mFilename, KCompressionDevice::BZip2);
file = new KCompressionDevice(compressFile, true, KCompressionDevice::BZip2);
if (!is_fastq(file))
file = Q_NULLPTR;
}
else if (is_xz(file))
{
file = new KCompressionDevice(mFilename, KCompressionDevice::Xz);
file = new KCompressionDevice(compressFile,true, KCompressionDevice::Xz);
if (!is_fastq(file))
file = Q_NULLPTR;
}
Expand Down Expand Up @@ -108,12 +109,6 @@ void AnalysisRunner::run()
FastqReader reader(file);
mStartTime.start();

// pre compute total size for sequencial access .
//emitUpdate(tr("Analysis ..."));
reader.computeTotalSize();

setStatus(Running);


for (Analysis * a : mAnalysisHash)
a->before();
Expand All @@ -138,7 +133,7 @@ void AnalysisRunner::run()
// this is critcal and can decrease the speed. Send message only 1 sequence / 1000
if (mSequenceCount % 1000 == 0)
{
int percentNow = reader.percentComplete();
int percentNow = (float)(compressFile->pos()) / fileInfo.size() * 100;
// if percentNow is still null, return empty percent ...
if ( (percentNow >= mProgression + 5) || (percentNow == 0))
{
Expand Down
4 changes: 2 additions & 2 deletions analysis/analysisrunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Copyright Copyright 2016-17 Sacha Schutz
#define ANALYSISRUNNER_H
#include <QtCore>
#include <KCompressionDevice>
#include <KFilterBase>
#include "analysis.h"
#include "fastqreader.h"
#include "imageformatdefinition.h"
Expand All @@ -43,8 +44,7 @@ class AnalysisRunner : public QRunnable
Waiting,
Running,
Canceled,
Finished,
Prepare
Finished
};

AnalysisRunner();
Expand Down
11 changes: 3 additions & 8 deletions model/mainanalysemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ QVariant MainAnalyseModel::data(const QModelIndex &index, int role) const
case AnalysisRunner::Canceled : return tr("Canceled"); break;
case AnalysisRunner::Running : return tr("Running"); break;
case AnalysisRunner::Finished : return tr("Finished"); break;
case AnalysisRunner::Prepare : return tr("Preparing ..."); break;

}

}
Expand All @@ -55,12 +53,9 @@ QVariant MainAnalyseModel::data(const QModelIndex &index, int role) const
return mRunners.at(index.row())->humanFileSize();


if (index.column() == ProgressColumn){
if (mRunners.at(index.row())->status() == AnalysisRunner::Prepare )
return -1;
else
return mRunners.at(index.row())->progression();
}
if (index.column() == ProgressColumn)
return mRunners.at(index.row())->progression();


if (index.column() == ReadsColumn)
return mRunners.at(index.row())->sequenceCount();
Expand Down
29 changes: 0 additions & 29 deletions sequence/abstractsequencereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,13 @@ AbstractSequenceReader::AbstractSequenceReader(QIODevice *device)
{


}

int AbstractSequenceReader::percentComplete() const
{
if (totalSize() == 0)
return 0;

quint64 percent = qFloor(qreal(mDevice->pos()) / totalSize() * 100);
return percent;

}

const Sequence &AbstractSequenceReader::sequence() const
{
return mSequence;
}

void AbstractSequenceReader::computeTotalSize()
{
if (mDevice->size() == 0) // sequential
{
while (!mDevice->atEnd())
mDevice->readLine();
mTotalSize = mDevice->pos();
mDevice->seek(0);
}
else { // Random access
mTotalSize = mDevice->size();
}
}

long long AbstractSequenceReader::totalSize() const
{
return mTotalSize;
}

QIODevice *AbstractSequenceReader::device() const
{
return mDevice;
Expand Down
10 changes: 0 additions & 10 deletions sequence/abstractsequencereader.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ class AbstractSequenceReader
* \return false if the file end has been reach.
*/
virtual bool next() = 0;
/*!
* \brief percentComplete return percent of bytes processed
* \return a a value between 0 and 100
*/
virtual int percentComplete() const;

/*!
* \brief Return the current sequence.
Expand All @@ -63,18 +58,13 @@ class AbstractSequenceReader
*/
const Sequence& sequence() const;


void computeTotalSize() ;
long long totalSize() const;

protected:
void setSequence(const Sequence& seq);
QIODevice * device() const;

private:
QIODevice * mDevice;
Sequence mSequence;
long long mTotalSize = 0;
};

#endif // ABSTRACTSEQUENCEREADER_H

0 comments on commit 7605421

Please sign in to comment.