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

Last change on this file since 2573 was 2573, checked in by Peter, 11 years ago

avoid long line

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