~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: 2012-11-12 15:58:12 UTC
  • Revision ID: package-import@ubuntu.com-20121112155812-vr15wtg9b50cuesg
Tags: upstream-1.9.0
ImportĀ upstreamĀ versionĀ 1.9.0

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
 
22
//
 
23
// --------------------------------------------------------------------------
 
24
// $Maintainer: Hendrik Weisser $
 
25
// $Authors: Hendrik Weisser $
 
26
// --------------------------------------------------------------------------
 
27
 
 
28
#include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/SeedListGenerator.h>
 
29
 
 
30
using namespace std;
 
31
 
 
32
namespace OpenMS
 
33
{
 
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
        
 
145
} // namespace OpenMS