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

« back to all changes in this revision

Viewing changes to source/TRANSFORMATIONS/FEATUREFINDER/SeedListGenerator.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: Hendrik Weisser $
31
38
 
32
39
namespace OpenMS
33
40
{
34
 
        SeedListGenerator::SeedListGenerator()
35
 
        {
36
 
        }
37
 
 
38
 
        
39
 
        void SeedListGenerator::generateSeedList(const MSExperiment<>& experiment,
40
 
                                                                                                                                                                         SeedList& seeds)
41
 
        {
42
 
                seeds.clear();
43
 
                for (MSExperiment<>::ConstIterator exp_it = experiment.begin();
44
 
                                 exp_it != experiment.end(); ++exp_it)
45
 
                {
46
 
                        if (exp_it->getMSLevel() == 2) // MS2 spectrum -> look for precursor
47
 
                        {
48
 
                                MSExperiment<>::ConstIterator prec_it =
49
 
                                        experiment.getPrecursorSpectrum(exp_it);
50
 
                                const vector<Precursor>& precursors = exp_it->getPrecursors();
51
 
                                DPosition<2> point(prec_it->getRT(), precursors[0].getMZ());
52
 
                                seeds.push_back(point);
53
 
                        }
54
 
                }
55
 
        }
56
 
 
57
 
 
58
 
        void SeedListGenerator::generateSeedList(vector<PeptideIdentification>& 
59
 
                                                                                                                                                                         peptides, SeedList& seeds, 
60
 
                                                                                                                                                                         bool use_peptide_mass)
61
 
        {
62
 
                seeds.clear();
63
 
                for (vector<PeptideIdentification>::iterator pep_it = peptides.begin(); 
64
 
                                 pep_it != peptides.end(); ++pep_it)
65
 
                {
66
 
                        DoubleReal mz;
67
 
                        if (!pep_it->getHits().empty() && use_peptide_mass)
68
 
                        {
69
 
                                pep_it->sort();
70
 
                                const PeptideHit& hit = pep_it->getHits().front();
71
 
                                Int charge = hit.getCharge();
72
 
                                mz = hit.getSequence().getMonoWeight(Residue::Full, charge) / 
73
 
                                        DoubleReal(charge);
74
 
                        }
75
 
                        else
76
 
                        {
77
 
                                mz = pep_it->getMetaValue("MZ");
78
 
                        }
79
 
                        DPosition<2> point(pep_it->getMetaValue("RT"), mz);
80
 
                        seeds.push_back(point);
81
 
                }
82
 
        }
83
 
 
84
 
        
85
 
        void SeedListGenerator::generateSeedLists(const ConsensusMap& consensus,
86
 
                                                                                                                                                                                Map<UInt64, SeedList>& seed_lists)
87
 
        {
88
 
                seed_lists.clear();
89
 
                // iterate over all consensus features...
90
 
                for (ConsensusMap::ConstIterator cons_it = consensus.begin();
91
 
                                 cons_it != consensus.end(); ++cons_it)
92
 
                {
93
 
                        DPosition<2> point(cons_it->getRT(), cons_it->getMZ());
94
 
                        // for each sub-map in the consensus map, add a seed at the position of
95
 
                        // this consensus feature:
96
 
                        for (ConsensusMap::FileDescriptions::ConstIterator file_it =
97
 
                                                 consensus.getFileDescriptions().begin(); file_it !=
98
 
                                                 consensus.getFileDescriptions().end(); ++file_it)
99
 
                                seed_lists[file_it->first].push_back(point);
100
 
                        // for each feature contained in the consensus feature, remove the seed of
101
 
                        // the corresponding map:
102
 
                        for (ConsensusFeature::HandleSetType::const_iterator feat_it =
103
 
                                                 cons_it->getFeatures().begin(); feat_it !=
104
 
                                                 cons_it->getFeatures().end(); ++feat_it)
105
 
                        {
106
 
                                seed_lists[feat_it->getMapIndex()].pop_back();
107
 
                        }
108
 
                        // this leaves seeds for maps where no feature was found near the
109
 
                        // consensus position
110
 
                }
111
 
        }
112
 
 
113
 
 
114
 
        void SeedListGenerator::convertSeedList(const SeedList& seeds, 
115
 
                                                                                                                                                                        FeatureMap<>& features)
116
 
        {
117
 
                features.clear(true); // "true" should really be a default value here...
118
 
                Size counter = 0;
119
 
                for (SeedList::const_iterator seed_it = seeds.begin();
120
 
                                 seed_it != seeds.end(); ++seed_it, ++counter)
121
 
                {
122
 
                        Feature feature;
123
 
                        feature.setRT(seed_it->getX());
124
 
                        feature.setMZ(seed_it->getY());
125
 
                        feature.setUniqueId(counter);
126
 
                        features.push_back(feature);
127
 
                }
128
 
                // // assign unique ids:
129
 
                // features.applyMemberFunction(&UniqueIdInterface::setUniqueId);
130
 
        }
131
 
 
132
 
 
133
 
        void SeedListGenerator::convertSeedList(const FeatureMap<>& features, 
134
 
                                                                                                                                                                        SeedList& seeds)
135
 
        {
136
 
                seeds.clear();
137
 
                for (FeatureMap<>::ConstIterator feat_it = features.begin();
138
 
                                 feat_it != features.end(); ++feat_it)
139
 
                {
140
 
                        DPosition<2> point(feat_it->getRT(), feat_it->getMZ());
141
 
                        seeds.push_back(point);
142
 
                }
143
 
        }
144
 
        
 
41
  SeedListGenerator::SeedListGenerator()
 
42
  {
 
43
  }
 
44
 
 
45
  void SeedListGenerator::generateSeedList(const MSExperiment<> & experiment,
 
46
                                           SeedList & seeds)
 
47
  {
 
48
    seeds.clear();
 
49
    for (MSExperiment<>::ConstIterator exp_it = experiment.begin();
 
50
         exp_it != experiment.end(); ++exp_it)
 
51
    {
 
52
      if (exp_it->getMSLevel() == 2)       // MS2 spectrum -> look for precursor
 
53
      {
 
54
        MSExperiment<>::ConstIterator prec_it =
 
55
          experiment.getPrecursorSpectrum(exp_it);
 
56
        const vector<Precursor> & precursors = exp_it->getPrecursors();
 
57
        DPosition<2> point(prec_it->getRT(), precursors[0].getMZ());
 
58
        seeds.push_back(point);
 
59
      }
 
60
    }
 
61
  }
 
62
 
 
63
  void SeedListGenerator::generateSeedList(vector<PeptideIdentification> &
 
64
                                           peptides, SeedList & seeds,
 
65
                                           bool use_peptide_mass)
 
66
  {
 
67
    seeds.clear();
 
68
    for (vector<PeptideIdentification>::iterator pep_it = peptides.begin();
 
69
         pep_it != peptides.end(); ++pep_it)
 
70
    {
 
71
      DoubleReal mz;
 
72
      if (!pep_it->getHits().empty() && use_peptide_mass)
 
73
      {
 
74
        pep_it->sort();
 
75
        const PeptideHit & hit = pep_it->getHits().front();
 
76
        Int charge = hit.getCharge();
 
77
        mz = hit.getSequence().getMonoWeight(Residue::Full, charge) /
 
78
             DoubleReal(charge);
 
79
      }
 
80
      else
 
81
      {
 
82
        mz = pep_it->getMetaValue("MZ");
 
83
      }
 
84
      DPosition<2> point(pep_it->getMetaValue("RT"), mz);
 
85
      seeds.push_back(point);
 
86
    }
 
87
  }
 
88
 
 
89
  void SeedListGenerator::generateSeedLists(const ConsensusMap & consensus,
 
90
                                            Map<UInt64, SeedList> & seed_lists)
 
91
  {
 
92
    seed_lists.clear();
 
93
    // iterate over all consensus features...
 
94
    for (ConsensusMap::ConstIterator cons_it = consensus.begin();
 
95
         cons_it != consensus.end(); ++cons_it)
 
96
    {
 
97
      DPosition<2> point(cons_it->getRT(), cons_it->getMZ());
 
98
      // for each sub-map in the consensus map, add a seed at the position of
 
99
      // this consensus feature:
 
100
      for (ConsensusMap::FileDescriptions::ConstIterator file_it =
 
101
             consensus.getFileDescriptions().begin(); file_it !=
 
102
           consensus.getFileDescriptions().end(); ++file_it)
 
103
        seed_lists[file_it->first].push_back(point);
 
104
      // for each feature contained in the consensus feature, remove the seed of
 
105
      // the corresponding map:
 
106
      for (ConsensusFeature::HandleSetType::const_iterator feat_it =
 
107
             cons_it->getFeatures().begin(); feat_it !=
 
108
           cons_it->getFeatures().end(); ++feat_it)
 
109
      {
 
110
        seed_lists[feat_it->getMapIndex()].pop_back();
 
111
      }
 
112
      // this leaves seeds for maps where no feature was found near the
 
113
      // consensus position
 
114
    }
 
115
  }
 
116
 
 
117
  void SeedListGenerator::convertSeedList(const SeedList & seeds,
 
118
                                          FeatureMap<> & features)
 
119
  {
 
120
    features.clear(true);     // "true" should really be a default value here...
 
121
    Size counter = 0;
 
122
    for (SeedList::const_iterator seed_it = seeds.begin();
 
123
         seed_it != seeds.end(); ++seed_it, ++counter)
 
124
    {
 
125
      Feature feature;
 
126
      feature.setRT(seed_it->getX());
 
127
      feature.setMZ(seed_it->getY());
 
128
      feature.setUniqueId(counter);
 
129
      features.push_back(feature);
 
130
    }
 
131
    // // assign unique ids:
 
132
    // features.applyMemberFunction(&UniqueIdInterface::setUniqueId);
 
133
  }
 
134
 
 
135
  void SeedListGenerator::convertSeedList(const FeatureMap<> & features,
 
136
                                          SeedList & seeds)
 
137
  {
 
138
    seeds.clear();
 
139
    for (FeatureMap<>::ConstIterator feat_it = features.begin();
 
140
         feat_it != features.end(); ++feat_it)
 
141
    {
 
142
      DPosition<2> point(feat_it->getRT(), feat_it->getMZ());
 
143
      seeds.push_back(point);
 
144
    }
 
145
  }
 
146
 
145
147
} // namespace OpenMS