1 /* 2 * scrm is an implementation of the Sequential-Coalescent-with-Recombination Model. 3 * 4 * Copyright (C) 2013, 2014 Paul R. Staab, Sha (Joe) Zhu, Dirk Metzler and Gerton Lunter 5 * 6 * This file is part of scrm. 7 * 8 * scrm is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 20 21 */ 22 23 #ifndef scrm_src_event 24 #define scrm_src_event 25 26 #include <iostream> 27 #include "node.h" 28 29 class Event { 30 public: Event()31 Event() { 32 type_ = 0; 33 time_ = -1; 34 node_ = NULL; 35 active_node_nr_ = -1; 36 mig_pop_ = -1; 37 }; 38 Event(double time)39 Event(double time) { 40 type_ = 0; 41 time_ = time; 42 node_ = NULL; 43 mig_pop_ = -1; 44 active_node_nr_ = -1; 45 } 46 47 friend std::ostream& operator<< (std::ostream& stream, const Event& event); 48 time()49 double time() const { return time_; } node()50 Node* node() const { return node_; } mig_pop()51 size_t mig_pop() const { return mig_pop_; } type()52 size_t type() const { return type_; } active_node_nr()53 size_t active_node_nr() const { return active_node_nr_; } 54 isNoEvent()55 bool isNoEvent() const { return (type_ == 0); } isCoalescence()56 bool isCoalescence() const { return (type_ == 1); } isPwCoalescence()57 bool isPwCoalescence() const { return (type_ == 2); } isMigration()58 bool isMigration() const { return (type_ == 3); } isRecombination()59 bool isRecombination() const { return (type_ == 4); } 60 set_time(const double time)61 void set_time(const double time) { time_ = time; } 62 setToCoalescence(Node * node,const size_t active_node_nr)63 void setToCoalescence(Node *node, const size_t active_node_nr) { 64 type_ = 1; 65 node_ = node; 66 active_node_nr_ = active_node_nr; 67 } setToPwCoalescence()68 void setToPwCoalescence() { 69 type_ = 2; 70 } setToMigration(Node * node,const size_t active_node_nr,const size_t mig_pop)71 void setToMigration(Node *node, const size_t active_node_nr, const size_t mig_pop) { 72 type_ = 3; 73 node_ = node; 74 active_node_nr_ = active_node_nr; 75 mig_pop_ = mig_pop; 76 } setToRecombination(Node * node,const size_t active_node_nr)77 void setToRecombination(Node *node, const size_t active_node_nr) { 78 type_ = 4; 79 node_ = node; 80 active_node_nr_ = active_node_nr; 81 } 82 83 private: 84 size_t type_; 85 size_t active_node_nr_; 86 double time_; 87 size_t mig_pop_; 88 Node* node_; 89 }; 90 91 inline std::ostream& operator<< (std::ostream& stream, const Event& event) { 92 if (event.isNoEvent()) { 93 stream << "No Event"; 94 return stream; 95 } 96 97 stream << "Event at time " << event.time() << ": "; 98 if (event.isCoalescence()) stream << "Coalesence of a" << event.active_node_nr(); 99 else if (event.isPwCoalescence()) stream << "Pair-wise coalescence"; 100 else if (event.isMigration()) stream << "Migration of Node " << event.node() 101 << " into pop " << event.mig_pop(); 102 else if (event.isRecombination()) stream << "Recombination of Node " << event.node(); 103 return stream; 104 } 105 106 #endif 107