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_BEDTOOLS_INTERSECT_TASK_H_ 23 #define _U2_BEDTOOLS_INTERSECT_TASK_H_ 24 25 #include <QFile> 26 27 #include <U2Core/ExternalToolRunTask.h> 28 29 namespace U2 { 30 31 //////////////////////////////////////////////////////////////////////////////////////////////////////////////// 32 // BedtoolIntersectSettings 33 class BedtoolsIntersectSettings { 34 public: 35 static const double DEFAULT_MIN_OVERLAP; 36 37 enum Report { 38 Report_OverlapedA = 0, // -wa 39 Report_NonOverlappedA = 1, // -v 40 Report_Intervals = 2 41 }; 42 43 BedtoolsIntersectSettings(double minOverlap = DEFAULT_MIN_OVERLAP, bool unique = true, Report r = Report_OverlapedA) minOverlap(minOverlap)44 : minOverlap(minOverlap), 45 unique(unique), 46 report(r) { 47 } 48 49 double minOverlap; // -f (0..1] 50 bool unique; // -u 51 Report report; 52 }; 53 54 class AnnotationTableObject; 55 56 class BedtoolsIntersectByEntityRefSettings : public BedtoolsIntersectSettings { 57 public: BedtoolsIntersectByEntityRefSettings()58 BedtoolsIntersectByEntityRefSettings() 59 : BedtoolsIntersectSettings() { 60 } 61 62 BedtoolsIntersectByEntityRefSettings(const QList<U2EntityRef> &entityA, const QList<U2EntityRef> &entityB, double minOverlap = DEFAULT_MIN_OVERLAP, bool unique = true, Report r = Report_OverlapedA) BedtoolsIntersectSettings(minOverlap,unique,r)63 : BedtoolsIntersectSettings(minOverlap, unique, r), 64 entitiesA(entityA), 65 entitiesB(entityB) { 66 } 67 68 QList<U2EntityRef> entitiesA; // -a 69 QList<U2EntityRef> entitiesB; // -b 70 }; 71 72 class BedtoolsIntersectFilesSettings : public BedtoolsIntersectSettings { 73 public: 74 BedtoolsIntersectFilesSettings(const QString &inputA, const QStringList &inputB, const QString &output, double minOverlap = DEFAULT_MIN_OVERLAP, bool unique = true, Report r = Report_OverlapedA) BedtoolsIntersectSettings(minOverlap,unique,r)75 : BedtoolsIntersectSettings(minOverlap, unique, r), 76 inputA(inputA), 77 inputB(inputB), 78 out(output) { 79 } 80 81 QString inputA; // -a 82 QStringList inputB; // -b 83 QString out; 84 }; 85 86 //////////////////////////////////////////////////////////////////////////////////////////////////////////////// 87 // BedToolsIntersectTask & BedtoolsIntersectLogParser 88 class BedtoolsIntersectTask : public ExternalToolSupportTask { 89 Q_OBJECT 90 public: 91 BedtoolsIntersectTask(const BedtoolsIntersectFilesSettings &settings); 92 void prepare(); 93 94 protected: 95 const QStringList getParameters() const; 96 97 private: 98 BedtoolsIntersectFilesSettings settings; 99 }; 100 101 class BedtoolsIntersectLogParser : public ExternalToolLogParser { 102 public: 103 BedtoolsIntersectLogParser(const QString &resultFile); 104 105 void parseOutput(const QString &partOfLog); parseErrOutput(const QString &)106 void parseErrOutput(const QString & /*partOfLog*/) { 107 } 108 109 private: 110 QFile result; 111 }; 112 113 //////////////////////////////////////////////////////////////////////////////////////////////////////////////// 114 // IntersectAnnotationsTask 115 class AnnotationGroup; 116 class SaveMultipleDocuments; 117 class LoadDocumentTask; 118 119 class BedtoolsIntersectAnnotationsByEntityTask : public ExternalToolSupportTask { 120 Q_OBJECT 121 public: 122 BedtoolsIntersectAnnotationsByEntityTask(const BedtoolsIntersectByEntityRefSettings &settings); 123 void prepare(); 124 QList<Task *> onSubTaskFinished(Task *subTask); 125 getResult()126 QList<GObject *> getResult() { 127 return result; 128 } 129 130 private: 131 Document *createAnnotationsDocument(const QString &url, const QList<U2EntityRef> &enities); 132 void renameAnnotationsForBed(AnnotationGroup *group); 133 void renameAnnotationsFromBed(AnnotationGroup *group); 134 135 BedtoolsIntersectByEntityRefSettings settings; 136 QList<GObject *> result; 137 138 QString tmpUrlA; 139 QString tmpUrlB; 140 QString tmpUrlResult; 141 142 SaveMultipleDocuments *saveAnnotationsTask; 143 BedtoolsIntersectTask *intersectTask; 144 LoadDocumentTask *loadResultTask; 145 }; 146 147 } // namespace U2 148 149 #endif // _U2_BEDTOOLS_INTERSECT_TASK_H_ 150