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

Last change on this file since 2387 was 2387, checked in by Peter, 12 years ago

avoid long lines

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1// $Id: GenomicPosition.cc 2387 2010-12-22 20:13:08Z 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, 
40                                   const std::string& pos)
41    : chr_(chr2int(chr)), 
42      pos_(yat::utility::convert<unsigned long int>(pos))
43  {}
44
45
46  unsigned short& GenomicPosition::chromosome(void)
47  { return chr_; }
48
49
50  const unsigned short& GenomicPosition::chromosome(void) const
51  { return chr_; }
52
53
54  unsigned long int& GenomicPosition::position(void)
55  { return pos_; }
56
57
58  const unsigned long int& GenomicPosition::position(void) const
59  { return pos_; }
60
61
62  bool operator<(const GenomicPosition& lhs, const GenomicPosition& rhs)
63  {
64    if (lhs.chromosome()==rhs.chromosome())
65      return lhs.position() < rhs.position();
66    return lhs.chromosome() < rhs.chromosome();
67  }
68
69
70  bool operator==(const GenomicPosition& lhs, const GenomicPosition& rhs)
71  {
72    return lhs.chromosome()==rhs.chromosome() && lhs.position()==rhs.position();
73  }
74
75
76  unsigned short chr2int(const std::string& str)
77  {
78    if (str.size()>3 && str.substr(0,3)=="chr")
79      return chr2int(str.substr(3));
80    if (str=="X")
81      return 23;
82    if (str=="Y")
83      return 24;
84    if (str=="M" || str=="MT")
85      return 25;
86    return utility::convert<unsigned short>(str);
87  }
88}}}
Note: See TracBrowser for help on using the repository browser.