1 /**
2  * UGENE - Integrated Bioinformatics Tools.
3  * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4  * http://ugene.net
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  */
21 
22 #ifndef _U2_GENOME_ALIGNER_TASK_H_
23 #define _U2_GENOME_ALIGNER_TASK_H_
24 
25 #include <QMutex>
26 #include <QSharedPointer>
27 #include <QTemporaryFile>
28 
29 #include <U2Algorithm/DnaAssemblyTask.h>
30 
31 #include <U2Formats/StreamSequenceReader.h>
32 #include <U2Formats/StreamSequenceWriter.h>
33 
34 #include "GenomeAlignerFindTask.h"
35 #include "GenomeAlignerIO.h"
36 #include "GenomeAlignerIndexPart.h"
37 #include "GenomeAlignerWriteTask.h"
38 
39 namespace U2 {
40 
41 class U2SequenceObject;
42 class DNATranslation;
43 class LoadDocumentTask;
44 class GenomeAlignerIndexTask;
45 class GenomeAlignerIndex;
46 class ReadShortReadsSubTask;
47 class WriteAlignedReadsSubTask;
48 class DbiConnection;
49 
50 class GenomeAlignerTask : public DnaAssemblyToReferenceTask {
51     Q_OBJECT
52     friend class ReadShortReadsSubTask;
53 
54 public:
55     GenomeAlignerTask(const DnaAssemblyToRefTaskSettings &settings, bool justBuildIndex = false);
56     ~GenomeAlignerTask();
57     virtual void prepare();
58     virtual ReportResult report();
59     virtual QList<Task *> onSubTaskFinished(Task *subTask);
60     QString getIndexPath();
61     static const QString OPTION_ALIGN_REVERSED;
62     static const QString OPTION_OPENCL;
63     static const QString OPTION_IF_ABS_MISMATCHES;
64     static const QString OPTION_MISMATCHES;
65     static const QString OPTION_PERCENTAGE_MISMATCHES;
66     static const QString OPTION_INDEX_DIR;
67     static const QString OPTION_QUAL_THRESHOLD;
68     static const QString OPTION_BEST;
69     static const QString OPTION_READS_MEMORY_SIZE;
70     static const QString OPTION_SEQ_PART_SIZE;
71     static const int MIN_SHORT_READ_LENGTH = 30;
72     static int calculateWindowSize(bool absMismatches, int nMismatches, int ptMismatches, int minReadLength, int maxReadLength);
73 
74     DNA_ASSEMBLEY_TO_REF_TASK_FACTORY(GenomeAlignerTask)
75 private:
76     LoadDocumentTask *loadDbiTask;
77     GenomeAlignerIndexTask *createIndexTask;
78     ReadShortReadsSubTask *readTask;
79     GenomeAlignerFindTask *findTask;
80     WriteAlignedReadsSubTask *writeTask;
81     GenomeAlignerWriteTask *pWriteTask;
82     Task *unzipTask;
83 
84     GenomeAlignerReader *seqReader;
85     GenomeAlignerWriter *seqWriter;
86     AlignContext alignContext;
87 
88     QTemporaryFile temp;
89 
90     bool justBuildIndex;
91 
92     bool alignReversed;
93     bool dbiIO;
94     QString indexFileName;
95     bool prebuiltIndex;
96     GenomeAlignerIndex *index;
97     int qualityThreshold;
98     qint64 readMemSize;
99     int seqPartSize;
100     SearchQuery *lastQuery;
101     bool noDataToAlign;
102 
103     // statistics
104     qint64 readsCount;
105     qint64 readsAligned;
106     qint64 shortreadLoadTime;
107     qint64 resultWriteTime;
108     qint64 indexLoadTime;
109     qint64 shortreadIOTime;
110     float currentProgress;
111 
112     QMutex writeLock;
113 
114     void setupCreateIndexTask();
115     void createGenomeAlignerWriteTask();
116 };
117 
118 }  // namespace U2
119 
120 #endif  // _U2_GENOME_ALIGNER_TASK_H_
121