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

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

New class GenomicPosition?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.2 KB
Line 
1#ifndef theplu_yat_omic_gemomic_position
2#define theplu_yat_omic_gemomic_position
3
4/*
5  $Id: GenomicPosition.h 2366 2010-12-06 02:17:02Z peter $
6
7  Copyright (C) 2010 Peter Johansson
8
9  The yat library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 3 of the
12  License, or (at your option) any later version.
13 
14  The yat 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  General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with this program. If not, see <http://www.gnu.org/licenses/>.
21*/
22
23#include <boost/operators.hpp>
24
25#include <string>
26
27namespace theplu {
28namespace yat {
29namespace omic {
30
31  /**
32     Class used to hold genomic location, i.e., chromosome and
33     position.
34
35     The class inherits from boost::operators, which means besides the
36     operators directly implemented (operator== and operator<) also
37     operator<=, operator>, operator>=, and operator!= are supported.
38
39     \since New in yat 0.7
40   */
41  class GenomicPosition : boost::operators<GenomicPosition>
42  {
43  public:
44    /**
45       Creates a GenomicPosition with undefined values.
46     */
47    GenomicPosition(void);
48
49    /**
50       \brief Constructor
51       \param chr chromosome
52       \param pos non-negative number describing location on chromosome
53     */
54    GenomicPosition(unsigned short chr , unsigned long pos);
55
56    /**
57       \brief Constructor
58       \param chr chromosome
59       \param pos non-negative number describing location on chromosome
60
61       chr2int is used to translate \a chr into an \c unsigned \c
62       short, and utility::convert is used to translate \a pos into an
63       \c unsigned \c long.
64
65       \see chr2int
66     */
67    GenomicPosition(const std::string& chr, const std::string& pos);
68
69    /**
70       \return reference to chr
71     */
72    unsigned short& chromosome(void);
73
74    /**
75       \return const reference to chr
76     */
77    const unsigned short& chromosome(void) const;
78
79    /**
80       \return reference to position
81     */
82    unsigned long int& position(void);
83
84    /**
85       \return const reference to position
86     */
87    const unsigned long int& position(void) const;
88   
89  private:
90    unsigned short chr_;
91    unsigned long pos_;
92  }; 
93
94  /**
95     \relates GenomicPosition
96
97     \return \c true if chromosome of \a lhs is less than chromosome
98     of \a rhs or if chromosome of \a lhs equals chromosome of \a rhs
99     and position of \a lhs is less than position of \a rhs.
100   */
101  bool operator<(const GenomicPosition& lhs, const GenomicPosition& rhs);
102
103  /**
104     \return \c true if chromosomes and positions are the same.
105   */
106  bool operator==(const GenomicPosition& lhs, const GenomicPosition& rhs);
107
108  /**
109     \brief transform a string to unsigned short chromosome number
110
111     If \a str starts with 'chr' that prefix is stripped away before
112     translating the string to chromosome number. Function translates
113     "X" to 23, "Y" to 24, and "M" or "MT" to 25. For other inputs
114     utility::convert is used to transform the input to an unsigned
115     short.
116
117     \return chromosome number
118   */
119  unsigned short chr2int(const std::string& str);
120
121}}}
122#endif
Note: See TracBrowser for help on using the repository browser.