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

« back to all changes in this revision

Viewing changes to source/APPLICATIONS/UTILS/DeMeanderize.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
 
// -*- mode: C++; tab-width: 2; -*-
2
 
// vi: set ts=2:
3
 
//
4
 
// --------------------------------------------------------------------------
5
 
//                   OpenMS Mass Spectrometry Framework
6
 
// --------------------------------------------------------------------------
7
 
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
8
 
//
9
 
//  This library is free software; you can redistribute it and/or
10
 
//  modify it under the terms of the GNU Lesser General Public
11
 
//  License as published by the Free Software Foundation; either
12
 
//  version 2.1 of the License, or (at your option) any later version.
13
 
//
14
 
//  This library is distributed in the hope that it will be useful,
15
 
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 
//  Lesser General Public License for more details.
18
 
//
19
 
//  You should have received a copy of the GNU Lesser General Public
20
 
//  License along with this library; if not, write to the Free Software
21
 
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
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.
22
29
//
23
30
// --------------------------------------------------------------------------
24
31
// $Maintainer: Andreas Bertsch $
37
44
//-------------------------------------------------------------
38
45
 
39
46
/**
40
 
        @page UTILS_DeMeanderize DeMeanderize
41
 
        
42
 
        @brief Repairs MALDI experiments which were spotted line by line.
43
 
 
44
 
        
45
 
 
46
 
        <B>The command line parameters of this tool are:</B>
47
 
        @verbinclude UTILS_DeMeanderize.cli
 
47
    @page UTILS_DeMeanderize DeMeanderize
 
48
 
 
49
    @brief Repairs MALDI experiments which were spotted line by line.
 
50
 
 
51
 
 
52
 
 
53
    <B>The command line parameters of this tool are:</B>
 
54
    @verbinclude UTILS_DeMeanderize.cli
 
55
    <B>INI file documentation of this tool:</B>
 
56
    @htmlinclude UTILS_DeMeanderize.html
48
57
*/
49
58
 
50
59
// We do not want this class to show up in the docu:
51
60
/// @cond TOPPCLASSES
52
61
 
53
 
class TOPPDeMeanderize
54
 
        : public TOPPBase
 
62
class TOPPDeMeanderize :
 
63
  public TOPPBase
55
64
{
56
 
        public:
57
 
                TOPPDeMeanderize()
58
 
                        : TOPPBase("DeMeanderize","Orders the spectra of MALDI spotting plates correctly.", false)
59
 
                {
60
 
                        
61
 
                }
62
 
        
63
 
        protected:
64
 
                void registerOptionsAndFlags_()
65
 
                {
66
 
                        registerInputFile_("in","<mzML-file>","","Input experiment file, containing the wrongly sorted spectra.");
67
 
                        setValidFormats_("in", StringList::create("mzML"));
68
 
                        registerOutputFile_("out","<mzML-file>","","Output experiment file with correctly sorted spectra.");
69
 
                        setValidFormats_("out", StringList::create("mzML"));
70
 
                        registerIntOption_("num_spots_per_row", "<integer>", 48, "Number of spots in one column, until next row is spotted.", false);
71
 
                        setMinInt_("num_spots_per_row", 1);
72
 
                        registerDoubleOption_("RT_distance", "<integer>", 1.0, "RT distance between two spots which is used to calculated pseudo RT.", false, true);
73
 
                        setMinFloat_("RT_distance", 0.0);
74
 
                }
75
 
 
76
 
                ExitCodes main_(int , const char**)
77
 
                {
78
 
                        //-------------------------------------------------------------
79
 
                        // parsing parameters
80
 
                        //-------------------------------------------------------------
81
 
                        String in(getStringOption_("in"));
82
 
                        String out(getStringOption_("out"));
83
 
                        Size num_spots_per_row(getIntOption_("num_spots_per_row"));
84
 
                        DoubleReal RT_distance(getDoubleOption_("RT_distance"));
85
 
                        
86
 
                        //-------------------------------------------------------------
87
 
                        // reading input
88
 
                        //-------------------------------------------------------------
89
 
 
90
 
                        PeakMap exp;
91
 
                        MzMLFile f;
92
 
            f.setLogType(log_type_);
93
 
                        f.load(in, exp);
94
 
 
95
 
                        //-------------------------------------------------------------
96
 
                        // calculations
97
 
                        //-------------------------------------------------------------                                 
98
 
 
99
 
                        ProgressLogger pl;
100
 
                        pl.setLogType(log_type_);
101
 
                        pl.startProgress(0, exp.size(), "Assigning pseudo RTs.");
102
 
                        Size num_ms1(0), num_ms1_base(0), row_counter(0);
103
 
                        bool row_to_reverse(false);
104
 
                        DoubleReal actual_RT(0);
105
 
                        for (Size i = 0; i != exp.size(); ++i)
106
 
                        {
107
 
                                pl.setProgress(i);
108
 
                                if (row_to_reverse)
109
 
                                {
110
 
                                        actual_RT = (DoubleReal)(num_ms1_base + (num_spots_per_row - row_counter)) * RT_distance;
111
 
                                        writeDebug_("RT=" + String(actual_RT) + " (modified, row_counter=" + String(row_counter) + ")", 1);
112
 
                                }
113
 
                                else
114
 
                                {
115
 
                                        actual_RT = (DoubleReal)num_ms1 * RT_distance;
116
 
                                        writeDebug_("RT=" + String(actual_RT), 1);
117
 
                                }
118
 
 
119
 
                                exp[i].setRT(actual_RT);
120
 
 
121
 
                                if (exp[i].getMSLevel() == 1)
122
 
                                {
123
 
                                        if (++row_counter >= num_spots_per_row)
124
 
                                        {
125
 
                                                row_counter = 0;
126
 
                                                if (row_to_reverse)
127
 
                                                {
128
 
                                                        row_to_reverse = false;
129
 
                                                }
130
 
                                                else
131
 
                                                {
132
 
                                                        row_to_reverse = true;
133
 
                                                }
134
 
                                        }
135
 
                                        ++num_ms1;
136
 
                                        if (!row_to_reverse)
137
 
                                        {
138
 
                                                num_ms1_base = num_ms1;
139
 
                                        }
140
 
                                }
141
 
                        }
142
 
                        pl.endProgress();
143
 
 
144
 
                        // sort the spectra according to their new RT
145
 
                        exp.sortSpectra();
146
 
 
147
 
                        //-------------------------------------------------------------
148
 
      // writing output
149
 
      //-------------------------------------------------------------
150
 
                
151
 
                        f.store(out, exp);
152
 
        
153
 
                        return EXECUTION_OK;
154
 
                }
 
65
public:
 
66
  TOPPDeMeanderize() :
 
67
    TOPPBase("DeMeanderize", "Orders the spectra of MALDI spotting plates correctly.", false)
 
68
  {
 
69
 
 
70
  }
 
71
 
 
72
protected:
 
73
  void registerOptionsAndFlags_()
 
74
  {
 
75
    registerInputFile_("in", "<mzML-file>", "", "Input experiment file, containing the wrongly sorted spectra.");
 
76
    setValidFormats_("in", StringList::create("mzML"));
 
77
    registerOutputFile_("out", "<mzML-file>", "", "Output experiment file with correctly sorted spectra.");
 
78
    setValidFormats_("out", StringList::create("mzML"));
 
79
    registerIntOption_("num_spots_per_row", "<integer>", 48, "Number of spots in one column, until next row is spotted.", false);
 
80
    setMinInt_("num_spots_per_row", 1);
 
81
    registerDoubleOption_("RT_distance", "<integer>", 1.0, "RT distance between two spots which is used to calculated pseudo RT.", false, true);
 
82
    setMinFloat_("RT_distance", 0.0);
 
83
  }
 
84
 
 
85
  ExitCodes main_(int, const char **)
 
86
  {
 
87
    //-------------------------------------------------------------
 
88
    // parsing parameters
 
89
    //-------------------------------------------------------------
 
90
    String in(getStringOption_("in"));
 
91
    String out(getStringOption_("out"));
 
92
    Size num_spots_per_row(getIntOption_("num_spots_per_row"));
 
93
    DoubleReal RT_distance(getDoubleOption_("RT_distance"));
 
94
 
 
95
    //-------------------------------------------------------------
 
96
    // reading input
 
97
    //-------------------------------------------------------------
 
98
 
 
99
    PeakMap exp;
 
100
    MzMLFile f;
 
101
    f.setLogType(log_type_);
 
102
    f.load(in, exp);
 
103
 
 
104
    //-------------------------------------------------------------
 
105
    // calculations
 
106
    //-------------------------------------------------------------
 
107
 
 
108
    ProgressLogger pl;
 
109
    pl.setLogType(log_type_);
 
110
    pl.startProgress(0, exp.size(), "Assigning pseudo RTs.");
 
111
    Size num_ms1(0), num_ms1_base(0), row_counter(0);
 
112
    bool row_to_reverse(false);
 
113
    DoubleReal actual_RT(0);
 
114
    for (Size i = 0; i != exp.size(); ++i)
 
115
    {
 
116
      pl.setProgress(i);
 
117
      if (row_to_reverse)
 
118
      {
 
119
        actual_RT = (DoubleReal)(num_ms1_base + (num_spots_per_row - row_counter)) * RT_distance;
 
120
        writeDebug_("RT=" + String(actual_RT) + " (modified, row_counter=" + String(row_counter) + ")", 1);
 
121
      }
 
122
      else
 
123
      {
 
124
        actual_RT = (DoubleReal)num_ms1 * RT_distance;
 
125
        writeDebug_("RT=" + String(actual_RT), 1);
 
126
      }
 
127
 
 
128
      exp[i].setRT(actual_RT);
 
129
 
 
130
      if (exp[i].getMSLevel() == 1)
 
131
      {
 
132
        if (++row_counter >= num_spots_per_row)
 
133
        {
 
134
          row_counter = 0;
 
135
          if (row_to_reverse)
 
136
          {
 
137
            row_to_reverse = false;
 
138
          }
 
139
          else
 
140
          {
 
141
            row_to_reverse = true;
 
142
          }
 
143
        }
 
144
        ++num_ms1;
 
145
        if (!row_to_reverse)
 
146
        {
 
147
          num_ms1_base = num_ms1;
 
148
        }
 
149
      }
 
150
    }
 
151
    pl.endProgress();
 
152
 
 
153
    // sort the spectra according to their new RT
 
154
    exp.sortSpectra();
 
155
 
 
156
    //-------------------------------------------------------------
 
157
    // writing output
 
158
    //-------------------------------------------------------------
 
159
 
 
160
    f.store(out, exp);
 
161
 
 
162
    return EXECUTION_OK;
 
163
  }
 
164
 
155
165
};
156
166
 
157
167
 
158
 
int main( int argc, const char** argv )
 
168
int main(int argc, const char ** argv)
159
169
{
160
 
        TOPPDeMeanderize tool;
161
 
        return tool.main(argc,argv);
 
170
  TOPPDeMeanderize tool;
 
171
  return tool.main(argc, argv);
162
172
}
163
 
  
 
173
 
164
174
/// @endcond
165
 
 
166
 
 
167
 
 
168
 
 
169