source: trunk/yat/microarray/DataSet.cc @ 720

Last change on this file since 720 was 720, checked in by Jari Häkkinen, 16 years ago

Fixes #170. Almost all inlines removed, some classes have no cc file.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1// $Id: DataSet.cc 720 2006-12-26 18:21:36Z jari $
2
3/*
4  Copyright (C) The authors contributing to this file.
5
6  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "DataSet.h"
25
26#include <set>
27
28namespace theplu {
29namespace yat {
30namespace microarray {
31
32  DataSet::DataSet(const classifier::MatrixLookup& data, 
33                   const classifier::Target& target,
34                   const std::vector<std::string>& probe)
35    : data_(data), probe_(probe), target_(target)
36  {
37  }
38
39 
40  DataSet::DataSet(const DataSet& first, 
41                   const std::vector<std::string>& probes)
42    : data_(classifier::MatrixLookup(0,0)), target_(first.target())
43  {
44    using std::vector;
45    using std::string;
46    std::set<std::string> probe_set;
47    std::vector<size_t> index;
48   
49    typedef std::set<std::string>::iterator ProbeIter; 
50       
51    // making a probe_set and checking for duplicates
52    for (vector<string>::const_iterator i=probes.begin(); i!=probes.end();++i){
53      ProbeIter iter = probe_set.lower_bound((*i));
54      if (iter!=probe_set.end() && (*iter) == (*i)){
55        std::cerr << "DataSet: Error: " << (*iter) << "found twice.\n";
56      }
57      probe_set.insert(iter, *i);
58    }
59
60    std::vector<size_t> new_index;
61    std::set<std::string> probe_set2;
62    for (size_t i = 0; i<first.probe().size(); ++i){
63      ProbeIter iter = probe_set.find(first.probe()[i]);
64      if (iter!=probe_set.end()) {
65        ProbeIter iter = probe_set2.lower_bound(first.probe()[i]);
66        if (iter!=probe_set2.end() && (*iter) == first.probe()[i]){
67          std::cerr << "DataSet: Warning: " << (*iter) << "found twice.\n";
68        }
69        else {
70          probe_set2.insert(iter, first.probe()[i]);
71          new_index.push_back(i);
72          probe_.push_back(first.probe()[i]);
73        }
74      }
75    }
76    data_ = classifier::MatrixLookup(first.data(),new_index,true);
77  }
78
79
80  const classifier::MatrixLookup& DataSet::data(void) const
81  {
82    return data_;
83  }
84
85
86  const std::vector<std::string>& DataSet::probe(void) const
87  {
88    return probe_;
89  }
90
91
92  const classifier::Target& DataSet::target(void) const
93  {
94    return target_;
95  }
96
97}}} // end of namespace microarray, yat, and theplu
Note: See TracBrowser for help on using the repository browser.