1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#ifndef VG_POSITION_HPP_INCLUDED
#define VG_POSITION_HPP_INCLUDED
#include <vg/vg.pb.h>
#include "types.hpp"
#include "utility.hpp"
#include "vg/io/json2pb.h"
#include <gcsa/gcsa.h>
#include "handle.hpp"
/** \file
* Functions for working with Positions and `pos_t`s.
*/
namespace vg {
using namespace std;
// duplicative with pos_t, but this will make it so much easier
// to refactor -- can always eliminate later
class position_t {
public:
position_t() = default;
position_t(const position_t&) = default;
position_t(position_t&&) = default;
~position_t() = default;
position_t& operator=(const position_t&) = default;
position_t& operator=(position_t&&) = default;
inline int64_t node_id() const;
inline void set_node_id(int64_t i);
inline int64_t offset() const;
inline void set_offset(int64_t o);
inline bool is_reverse() const;
inline void set_is_reverse(bool r);
inline bool operator==(const position_t& other) const;
inline bool operator!=(const position_t& other) const;
private:
int64_t _node_id;
int64_t _offset;
bool _is_reverse;
};
/// Reverse a Position and get a Position at the same **point between bases**, going the other direction.
/// To get a Position to the same *base*, subtract 1 from the resulting offset.
Position reverse(const Position& pos, size_t node_length);
/// Convert a Position to a (much smaller) pos_t.
pos_t make_pos_t(const Position& pos);
pos_t make_pos_t(const position_t& pos);
/// Create a pos_t from a gcsa node
pos_t make_pos_t(gcsa::node_type node);
/// Convert a pos_t to a Position.
Position make_position(const pos_t& pos);
/// Create a Position from a Node ID, an orientation flag, and an offset along that strand of the node.
Position make_position(id_t id, bool is_rev, off_t off);
/// Make a Position from a gcsa node
Position make_position(gcsa::node_type node);
/// Find the min distance in the path offsets where the path orientation is the same and different
pair<int64_t, int64_t> min_oriented_distances(const unordered_map<path_handle_t, vector<pair<size_t, bool> > >& path_offsets1,
const unordered_map<path_handle_t, vector<pair<size_t, bool> > >& path_offsets2);
string debug_string(const position_t& pos);
/*
* position_t
*/
inline int64_t position_t::node_id() const {
return _node_id;
}
inline void position_t::set_node_id(int64_t i) {
_node_id = i;
}
inline int64_t position_t::offset() const {
return _offset;
}
inline void position_t::set_offset(int64_t o) {
_offset = o;
}
inline bool position_t::is_reverse() const {
return _is_reverse;
}
inline void position_t::set_is_reverse(bool r) {
_is_reverse = r;
}
inline bool position_t::operator==(const position_t& other) const {
return (_node_id == other._node_id
&& _is_reverse == other._is_reverse
&& _offset == other._offset);
}
inline bool position_t::operator!=(const position_t& other) const {
return !(*this == other);
}
}
#endif
|