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

Last change on this file since 2993 was 2993, checked in by Peter, 9 years ago

conform GPL header to same style as in other yat files

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1#ifndef theplu_yat_omic_gemomic_position
2#define theplu_yat_omic_gemomic_position
3
4// $Id: GenomicPosition.h 2993 2013-03-03 07:38:22Z peter $
5
6/*
7  Copyright (C) 2010, 2012 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     \since New in yat 0.7
102   */
103  bool operator<(const GenomicPosition& lhs, const GenomicPosition& rhs);
104
105  /**
106     \relates GenomicPosition
107
108     \return \c true if chromosomes and positions are the same.
109
110     \since New in yat 0.7
111   */
112  bool operator==(const GenomicPosition& lhs, const GenomicPosition& rhs);
113
114  /**
115     \brief transform a string to unsigned short chromosome number
116
117     If \a str starts with 'chr' that prefix is stripped away before
118     translating the string to chromosome number. Function translates
119     "X" to 23, "Y" to 24, and "M" or "MT" to 25. For other inputs
120     utility::convert is used to transform the input to an unsigned
121     short.
122
123     \return chromosome number
124
125     \since New in yat 0.7
126   */
127  unsigned short chr2int(const std::string& str);
128
129}}}
130#endif
Note: See TracBrowser for help on using the repository browser.