source: trunk/yat/omic/GenomicPosition.cc @ 2366

Last change on this file since 2366 was 2366, checked in by Peter, 13 years ago

New class GenomicPosition?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1// $Id: GenomicPosition.cc 2366 2010-12-06 02:17:02Z peter $
2
3/*
4  Copyright (C) 2010 Peter Johansson
5
6  The yat library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation; either version 3 of the
9  License, or (at your option) any later version.
10 
11  The yat library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#include "GenomicPosition.h"
21
22#include "yat/utility/utility.h"
23
24#include <string>
25
26namespace theplu {
27namespace yat {
28namespace omic {
29
30  GenomicPosition::GenomicPosition(void) 
31  {}
32
33
34  GenomicPosition::GenomicPosition(unsigned short int chr, unsigned long int pos)
35    : chr_(chr), pos_(pos)
36  {}
37
38
39  GenomicPosition::GenomicPosition(const std::string& chr, const std::string& pos)
40    : chr_(chr2int(chr)), 
41      pos_(yat::utility::convert<unsigned long int>(pos))
42  {}
43
44
45  unsigned short& GenomicPosition::chromosome(void)
46  { return chr_; }
47
48
49  const unsigned short& GenomicPosition::chromosome(void) const
50  { return chr_; }
51
52
53  unsigned long int& GenomicPosition::position(void)
54  { return pos_; }
55
56
57  const unsigned long int& GenomicPosition::position(void) const
58  { return pos_; }
59
60
61  bool operator<(const GenomicPosition& lhs, const GenomicPosition& rhs)
62  {
63    if (lhs.chromosome()==rhs.chromosome())
64      return lhs.position() < rhs.position();
65    return lhs.chromosome() < rhs.chromosome();
66  }
67
68
69  bool operator==(const GenomicPosition& lhs, const GenomicPosition& rhs)
70  {
71    return lhs.chromosome()==rhs.chromosome() && lhs.position()==rhs.position();
72  }
73
74
75  unsigned short chr2int(const std::string& str)
76  {
77    if (str.size()>3 && str.substr(0,3)=="chr")
78      return chr2int(str.substr(3));
79    if (str=="X")
80      return 23;
81    if (str=="Y")
82      return 24;
83    if (str=="M" || str=="MT")
84      return 25;
85    return utility::convert<unsigned short>(str);
86  }
87}}}
Note: See TracBrowser for help on using the repository browser.