~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to source/APPLICATIONS/UTILS/QCShrinker.C

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2013-12-20 11:30:16 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131220113016-wre5g9bteeheq6he
Tags: 1.11.1-3
* remove version number from libbost development package names;
* ensure that AUTHORS is correctly shipped in all packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// --------------------------------------------------------------------------
 
2
//                   OpenMS -- Open-Source Mass Spectrometry
 
3
// --------------------------------------------------------------------------
 
4
// Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
 
5
// ETH Zurich, and Freie Universitaet Berlin 2002-2013.
 
6
//
 
7
// This software is released under a three-clause BSD license:
 
8
//  * Redistributions of source code must retain the above copyright
 
9
//    notice, this list of conditions and the following disclaimer.
 
10
//  * Redistributions in binary form must reproduce the above copyright
 
11
//    notice, this list of conditions and the following disclaimer in the
 
12
//    documentation and/or other materials provided with the distribution.
 
13
//  * Neither the name of any author or any participating institution
 
14
//    may be used to endorse or promote products derived from this software
 
15
//    without specific prior written permission.
 
16
// For a full list of authors, refer to the file AUTHORS.
 
17
// --------------------------------------------------------------------------
 
18
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
19
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
20
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
21
// ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
 
22
// INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
23
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
24
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 
25
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 
26
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 
27
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 
28
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
29
//
 
30
// --------------------------------------------------------------------------
 
31
// $Maintainer: Mathias Walzer $
 
32
// $Author: Mathias Walzer $
 
33
// --------------------------------------------------------------------------
 
34
 
 
35
#include <OpenMS/APPLICATIONS/TOPPBase.h>
 
36
#include <OpenMS/FORMAT/CsvFile.h>
 
37
#include <OpenMS/KERNEL/StandardTypes.h>
 
38
#include <OpenMS/DATASTRUCTURES/String.h>
 
39
#include <OpenMS/FORMAT/QcMLFile.h>
 
40
 
 
41
#include <QByteArray>
 
42
#include <QFile>
 
43
#include <QString>
 
44
#include <QFileInfo>
 
45
 
 
46
//~ #include <QIODevice>
 
47
#include <fstream>
 
48
#include <vector>
 
49
#include <map>
 
50
 
 
51
using namespace OpenMS;
 
52
using namespace std;
 
53
 
 
54
//-------------------------------------------------------------
 
55
//Doxygen docu
 
56
//-------------------------------------------------------------
 
57
 
 
58
/**
 
59
    @page UTILS_QCShrinker QCShrinker
 
60
 
 
61
    @brief This application is used to remove the verbose table attachments from a qcml file that are not needed anymore, e.g. for a final report.
 
62
 
 
63
    <CENTER>
 
64
      <table>
 
65
        <tr>
 
66
        <td ALIGN = "center" BGCOLOR="#EBEBEB"> pot. predecessor tools </td>
 
67
        <td VALIGN="middle" ROWSPAN=3> \f$ \longrightarrow \f$ QCShrinker \f$ \longrightarrow \f$</td>
 
68
        <td ALIGN = "center" BGCOLOR="#EBEBEB"> pot. successor tools </td>
 
69
        </tr>
 
70
        <tr>
 
71
        <td VALIGN="middle" ALIGN = "center" ROWSPAN=2> @ref UTILS_QCMerger </td>
 
72
        </tr>
 
73
        <tr>
 
74
        <td VALIGN="middle" ALIGN = "center" ROWSPAN=1> ... </td>
 
75
        </tr>
 
76
      </table>
 
77
    </CENTER>
 
78
 
 
79
    If there is a lot of verbose or deprecated information in the given qcml file at @p in that can be purged.
 
80
    
 
81
    - @p qp_accessions A list of cv accessions that should be removed. If empty, the usual suspects will be removed.
 
82
    - @p run the file that defined the run under which the qp for the attachment is aggregated as MZML file. The file is only used to extract the run name from the file name;
 
83
    - @p name if no file for the run was given (or if the target qp is contained in a set), at least a name of the target run/set containing the the qp for the attachment has to be given;
 
84
    
 
85
    Output is in qcML format (see parameter @p out) which can be viewed directly in a modern browser (chromium, firefox). 
 
86
    
 
87
    <B>The command line parameters of this tool are:</B>
 
88
    @verbinclude UTILS_QCShrinker.cli
 
89
    <B>INI file documentation of this tool:</B>
 
90
    @htmlinclude UTILS_QCShrinker.html
 
91
 
 
92
*/
 
93
 
 
94
// We do not want this class to show up in the docu:
 
95
/// @cond TOPPCLASSES
 
96
class TOPPQCShrinker :
 
97
  public TOPPBase
 
98
{
 
99
public:
 
100
  TOPPQCShrinker() :
 
101
    TOPPBase("QCShrinker", "This application is used to remove the verbose table attachments from a qcml file that are not needed anymore, e.g. for a final report.", false)
 
102
  {
 
103
  }
 
104
 
 
105
protected:
 
106
  void registerOptionsAndFlags_()
 
107
  {
 
108
    registerInputFile_("in", "<file>", "", "Input qcml file");
 
109
    setValidFormats_("in", StringList::create("qcML"));
 
110
    //~ registerFlag_("tables", "Remove all tables. (Of all runs and sets if these are not given with parameter name or run.)");
 
111
    registerStringList_("qp_accessions", "<names>", StringList(), "A list of cv accessions that should be removed. If empty, the usual suspects will be removed!", false);
 
112
    registerStringOption_("name", "<string>", "", "The name of the target run or set that contains the requested quality parameter.", false);
 
113
    registerInputFile_("run", "<file>", "", "The file from which the name of the target run that contains the requested quality parameter is taken. This overrides the name parameter!", false);
 
114
    setValidFormats_("run", StringList::create("mzML"));
 
115
    registerOutputFile_("out", "<file>", "", "Output extended/reduced qcML file");
 
116
    setValidFormats_("out", StringList::create("qcML"));
 
117
  }
 
118
 
 
119
  ExitCodes main_(int, const char**)
 
120
  {
 
121
    //-------------------------------------------------------------
 
122
    // parsing parameters
 
123
    //-------------------------------------------------------------
 
124
    String in                   = getStringOption_("in");
 
125
    String out                  = getStringOption_("out");
 
126
    String target_run           = getStringOption_("name");
 
127
    String target_file          = getStringOption_("run");
 
128
    StringList qp_accs          = getStringList_("qp_accessions");
 
129
 
 
130
    //-------------------------------------------------------------
 
131
    // reading input
 
132
    //------------------------------------------------------------
 
133
    if (target_file != "")
 
134
    {
 
135
      target_run = QFileInfo(QString::fromStdString(target_file)).baseName();
 
136
    }
 
137
 
 
138
    //~ !getFlag_("tables")
 
139
 
 
140
    QcMLFile qcmlfile;
 
141
    qcmlfile.load(in);
 
142
 
 
143
    if (qp_accs.empty())
 
144
    {
 
145
      qp_accs << "QC:0000044";
 
146
      qp_accs << "QC:0000047";
 
147
      qp_accs << "QC:0000022";
 
148
      qp_accs << "QC:0000038";
 
149
      qp_accs << "QC:0000049";
 
150
    }
 
151
 
 
152
    //TODO care for QualityParameter s
 
153
    if (target_run == "")
 
154
    {
 
155
      for (Size i = 0; i < qp_accs.size(); ++i)
 
156
      {
 
157
        qcmlfile.removeAllAttachments(qp_accs[i]);
 
158
      }
 
159
    }
 
160
    else
 
161
    {
 
162
      for (Size i = 0; i < qp_accs.size(); ++i)
 
163
      {
 
164
        qcmlfile.removeAttachment(target_run,qp_accs[i]);
 
165
      }
 
166
    }
 
167
 
 
168
    qcmlfile.store(out);
 
169
    return EXECUTION_OK;
 
170
  }
 
171
 
 
172
};
 
173
int main(int argc, const char** argv)
 
174
{
 
175
  TOPPQCShrinker tool;
 
176
  return tool.main(argc, argv);
 
177
}
 
178
 
 
179
/// @endcond