├── .gitignore ├── .travis.yml ├── COPYING ├── README.md ├── build.xml ├── examples ├── README.md ├── smoothingpriors │ ├── OUPriorTests.Rmd │ ├── OUPriorTests.html │ ├── OUPriorTests.md │ ├── comparison │ │ └── hcv_bdsky.xml │ ├── figs │ │ ├── ouprior_test1-1.png │ │ ├── ouprior_test2-1.png │ │ ├── ouprior_test3-1.png │ │ ├── ouprior_test4-1.png │ │ └── ouprior_test5-1.png │ ├── ouprior_test1.xml │ ├── ouprior_test2.xml │ ├── ouprior_test3.xml │ ├── ouprior_test4.xml │ └── ouprior_test5.xml └── treeslicer │ ├── comparison │ ├── dengue4_bdsky_csc.xml │ ├── dengue4_bdsky_equidistant5.xml │ ├── dengue4_bdsky_equidistant5_rootcondition.xml │ └── dengue4_bdsky_fixeddates.xml │ ├── dengue4_bdsky_csc_treeslicer.xml │ ├── dengue4_bdsky_csc_treeslicer_joint.xml │ ├── dengue4_bdsky_datestrings_treeslicer.xml │ ├── dengue4_bdsky_equidistant5_treeslicer.xml │ ├── dengue4_bdsky_equidistant5_treeslicer_joint.xml │ └── dengue4_bdsky_fixeddates_treeslicer.xml ├── src ├── beast │ └── evolution │ │ └── speciation │ │ └── BirthDeathSkylineModelTestHelper.java └── skylinetools │ ├── distributions │ ├── BMPrior.java │ └── OUPrior.java │ ├── parameter │ ├── DateParser.java │ └── RealParameterSequence.java │ └── util │ ├── TreeDateLogger.java │ ├── TreeDateSlicer.java │ ├── TreeSliceDateLogger.java │ └── TreeSlicer.java ├── test ├── README.md ├── beast │ └── evolution │ │ └── speciation │ │ └── SkylineTimesTest.java ├── skylinetools │ ├── distributions │ │ └── OUPriorLkTest.java │ ├── parameter │ │ ├── DateParserTest.java │ │ └── RealParameterSequenceTest.java │ └── util │ │ ├── TreeDateSlicerTest.java │ │ └── TreeSlicerTest.java ├── tree.C1.MCC.trim.round.figtree.tree └── tree.C2.MCC.trim.round.figtree.tree └── version.xml /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .Rhistory 3 | *.log 4 | *.trees 5 | *.state 6 | *.iml 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | install: ant build 4 | 5 | before_script: sudo apt-get install ant-optional 6 | 7 | script: ant test 8 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Skyline Tools 2 | 3 | Package of useful utilities and distributions to use with skyline models in BEAST2. For now the package only supports the birth-death skyline (BDSKY) and multitype birth-death process (BDMM), but there is no reason these utilities cannot be used by other models. 4 | 5 | - [**Documentation**](https://github.com/laduplessis/skylinetools/wiki) 6 | - [**Examples**](examples/) 7 | - [**Unit tests**](test/) 8 | 9 | [![Build Status](https://travis-ci.com/laduplessis/skylinetools.svg?branch=master)](https://travis-ci.com/laduplessis/skylinetools) 10 | 11 | ## Package contents 12 | 13 | - *Parameters* 14 | - **RealParameterSequence:** Shortcut to create a linear sequence of real numbers with equal increments. 15 | - *Smoothing priors* 16 | - **Brownian-motion smoothing prior:** Time-aware smoothing prior for a skyline parameter based on a Brownian-motion process. (Similar to the GMRF used for the Skyride/Skygrid). _(not fully tested)_ 17 | - **Ornstein-Uhlenbeck smoothing prior:** Time-aware smoothing prior for a skyline parameter based on an Ornstein-Uhlenbeck process. _(not fullly tested)_ 18 | - *Utilities* 19 | - **TreeSlicer:** Interface for getting times on a tree. 20 | - **TreeSliceDateLogger:** Log dates of treeslice times. 21 | - **TreeDateLogger:** Log treeheight or other parameters as dates. 22 | 23 | 24 | ## Installation 25 | 26 | To install Skyline Tools: 27 | 28 | 1. Download and install [BEAST2](www.beast2.org). 29 | 2. Launch the BEAUti application distributed with BEAST. 30 | 3. From the File menu select "Manage Packages". 31 | 4. Click the "Package repositories" button at the bottom of the Package Manager dialog box. 32 | 5. Select "Add URL" and enter the following URL: `https://laduplessis.github.io/skylinetools/package.xml`. 33 | 7. Click the "Done" button, then select "skylinetools" from the list of packages. 34 | 8. Click the "Install/Upgrade" button. Once installation is complete, XML files using SkylineTools can be run from BEAST2. 35 | 36 | 37 | ## Citation 38 | 39 | If you use TreeSlicer in any of your XML files please add a link to this repository. 40 | 41 | ## License 42 | 43 | This package is distributed under the GNU General Public Licence version 3, which is contained in this directory in the file named COPYING. 44 | 45 | 46 | --- 47 | _Louis du Plessis, 2018_ 48 | -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | ** Required file version.xml does not exist. ** 40 | If this is a new project, run "ant skeleton" from 41 | the command line to create the files required for 42 | your BEAST 2 package. 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | No local copy of the beast2 source found at ${beastDir}. 67 | Compiling against version ${beast-version} from GitHub. 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | Compiling against beast2 source found at ${beastDir}. 93 | 94 | 95 | 96 | 97 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | Downloading dependencies... 118 | 119 | BDSKY: 120 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | ** Package ${dist}/${fullName}.zip created successfuly! ** 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | ** This directory contains files besides the build script. ** 267 | You should run "ant skeleton" in a directory containing only the build script. 268 | 269 | 270 | =============================== 271 | Create skeleton BEAST 2 package 272 | =============================== 273 | 274 | First, we need some information... 275 | 276 | 277 | 278 | 279 | Enter package name 280 | Select open source software license 281 | Enter package version 282 | Enter minimum required BEAST 2 version 283 | 284 | Assembling files and directory structure... 285 | 286 | <addon name="${projName}" version="${projVersion}"> 287 | <depends on="BEAST" atleast="${beastVersionReq}"/> 288 | 289 | <!-- Add other dependencies as necessary. --> 290 | </addon> 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | Done. 319 | 320 | The directory structure is as follows: 321 | ${src} - your java source goes here 322 | ${test} - your junit tests go here (You _are_ going to write, those, aren't you!) 323 | ${doc} - your documentation goes here 324 | ${examples} - your example XML scripts go here 325 | ${templates} - your BEAUti templates go here 326 | 327 | To build your package, just type "ant" at the command line. 328 | 329 | To run unit tests, type "ant test". 330 | 331 | That's it! Happy coding! 332 | 333 | 334 | 335 | 336 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | ## 1. OUPrior 4 | 5 | ### 1.1. OUPrior Tests 6 | 7 | `ouprior_test1.xml`-`ouprior_test5.xml`: Tests to check that the OU-prior implemented in BEAST2 is correct. Check that MCMC samples correct trajectories and that it is possible to estimate parameters given a trajectory. ([Results](smoothingpriors/OUPriorTests.md)) 8 | 9 | 10 | ### 1.2. OUPrior examples 11 | 12 | **With OUPrior** 13 | 14 | 1. `hcv_bdsky_ouprior.xml`: Egyptian HCV dataset (contemporaneous sampling only), with relative times (between 0 and 1). OUPrior on reproductive number with dimension 40. 15 | 2. Serial sampling and real times (Ebola) 16 | 17 | **Comparison xml files (without OUPrior)** 18 | 19 | 1. `hcv_bdsky.xml`: Egyptian HCV dataset (contemporaneous sampling only), reproductive number with dimension 40. 20 | 21 | 22 | 23 | --- 24 | 25 | 26 | ## 2. TreeSlicer 27 | 28 | ### 2.1. TreeSlicer Tests 29 | Tests to compare the result of using TreeSlicer to obtaining the same or similar results in a more complicated way without it. Note that some XMLs log more statistics than necessary and contain some unnecessary RPN calculators to check correctness of the results. 30 | 31 | **With TreeSlicer** 32 | 33 | 1. `dengue4_bdsky_equidistant5_treeslicer.xml`: 5 intervals for R_e, equally spaced between tmrca and present, sampling proportion 0 before oldest sample. 34 | 2. `dengue4_bdsky_fixeddates_treeslicer.xml`: 5 intervals for R_e at specific fixed dates, sampling proportion 0 before oldest sample. 35 | 3. `dengue4_bdsky_csc_treeslicer.xml`: 2 intervals for R_e, with the shift-date estimated. 36 | 4. `dengue4_bdsky_csc_treeslicer_hierarchical.xml`: 2 trees, each with 2 intervals for R_e, with a shared shift-date, which is estimated. 37 | 5. `dengue4_bdsky_equidistant5_treeslicer_hierarchical.xml`: 2 trees, each with the same 3 shared intervals for R_e. 38 | 39 | **Comparison xml files (without TreeSlicer)** 40 | 41 | 1. `dengue4_bdsky_equidistant5.xml`: 5 intervals for R_e, equally spaced between origin and present, sampling proportion 0 before oldest sample. 42 | 2. `dengue4_bdsky_equidistant5_rootcondition.xml`: 5 intervals for R_e, equally spaced between tmrca and present, sampling proportion 0 before oldest sample (no origin estimated). 43 | 3. `dengue4_bdsky_fixeddates.xml`: 5 intervals for R_e at specific fixed dates, sampling proportion 0 before oldest sample. 44 | 4. `dengue4_bdsky_csc.xml`: 2 intervals for R_e, with the shift-time estimated. 45 | 46 | 47 | 48 | ### 2.2 TreeSlicer Examples 49 | _Coming soon_ 50 | 51 | 52 | --- 53 | _Louis du Plessis, 2018_ -------------------------------------------------------------------------------- /examples/smoothingpriors/OUPriorTests.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Ornstein-Uhlenbeck smoothing prior tests" 3 | author: "Louis du Plessis" 4 | date: "7/19/2018" 5 | output: 6 | html_document: 7 | keep_md: true 8 | theme: paper 9 | self_contained: false 10 | --- 11 | 12 | Tests to check that the OU-prior implemented in BEAST2 is correct. In particular checking that sampling trajectories in BEAST2 with MCMC produces the correct theoretical distribution as well as the same distribution as simulating trajectories using the analytical solution (when drawing parameter values from prior distributions). Additionally, also test the ability of the BEAST2 implementation to estimate parameter values given a trajectory. 13 | 14 | 15 | ```{r setup, include=FALSE} 16 | knitr::opts_chunk$set(echo = TRUE, fig.path="figs/", fig.width=7.5, fig.height=5) 17 | 18 | rm(list = ls()) 19 | library(bdskytools) 20 | ``` 21 | 22 | 23 | 24 | ### Test 1: `ouprior_test1.xml` 25 | 26 | - OU-process with all parameters fixed. 27 | - Sample x using MCMC in BEAST2 and compare to theoretical quantiles. 28 | 29 | 30 | ```{r ouprior_test1} 31 | 32 | ##################### 33 | # ouprior_test1.xml # 34 | ##################### 35 | 36 | # Calculate density of OU-process and get percentiles (blue and red) 37 | t <- seq(0,9,by=1) 38 | x0 <- 10 39 | mu <- 3 40 | sigma <- 1 41 | nu <- 0.1 42 | X <- plotOUProcessHPD(x0, t, mu, sigma, nu, ylim = c(0,12), main='ouprior_test1.xml', xlab="", ylab="") 43 | sim_hpd <- getMatrixHPD(X) 44 | 45 | # Sample from posterior in BEAST2 and get HPD (orange and green) 46 | lf <- readLogfile("ouprior_test1.log") 47 | 48 | xsample <- getSkylineSubset(lf,"x") 49 | for (i in 1:nrow(xsample)) { 50 | lines(t,xsample[i,],col=pal.dark(corange,0.1),lwd=0.5) 51 | } 52 | sample_hpd <- getMatrixHPD(xsample) 53 | lines(t,sample_hpd[1,],col=pal.dark(cgreen),lty=2,lwd=2) 54 | lines(t,sample_hpd[2,],col=pal.dark(cgreen),lty=2,lwd=2) 55 | lines(t,sample_hpd[3,],col=pal.dark(cgreen),lty=2,lwd=2) 56 | ``` 57 | 58 | 59 | 60 | ### Test 2: `ouprior_test2.xml` 61 | 62 | - OU-process with all parameters fixed and x_0 sampled from an exponential prior. 63 | - Sample x using MCMC in BEAST2 and compare HPDs of x to 1000 simulated trajectories (using analytical solution from time-transformed Wiener process). 64 | 65 | 66 | ```{r ouprior_test2} 67 | 68 | ##################### 69 | # ouprior_test2.xml # 70 | ##################### 71 | 72 | # Simulate OU-trajectory and get HPD (blue and red) 73 | t <- seq(0,9,by=1) 74 | x0_p <- getPrior(rexp,1,rate=10) 75 | mu <- 3 76 | sigma <- 1 77 | nu <- 0.1 78 | X <- plotOUProcessHPDEmpirical(x0_p, t, mu, sigma, nu, ylim = c(-4,6), main='ouprior_test2.xml') 79 | sim_hpd <- getMatrixHPD(X) 80 | 81 | # Sample from posterior in BEAST2 and get HPD (orange and green) 82 | lf <- readLogfile("ouprior_test2.log") 83 | 84 | xsample <- getSkylineSubset(lf,"x") 85 | for (i in 1:nrow(xsample)) { 86 | lines(t,xsample[i,],col=pal.dark(corange,0.1),lwd=0.5) 87 | } 88 | sample_hpd <- getMatrixHPD(xsample) 89 | lines(t,sample_hpd[1,],col=pal.dark(cgreen),lty=2,lwd=2) 90 | lines(t,sample_hpd[2,],col=pal.dark(cgreen),lty=2,lwd=2) 91 | lines(t,sample_hpd[3,],col=pal.dark(cgreen),lty=2,lwd=2) 92 | 93 | ``` 94 | 95 | 96 | ### Test 3: `ouprior_test3.xml` 97 | 98 | - OU-process with all parameters drawn from priors. 99 | - Sample x using MCMC in BEAST2 and compare HPDs of x to 1000 simulated trajectories (using analytical solution from time-transformed Wiener process). 100 | - Compare posterior distributions for parameters to priors (without data posterior should equal prior). 101 | 102 | ```{r ouprior_test3, fig.height=8, results='hide'} 103 | 104 | ##################### 105 | # ouprior_test3.xml # 106 | ##################### 107 | 108 | layout(matrix(c(1,1,1,1,2,3,4,5), nrow=2, byrow=TRUE), heights = c(5,3)) 109 | 110 | # Simulate OU-trajectory and get HPD (blue and red) 111 | t <- seq(0,0.9,by=0.1) 112 | x0_p <- getPrior(runif, 1, min=1.5, max=2.5) 113 | mu_p <- getPrior(rlnorm, 1, meanlog=0, sdlog=0.5) 114 | sigma_p <- getPrior(rnorm, 1, mean=0.5, sd=0.1) 115 | nu_p <- getPrior(rgamma, 1, shape=1, scale=5) 116 | X <- plotOUProcessHPDEmpirical(x0_p, t, mu_p, sigma_p, nu_p, ylim = c(0,4), main='ouprior_test3.xml') 117 | sim_hpd <- getMatrixHPD(X) 118 | 119 | # Sample from posterior in BEAST2 and get HPD (orange and green) 120 | lf <- readLogfile("ouprior_test3.log") 121 | 122 | xsample <- getSkylineSubset(lf,"x") 123 | for (i in 1:nrow(xsample)) { 124 | lines(t,xsample[i,],col=pal.dark(corange,0.1),lwd=0.5) 125 | } 126 | sample_hpd <- getMatrixHPD(xsample) 127 | lines(t,sample_hpd[1,],col=pal.dark(cgreen),lty=2,lwd=2) 128 | lines(t,sample_hpd[2,],col=pal.dark(cgreen),lty=2,lwd=2) 129 | lines(t,sample_hpd[3,],col=pal.dark(cgreen),lty=2,lwd=2) 130 | 131 | # mu 132 | mu_density <- density(lf$mu) 133 | plotPrior('lnorm',list(meanlog=0, sdlog=0.5), main='mu') 134 | lines(mu_density$x, mu_density$y, lwd=2, lty=2, col=pal.dark(cgreen)) 135 | polygon(c(0, mu_density$x, 0), c(0, mu_density$y, 0), col=pal.dark(cgreen,0.5), border=NA) 136 | 137 | # Sigma 138 | sigma_density <- density(lf$sigma) 139 | plotPrior('norm',list(mean=0.5, sd=0.1), main='sigma') 140 | lines(sigma_density$x, sigma_density$y, lwd=2, lty=2, col=pal.dark(cgreen)) 141 | polygon(c(0, sigma_density$x, 0), c(0, sigma_density$y, 0), col=pal.dark(cgreen,0.5), border=NA) 142 | 143 | # nu 144 | nu_density <- density(lf$nu, bw=0.3) 145 | plotPrior('gamma',list(shape=1, scale=5), main='nu') 146 | lines(nu_density$x, nu_density$y, lwd=2, lty=2, col=pal.dark(cgreen)) 147 | polygon(c(0, nu_density$x, 0), c(0, nu_density$y, 0), col=pal.dark(cgreen,0.5), border=NA) 148 | 149 | #x0 150 | x0_density <- density(lf$x1, bw=0.05) 151 | plotPrior('unif',list(min=1.5, max=2.5), main=expression(x[0])) 152 | lines(x0_density$x, x0_density$y, lwd=2, lty=2, col=pal.dark(cgreen)) 153 | polygon(c(0, x0_density$x, 0), c(0, x0_density$y, 0), col=pal.dark(cgreen,0.5), border=NA) 154 | 155 | 156 | ``` 157 | 158 | 159 | 160 | ### Test 4: `ouprior_test4.xml` 161 | 162 | - OU-process with all parameters drawn from priors, except for the mean. 163 | - Run for 51 time points instead of just 10 as above. 164 | - Sample x using MCMC in BEAST2 and compare HPDs of x to 1000 simulated trajectories (using analytical solution from time-transformed Wiener process). 165 | - Compare posterior distributions for parameters to priors (without data posterior should equal prior). 166 | 167 | 168 | ```{r ouprior_test4, fig.height=8, results='hide'} 169 | 170 | ##################### 171 | # ouprior_test4.xml # 172 | ##################### 173 | 174 | layout(matrix(c(1,1,1,2,3,4), nrow=2, byrow=TRUE), heights=c(5,3)) 175 | 176 | # Simulate OU-trajectory and get HPD (blue and red) 177 | t <- seq(0,1,length.out=51) 178 | x0_p <- getPrior(rexp, 1, rate=1) 179 | mu <- 1 180 | sigma_p <- getPrior(rnorm, 1, mean=0.3, sd=0.1) 181 | nu_p <- getPrior(rgamma, 1, shape=1, scale=50) 182 | X <- plotOUProcessHPDEmpirical(x0_p, t, mu, sigma_p, nu_p, ylim = c(0.5,2.5), main='ouprior_test4.xml') 183 | sim_hpd <- getMatrixHPD(X) 184 | 185 | # Sample from posterior in BEAST2 and get HPD (orange and green) 186 | lf <- readLogfile("ouprior_test4.log") 187 | 188 | xsample <- getSkylineSubset(lf,"x") 189 | for (i in 1:nrow(xsample)) { 190 | lines(t,xsample[i,],col=pal.dark(corange,0.1),lwd=0.5) 191 | } 192 | sample_hpd <- getMatrixHPD(xsample) 193 | lines(t,sample_hpd[1,],col=pal.dark(cgreen),lty=2,lwd=2) 194 | lines(t,sample_hpd[2,],col=pal.dark(cgreen),lty=2,lwd=2) 195 | lines(t,sample_hpd[3,],col=pal.dark(cgreen),lty=2,lwd=2) 196 | 197 | # Sigma 198 | sigma_density <- density(lf$sigma) 199 | plotPrior('norm',list(mean=0.3, sd=0.1), main='sigma') 200 | lines(sigma_density$x, sigma_density$y, lwd=2, lty=2, col=pal.dark(cgreen)) 201 | polygon(c(0, sigma_density$x, 0), c(0, sigma_density$y, 0), col=pal.dark(cgreen,0.5), border=NA) 202 | 203 | # nu 204 | nu_density <- density(lf$nu, bw=5) 205 | plotPrior('gamma',list(shape=1, scale=50), main='nu') 206 | lines(nu_density$x, nu_density$y, lwd=2, lty=2, col=pal.dark(cgreen)) 207 | polygon(c(0, nu_density$x, 0), c(0, nu_density$y, 0), col=pal.dark(cgreen,0.5), border=NA) 208 | 209 | #x0 210 | x0_density <- density(lf$x1) 211 | plotPrior('exp',list(rate=1), main=expression(x[0])) 212 | lines(x0_density$x, x0_density$y, lwd=2, lty=2, col=pal.dark(cgreen)) 213 | polygon(c(0, x0_density$x, 0), c(0, x0_density$y, 0), col=pal.dark(cgreen,0.5), border=NA) 214 | 215 | ``` 216 | 217 | 218 | ### Test 5: `ouprior_test5.xml` 219 | 220 | - OU-process with fixed parameters, simulate a single trajectory with 101 time points. 221 | - Fix trajectory in BEAST2 and attempt to estimate mean and variance (mean-reversion fixed to true value). 222 | 223 | ```{r ouprior_test5, results='hide'} 224 | 225 | ##################### 226 | # ouprior_test5.xml # 227 | ##################### 228 | 229 | set.seed(10) 230 | 231 | t <- seq(0,10,by=0.1) 232 | x0 <- 6 233 | mu <- 5 234 | sigma <- 0.1 235 | nu <- 1 236 | x <- simulateOU(x0, t, mu, sigma, nu) 237 | 238 | #plot(t,x,type='l',col=pal.dark(cblue)) 239 | print(paste(x,collapse = " ")) 240 | 241 | # Posterior estimates in BEAST2 and get HPD (orange and green) 242 | lf <- readLogfile("ouprior_test5.log") 243 | 244 | par(mfrow=c(1,2)) 245 | 246 | # mu 247 | mu_density <- density(lf$mu) 248 | plot(mu_density$x, mu_density$y, lwd=2, lty=2, col=pal.dark(cgreen), type='l',ylab="",xlab="mu estimate") 249 | polygon(c(0, mu_density$x, 0), c(0, mu_density$y, 0), col=pal.dark(cgreen,0.5), border=NA) 250 | abline(v=mu,lty=2,lwd=2,col=pal.dark(cred)) 251 | title("ouprior_test5.xml") 252 | 253 | # sigma 254 | sigma_density <- density(lf$sigma) 255 | plot(sigma_density$x, sigma_density$y, lwd=2, lty=2, col=pal.dark(cgreen), type='l',ylab="",xlab="sigma estimate") 256 | polygon(c(0, sigma_density$x, 0), c(0, sigma_density$y, 0), col=pal.dark(cgreen,0.5), border=NA) 257 | abline(v=sigma,lty=2,lwd=2,col=pal.dark(cred)) 258 | 259 | ``` -------------------------------------------------------------------------------- /examples/smoothingpriors/OUPriorTests.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | Ornstein-Uhlenbeck smoothing prior tests 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 33 | 42 | 43 | 44 | 45 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 98 | 99 | 100 | 101 |
102 | 103 | 104 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 126 | 127 | 128 |

Tests to check that the OU-prior implemented in BEAST2 is correct. In particular checking that sampling trajectories in BEAST2 with MCMC produces the correct theoretical distribution as well as the same distribution as simulating trajectories using the analytical solution (when drawing parameter values from prior distributions). Additionally, also test the ability of the BEAST2 implementation to estimate parameter values given a trajectory.

129 |
130 |

Test 1: ouprior_test1.xml

131 |
    132 |
  • OU-process with all parameters fixed.
  • 133 |
  • Sample x using MCMC in BEAST2 and compare to theoretical quantiles.
  • 134 |
135 |
    #####################
136 |     # ouprior_test1.xml #
137 |     #####################
138 |     
139 |     # Calculate density of OU-process and get percentiles (blue and red)
140 |     t     <- seq(0,9,by=1)
141 |     x0    <- 10
142 |     mu    <- 3
143 |     sigma <- 1
144 |     nu    <- 0.1
145 |     X     <- plotOUProcessHPD(x0, t, mu, sigma, nu, ylim = c(0,12), main='ouprior_test1.xml', xlab="", ylab="")
146 |     sim_hpd <- getMatrixHPD(X)
147 |     
148 |     # Sample from posterior in BEAST2 and get HPD (orange and green)
149 |     lf <- readLogfile("ouprior_test1.log")
150 |     
151 |     xsample <- getSkylineSubset(lf,"x")
152 |     for (i in 1:nrow(xsample)) {
153 |       lines(t,xsample[i,],col=pal.dark(corange,0.1),lwd=0.5)
154 |     }
155 |     sample_hpd <- getMatrixHPD(xsample)
156 |     lines(t,sample_hpd[1,],col=pal.dark(cgreen),lty=2,lwd=2)
157 |     lines(t,sample_hpd[2,],col=pal.dark(cgreen),lty=2,lwd=2)
158 |     lines(t,sample_hpd[3,],col=pal.dark(cgreen),lty=2,lwd=2)
159 |

160 |
161 |
162 |

Test 2: ouprior_test2.xml

163 |
    164 |
  • OU-process with all parameters fixed and x_0 sampled from an exponential prior.
  • 165 |
  • Sample x using MCMC in BEAST2 and compare HPDs of x to 1000 simulated trajectories (using analytical solution from time-transformed Wiener process).
  • 166 |
167 |
    #####################
168 |     # ouprior_test2.xml #
169 |     #####################
170 |     
171 |     # Simulate OU-trajectory and get HPD (blue and red)
172 |     t     <- seq(0,9,by=1)
173 |     x0_p  <- getPrior(rexp,1,rate=10)
174 |     mu    <- 3
175 |     sigma <- 1
176 |     nu    <- 0.1
177 |     X     <- plotOUProcessHPDEmpirical(x0_p, t, mu, sigma, nu, ylim = c(-4,6), main='ouprior_test2.xml')
178 |     sim_hpd <- getMatrixHPD(X)
179 |     
180 |     # Sample from posterior in BEAST2 and get HPD (orange and green)
181 |     lf <- readLogfile("ouprior_test2.log")
182 |     
183 |     xsample <- getSkylineSubset(lf,"x")
184 |     for (i in 1:nrow(xsample)) {
185 |         lines(t,xsample[i,],col=pal.dark(corange,0.1),lwd=0.5)
186 |     }
187 |     sample_hpd <- getMatrixHPD(xsample)
188 |     lines(t,sample_hpd[1,],col=pal.dark(cgreen),lty=2,lwd=2)
189 |     lines(t,sample_hpd[2,],col=pal.dark(cgreen),lty=2,lwd=2)
190 |     lines(t,sample_hpd[3,],col=pal.dark(cgreen),lty=2,lwd=2)
191 |

192 |
193 |
194 |

Test 3: ouprior_test3.xml

195 |
    196 |
  • OU-process with all parameters drawn from priors.
  • 197 |
  • Sample x using MCMC in BEAST2 and compare HPDs of x to 1000 simulated trajectories (using analytical solution from time-transformed Wiener process).
  • 198 |
  • Compare posterior distributions for parameters to priors (without data posterior should equal prior).
  • 199 |
200 |
    #####################
201 |     # ouprior_test3.xml #
202 |     #####################
203 |     
204 |     layout(matrix(c(1,1,1,1,2,3,4,5), nrow=2, byrow=TRUE), heights = c(5,3))
205 |     
206 |     # Simulate OU-trajectory and get HPD (blue and red)
207 |     t       <- seq(0,0.9,by=0.1)
208 |     x0_p    <- getPrior(runif,  1, min=1.5, max=2.5)     
209 |     mu_p    <- getPrior(rlnorm, 1, meanlog=0, sdlog=0.5)
210 |     sigma_p <- getPrior(rnorm,  1, mean=0.5, sd=0.1)
211 |     nu_p    <- getPrior(rgamma, 1, shape=1, scale=5)
212 |     X     <- plotOUProcessHPDEmpirical(x0_p, t, mu_p, sigma_p, nu_p, ylim = c(0,4), main='ouprior_test3.xml')
213 |     sim_hpd <- getMatrixHPD(X)
214 |     
215 |     # Sample from posterior in BEAST2 and get HPD (orange and green)
216 |     lf <- readLogfile("ouprior_test3.log")
217 |     
218 |     xsample <- getSkylineSubset(lf,"x")
219 |     for (i in 1:nrow(xsample)) {
220 |       lines(t,xsample[i,],col=pal.dark(corange,0.1),lwd=0.5)
221 |     }
222 |     sample_hpd <- getMatrixHPD(xsample)
223 |     lines(t,sample_hpd[1,],col=pal.dark(cgreen),lty=2,lwd=2)
224 |     lines(t,sample_hpd[2,],col=pal.dark(cgreen),lty=2,lwd=2)
225 |     lines(t,sample_hpd[3,],col=pal.dark(cgreen),lty=2,lwd=2)
226 |     
227 |     # mu
228 |     mu_density <- density(lf$mu)
229 |     plotPrior('lnorm',list(meanlog=0, sdlog=0.5), main='mu')
230 |     lines(mu_density$x, mu_density$y, lwd=2, lty=2, col=pal.dark(cgreen))
231 |     polygon(c(0, mu_density$x, 0), c(0, mu_density$y, 0), col=pal.dark(cgreen,0.5), border=NA)
232 |     
233 |     # Sigma
234 |     sigma_density <- density(lf$sigma)
235 |     plotPrior('norm',list(mean=0.5, sd=0.1), main='sigma')
236 |     lines(sigma_density$x, sigma_density$y, lwd=2, lty=2, col=pal.dark(cgreen))
237 |     polygon(c(0, sigma_density$x, 0), c(0, sigma_density$y, 0), col=pal.dark(cgreen,0.5), border=NA)
238 |     
239 |     # nu
240 |     nu_density <- density(lf$nu, bw=0.3)
241 |     plotPrior('gamma',list(shape=1, scale=5), main='nu')
242 |     lines(nu_density$x, nu_density$y, lwd=2, lty=2, col=pal.dark(cgreen))
243 |     polygon(c(0, nu_density$x, 0), c(0, nu_density$y, 0), col=pal.dark(cgreen,0.5), border=NA)
244 |     
245 |     #x0 
246 |     x0_density <- density(lf$x1, bw=0.05)
247 |     plotPrior('unif',list(min=1.5, max=2.5), main=expression(x[0]))
248 |     lines(x0_density$x, x0_density$y, lwd=2, lty=2, col=pal.dark(cgreen))
249 |     polygon(c(0, x0_density$x, 0), c(0, x0_density$y, 0), col=pal.dark(cgreen,0.5), border=NA)
250 |

251 |
252 |
253 |

Test 4: ouprior_test4.xml

254 |
    255 |
  • OU-process with all parameters drawn from priors, except for the mean.
  • 256 |
  • Run for 51 time points instead of just 10 as above.
  • 257 |
  • Sample x using MCMC in BEAST2 and compare HPDs of x to 1000 simulated trajectories (using analytical solution from time-transformed Wiener process).
  • 258 |
  • Compare posterior distributions for parameters to priors (without data posterior should equal prior).
  • 259 |
260 |
    #####################
261 |     # ouprior_test4.xml #
262 |     #####################
263 |     
264 |     layout(matrix(c(1,1,1,2,3,4), nrow=2, byrow=TRUE), heights=c(5,3))
265 |     
266 |     # Simulate OU-trajectory and get HPD (blue and red)
267 |     t       <- seq(0,1,length.out=51)
268 |     x0_p    <- getPrior(rexp,  1, rate=1)     
269 |     mu      <- 1
270 |     sigma_p <- getPrior(rnorm,  1, mean=0.3, sd=0.1)
271 |     nu_p    <- getPrior(rgamma, 1, shape=1, scale=50)
272 |     X       <- plotOUProcessHPDEmpirical(x0_p, t, mu, sigma_p, nu_p, ylim = c(0.5,2.5), main='ouprior_test4.xml')
273 |     sim_hpd <- getMatrixHPD(X)
274 |     
275 |     # Sample from posterior in BEAST2 and get HPD (orange and green)
276 |     lf <- readLogfile("ouprior_test4.log")
277 |     
278 |     xsample <- getSkylineSubset(lf,"x")
279 |     for (i in 1:nrow(xsample)) {
280 |       lines(t,xsample[i,],col=pal.dark(corange,0.1),lwd=0.5)
281 |     }
282 |     sample_hpd <- getMatrixHPD(xsample)
283 |     lines(t,sample_hpd[1,],col=pal.dark(cgreen),lty=2,lwd=2)
284 |     lines(t,sample_hpd[2,],col=pal.dark(cgreen),lty=2,lwd=2)
285 |     lines(t,sample_hpd[3,],col=pal.dark(cgreen),lty=2,lwd=2)
286 |     
287 |     # Sigma
288 |     sigma_density <- density(lf$sigma)
289 |     plotPrior('norm',list(mean=0.3, sd=0.1), main='sigma')
290 |     lines(sigma_density$x, sigma_density$y, lwd=2, lty=2, col=pal.dark(cgreen))
291 |     polygon(c(0, sigma_density$x, 0), c(0, sigma_density$y, 0), col=pal.dark(cgreen,0.5), border=NA)
292 |     
293 |     # nu
294 |     nu_density <- density(lf$nu, bw=5)
295 |     plotPrior('gamma',list(shape=1, scale=50), main='nu')
296 |     lines(nu_density$x, nu_density$y, lwd=2, lty=2, col=pal.dark(cgreen))
297 |     polygon(c(0, nu_density$x, 0), c(0, nu_density$y, 0), col=pal.dark(cgreen,0.5), border=NA)
298 |     
299 |     #x0 
300 |     x0_density <- density(lf$x1)
301 |     plotPrior('exp',list(rate=1), main=expression(x[0]))
302 |     lines(x0_density$x, x0_density$y, lwd=2, lty=2, col=pal.dark(cgreen))
303 |     polygon(c(0, x0_density$x, 0), c(0, x0_density$y, 0), col=pal.dark(cgreen,0.5), border=NA)
304 |

305 |
306 |
307 |

Test 5: ouprior_test5.xml

308 |
    309 |
  • OU-process with fixed parameters, simulate a single trajectory with 101 time points.
  • 310 |
  • Fix trajectory in BEAST2 and attempt to estimate mean and variance (mean-reversion fixed to true value).
  • 311 |
312 |
    #####################
313 |     # ouprior_test5.xml #
314 |     #####################
315 |     
316 |     set.seed(10)
317 |     
318 |     t     <- seq(0,10,by=0.1)
319 |     x0    <- 6
320 |     mu    <- 5
321 |     sigma <- 0.1
322 |     nu    <- 1
323 |     x <- simulateOU(x0, t, mu, sigma, nu)
324 |     
325 |     #plot(t,x,type='l',col=pal.dark(cblue))
326 |     print(paste(x,collapse = " "))
327 |     
328 |     # Posterior estimates in BEAST2 and get HPD (orange and green)
329 |     lf <- readLogfile("ouprior_test5.log")
330 |     
331 |     par(mfrow=c(1,2))
332 |     
333 |     # mu
334 |     mu_density <- density(lf$mu)
335 |     plot(mu_density$x, mu_density$y, lwd=2, lty=2, col=pal.dark(cgreen), type='l',ylab="",xlab="mu estimate")
336 |     polygon(c(0, mu_density$x, 0), c(0, mu_density$y, 0), col=pal.dark(cgreen,0.5), border=NA)
337 |     abline(v=mu,lty=2,lwd=2,col=pal.dark(cred))
338 |     title("ouprior_test5.xml")
339 |     
340 |     # sigma
341 |     sigma_density <- density(lf$sigma)
342 |     plot(sigma_density$x, sigma_density$y, lwd=2, lty=2, col=pal.dark(cgreen), type='l',ylab="",xlab="sigma estimate")
343 |     polygon(c(0, sigma_density$x, 0), c(0, sigma_density$y, 0), col=pal.dark(cgreen,0.5), border=NA)
344 |     abline(v=sigma,lty=2,lwd=2,col=pal.dark(cred))
345 |

346 |
347 | 348 | 349 | 350 | 351 |
352 | 353 | 365 | 366 | 367 | 375 | 376 | 377 | 378 | -------------------------------------------------------------------------------- /examples/smoothingpriors/OUPriorTests.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Ornstein-Uhlenbeck smoothing prior tests" 3 | author: "Louis du Plessis" 4 | date: "7/19/2018" 5 | output: 6 | html_document: 7 | keep_md: true 8 | theme: cosmo 9 | self_contained: false 10 | --- 11 | 12 | Tests to check that the OU-prior implemented in BEAST2 is correct. In particular checking that sampling trajectories in BEAST2 with MCMC produces the correct theoretical distribution as well as the same distribution as simulating trajectories using the analytical solution (when drawing parameter values from prior distributions). Additionally, also test the ability of the BEAST2 implementation to estimate parameter values given a trajectory. 13 | 14 | 15 | 16 | 17 | 18 | 19 | ### Test 1: `ouprior_test1.xml` 20 | 21 | - OU-process with all parameters fixed. 22 | - Sample x using MCMC in BEAST2 and compare to theoretical quantiles. 23 | 24 | 25 | 26 | ```r 27 | ##################### 28 | # ouprior_test1.xml # 29 | ##################### 30 | 31 | # Calculate density of OU-process and get percentiles (blue and red) 32 | t <- seq(0,9,by=1) 33 | x0 <- 10 34 | mu <- 3 35 | sigma <- 1 36 | nu <- 0.1 37 | X <- plotOUProcessHPD(x0, t, mu, sigma, nu, ylim = c(0,12), main='ouprior_test1.xml', xlab="", ylab="") 38 | sim_hpd <- getMatrixHPD(X) 39 | 40 | # Sample from posterior in BEAST2 and get HPD (orange and green) 41 | lf <- readLogfile("ouprior_test1.log") 42 | 43 | xsample <- getSkylineSubset(lf,"x") 44 | for (i in 1:nrow(xsample)) { 45 | lines(t,xsample[i,],col=pal.dark(corange,0.1),lwd=0.5) 46 | } 47 | sample_hpd <- getMatrixHPD(xsample) 48 | lines(t,sample_hpd[1,],col=pal.dark(cgreen),lty=2,lwd=2) 49 | lines(t,sample_hpd[2,],col=pal.dark(cgreen),lty=2,lwd=2) 50 | lines(t,sample_hpd[3,],col=pal.dark(cgreen),lty=2,lwd=2) 51 | ``` 52 | 53 | ![](figs/ouprior_test1-1.png) 54 | 55 | 56 | 57 | ### Test 2: `ouprior_test2.xml` 58 | 59 | - OU-process with all parameters fixed and x_0 sampled from an exponential prior. 60 | - Sample x using MCMC in BEAST2 and compare HPDs of x to 1000 simulated trajectories (using analytical solution from time-transformed Wiener process). 61 | 62 | 63 | 64 | ```r 65 | ##################### 66 | # ouprior_test2.xml # 67 | ##################### 68 | 69 | # Simulate OU-trajectory and get HPD (blue and red) 70 | t <- seq(0,9,by=1) 71 | x0_p <- getPrior(rexp,1,rate=10) 72 | mu <- 3 73 | sigma <- 1 74 | nu <- 0.1 75 | X <- plotOUProcessHPDEmpirical(x0_p, t, mu, sigma, nu, ylim = c(-4,6), main='ouprior_test2.xml') 76 | sim_hpd <- getMatrixHPD(X) 77 | 78 | # Sample from posterior in BEAST2 and get HPD (orange and green) 79 | lf <- readLogfile("ouprior_test2.log") 80 | 81 | xsample <- getSkylineSubset(lf,"x") 82 | for (i in 1:nrow(xsample)) { 83 | lines(t,xsample[i,],col=pal.dark(corange,0.1),lwd=0.5) 84 | } 85 | sample_hpd <- getMatrixHPD(xsample) 86 | lines(t,sample_hpd[1,],col=pal.dark(cgreen),lty=2,lwd=2) 87 | lines(t,sample_hpd[2,],col=pal.dark(cgreen),lty=2,lwd=2) 88 | lines(t,sample_hpd[3,],col=pal.dark(cgreen),lty=2,lwd=2) 89 | ``` 90 | 91 | ![](figs/ouprior_test2-1.png) 92 | 93 | 94 | ### Test 3: `ouprior_test3.xml` 95 | 96 | - OU-process with all parameters drawn from priors. 97 | - Sample x using MCMC in BEAST2 and compare HPDs of x to 1000 simulated trajectories (using analytical solution from time-transformed Wiener process). 98 | - Compare posterior distributions for parameters to priors (without data posterior should equal prior). 99 | 100 | 101 | ```r 102 | ##################### 103 | # ouprior_test3.xml # 104 | ##################### 105 | 106 | layout(matrix(c(1,1,1,1,2,3,4,5), nrow=2, byrow=TRUE), heights = c(5,3)) 107 | 108 | # Simulate OU-trajectory and get HPD (blue and red) 109 | t <- seq(0,0.9,by=0.1) 110 | x0_p <- getPrior(runif, 1, min=1.5, max=2.5) 111 | mu_p <- getPrior(rlnorm, 1, meanlog=0, sdlog=0.5) 112 | sigma_p <- getPrior(rnorm, 1, mean=0.5, sd=0.1) 113 | nu_p <- getPrior(rgamma, 1, shape=1, scale=5) 114 | X <- plotOUProcessHPDEmpirical(x0_p, t, mu_p, sigma_p, nu_p, ylim = c(0,4), main='ouprior_test3.xml') 115 | sim_hpd <- getMatrixHPD(X) 116 | 117 | # Sample from posterior in BEAST2 and get HPD (orange and green) 118 | lf <- readLogfile("ouprior_test3.log") 119 | 120 | xsample <- getSkylineSubset(lf,"x") 121 | for (i in 1:nrow(xsample)) { 122 | lines(t,xsample[i,],col=pal.dark(corange,0.1),lwd=0.5) 123 | } 124 | sample_hpd <- getMatrixHPD(xsample) 125 | lines(t,sample_hpd[1,],col=pal.dark(cgreen),lty=2,lwd=2) 126 | lines(t,sample_hpd[2,],col=pal.dark(cgreen),lty=2,lwd=2) 127 | lines(t,sample_hpd[3,],col=pal.dark(cgreen),lty=2,lwd=2) 128 | 129 | # mu 130 | mu_density <- density(lf$mu) 131 | plotPrior('lnorm',list(meanlog=0, sdlog=0.5), main='mu') 132 | lines(mu_density$x, mu_density$y, lwd=2, lty=2, col=pal.dark(cgreen)) 133 | polygon(c(0, mu_density$x, 0), c(0, mu_density$y, 0), col=pal.dark(cgreen,0.5), border=NA) 134 | 135 | # Sigma 136 | sigma_density <- density(lf$sigma) 137 | plotPrior('norm',list(mean=0.5, sd=0.1), main='sigma') 138 | lines(sigma_density$x, sigma_density$y, lwd=2, lty=2, col=pal.dark(cgreen)) 139 | polygon(c(0, sigma_density$x, 0), c(0, sigma_density$y, 0), col=pal.dark(cgreen,0.5), border=NA) 140 | 141 | # nu 142 | nu_density <- density(lf$nu, bw=0.3) 143 | plotPrior('gamma',list(shape=1, scale=5), main='nu') 144 | lines(nu_density$x, nu_density$y, lwd=2, lty=2, col=pal.dark(cgreen)) 145 | polygon(c(0, nu_density$x, 0), c(0, nu_density$y, 0), col=pal.dark(cgreen,0.5), border=NA) 146 | 147 | #x0 148 | x0_density <- density(lf$x1, bw=0.05) 149 | plotPrior('unif',list(min=1.5, max=2.5), main=expression(x[0])) 150 | lines(x0_density$x, x0_density$y, lwd=2, lty=2, col=pal.dark(cgreen)) 151 | polygon(c(0, x0_density$x, 0), c(0, x0_density$y, 0), col=pal.dark(cgreen,0.5), border=NA) 152 | ``` 153 | 154 | ![](figs/ouprior_test3-1.png) 155 | 156 | 157 | 158 | ### Test 4: `ouprior_test4.xml` 159 | 160 | - OU-process with all parameters drawn from priors, except for the mean. 161 | - Run for 51 time points instead of just 10 as above. 162 | - Sample x using MCMC in BEAST2 and compare HPDs of x to 1000 simulated trajectories (using analytical solution from time-transformed Wiener process). 163 | - Compare posterior distributions for parameters to priors (without data posterior should equal prior). 164 | 165 | 166 | 167 | ```r 168 | ##################### 169 | # ouprior_test4.xml # 170 | ##################### 171 | 172 | layout(matrix(c(1,1,1,2,3,4), nrow=2, byrow=TRUE), heights=c(5,3)) 173 | 174 | # Simulate OU-trajectory and get HPD (blue and red) 175 | t <- seq(0,1,length.out=51) 176 | x0_p <- getPrior(rexp, 1, rate=1) 177 | mu <- 1 178 | sigma_p <- getPrior(rnorm, 1, mean=0.3, sd=0.1) 179 | nu_p <- getPrior(rgamma, 1, shape=1, scale=50) 180 | X <- plotOUProcessHPDEmpirical(x0_p, t, mu, sigma_p, nu_p, ylim = c(0.5,2.5), main='ouprior_test4.xml') 181 | sim_hpd <- getMatrixHPD(X) 182 | 183 | # Sample from posterior in BEAST2 and get HPD (orange and green) 184 | lf <- readLogfile("ouprior_test4.log") 185 | 186 | xsample <- getSkylineSubset(lf,"x") 187 | for (i in 1:nrow(xsample)) { 188 | lines(t,xsample[i,],col=pal.dark(corange,0.1),lwd=0.5) 189 | } 190 | sample_hpd <- getMatrixHPD(xsample) 191 | lines(t,sample_hpd[1,],col=pal.dark(cgreen),lty=2,lwd=2) 192 | lines(t,sample_hpd[2,],col=pal.dark(cgreen),lty=2,lwd=2) 193 | lines(t,sample_hpd[3,],col=pal.dark(cgreen),lty=2,lwd=2) 194 | 195 | # Sigma 196 | sigma_density <- density(lf$sigma) 197 | plotPrior('norm',list(mean=0.3, sd=0.1), main='sigma') 198 | lines(sigma_density$x, sigma_density$y, lwd=2, lty=2, col=pal.dark(cgreen)) 199 | polygon(c(0, sigma_density$x, 0), c(0, sigma_density$y, 0), col=pal.dark(cgreen,0.5), border=NA) 200 | 201 | # nu 202 | nu_density <- density(lf$nu, bw=5) 203 | plotPrior('gamma',list(shape=1, scale=50), main='nu') 204 | lines(nu_density$x, nu_density$y, lwd=2, lty=2, col=pal.dark(cgreen)) 205 | polygon(c(0, nu_density$x, 0), c(0, nu_density$y, 0), col=pal.dark(cgreen,0.5), border=NA) 206 | 207 | #x0 208 | x0_density <- density(lf$x1) 209 | plotPrior('exp',list(rate=1), main=expression(x[0])) 210 | lines(x0_density$x, x0_density$y, lwd=2, lty=2, col=pal.dark(cgreen)) 211 | polygon(c(0, x0_density$x, 0), c(0, x0_density$y, 0), col=pal.dark(cgreen,0.5), border=NA) 212 | ``` 213 | 214 | ![](figs/ouprior_test4-1.png) 215 | 216 | 217 | ### Test 5: `ouprior_test5.xml` 218 | 219 | - OU-process with fixed parameters, simulate a single trajectory with 101 time points. 220 | - Fix trajectory in BEAST2 and attempt to estimate mean and variance (mean-reversion fixed to true value). 221 | 222 | 223 | ```r 224 | ##################### 225 | # ouprior_test5.xml # 226 | ##################### 227 | 228 | set.seed(10) 229 | 230 | t <- seq(0,10,by=0.1) 231 | x0 <- 6 232 | mu <- 5 233 | sigma <- 0.1 234 | nu <- 1 235 | x <- simulateOU(x0, t, mu, sigma, nu) 236 | 237 | #plot(t,x,type='l',col=pal.dark(cblue)) 238 | print(paste(x,collapse = " ")) 239 | 240 | # Posterior estimates in BEAST2 and get HPD (orange and green) 241 | lf <- readLogfile("ouprior_test5.log") 242 | 243 | par(mfrow=c(1,2)) 244 | 245 | # mu 246 | mu_density <- density(lf$mu) 247 | plot(mu_density$x, mu_density$y, lwd=2, lty=2, col=pal.dark(cgreen), type='l',ylab="",xlab="mu estimate") 248 | polygon(c(0, mu_density$x, 0), c(0, mu_density$y, 0), col=pal.dark(cgreen,0.5), border=NA) 249 | abline(v=mu,lty=2,lwd=2,col=pal.dark(cred)) 250 | title("ouprior_test5.xml") 251 | 252 | # sigma 253 | sigma_density <- density(lf$sigma) 254 | plot(sigma_density$x, sigma_density$y, lwd=2, lty=2, col=pal.dark(cgreen), type='l',ylab="",xlab="sigma estimate") 255 | polygon(c(0, sigma_density$x, 0), c(0, sigma_density$y, 0), col=pal.dark(cgreen,0.5), border=NA) 256 | abline(v=sigma,lty=2,lwd=2,col=pal.dark(cred)) 257 | ``` 258 | 259 | ![](figs/ouprior_test5-1.png) 260 | -------------------------------------------------------------------------------- /examples/smoothingpriors/figs/ouprior_test1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laduplessis/skylinetools/7993f64ca5699ad0da053af2f2a6d8e8a4c45fa8/examples/smoothingpriors/figs/ouprior_test1-1.png -------------------------------------------------------------------------------- /examples/smoothingpriors/figs/ouprior_test2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laduplessis/skylinetools/7993f64ca5699ad0da053af2f2a6d8e8a4c45fa8/examples/smoothingpriors/figs/ouprior_test2-1.png -------------------------------------------------------------------------------- /examples/smoothingpriors/figs/ouprior_test3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laduplessis/skylinetools/7993f64ca5699ad0da053af2f2a6d8e8a4c45fa8/examples/smoothingpriors/figs/ouprior_test3-1.png -------------------------------------------------------------------------------- /examples/smoothingpriors/figs/ouprior_test4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laduplessis/skylinetools/7993f64ca5699ad0da053af2f2a6d8e8a4c45fa8/examples/smoothingpriors/figs/ouprior_test4-1.png -------------------------------------------------------------------------------- /examples/smoothingpriors/figs/ouprior_test5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/laduplessis/skylinetools/7993f64ca5699ad0da053af2f2a6d8e8a4c45fa8/examples/smoothingpriors/figs/ouprior_test5-1.png -------------------------------------------------------------------------------- /examples/smoothingpriors/ouprior_test1.xml: -------------------------------------------------------------------------------- 1 | 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 | -------------------------------------------------------------------------------- /examples/smoothingpriors/ouprior_test2.xml: -------------------------------------------------------------------------------- 1 | 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 | -------------------------------------------------------------------------------- /examples/smoothingpriors/ouprior_test3.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | beast.math.distributions.Uniform 7 | beast.math.distributions.Exponential 8 | beast.math.distributions.LogNormalDistributionModel 9 | beast.math.distributions.Normal 10 | beast.math.distributions.Beta 11 | beast.math.distributions.Gamma 12 | beast.math.distributions.LaplaceDistribution 13 | beast.math.distributions.Prior 14 | beast.math.distributions.InverseGamma 15 | beast.math.distributions.OneOnX 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 | -------------------------------------------------------------------------------- /examples/smoothingpriors/ouprior_test4.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | beast.math.distributions.Uniform 7 | beast.math.distributions.Exponential 8 | beast.math.distributions.LogNormalDistributionModel 9 | beast.math.distributions.Normal 10 | beast.math.distributions.Beta 11 | beast.math.distributions.Gamma 12 | beast.math.distributions.LaplaceDistribution 13 | beast.math.distributions.Prior 14 | beast.math.distributions.InverseGamma 15 | beast.math.distributions.OneOnX 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 | -------------------------------------------------------------------------------- /examples/smoothingpriors/ouprior_test5.xml: -------------------------------------------------------------------------------- 1 | 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 | -------------------------------------------------------------------------------- /examples/treeslicer/comparison/dengue4_bdsky_fixeddates.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | 19 | 20 | beast.math.distributions.Uniform 21 | beast.math.distributions.Exponential 22 | beast.math.distributions.LogNormalDistributionModel 23 | beast.math.distributions.Normal 24 | beast.math.distributions.Beta 25 | beast.math.distributions.Gamma 26 | beast.math.distributions.LaplaceDistribution 27 | beast.math.distributions.Prior 28 | beast.math.distributions.InverseGamma 29 | beast.math.distributions.OneOnX 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 | D4Brazi82=1982, 61 | D4ElSal83=1983, 62 | D4ElSal94=1994, 63 | D4Indon76=1976, 64 | D4Indon77=1977, 65 | D4Mexico84=1984, 66 | D4NewCal81=1981, 67 | D4Philip64=1964, 68 | D4Philip56=1956, 69 | D4Philip84=1984, 70 | D4PRico86=1986, 71 | D4SLanka78=1978, 72 | D4Tahiti79=1979, 73 | D4Tahiti85=1985, 74 | D4Thai63=1963, 75 | D4Thai78=1978, 76 | D4Thai84=1984 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 2.0 85 | 0.25 86 | 1.0 87 | 88 | 100.0 89 | 0 0.01 90 | 1.0 91 | 2.0 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 1.0 150 | 1.0 151 | 0.0 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | -------------------------------------------------------------------------------- /src/beast/evolution/speciation/BirthDeathSkylineModelTestHelper.java: -------------------------------------------------------------------------------- 1 | package beast.evolution.speciation; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by dlouis on 06/04/16. 7 | */ 8 | public class BirthDeathSkylineModelTestHelper extends BirthDeathSkylineModel { 9 | 10 | public List getBirthRateChangeTimes() { return birthRateChangeTimes; } 11 | 12 | public List getDeathRateChangeTimes() { return deathRateChangeTimes; } 13 | 14 | public List getSamplingRateChangeTimes() { return samplingRateChangeTimes; } 15 | 16 | public List getrhoSamplingChangeTimes() { return rhoSamplingChangeTimes; } 17 | 18 | public List rChangeTimes() { return rChangeTimes; } 19 | 20 | } -------------------------------------------------------------------------------- /src/skylinetools/distributions/BMPrior.java: -------------------------------------------------------------------------------- 1 | package skylinetools.distributions; 2 | 3 | import beast.core.Distribution; 4 | import beast.core.Function; 5 | import beast.core.Input; 6 | import beast.core.State; 7 | import beast.core.parameter.RealParameter; 8 | import beast.math.distributions.ParametricDistribution; 9 | 10 | import java.util.List; 11 | import java.util.Random; 12 | 13 | /** 14 | * Implementation of the Brownian motion probability density for use as a prior on a sequence of (x_i,t_i) pairs. 15 | * 16 | * The density is *almost* identical to the GMRF smoothing prior used in the Skyride, Skygrid family of models, but with 17 | * a distribution placed on x0 (can be null, in which case density should be equal to GMRF density) 18 | * 19 | * GMRF implementation in Skyride/Skygrid models uses a matrix algebra library to calculate the density (as a MVN 20 | * distribution) and is paired with a GMRF block update operator. 21 | * 22 | * For now missing the same constant as the OUPrior 23 | * 24 | * @author Louis du Plessis 25 | * Date: 2018/07/23 26 | */ 27 | public class BMPrior extends Distribution { 28 | 29 | // the trajectory to compute Ornstein-Uhlenbeck prior of 30 | public Input xInput = 31 | new Input<>("x", "The x_i values", (Function) null); 32 | 33 | // the times associated with the x_i values 34 | public Input timeInput = 35 | new Input<>("times", "The times t_i specifying when x changes", (Function) null); 36 | 37 | // tau 38 | public Input tauInput = 39 | new Input("precision", "The precision parameter of the distribution (reciprocal of variance)", (RealParameter) null); 40 | 41 | // sigma 42 | public Input sigmaInput = 43 | new Input("sigma", "The standard deviation parameter of the distribution", (RealParameter) null, Input.Validate.XOR, tauInput); 44 | 45 | public Input x0PriorInput = 46 | new Input<>("x0Prior", "The prior to use on x0, or null if none.", (ParametricDistribution) null); 47 | 48 | public Input logSpace = new Input<>("logspace", "true if prior should be applied to log(x).", false); 49 | 50 | 51 | 52 | public double calculateLogP() { 53 | 54 | double tau; 55 | if (tauInput.get() == null) { 56 | double sigma = sigmaInput.get().getValue(); 57 | tau = 1/(sigma * sigma); 58 | } else { 59 | tau = tauInput.get().getValue(); 60 | } 61 | 62 | ParametricDistribution x0Prior = x0PriorInput.get(); 63 | 64 | double[] t = timeInput.get().getDoubleValues(); 65 | double[] x = xInput.get().getDoubleValues(); 66 | 67 | boolean logspace = logSpace.get(); 68 | if (logspace) { 69 | for (int i = 0; i < x.length; i++) { 70 | x[i] = Math.log(x[i]); 71 | } 72 | } 73 | 74 | int n = x.length - 1; 75 | 76 | double logL = n/2.0 * Math.log(tau); 77 | 78 | for (int i = 1; i <= n; i++) { 79 | 80 | double dt = t[i]-t[i-1]; 81 | double dx = x[i]-x[i-1]; 82 | 83 | logL -= 0.5*Math.log(dt); 84 | logL -= (0.5*tau*dx*dx)/dt; 85 | } 86 | 87 | if (x0Prior != null) logL += x0Prior.calcLogP(new Function() { 88 | @Override 89 | public int getDimension() { 90 | return 1; 91 | } 92 | 93 | @Override 94 | public double getArrayValue() { 95 | return x[0]; 96 | } 97 | 98 | @Override 99 | public double getArrayValue(int iDim) { 100 | return x[0]; 101 | } 102 | }); 103 | 104 | logP = logL; 105 | return logP; 106 | } 107 | 108 | @Override 109 | public List getArguments() { 110 | return null; 111 | } 112 | 113 | @Override 114 | public List getConditions() { 115 | return null; 116 | } 117 | 118 | @Override 119 | public void sample(State state, Random random) { 120 | 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /src/skylinetools/distributions/OUPrior.java: -------------------------------------------------------------------------------- 1 | package skylinetools.distributions; 2 | 3 | import beast.core.Distribution; 4 | import beast.core.Function; 5 | import beast.core.Input; 6 | import beast.core.State; 7 | import beast.core.parameter.RealParameter; 8 | import beast.math.distributions.ParametricDistribution; 9 | 10 | import java.util.Arrays; 11 | import java.util.List; 12 | import java.util.Random; 13 | 14 | /** 15 | * Implementation of the Ornstein-Uhlenbeck probability density for use as a prior on a sequence of (x_i,t_i) pairs. 16 | * 17 | * TODO: 18 | * - Check that dimension of timeInput and xInput match 19 | * - Add constant to likelihood calculation 20 | * - Should sample method be implemented? Shouldn't be too difficult, but this is never used 21 | * 22 | * To ponder: Should normalization be included? I think not... 23 | * 24 | * @author Alexei Drummond. 25 | */ 26 | public class OUPrior extends Distribution { 27 | 28 | 29 | // the trajectory to compute Ornstein-Uhlenbeck prior of 30 | public Input xInput = 31 | new Input<>("x", "The x_i values", (Function) null); 32 | 33 | // the times associated with the x_i values 34 | public Input timeInput = 35 | new Input<>("times", "The times t_i specifying when x changes", (Function) null); 36 | 37 | // mean 38 | public Input meanInput = 39 | new Input("mean", "The mean of the equilibrium distribution", (RealParameter) null); 40 | 41 | // sigma 42 | public Input sigmaInput = 43 | new Input("sigma", "The standard deviation parameter of the equilibrium distribution", (RealParameter) null); 44 | 45 | // nu 46 | public Input nuInput = 47 | new Input("nu", "The reversion parameter of the Ornstein-Uhlenbeck mean reversion process", (RealParameter) null); 48 | 49 | public Input x0PriorInput = 50 | new Input<>("x0Prior", "The prior to use on x0, or null if none.", (ParametricDistribution) null); 51 | 52 | public Input logSpace = new Input<>("logspace", "true if prior should be applied to log(x).", false); 53 | 54 | public Input normalize = new Input<>("normalize", "true if times should be normalized such that t[n]-t[0]=1", false); 55 | 56 | 57 | public double calculateLogP() { 58 | 59 | double mu = meanInput.get().getValue(); 60 | double sigma = sigmaInput.get().getValue(); 61 | double sigsq = sigma * sigma; 62 | double nu = nuInput.get().getValue(); 63 | 64 | ParametricDistribution x0Prior = x0PriorInput.get(); 65 | 66 | double[] t = timeInput.get().getDoubleValues(); 67 | double[] x = xInput.get().getDoubleValues(); 68 | 69 | boolean logspace = logSpace.get(); 70 | if (logspace) { 71 | for (int i = 0; i < x.length; i++) { 72 | x[i] = Math.log(x[i]); 73 | } 74 | } 75 | 76 | int n = x.length - 1; 77 | 78 | 79 | double logL = -n/2.0 * Math.log(sigsq / (2.0*nu)); 80 | 81 | double period = 1; 82 | // Standardize differences between times 83 | // (so variance and mean-reversion are not dependent on time-scale) 84 | if (normalize.get() == true) { 85 | period = t[t.length-1]-t[0]; 86 | } 87 | System.out.println(Arrays.toString(t)); 88 | System.out.println(period); 89 | 90 | for (int i = 1; i <= n; i++) { 91 | 92 | double dt = (t[i]-t[i-1])/period; 93 | double relterm = 1.0-Math.exp(-2.0*nu*(dt)); 94 | 95 | logL -= Math.log(relterm)/2.0; 96 | 97 | double term = x[i] - mu - (x[i-1]-mu) * Math.exp(-nu*(dt)); 98 | 99 | logL -= nu / sigsq * (term*term / relterm); 100 | 101 | System.out.print(dt+" + "); 102 | } 103 | System.out.println(); 104 | 105 | if (x0Prior != null) logL += x0Prior.calcLogP(new Function() { 106 | @Override 107 | public int getDimension() { 108 | return 1; 109 | } 110 | 111 | @Override 112 | public double getArrayValue() { 113 | return x[0]; 114 | } 115 | 116 | @Override 117 | public double getArrayValue(int iDim) { 118 | return x[0]; 119 | } 120 | }); 121 | 122 | logP = logL; 123 | return logP; 124 | } 125 | 126 | @Override 127 | public List getArguments() { 128 | return null; 129 | } 130 | 131 | @Override 132 | public List getConditions() { 133 | return null; 134 | } 135 | 136 | @Override 137 | public void sample(State state, Random random) { 138 | 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/skylinetools/parameter/DateParser.java: -------------------------------------------------------------------------------- 1 | package skylinetools.parameter; 2 | 3 | import beast.core.Input; 4 | import beast.core.parameter.RealParameter; 5 | import beast.core.util.Log; 6 | 7 | import java.time.LocalDate; 8 | import java.time.format.DateTimeFormatter; 9 | import java.time.format.DateTimeParseException; 10 | 11 | 12 | /** 13 | * Class for converting formatted date strings to decimal year dates, e.g. 01-Jan-2015 = 2015.0 14 | * 15 | * Can be used as input to TreeDateSlicer or any other class that needs a decimal date. 16 | * Heavily borrows from TimeParameter.java in feast by Tim Vaughan 17 | * 18 | * See https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html for the date format string. 19 | * 20 | * Note that the date strings are only converted on initialisation. Any operations on the values after that will leave 21 | * the input date strings unaffected. 22 | * 23 | * @author Louis du Plessis 24 | * Date: 2018/12/28 25 | */ 26 | public class DateParser extends RealParameter { 27 | 28 | public Input DateFormatInput = new Input<>("format","Date format (yyyy-MM-dd)"); 29 | public Input DatesInput = new Input<>("dates","Dates to be parsed"); 30 | 31 | 32 | public DateParser() { 33 | valuesInput.setRule(Input.Validate.OPTIONAL); 34 | } 35 | 36 | @Override 37 | public void initAndValidate() { 38 | 39 | for (String date : DatesInput.get().trim().split("\\s+")) { 40 | valuesInput.setValue(parseDate(date), this); 41 | } 42 | 43 | super.initAndValidate(); 44 | } 45 | 46 | 47 | protected double getYearDate(LocalDate date) { 48 | return date.getYear() + (date.getDayOfYear() - 1.0) / (date.isLeapYear() ? 366.0 : 365.0); 49 | } 50 | 51 | /** 52 | * 53 | * (Partly copied from TimeParameter.java in feast by Tim Vaughan) 54 | * 55 | * @param dateString 56 | * @return 57 | */ 58 | protected double parseDate(String dateString) { 59 | 60 | double yeardate; 61 | 62 | try { 63 | if (DateFormatInput.get() != null) { 64 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateFormatInput.get()); 65 | LocalDate date = LocalDate.parse(dateString, formatter); 66 | yeardate = getYearDate(date); 67 | 68 | Log.warning.println("Using format '" + DateFormatInput.get() + "' to parse '" + dateString + 69 | "' as: " + yeardate); 70 | } else { 71 | yeardate = Double.parseDouble(dateString); 72 | } 73 | } catch (NumberFormatException | DateTimeParseException ex) { 74 | throw new IllegalArgumentException("Error parsing input dates - " + 75 | "must be either a number or a properly formatted date string (" + dateString + " failed)."); 76 | } 77 | 78 | return yeardate; 79 | } 80 | 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/skylinetools/parameter/RealParameterSequence.java: -------------------------------------------------------------------------------- 1 | package skylinetools.parameter; 2 | 3 | import beast.core.Description; 4 | import beast.core.Input; 5 | import beast.core.parameter.RealParameter; 6 | 7 | import java.util.Arrays; 8 | 9 | 10 | /** 11 | * A parameter object to easily initialise a linear sequence of real numbers 12 | * Can either use the "by" input to specify the step size or simply use the "dimension" 13 | * input to specify the length of the sequence (the step size will be calculated). 14 | * 15 | * @author Louis du Plessis 16 | * Date: 2018/07/17 17 | */ 18 | @Description("A real-valued sequence of numbers with a fixed step-size between them (at initialisation).") 19 | public class RealParameterSequence extends RealParameter { 20 | 21 | 22 | public final Input fromInput = new Input<>("from", "Starting value of the sequence", 23 | Input.Validate.REQUIRED); 24 | 25 | public final Input toInput = new Input<>("to", "End value of the sequence", 26 | Input.Validate.REQUIRED); 27 | 28 | // Specify either byInput or dimensionInput 29 | public final Input byInput = new Input<>("by", "Increment of the sequence"); 30 | 31 | 32 | // Override input rule of RealParameter (base class) 33 | // (values are derived here) 34 | public RealParameterSequence() { 35 | valuesInput.setRule(Input.Validate.OPTIONAL); 36 | } 37 | 38 | 39 | @Override 40 | public void initAndValidate() { 41 | 42 | double from = fromInput.get().doubleValue(), 43 | to = toInput.get().doubleValue(); 44 | 45 | double step; 46 | int dim; 47 | 48 | if (from == to) { 49 | throw new IllegalArgumentException("from cannot be equal to to"); 50 | } 51 | 52 | // Set limits (from RealParameter) 53 | if (lowerValueInput.get() != null) { 54 | m_fLower = lowerValueInput.get(); 55 | } else { 56 | m_fLower = Double.NEGATIVE_INFINITY; 57 | } 58 | if (upperValueInput.get() != null) { 59 | m_fUpper = upperValueInput.get(); 60 | } else { 61 | m_fUpper = Double.POSITIVE_INFINITY; 62 | } 63 | 64 | // Calculate dimension and stepsize 65 | if (byInput.get() == null) { 66 | //System.out.println("Length"); 67 | 68 | dim = dimensionInput.get().intValue(); 69 | 70 | if (dim <= 0) { 71 | throw new IllegalArgumentException("Length needs to be bigger than 0"); 72 | } 73 | 74 | step = (to-from)/(dim - 1); 75 | } else { 76 | //System.out.println("By"); 77 | 78 | step = byInput.get().doubleValue(); 79 | 80 | if (step == 0) { 81 | throw new IllegalArgumentException("Step size cannot be 0"); 82 | } 83 | 84 | dim = (int) Math.floor((to-from)/step) + 1; 85 | 86 | if ((from > to && step > 0) || (to > from && step < 0)) { 87 | throw new IllegalArgumentException("No way to reach to from from with by input"); 88 | } 89 | 90 | } 91 | 92 | // Set values 93 | dimensionInput.setValue(dim, this); 94 | values = new Double[dim]; 95 | for (int i = 0; i < dim; i++) { 96 | values[i] = from + i*step; 97 | } 98 | //System.out.println(Arrays.toString(values)+": "+dim); 99 | 100 | // Accounting (from Parameter.Base) 101 | storedValues = new Double[dim]; 102 | m_bIsDirty = new boolean[dimensionInput.get()]; 103 | minorDimension = minorDimensionInput.get(); 104 | if (minorDimension > 0 && dimensionInput.get() % minorDimension > 0) { 105 | throw new IllegalArgumentException("Dimension must be divisible by stride"); 106 | } 107 | this.storedValues = values.clone(); 108 | 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /src/skylinetools/util/TreeDateLogger.java: -------------------------------------------------------------------------------- 1 | package skylinetools.util; 2 | 3 | import beast.core.CalculationNode; 4 | import beast.core.Function; 5 | import beast.core.Input; 6 | import beast.core.Loggable; 7 | import beast.core.parameter.RealParameter; 8 | import beast.core.util.Log; 9 | import beast.evolution.tree.Tree; 10 | 11 | import java.io.PrintStream; 12 | 13 | /** 14 | * Log date of tMRCA or if parameter is supplied, logs dates of those parameters subtracted from most recent date in tree 15 | * E.g. log the date of the origin in a birth-death model. 16 | * 17 | * @author Louis du Plessis 18 | * Date: 2018/08/05 19 | * 20 | */ 21 | public class TreeDateLogger extends CalculationNode implements Loggable, Function { 22 | 23 | final public Input treeInput = new Input<>("tree", "Tree to report dates for.", Input.Validate.REQUIRED); 24 | 25 | final public Input parameterInput = new Input<>("parameter", "Parameter to report dates for on tree.", Input.Validate.OPTIONAL); 26 | 27 | int dim; 28 | 29 | @Override 30 | public void initAndValidate() { 31 | if (!treeInput.get().hasDateTrait()) { 32 | Log.warning.println("Tree "+treeInput.get().getID()+ " does not have a date trait. TreeDateLogger "+ getID() + " will log heights instead"); 33 | } 34 | 35 | if (parameterInput.get() != null) { 36 | dim = parameterInput.get().getDimension(); 37 | } else { 38 | dim = 1; 39 | } 40 | 41 | } 42 | 43 | @Override 44 | public void init(PrintStream out) { 45 | final Tree tree = treeInput.get(); 46 | 47 | if (parameterInput.get() != null) { 48 | if (dim == 1) { 49 | out.print(tree.getID() + "." + parameterInput.get().getID() + ".date\t"); 50 | } else { 51 | 52 | for (int i = 0; i < dim; i++) { 53 | out.print(tree.getID() + "." + parameterInput.get().getID() + ".dates" + (i+1) + "\t"); 54 | } 55 | 56 | } 57 | } else { 58 | out.print(tree.getID() + ".height.date\t"); 59 | } 60 | } 61 | 62 | @Override 63 | public void log(long sample, PrintStream out) { 64 | final Tree tree = treeInput.get(); 65 | 66 | if (parameterInput.get() != null) { 67 | for (int i = 0; i < dim; i++) { 68 | out.print(tree.getDate(parameterInput.get().getValue(i)) + "\t"); 69 | } 70 | } else { 71 | out.print(tree.getDate(tree.getRoot().getHeight()) + "\t"); 72 | } 73 | } 74 | 75 | @Override 76 | public void close(PrintStream out) { 77 | // nothing to do 78 | } 79 | 80 | @Override 81 | public int getDimension() { 82 | return dim; 83 | } 84 | 85 | @Override 86 | public double getArrayValue() { 87 | final Tree tree = treeInput.get(); 88 | 89 | if (parameterInput.get() != null) { 90 | return tree.getDate(parameterInput.get().getValue(0)); 91 | } else { 92 | return tree.getDate(tree.getRoot().getHeight()); 93 | } 94 | } 95 | 96 | @Override 97 | public double getArrayValue(int dim) { 98 | final Tree tree = treeInput.get(); 99 | 100 | if (parameterInput.get() != null) { 101 | return tree.getDate(parameterInput.get().getValue(dim)); 102 | } else { 103 | return tree.getDate(tree.getRoot().getHeight()); 104 | } 105 | } 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/skylinetools/util/TreeDateSlicer.java: -------------------------------------------------------------------------------- 1 | package skylinetools.util; 2 | 3 | import beast.core.Function; 4 | import beast.core.Input; 5 | import beast.evolution.tree.Tree; 6 | import beast.util.HeapSort; 7 | 8 | import java.util.Arrays; 9 | 10 | /** 11 | * TreeSlicer class that slices a tree at fixed calendar dates 12 | * 13 | * TODO: Make the class read dates in different formats and convert to decimal year date. (or use separate DateParser class) 14 | * 15 | * @author Louis du Plessis 16 | * Date: 2018/12/28 17 | * 18 | **/ 19 | public class TreeDateSlicer extends TreeSlicer { 20 | 21 | public Input datesInput = 22 | new Input<>("dates", "Dates at which to slice the tree"); 23 | 24 | protected double[] dates; 25 | 26 | @Override 27 | public void initAndValidate() { 28 | 29 | int dimension; 30 | 31 | /* Read tree */ 32 | tree = treeInput.get(); 33 | //updateAnchorTimes(tree); 34 | Anchor.update(tree); 35 | 36 | /* Read dates and set dimension accordingly (depends on whether present date is included or not) */ 37 | updateDates(); 38 | 39 | if (dates[dates.length-1] == Anchor.PRESENT.getDate()) { 40 | dimension = dates.length; 41 | } else 42 | dimension = dates.length+1; 43 | dimensionInput.setValue(dimension, this); 44 | 45 | 46 | /* Initialise arrays */ 47 | values = new Double[dimension]; 48 | storedValues = new Double[dimension]; 49 | calculateTimes(tree); 50 | // System.out.println(this.ID+"\t"+this.getDimension()); 51 | 52 | 53 | // Initialization accounting (not really used) 54 | // Don't want to use super.initAndValidate() because we're doing something else with the values 55 | // m_fLower = Double.NEGATIVE_INFINITY; 56 | m_fLower = 0.0; // Height cannot be negative 57 | m_fUpper = Double.POSITIVE_INFINITY; 58 | m_bIsDirty = new boolean[dimensionInput.get()]; 59 | minorDimension = minorDimensionInput.get(); 60 | if (minorDimension > 0 && dimensionInput.get() % minorDimension > 0) { 61 | throw new IllegalArgumentException("Error in "+this.getID()+": Dimension must be divisible by stride"); 62 | } 63 | this.storedValues = values.clone(); 64 | 65 | timesKnown = false; 66 | } 67 | 68 | 69 | 70 | /** 71 | * Update the dates and order them (in case they are sampled) 72 | */ 73 | protected void updateDates() { 74 | dates = datesInput.get().getDoubleValues(); 75 | HeapSort.sort(dates); 76 | } 77 | 78 | 79 | @Override 80 | protected void calculateTimes(Tree tree) { 81 | 82 | /* Update newest, oldest, tmrca */ 83 | //updateAnchorTimes(tree); 84 | Anchor.update(tree); 85 | //System.out.println(tmrca+"\t"+oldest+"\t"+heightToDate(oldest)+"\t"+newest+"\t"+presentDate); 86 | 87 | updateDates(); 88 | for (int i = 1; i < getDimension(); i++) 89 | values[values.length - i] = Math.max(0.0, dateToHeight(dates[i - 1])); 90 | values[0] = 0.0; // This has to be set to 0.0 for BDSKY to run 91 | 92 | timesKnown = true; 93 | } 94 | 95 | } -------------------------------------------------------------------------------- /src/skylinetools/util/TreeSliceDateLogger.java: -------------------------------------------------------------------------------- 1 | package skylinetools.util; 2 | 3 | import beast.core.CalculationNode; 4 | import beast.core.Function; 5 | import beast.core.Input; 6 | import beast.core.Loggable; 7 | 8 | import java.io.PrintStream; 9 | 10 | /** 11 | * Class to convert the interval times of a TreeSlicer object into calendar dates 12 | * Can be logged or just used as a CalculationNode 13 | * 14 | * @author Louis du Plessis 15 | * Date: 2018/02/12 16 | * 17 | */ 18 | public class TreeSliceDateLogger extends CalculationNode implements Loggable, Function { 19 | 20 | final public Input treeSliceInput = 21 | new Input<>("treeSlice", "TreeSlicer to log dates for", Input.Validate.REQUIRED); 22 | 23 | @Override 24 | public void initAndValidate() { 25 | // nothing to do 26 | } 27 | 28 | @Override 29 | public void init(PrintStream out) { 30 | final TreeSlicer treeslice = treeSliceInput.get(); 31 | final int valueCount = treeslice.getDimension(); 32 | 33 | if (valueCount == 1) { 34 | out.print(treeslice.getID()+".dates\t"); 35 | } else { 36 | for (int value = 0; value < valueCount; value++) { 37 | out.print(treeslice.getID()+ ".dates" + (value + 1) + "\t"); 38 | 39 | } 40 | } 41 | } 42 | 43 | @Override 44 | public void log(long sample, PrintStream out) { 45 | final TreeSlicer treeslice = treeSliceInput.get(); 46 | 47 | final int values = treeslice.getDimension(); 48 | for (int value = 0; value < values; value++) { 49 | out.print(treeslice.heightToDate(treeslice.getValue(value)) + "\t"); 50 | } 51 | } 52 | 53 | @Override 54 | public void close(PrintStream out) { 55 | // nothing to do 56 | } 57 | 58 | @Override 59 | public int getDimension() { 60 | final TreeSlicer treeslice = treeSliceInput.get(); 61 | return treeslice.getDimension(); 62 | } 63 | 64 | // Remember to convert height to date! 65 | @Override 66 | public double getArrayValue() { 67 | final TreeSlicer treeslice = treeSliceInput.get(); 68 | return treeslice.heightToDate(treeslice.getArrayValue()); 69 | } 70 | 71 | // Remember to convert height to date! 72 | @Override 73 | public double getArrayValue(int dim) { 74 | final TreeSlicer treeslice = treeSliceInput.get(); 75 | return treeslice.heightToDate(treeslice.getArrayValue(dim)); 76 | } 77 | 78 | 79 | 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/skylinetools/util/TreeSlicer.java: -------------------------------------------------------------------------------- 1 | package skylinetools.util; 2 | 3 | import beast.core.*; 4 | import beast.core.parameter.Parameter; 5 | import beast.core.parameter.RealParameter; 6 | import beast.evolution.tree.Node; 7 | import beast.evolution.tree.Tree; 8 | import beast.util.HeapSort; 9 | 10 | import java.util.ArrayList; 11 | import java.util.Arrays; 12 | import java.util.List; 13 | 14 | 15 | /** 16 | * Base TreeSlicer class 17 | * 18 | * Equidistant slices between present and an anchor point on the tree. 19 | * 20 | * Input dates always have dimension one less than the treeslicer itself (unless the last date is equal to the most recent tip). 21 | * (Since the last value in the slice has to be 0 (i.e. the most recent tip in the tree). 22 | * 23 | * 24 | * @author Louis du Plessis 25 | * Date: 2018/02/12 26 | * 27 | */ 28 | public class TreeSlicer extends RealParameter { 29 | 30 | public Input treeInput = 31 | new Input<>("tree", "Tree over which to calculate the slice", Input.Validate.REQUIRED); 32 | 33 | public Input toInput = 34 | new Input<>("to", "Anchor point to stop the slicing intervals (tmrca/oldestsample)", "tmrca"); 35 | 36 | public Input inclusiveInput = 37 | new Input<>("inclusive", "Include the final anchor point (to criterion) in the vector",true); 38 | 39 | 40 | 41 | /* Anchor times on the tree */ 42 | protected enum Anchor { 43 | 44 | PRESENT, // The present, or the time of the most recent sample, should be at height 0.0 45 | OLDESTSAMPLE, // The height of the oldest sample in the tree, 0 <= OLDESTSAMPLE <= TMRCA 46 | TMRCA; // The height of the tree (tMRCA) 47 | 48 | 49 | private double height, date; 50 | 51 | public double getHeight() { return this.height; } 52 | 53 | public double getDate() { return this.date; } 54 | 55 | 56 | /** 57 | * Update anchor times in the tree 58 | * 59 | * O(n) for n nodes 60 | * 61 | * Use getNodesAsArray() instead of getExternalNodes() because it only passes a pointer whereas getExterNodes() 62 | * requires constructing an ArrayList (so it is O(n) plus a lot of extra memory operations). 63 | * 64 | * Unfortunately tree.somethingIsDirty() does NOT appear to work to indicate if anchor times would have changed or 65 | * not, so this MUST be recalculated every time the times are updated. 66 | * 67 | * @param tree 68 | */ 69 | public static void update(Tree tree) { 70 | 71 | final double EPS = 1e-7; 72 | 73 | double height; 74 | 75 | TMRCA.height = tree.getRoot().getHeight(); 76 | TMRCA.date = tree.getRoot().getDate(); 77 | 78 | // This next part should only be necessary when tipdates are sampled (How can this be checked?) 79 | // May be optimised by skipping the first n-1 nodes, but this way is very secure, though slightly slower 80 | OLDESTSAMPLE.height = 0; 81 | PRESENT.height = TMRCA.height; 82 | for (Node N : tree.getNodesAsArray()) { 83 | if (N.isLeaf()) { 84 | height = N.getHeight(); 85 | 86 | if (height > OLDESTSAMPLE.height) { 87 | // Need to adjust so BDSKY likelihood nonzero 88 | OLDESTSAMPLE.height = height+EPS; 89 | OLDESTSAMPLE.date = N.getDate(); 90 | } 91 | 92 | if (height < PRESENT.height) { 93 | PRESENT.height = height; 94 | PRESENT.date = N.getDate(); 95 | } 96 | } 97 | } 98 | 99 | } 100 | 101 | } 102 | /* End Anchor times */ 103 | 104 | 105 | protected Tree tree; 106 | protected Anchor stop; 107 | protected boolean inclusive; 108 | protected boolean timesKnown; 109 | 110 | 111 | // Override input rule of RealParameter (base class) 112 | public TreeSlicer() { 113 | valuesInput.setRule(Input.Validate.OPTIONAL); 114 | } 115 | 116 | @Override 117 | public void initAndValidate() { 118 | 119 | int dimension; 120 | String stopStr; 121 | 122 | /* Read tree */ 123 | tree = treeInput.get(); 124 | Anchor.update(tree); 125 | 126 | 127 | /* Read dimension of the slice */ 128 | dimension = dimensionInput.get(); 129 | 130 | 131 | /* Read to input (where to end slice) */ 132 | if (toInput.get() != null) 133 | stopStr = toInput.get().toUpperCase().trim(); 134 | else 135 | stopStr = "TMRCA"; 136 | 137 | stop = null; 138 | for (Anchor a : Anchor.values()) { 139 | if (Anchor.valueOf(stopStr) == a) { 140 | stop = a; 141 | } 142 | } 143 | if (stop == null) { 144 | throw new IllegalArgumentException("Error in "+this.getID()+": Unknown anchor point ("+stopStr+") for to input."); 145 | } 146 | 147 | 148 | /* Include the final anchor point as a breakpoint */ 149 | inclusive = inclusiveInput.get(); 150 | 151 | 152 | /* Initialise arrays */ 153 | values = new Double[dimension]; 154 | storedValues = new Double[dimension]; 155 | calculateTimes(tree); 156 | // System.out.println(this.ID+"\t"+this.getDimension()); 157 | 158 | 159 | // Initialization accounting (not really used) 160 | // Don't want to use super.initAndValidate() because we're doing something else with the values 161 | // m_fLower = Double.NEGATIVE_INFINITY; 162 | m_fLower = 0.0; // Height cannot be negative 163 | m_fUpper = Double.POSITIVE_INFINITY; 164 | m_bIsDirty = new boolean[dimensionInput.get()]; 165 | minorDimension = minorDimensionInput.get(); 166 | if (minorDimension > 0 && dimensionInput.get() % minorDimension > 0) { 167 | throw new IllegalArgumentException("Error in "+this.getID()+": Dimension must be divisible by stride"); 168 | } 169 | this.storedValues = values.clone(); 170 | 171 | timesKnown = false; 172 | } 173 | 174 | 175 | 176 | /* Methods should only be called after anchor times have been updated */ 177 | 178 | protected double dateToHeight(double date) { 179 | Anchor.update(tree); 180 | return (Anchor.PRESENT.getDate() - date); 181 | } 182 | 183 | protected double heightToDate(double height) { 184 | Anchor.update(tree); 185 | return (Anchor.PRESENT.getDate() - height); 186 | } 187 | 188 | 189 | /** 190 | * Update the slice times 191 | * 192 | * Unfortunately tree.somethingIsDirty() does NOT appear to work to indicate if anchor times have changed so 193 | * updateAnchortimes() MUST be called. 194 | * 195 | * @param tree 196 | */ 197 | protected void calculateTimes(Tree tree) { 198 | 199 | double endTime, stepSize; 200 | 201 | /* Update anchor times */ 202 | Anchor.update(tree); 203 | //for (Anchor a : Anchor.values()) { 204 | // System.out.println(a.toString()+"\t"+a.getHeight()+"\t"+a.getDate()); 205 | //} 206 | 207 | endTime = stop.getHeight(); 208 | if (inclusive) 209 | stepSize = endTime / (getDimension() - 1); 210 | else 211 | stepSize = endTime / (getDimension()); 212 | 213 | 214 | for (int i = 0; i < getDimension(); i++) { 215 | values[i] = i * stepSize; 216 | } 217 | 218 | timesKnown = true; 219 | } 220 | 221 | 222 | @Override 223 | protected boolean requiresRecalculation() { 224 | // Tree is a stateNode so should always use somethingIsDirty() and NOT isDirtyCalculation! 225 | //System.out.println("Checking recalculation "+this.ID+" "+tree.isDirtyCalculation()+" "+tree.somethingIsDirty()); 226 | timesKnown = false; 227 | return true; 228 | //return tree.somethingIsDirty(); 229 | } 230 | 231 | 232 | /* Override methods to make sure times get recalculated whenever times are accessed */ 233 | 234 | @Override 235 | public Double getValue() { 236 | if (!timesKnown) { 237 | calculateTimes(tree); 238 | } 239 | return values[0]; 240 | } 241 | 242 | @Override 243 | public Double getValue(final int index) { 244 | if (!timesKnown) { 245 | calculateTimes(tree); 246 | } 247 | return values[index]; 248 | } 249 | 250 | @Override 251 | public double getArrayValue() { 252 | if (!timesKnown) { 253 | calculateTimes(tree); 254 | } 255 | return values[0]; 256 | } 257 | 258 | @Override 259 | public double getArrayValue(final int index) { 260 | if (!timesKnown) { 261 | calculateTimes(tree); 262 | } 263 | return values[index]; 264 | } 265 | 266 | @Override 267 | public Double [] getValues() { 268 | if (!timesKnown) { 269 | calculateTimes(tree); 270 | } 271 | return Arrays.copyOf(values, values.length); 272 | } 273 | 274 | } 275 | -------------------------------------------------------------------------------- /test/README.md: -------------------------------------------------------------------------------- 1 | # Tests 2 | 3 | Tests implemented 4 | 5 | 6 | ## TreeSlicer 7 | - Check on two fixed trees of tractable size that slices are correct. 8 | 9 | 10 | ## OUPrior 11 | 12 | - Likelihood of single point calculated correctly 13 | - Likelihood of trajectory calculated correctly (all values equal) 14 | - Likelihood of trajectory calculated correctly (different values) 15 | 16 | 17 | ## RealParameterSequence 18 | - Using by input with different positive and negative increments 19 | - Using dimension input with positive and negative increments 20 | 21 | 22 | --- 23 | _Louis du Plessis, 2018_ -------------------------------------------------------------------------------- /test/beast/evolution/speciation/SkylineTimesTest.java: -------------------------------------------------------------------------------- 1 | package beast.evolution.speciation; 2 | 3 | import beast.core.parameter.BooleanParameter; 4 | import beast.core.parameter.RealParameter; 5 | import beast.evolution.speciation.BirthDeathSkylineModelTestHelper; 6 | import beast.evolution.tree.Tree; 7 | import beast.util.TreeParser; 8 | import org.junit.Test; 9 | import junit.framework.TestCase; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * This test is to check how bdsky (beast.evolution.speciation.BirthDeathSkylineModel) sets change-point times, depending 15 | * on the input. 16 | * 17 | * There are 5 different ways to set the change-point times: 18 | * 19 | * 1.) Equally spaced between origin and present 20 | * 21 | * 2.) Time from the origin to the present: 22 | * a) Absolute times (in the same units as the tree branches) 23 | * b) Relative times (between 0 and 1) 24 | * 25 | * 3.) Time from the present to the origin (reverse-time): 26 | * a) Absolute times (in the same units as the tree branches) 27 | * b) Relative times (between 0 and 1) 28 | * 29 | * The bdsky package itself never tests that this actually works in the expected way. 30 | * 31 | * 32 | * Created by dlouis on 06/04/16. 33 | */ 34 | public class SkylineTimesTest extends TestCase { 35 | 36 | 37 | /* 38 | * Tree used simulated by: 39 | * 40 | * library(TreeSim) 41 | * set.seed(1) 42 | * tree <- sim.bd.taxa(n=10, numbsim=1, lambda=2, mu=0.5, frac=1, complete=FALSE, stochsampling=TRUE) 43 | * 44 | * Tree MRCA = 2.55557351 45 | * 46 | */ 47 | 48 | 49 | /** 50 | * Expect (1, 2, 3, 4, 5.0) 51 | * 52 | * 53 | * @throws Exception 54 | */ 55 | @Test 56 | public void testSkylineTimesEquallySpaced() throws Exception { 57 | 58 | Tree tree = new TreeParser(); 59 | 60 | tree.initByName("newick", "(((((t8:0.7222085766,(t5:0.04762441103,t1:0.6054274304):0.6506888754):0.5517904073,(t2:0.514380477,t10:0.4632931469):0.5324084692):0.3951336571,t6:0.7816201891):0.3005419225,t4:0.1858745544):0.05199122007,((t7:0.1588048418,t9:0.03676356945):0.5750080554,t3:1.336592522):0.02329921031):0.2517272777;", 61 | "IsLabelledNewick", true, "adjustTipHeights", false); 62 | 63 | BirthDeathSkylineModelTestHelper bdsky = new BirthDeathSkylineModelTestHelper(); 64 | 65 | RealParameter origin = new RealParameter("5"); 66 | RealParameter Re = new RealParameter("1 1 1 1 1"); 67 | RealParameter delta = new RealParameter("1 1 1 1 1"); 68 | RealParameter s = new RealParameter("1 1 1 1 1"); 69 | BooleanParameter reverse = new BooleanParameter("true true true true true"); 70 | 71 | 72 | bdsky.initByName("tree", tree, "origin", origin, 73 | "reproductiveNumber", Re, "becomeUninfectiousRate", delta, "samplingProportion", s, "reverseTimeArrays", reverse); 74 | 75 | List birthRateTimes = bdsky.getBirthRateChangeTimes(); 76 | double [] expected = new double [] {1, 2, 3, 4, 5.0}; 77 | int i = 0; 78 | for (Double t : birthRateTimes) { 79 | //System.out.println(t); 80 | assertEquals(t, expected[i]); 81 | i++; 82 | } 83 | 84 | //double logP = bdsky.calculateTreeLogLikelihood(tree); 85 | } 86 | 87 | 88 | /** 89 | * Expect (1.0, 2.0, 3.0, 4.0, 5.0) 90 | * 91 | * 92 | * @throws Exception 93 | */ 94 | @Test 95 | public void testSkylineTimesRelative() throws Exception { 96 | 97 | Tree tree = new TreeParser(); 98 | 99 | tree.initByName("newick", "(((((t8:0.7222085766,(t5:0.04762441103,t1:0.6054274304):0.6506888754):0.5517904073,(t2:0.514380477,t10:0.4632931469):0.5324084692):0.3951336571,t6:0.7816201891):0.3005419225,t4:0.1858745544):0.05199122007,((t7:0.1588048418,t9:0.03676356945):0.5750080554,t3:1.336592522):0.02329921031):0.2517272777;", 100 | "IsLabelledNewick", true, "adjustTipHeights", false); 101 | 102 | BirthDeathSkylineModelTestHelper bdsky = new BirthDeathSkylineModelTestHelper(); 103 | 104 | RealParameter origin = new RealParameter("5"); 105 | RealParameter Re = new RealParameter("1 1 1 1 1"); 106 | RealParameter delta = new RealParameter("1 1 1 1 1"); 107 | RealParameter s = new RealParameter("1 1 1 1 1"); 108 | RealParameter birthtimes = new RealParameter("0.0 0.2 0.4 0.6 0.8"); 109 | BooleanParameter reverse = new BooleanParameter("false false false false false"); 110 | 111 | bdsky.initByName("tree", tree, "origin", origin, 112 | "reproductiveNumber", Re, "becomeUninfectiousRate", delta, "samplingProportion", s, 113 | "birthRateTimesRelative", true, "birthRateChangeTimes", birthtimes, 114 | "reverseTimeArrays", reverse); 115 | 116 | List birthRateTimes = bdsky.getBirthRateChangeTimes(); 117 | double [] expected = new double [] {1.0, 2.0, 3.0, 4.0, 5.0}; 118 | int i = 0; 119 | for (Double t : birthRateTimes) { 120 | //System.out.println(t); 121 | assertEquals(t, expected[i]); 122 | i++; 123 | } 124 | 125 | //double logP = bdsky.calculateTreeLogLikelihood(tree); 126 | } 127 | 128 | /** 129 | * Expect (0.2, 0.4, 0.6, 0.8, 5.0) 130 | * 131 | * 132 | * @throws Exception 133 | */ 134 | @Test 135 | public void testSkylineTimes() throws Exception { 136 | 137 | Tree tree = new TreeParser(); 138 | 139 | tree.initByName("newick", "(((((t8:0.7222085766,(t5:0.04762441103,t1:0.6054274304):0.6506888754):0.5517904073,(t2:0.514380477,t10:0.4632931469):0.5324084692):0.3951336571,t6:0.7816201891):0.3005419225,t4:0.1858745544):0.05199122007,((t7:0.1588048418,t9:0.03676356945):0.5750080554,t3:1.336592522):0.02329921031):0.2517272777;", 140 | "IsLabelledNewick", true, "adjustTipHeights", false); 141 | 142 | BirthDeathSkylineModelTestHelper bdsky = new BirthDeathSkylineModelTestHelper(); 143 | 144 | RealParameter origin = new RealParameter("5"); 145 | RealParameter Re = new RealParameter("1 1 1 1 1"); 146 | RealParameter delta = new RealParameter("1 1 1 1 1"); 147 | RealParameter s = new RealParameter("1 1 1 1 1"); 148 | RealParameter birthtimes = new RealParameter("0 0.2 0.4 0.6 0.8"); 149 | BooleanParameter reverse = new BooleanParameter("false false false false false"); 150 | 151 | 152 | bdsky.initByName("tree", tree, "origin", origin, 153 | "reproductiveNumber", Re, "becomeUninfectiousRate", delta, "samplingProportion", s, 154 | "birthRateTimesRelative", false, "birthRateChangeTimes", birthtimes, 155 | "reverseTimeArrays", reverse); 156 | 157 | List birthRateTimes = bdsky.getBirthRateChangeTimes(); 158 | double [] expected = new double [] {0.2, 0.4, 0.6, 0.8, 5.0}; 159 | int i = 0; 160 | for (Double t : birthRateTimes) { 161 | //System.out.println(t); 162 | assertEquals(t, expected[i]); 163 | i++; 164 | } 165 | 166 | } 167 | 168 | 169 | /** 170 | * Expect (1.0, 2.0, 3.0, 4.0, 5.0) 171 | * 172 | * 173 | * @throws Exception 174 | */ 175 | @Test 176 | public void testSkylineTimesRelativeReverse() throws Exception { 177 | 178 | Tree tree = new TreeParser(); 179 | 180 | tree.initByName("newick", "(((((t8:0.7222085766,(t5:0.04762441103,t1:0.6054274304):0.6506888754):0.5517904073,(t2:0.514380477,t10:0.4632931469):0.5324084692):0.3951336571,t6:0.7816201891):0.3005419225,t4:0.1858745544):0.05199122007,((t7:0.1588048418,t9:0.03676356945):0.5750080554,t3:1.336592522):0.02329921031):0.2517272777;", 181 | "IsLabelledNewick", true, "adjustTipHeights", false); 182 | 183 | BirthDeathSkylineModelTestHelper bdsky = new BirthDeathSkylineModelTestHelper(); 184 | 185 | RealParameter origin = new RealParameter("5"); 186 | RealParameter Re = new RealParameter("1 1 1 1 1"); 187 | RealParameter delta = new RealParameter("1 1 1 1 1"); 188 | RealParameter s = new RealParameter("1 1 1 1 1"); 189 | RealParameter birthtimes = new RealParameter("0 0.2 0.4 0.6 0.8"); 190 | BooleanParameter reverse = new BooleanParameter("true true true true true"); 191 | 192 | 193 | bdsky.initByName("tree", tree, "origin", origin, 194 | "reproductiveNumber", Re, "becomeUninfectiousRate", delta, "samplingProportion", s, 195 | "birthRateTimesRelative", true, "birthRateChangeTimes", birthtimes, 196 | "reverseTimeArrays", reverse); 197 | 198 | List birthRateTimes = bdsky.getBirthRateChangeTimes(); 199 | double [] expected = new double [] {1.0, 2.0, 3.0, 4.0, 5.0}; 200 | int i = 0; 201 | for (Double t : birthRateTimes) { 202 | //System.out.println(t); 203 | assertEquals(t, expected[i], 1E-4); 204 | i++; 205 | } 206 | 207 | } 208 | 209 | 210 | /** 211 | * Expect (4.2, 4.4, 4.6, 4.8, 5.0) 212 | * 213 | * 214 | * @throws Exception 215 | */ 216 | @Test 217 | public void testSkylineTimesReverse() throws Exception { 218 | 219 | Tree tree = new TreeParser(); 220 | 221 | tree.initByName("newick", "(((((t8:0.7222085766,(t5:0.04762441103,t1:0.6054274304):0.6506888754):0.5517904073,(t2:0.514380477,t10:0.4632931469):0.5324084692):0.3951336571,t6:0.7816201891):0.3005419225,t4:0.1858745544):0.05199122007,((t7:0.1588048418,t9:0.03676356945):0.5750080554,t3:1.336592522):0.02329921031):0.2517272777;", 222 | "IsLabelledNewick", true, "adjustTipHeights", false); 223 | 224 | BirthDeathSkylineModelTestHelper bdsky = new BirthDeathSkylineModelTestHelper(); 225 | 226 | RealParameter origin = new RealParameter("5"); 227 | RealParameter Re = new RealParameter("1 1 1 1 1"); 228 | RealParameter delta = new RealParameter("1 1 1 1 1"); 229 | RealParameter s = new RealParameter("1 1 1 1 1"); 230 | RealParameter birthtimes = new RealParameter("0 0.2 0.4 0.6 0.8"); 231 | BooleanParameter reverse = new BooleanParameter("true true true true true"); 232 | 233 | 234 | bdsky.initByName("tree", tree, "origin", origin, 235 | "reproductiveNumber", Re, "becomeUninfectiousRate", delta, "samplingProportion", s, 236 | "birthRateTimesRelative", false, "birthRateChangeTimes", birthtimes, 237 | "reverseTimeArrays", reverse); 238 | 239 | List birthRateTimes = bdsky.getBirthRateChangeTimes(); 240 | double [] expected = new double [] {4.2, 4.4, 4.6, 4.8, 5.0}; 241 | int i = 0; 242 | for (Double t : birthRateTimes) { 243 | System.out.println(t); 244 | assertEquals(t, expected[i]); 245 | i++; 246 | } 247 | 248 | //double logP = bdsky.calculateTreeLogLikelihood(tree); 249 | } 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | } 261 | -------------------------------------------------------------------------------- /test/skylinetools/distributions/OUPriorLkTest.java: -------------------------------------------------------------------------------- 1 | package skylinetools.distributions; 2 | 3 | import beast.core.parameter.RealParameter; 4 | import junit.framework.TestCase; 5 | import org.junit.Test; 6 | import skylinetools.distributions.OUPrior; 7 | import test.beast.BEASTTestCase; 8 | 9 | /** 10 | * @author Louis du Plessis 11 | * Date: 2018/07/09 12 | */ 13 | public class OUPriorLkTest extends TestCase { 14 | 15 | 16 | /** 17 | * Test that log-likelihood is calculated correctly for a single point 18 | */ 19 | @Test 20 | public void testCalculateLogPSingle1() { 21 | 22 | System.out.println("OUPrior log-likelihood (single point 1)"); 23 | 24 | // Parameters of the OU-process 25 | RealParameter x = new RealParameter(); 26 | RealParameter t = new RealParameter(); 27 | RealParameter mu = new RealParameter(); 28 | RealParameter sigma = new RealParameter(); 29 | RealParameter nu = new RealParameter(); 30 | 31 | // Initialise values 32 | x.initByName("value","3.0 1.0"); 33 | t.initByName("value","0.0 1.0"); 34 | mu.initByName("value","1"); 35 | sigma.initByName("value","1"); 36 | nu.initByName("value","5"); 37 | 38 | // Set up OUPrior instance and evaluate likelihood 39 | OUPrior likelihood = new OUPrior(); 40 | likelihood.initByName("x",x,"times",t,"mean",mu,"sigma",sigma,"nu",nu); 41 | 42 | double expected = 1.150407; // Calculated in R 43 | double result = likelihood.calculateLogP(); 44 | 45 | System.out.println(expected+"\t"+result); 46 | assertEquals(expected, result, BEASTTestCase.PRECISION); 47 | } 48 | 49 | 50 | /** 51 | * Test that log-likelihood is calculated correctly for a trajectory of points (all equal) 52 | */ 53 | @Test 54 | public void testCalculateLogPTrajectory1() { 55 | 56 | System.out.println("OUPrior log-likelihood test (trajectory 1: all equal)"); 57 | 58 | // Parameters of the OU-process 59 | RealParameter x = new RealParameter(); 60 | RealParameter t = new RealParameter(); 61 | RealParameter mu = new RealParameter(); 62 | RealParameter sigma = new RealParameter(); 63 | RealParameter nu = new RealParameter(); 64 | 65 | // Initialise values 66 | x.initByName("value","5.0","dimension","11"); 67 | t.initByName("value","0 1 2 3 4 5 6 7 8 9 10"); 68 | mu.initByName("value","5"); 69 | sigma.initByName("value","1"); 70 | nu.initByName("value","2"); 71 | 72 | // Set up OUPrior instance and evaluate likelihood 73 | OUPrior likelihood = new OUPrior(); 74 | likelihood.initByName("x",x,"times",t,"mean",mu,"sigma",sigma,"nu",nu); 75 | 76 | double expected = 7.02389903972889; // Calculated in R 77 | double result = likelihood.calculateLogP(); 78 | 79 | System.out.println(expected+"\t"+result); 80 | assertEquals(expected, result, BEASTTestCase.PRECISION); 81 | } 82 | 83 | /** 84 | * Test that log-likelihood is calculated correctly for a trajectory of points (not all equal) 85 | */ 86 | @Test 87 | public void testCalculateLogPTrajectory2() { 88 | 89 | System.out.println("OUPrior log-likelihood test (trajectory 2: evolving)"); 90 | 91 | // Parameters of the OU-process 92 | RealParameter x = new RealParameter(); 93 | RealParameter t = new RealParameter(); 94 | RealParameter mu = new RealParameter(); 95 | RealParameter sigma = new RealParameter(); 96 | RealParameter nu = new RealParameter(); 97 | 98 | // Initialise values 99 | x.initByName("value","10 9 8 7 6 5 5 5 5 6 5"); 100 | t.initByName("value","0 1 2 3 4 5 6 7 8 9 10"); 101 | mu.initByName("value","5"); 102 | sigma.initByName("value","1"); 103 | nu.initByName("value","2"); 104 | 105 | // Set up OUPrior instance and evaluate likelihood 106 | OUPrior likelihood = new OUPrior(); 107 | likelihood.initByName("x",x,"times",t,"mean",mu,"sigma",sigma,"nu",nu); 108 | 109 | double expected = -36.1648364818251; // Calculated in R 110 | double result = likelihood.calculateLogP(); 111 | 112 | System.out.println(expected+"\t"+result); 113 | assertEquals(expected, result, BEASTTestCase.PRECISION); 114 | } 115 | 116 | /** 117 | * Test that log-likelihood is calculated correctly for a trajectory of points (not all equal + times normalised) 118 | */ 119 | @Test 120 | public void testCalculateLogPTrajectory3() { 121 | 122 | System.out.println("OUPrior log-likelihood test (trajectory 3: evolving + times normalised)"); 123 | 124 | // Parameters of the OU-process 125 | RealParameter x = new RealParameter(); 126 | RealParameter t = new RealParameter(); 127 | RealParameter mu = new RealParameter(); 128 | RealParameter sigma = new RealParameter(); 129 | RealParameter nu = new RealParameter(); 130 | 131 | // Initialise values 132 | x.initByName("value","10 9 8 7 6 5 5 5 5 6 5"); 133 | t.initByName("value","0 1 2 3 4 5 6 7 8 9 10"); 134 | mu.initByName("value","5"); 135 | sigma.initByName("value","1"); 136 | nu.initByName("value","2"); 137 | 138 | // Set up OUPrior instance and evaluate likelihood 139 | OUPrior likelihood = new OUPrior(); 140 | likelihood.initByName("x",x,"times",t,"mean",mu,"sigma",sigma,"nu",nu,"normalize","true"); 141 | 142 | double expected = -5.95923005052868; // Calculated in R 143 | double result = likelihood.calculateLogP(); 144 | 145 | System.out.println(expected+"\t"+result); 146 | assertEquals(expected, result, BEASTTestCase.PRECISION); 147 | } 148 | 149 | } -------------------------------------------------------------------------------- /test/skylinetools/parameter/DateParserTest.java: -------------------------------------------------------------------------------- 1 | package skylinetools.parameter; 2 | 3 | import junit.framework.TestCase; 4 | import org.junit.Test; 5 | import skylinetools.parameter.DateParser; 6 | import test.beast.BEASTTestCase; 7 | 8 | 9 | /** 10 | * @author Louis du Plessis 11 | * Date: 2018/12/28 12 | */ 13 | public class DateParserTest extends TestCase { 14 | 15 | @Test 16 | public void testDateParser1() { 17 | 18 | System.out.println("DateParser: Dates in different formats"); 19 | 20 | DateParser parser1 = new DateParser(), 21 | parser2 = new DateParser(), 22 | parser3 = new DateParser(); 23 | 24 | parser1.initByName("dates","10/02/2005 22/02/2000 15/11/1999 01/01/2004 31/12/2004 01/01/2015 31/12/2015","format","dd/MM/yyyy"); 25 | parser2.initByName("dates", "10-Feb-2005 22-Feb-2000 15-Nov-1999 1-Jan-2004 31-Dec-2004 1-Jan-2015 31-Dec-2015", "format","d-MMM-yyyy"); 26 | parser3.initByName("dates", " 2005.1095890411 2000.1420765027 1999.8712328767 2004.0000000000 2004.9972677596 2015.0000000000 2015.9972602740"); 27 | 28 | Double [] values1 = parser1.getValues(); 29 | Double [] values2 = parser2.getValues(); 30 | Double [] values3 = parser3.getValues(); 31 | Double [] expected = {2005.1095890411, 2000.1420765027, 1999.8712328767, 2004.0000000000, 32 | 2004.9972677596, 2015.0000000000, 2015.9972602740}; 33 | 34 | for (int i = 0; i < values2.length; i++) { 35 | assertEquals(expected[i], values1[i], BEASTTestCase.PRECISION); 36 | assertEquals(expected[i], values2[i], BEASTTestCase.PRECISION); 37 | assertEquals(expected[i], values3[i], BEASTTestCase.PRECISION); 38 | } 39 | //System.out.println(Arrays.toString(values1)); 40 | //System.out.println(Arrays.toString(values2)); 41 | //System.out.println(Arrays.toString(values3)); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /test/skylinetools/parameter/RealParameterSequenceTest.java: -------------------------------------------------------------------------------- 1 | package skylinetools.parameter; 2 | 3 | 4 | import junit.framework.TestCase; 5 | import org.junit.Test; 6 | import skylinetools.parameter.RealParameterSequence; 7 | import test.beast.BEASTTestCase; 8 | 9 | /** 10 | * @author Louis du Plessis 11 | * Date: 2018/07/17 12 | */ 13 | public class RealParameterSequenceTest extends TestCase { 14 | 15 | @Test 16 | public void testSeqBy1() { 17 | 18 | System.out.println("Test sequence from 5 to 15 with integer increments"); 19 | 20 | RealParameterSequence seq = new RealParameterSequence(); 21 | seq.initByName("from","5","to","15","by","1"); 22 | 23 | double [] vals = seq.getDoubleValues(), 24 | expected = {5,6,7,8,9,10,11,12,13,14,15}; 25 | 26 | // Check dimension 27 | assertEquals(expected.length, seq.getDimension()); 28 | 29 | // Check values 30 | for (int i = 0; i < vals.length; i++) { 31 | assertEquals(expected[i], vals[i]); 32 | } 33 | } 34 | 35 | @Test 36 | public void testSeqBy2() { 37 | 38 | System.out.println("Test sequence from 5 to 15 with integer increments (non-divisible)"); 39 | 40 | RealParameterSequence seq = new RealParameterSequence(); 41 | seq.initByName("from","5","to","15","by","4"); 42 | 43 | double [] vals = seq.getDoubleValues(), 44 | expected = {5,9,13}; 45 | 46 | // Check dimension 47 | assertEquals(expected.length, seq.getDimension()); 48 | assertEquals(expected.length, vals.length); 49 | 50 | 51 | // Check values 52 | for (int i = 0; i < vals.length; i++) { 53 | assertEquals(expected[i], vals[i]); 54 | } 55 | } 56 | 57 | @Test 58 | public void testSeqBy3() { 59 | 60 | System.out.println("Test sequence from 1 to 0 with negative increments"); 61 | 62 | RealParameterSequence seq = new RealParameterSequence(); 63 | seq.initByName("from","1","to","0","by","-0.1"); 64 | 65 | double [] vals = seq.getDoubleValues(), 66 | expected = {1, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0.0}; 67 | 68 | // Check dimension 69 | assertEquals(expected.length, seq.getDimension()); 70 | assertEquals(expected.length, vals.length); 71 | 72 | 73 | // Check values 74 | for (int i = 0; i < vals.length; i++) { 75 | assertEquals(expected[i], vals[i], BEASTTestCase.PRECISION); 76 | } 77 | } 78 | 79 | @Test 80 | public void testSeqBy4() { 81 | 82 | System.out.println("Test sequence from 1 to 0 with negative increments (non-divisible)"); 83 | 84 | RealParameterSequence seq = new RealParameterSequence(); 85 | seq.initByName("from","1","to","0","by","-0.3"); 86 | 87 | double [] vals = seq.getDoubleValues(), 88 | expected = {1, 0.7, 0.4, 0.1}; 89 | 90 | // Check dimension 91 | assertEquals(expected.length, seq.getDimension()); 92 | assertEquals(expected.length, vals.length); 93 | 94 | // Check values 95 | for (int i = 0; i < vals.length; i++) { 96 | assertEquals(expected[i], vals[i], BEASTTestCase.PRECISION); 97 | } 98 | } 99 | 100 | 101 | 102 | @Test 103 | public void testSeqLength1() { 104 | 105 | System.out.println("Test sequence from 5 to 15 with length 11"); 106 | 107 | RealParameterSequence seq = new RealParameterSequence(); 108 | seq.initByName("from","5","to","15","dimension","11"); 109 | 110 | double [] vals = seq.getDoubleValues(), 111 | expected = {5,6,7,8,9,10,11,12,13,14,15}; 112 | 113 | // Check dimension 114 | assertEquals(expected.length, seq.getDimension()); 115 | 116 | // Check values 117 | for (int i = 0; i < vals.length; i++) { 118 | assertEquals(expected[i], vals[i]); 119 | } 120 | } 121 | 122 | @Test 123 | public void testSeqLength2() { 124 | 125 | System.out.println("Test sequence from 5.5 to 14.3 with length 3"); 126 | 127 | RealParameterSequence seq = new RealParameterSequence(); 128 | seq.initByName("from","5.5","to","14.3","dimension","3"); 129 | 130 | double [] vals = seq.getDoubleValues(), 131 | expected = {5.5, 9.9, 14.3}; 132 | 133 | // Check dimension 134 | assertEquals(expected.length, seq.getDimension()); 135 | 136 | // Check values 137 | for (int i = 0; i < vals.length; i++) { 138 | assertEquals(expected[i], vals[i]); 139 | } 140 | } 141 | 142 | @Test 143 | public void testSeqLength3() { 144 | 145 | System.out.println("Test sequence from 10 to 0 with length 5"); 146 | 147 | RealParameterSequence seq = new RealParameterSequence(); 148 | seq.initByName("from","10","to","0","dimension","5"); 149 | 150 | double [] vals = seq.getDoubleValues(), 151 | expected = {10, 7.5, 5, 2.5, 0.0}; 152 | 153 | // Check dimension 154 | assertEquals(expected.length, seq.getDimension()); 155 | 156 | // Check values 157 | for (int i = 0; i < vals.length; i++) { 158 | assertEquals(expected[i], vals[i]); 159 | } 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /test/skylinetools/util/TreeDateSlicerTest.java: -------------------------------------------------------------------------------- 1 | package skylinetools.util; 2 | 3 | import beast.evolution.alignment.Taxon; 4 | import beast.evolution.alignment.TaxonSet; 5 | import beast.evolution.tree.TraitSet; 6 | import beast.evolution.tree.Tree; 7 | import beast.util.TreeParser; 8 | import junit.framework.TestCase; 9 | import org.junit.Test; 10 | import skylinetools.parameter.DateParser; 11 | import test.beast.BEASTTestCase; 12 | 13 | import java.util.ArrayList; 14 | import java.util.Arrays; 15 | import java.util.List; 16 | 17 | /** 18 | * @author Louis du Plessis 19 | * Date: 2018/07/10 20 | */ 21 | public class TreeDateSlicerTest extends TestCase { 22 | 23 | @Test 24 | public void testSliceTMRCA1() { 25 | 26 | System.out.println("TreeDateSlicer: Slice at specific years (tree 1)"); 27 | 28 | 29 | 30 | String [] taxa = {"D4Philip56", 31 | "D4Philip64", 32 | "D4Philip84", 33 | "D4SLanka78", 34 | "D4Thai78", 35 | "D4Thai84"}; 36 | List taxalist = Taxon.createTaxonList(new ArrayList(Arrays.asList(taxa))); 37 | Tree tree = new TreeParser(); 38 | TaxonSet taxonSet = new TaxonSet(taxalist); 39 | TraitSet dateTrait = new TraitSet(); 40 | 41 | // Years are not as specified in the names because I modified the trees... 42 | dateTrait.initByName("traitname","date","taxa",taxonSet,"value","D4Philip56=1956,"+ 43 | "D4Philip64=1964,"+ 44 | "D4Philip84=1984,"+ 45 | "D4SLanka78=1978,"+ 46 | "D4Thai78=1978,"+ 47 | "D4Thai84=1984"); 48 | 49 | tree.initByName("newick","((D4Philip56:2.0,(D4Philip64:3.0,D4Philip84:23.0):7.0):10.0,(D4SLanka78:19.0,(D4Thai78:5.0,D4Thai84:11.0):14.0):15.0);", 50 | "adjustTipHeights","false", "trait",dateTrait, "taxonset",taxonSet); 51 | 52 | TreeSlicer treeSlicer = new TreeDateSlicer(); 53 | treeSlicer.initByName("tree",tree,"dates","1950 1965 1970 1980"); 54 | 55 | 56 | /* tmrca = 40 / 1944, most recent tip = 1984 57 | 58 | 4 intervals at 1980, 1970, 1965, 1950: (4, 14, 19, 34) 59 | 60 | */ 61 | 62 | Double [] values = treeSlicer.getValues(); 63 | Double [] expected = {0.0, 4.0, 14.0, 19.0, 34.0}; 64 | 65 | for (int i = 0; i < values.length; i++) { 66 | //System.out.print(values[i]+"\t"); 67 | assertEquals(expected[i], values[i]); 68 | } 69 | //System.out.println(); 70 | } 71 | 72 | 73 | @Test 74 | public void testSliceTMRCA2() { 75 | 76 | System.out.println("TreeDateSlicer: Slice at specific dates as formatted strings (tree 1)"); 77 | 78 | String [] taxa = {"D4Philip56", 79 | "D4Philip64", 80 | "D4Philip84", 81 | "D4SLanka78", 82 | "D4Thai78", 83 | "D4Thai84"}; 84 | List taxalist = Taxon.createTaxonList(new ArrayList(Arrays.asList(taxa))); 85 | Tree tree = new TreeParser(); 86 | TaxonSet taxonSet = new TaxonSet(taxalist); 87 | TraitSet dateTrait = new TraitSet(); 88 | 89 | // Years are not as specified in the names because I modified the trees... 90 | dateTrait.initByName("traitname","date","taxa",taxonSet,"value","D4Philip56=1956,"+ 91 | "D4Philip64=1964,"+ 92 | "D4Philip84=1984,"+ 93 | "D4SLanka78=1978,"+ 94 | "D4Thai78=1978,"+ 95 | "D4Thai84=1984"); 96 | 97 | tree.initByName("newick","((D4Philip56:2.0,(D4Philip64:3.0,D4Philip84:23.0):7.0):10.0,(D4SLanka78:19.0,(D4Thai78:5.0,D4Thai84:11.0):14.0):15.0);", 98 | "adjustTipHeights","false", "trait",dateTrait, "taxonset",taxonSet); 99 | 100 | DateParser dates = new DateParser(); 101 | dates.initByName("dates", "21-Jun-1980 15-Sep-1966", "format", "dd-MMM-yyyy"); 102 | 103 | TreeSlicer treeSlicer = new TreeDateSlicer(); 104 | treeSlicer.initByName("tree",tree,"dates",dates); 105 | 106 | Double [] values = treeSlicer.getValues(); 107 | Double [] expected = {0.0, 3.5300546448088426, 17.29589041095892}; 108 | 109 | for (int i = 0; i < values.length; i++) { 110 | assertEquals(expected[i], values[i]); 111 | } 112 | // System.out.println(Arrays.toString(dates.getValues())); 113 | // System.out.println(Arrays.toString(values)); 114 | } 115 | 116 | 117 | 118 | 119 | 120 | 121 | } 122 | -------------------------------------------------------------------------------- /test/skylinetools/util/TreeSlicerTest.java: -------------------------------------------------------------------------------- 1 | package skylinetools.util; 2 | 3 | import beast.evolution.tree.Tree; 4 | import beast.util.TreeParser; 5 | import junit.framework.TestCase; 6 | import org.junit.Test; 7 | import test.beast.BEASTTestCase; 8 | 9 | /** 10 | * @author Louis du Plessis 11 | * Date: 2018/07/10 12 | */ 13 | public class TreeSlicerTest extends TestCase { 14 | 15 | 16 | /** 17 | * Test slice that divides in equidistant intervals between present and tmrca 18 | */ 19 | @Test 20 | public void testSliceTMRCA1() { 21 | 22 | System.out.println("TreeSlicer: Equidistant between present and tmrca (tree 1)"); 23 | 24 | Tree tree = new TreeParser("((D4Philip56:2.0,(D4Philip64:3.0,D4Philip84:23.0):7.0):10.0,(D4SLanka78:19.0,(D4Thai78:5.0,D4Thai84:11.0):14.0):15.0);",false); 25 | 26 | TreeSlicer treeSlicer = new TreeSlicer(); 27 | treeSlicer.initByName("tree",tree,"to","tmrca","inclusive","false","dimension","4"); 28 | 29 | 30 | /* tmrca = 40 / 1944, most recent tip = 1984 31 | 32 | 4 intervals: 33 | 40/4 = 10.00 34 | (0.0, 10, 20, 30) 35 | */ 36 | 37 | Double [] values = treeSlicer.getValues(); 38 | Double [] expected = {0.0, 10.0, 20.0, 30.0}; 39 | 40 | for (int i = 0; i < values.length; i++) { 41 | //System.out.print(values[i]+"\t"); 42 | assertEquals(expected[i], values[i]); } 43 | //System.out.println(); 44 | } 45 | 46 | /** 47 | * Test slice that divides in equidistant intervals between present and tmrca 48 | */ 49 | @Test 50 | public void testSliceTMRCA2() { 51 | 52 | System.out.println("TreeSlicer: Equidistant between present and tmrca (tree 2)"); 53 | 54 | Tree tree = new TreeParser("((((D4Mexico84:5.0,D4ElSal94:15.0):1.0,D4PRico86:8.0):1.0,D4Tahiti79:2.0):5.0,D4Indon77:5.0);",false); 55 | 56 | TreeSlicer treeSlicer = new TreeSlicer(); 57 | treeSlicer.initByName("tree",tree,"to","tmrca","inclusive","false","dimension","4"); 58 | 59 | /* tmrca = 22 / 1972, most recent tip = 1994 60 | 61 | 4 intervals: 62 | 22/4 = 5.5 63 | (0.0, 5.5, 11, 16.5) 64 | */ 65 | 66 | Double [] values = treeSlicer.getValues(); 67 | Double [] expected = {0.0, 5.5, 11.0, 16.5}; 68 | 69 | for (int i = 0; i < values.length; i++) { 70 | //System.out.print(values[i]+"\t"); 71 | assertEquals(expected[i], values[i]); 72 | } 73 | //System.out.println(); 74 | } 75 | 76 | 77 | /** 78 | * Test slice that divides in equidistant intervals between present and tmrca 79 | * Stop time of the slice is included in the slice 80 | */ 81 | @Test 82 | public void testSliceTMRCAincludeLast1() { 83 | 84 | System.out.println("TreeSlicer: Equidistant between present and tmrca, includeLast (tree 1)"); 85 | 86 | Tree tree = new TreeParser("((D4Philip56:2.0,(D4Philip64:3.0,D4Philip84:23.0):7.0):10.0,(D4SLanka78:19.0,(D4Thai78:5.0,D4Thai84:11.0):14.0):15.0);",false); 87 | 88 | TreeSlicer treeSlicer = new TreeSlicer(); 89 | treeSlicer.initByName("tree",tree,"to","tmrca","inclusive","true","dimension","4"); 90 | 91 | 92 | /* tmrca = 40 / 1944, most recent tip = 1984 93 | 94 | 4 intervals: 95 | 40/3 = 13.334 96 | (0.0, 13.334, 26.667, 40) 97 | */ 98 | 99 | Double [] values = treeSlicer.getValues(); 100 | Double [] expected = {0.0, 13.333333333, 26.666666666, 40.0}; 101 | 102 | for (int i = 0; i < values.length; i++) { 103 | //System.out.print(values[i]+"\t"); 104 | assertEquals(expected[i], values[i], BEASTTestCase.PRECISION); 105 | } 106 | //System.out.println(); 107 | } 108 | 109 | /** 110 | * Test slice that divides in equidistant intervals between present and tmrca 111 | * Stop time of the slice is included in the slice 112 | */ 113 | @Test 114 | public void testSliceTMRCAincludeLast2() { 115 | 116 | System.out.println("TreeSlicer: Equidistant between present and tmrca, includeLast (tree 2)"); 117 | 118 | Tree tree = new TreeParser("((((D4Mexico84:5.0,D4ElSal94:15.0):1.0,D4PRico86:8.0):1.0,D4Tahiti79:2.0):5.0,D4Indon77:5.0);",false); 119 | 120 | TreeSlicer treeSlicer = new TreeSlicer(); 121 | treeSlicer.initByName("tree",tree,"to","tmrca","inclusive","true","dimension","4"); 122 | 123 | /* tmrca = 22 / 1972, most recent tip = 1994 124 | 125 | 4 intervals: 126 | 22/3 = 5.5 127 | (0.0, 7.334, 14.667, 22) 128 | */ 129 | 130 | Double [] values = treeSlicer.getValues(); 131 | Double [] expected = {0.0, 7.333333, 14.6666666, 22.0}; 132 | 133 | for (int i = 0; i < values.length; i++) { 134 | //System.out.print(values[i]+"\t"); 135 | assertEquals(expected[i], values[i], BEASTTestCase.PRECISION); 136 | } 137 | //System.out.println(); 138 | } 139 | 140 | /** 141 | * Test slice that divides in equidistant intervals between present and oldest sample 142 | * Stop time of the slice is included in the slice 143 | */ 144 | @Test 145 | public void testSliceOldestSample1() { 146 | 147 | System.out.println("TreeSlicer: Equidistant between present and oldest sample (tree 1)"); 148 | 149 | Tree tree = new TreeParser("((D4Philip56:2.0,(D4Philip64:3.0,D4Philip84:23.0):7.0):10.0,(D4SLanka78:19.0,(D4Thai78:5.0,D4Thai84:11.0):14.0):15.0);",false); 150 | 151 | TreeSlicer treeSlicer = new TreeSlicer(); 152 | treeSlicer.initByName("tree",tree,"to","oldestSample","inclusive","true","dimension","5"); 153 | 154 | 155 | /* oldest tip = 28 / 1956, most recent tip = 0 / 1984 156 | 157 | 4 intervals: 158 | 28/4 = 7 159 | (0.0, 7, 14, 21, 28) 160 | */ 161 | 162 | Double [] values = treeSlicer.getValues(); 163 | Double [] expected = {0.0, 7.0, 14.0, 21.0, 28.0}; 164 | 165 | for (int i = 0; i < values.length; i++) { 166 | //System.out.print(values[i]+"\t"); 167 | assertEquals(expected[i], values[i], BEASTTestCase.PRECISION); 168 | } 169 | //System.out.println(); 170 | } 171 | 172 | /** 173 | * Test slice that divides in equidistant intervals between present and tmrca 174 | * Stop time of the slice is included in the slice 175 | */ 176 | @Test 177 | public void testSliceOldestSample2() { 178 | 179 | System.out.println("TreeSlicer: Equidistant between present and oldest sample (tree 2)"); 180 | 181 | Tree tree = new TreeParser("((((D4Mexico84:5.0,D4ElSal94:15.0):1.0,D4PRico86:8.0):1.0,D4Tahiti79:2.0):5.0,D4Indon77:5.0);",false); 182 | 183 | TreeSlicer treeSlicer = new TreeSlicer(); 184 | treeSlicer.initByName("tree",tree,"to","oldestSample","inclusive","true","dimension","5"); 185 | 186 | /* tmrca = 17 / 1977, most recent tip = 1994 187 | 188 | 4 intervals: 189 | 17/4 = 4.25 190 | (0.0, 4.25, 8.5, 12.75, 17) 191 | */ 192 | 193 | Double [] values = treeSlicer.getValues(); 194 | Double [] expected = {0.0, 4.25, 8.5, 12.75, 17.0}; 195 | 196 | for (int i = 0; i < values.length; i++) { 197 | //System.out.print(values[i]+"\t"); 198 | assertEquals(expected[i], values[i], BEASTTestCase.PRECISION); 199 | } 200 | //System.out.println(); 201 | } 202 | 203 | } 204 | -------------------------------------------------------------------------------- /test/tree.C1.MCC.trim.round.figtree.tree: -------------------------------------------------------------------------------- 1 | #NEXUS 2 | begin taxa; 3 | dimensions ntax=6; 4 | taxlabels 5 | D4Philip56 6 | D4Philip64 7 | D4Philip84 8 | D4SLanka78 9 | D4Thai78 10 | D4Thai84 11 | ; 12 | end; 13 | 14 | begin trees; 15 | tree tree_1 = [&R] ((D4Philip56:2.0,(D4Philip64:3.0,D4Philip84:23.0):7.0):10.0,(D4SLanka78:19.0,(D4Thai78:5.0,D4Thai84:11.0):14.0):15.0); 16 | end; 17 | 18 | begin figtree; 19 | set appearance.backgroundColorAttribute="Default"; 20 | set appearance.backgroundColour=#ffffff; 21 | set appearance.branchColorAttribute="User selection"; 22 | set appearance.branchColorGradient=false; 23 | set appearance.branchLineWidth=2.0; 24 | set appearance.branchMinLineWidth=0.0; 25 | set appearance.branchWidthAttribute="Fixed"; 26 | set appearance.foregroundColour=#000000; 27 | set appearance.hilightingGradient=false; 28 | set appearance.selectionColour=#2d3680; 29 | set branchLabels.colorAttribute="User selection"; 30 | set branchLabels.displayAttribute="Branch lengths (raw)"; 31 | set branchLabels.fontName="sansserif"; 32 | set branchLabels.fontSize=8; 33 | set branchLabels.fontStyle=0; 34 | set branchLabels.isShown=true; 35 | set branchLabels.significantDigits=4; 36 | set layout.expansion=0; 37 | set layout.layoutType="RECTILINEAR"; 38 | set layout.zoom=0; 39 | set legend.attribute=null; 40 | set legend.fontSize=10.0; 41 | set legend.isShown=false; 42 | set legend.significantDigits=4; 43 | set nodeBars.barWidth=4.0; 44 | set nodeBars.displayAttribute=null; 45 | set nodeBars.isShown=false; 46 | set nodeLabels.colorAttribute="User selection"; 47 | set nodeLabels.displayAttribute="Node heights (raw)"; 48 | set nodeLabels.fontName="sansserif"; 49 | set nodeLabels.fontSize=10; 50 | set nodeLabels.fontStyle=0; 51 | set nodeLabels.isShown=true; 52 | set nodeLabels.significantDigits=4; 53 | set nodeShapeExternal.colourAttribute="User selection"; 54 | set nodeShapeExternal.isShown=true; 55 | set nodeShapeExternal.minSize=10.0; 56 | set nodeShapeExternal.scaleType=Width; 57 | set nodeShapeExternal.shapeType=Circle; 58 | set nodeShapeExternal.size=10.0; 59 | set nodeShapeExternal.sizeAttribute="Fixed"; 60 | set nodeShapeInternal.colourAttribute="User selection"; 61 | set nodeShapeInternal.isShown=false; 62 | set nodeShapeInternal.minSize=10.0; 63 | set nodeShapeInternal.scaleType=Width; 64 | set nodeShapeInternal.shapeType=Circle; 65 | set nodeShapeInternal.size=4.0; 66 | set nodeShapeInternal.sizeAttribute="Fixed"; 67 | set polarLayout.alignTipLabels=false; 68 | set polarLayout.angularRange=0; 69 | set polarLayout.rootAngle=0; 70 | set polarLayout.rootLength=100; 71 | set polarLayout.showRoot=true; 72 | set radialLayout.spread=0.0; 73 | set rectilinearLayout.alignTipLabels=true; 74 | set rectilinearLayout.curvature=0; 75 | set rectilinearLayout.rootLength=100; 76 | set scale.offsetAge=1984.0; 77 | set scale.rootAge=1.0; 78 | set scale.scaleFactor=1.0; 79 | set scale.scaleRoot=false; 80 | set scaleAxis.automaticScale=false; 81 | set scaleAxis.fontSize=12.0; 82 | set scaleAxis.isShown=true; 83 | set scaleAxis.lineWidth=1.0; 84 | set scaleAxis.majorTicks=5.0; 85 | set scaleAxis.minorTicks=1.0; 86 | set scaleAxis.origin=0.0; 87 | set scaleAxis.reverseAxis=true; 88 | set scaleAxis.showGrid=true; 89 | set scaleBar.automaticScale=true; 90 | set scaleBar.fontSize=10.0; 91 | set scaleBar.isShown=false; 92 | set scaleBar.lineWidth=1.0; 93 | set scaleBar.scaleRange=5.0; 94 | set tipLabels.colorAttribute="User selection"; 95 | set tipLabels.displayAttribute="Names"; 96 | set tipLabels.fontName="sansserif"; 97 | set tipLabels.fontSize=12; 98 | set tipLabels.fontStyle=0; 99 | set tipLabels.isShown=true; 100 | set tipLabels.significantDigits=4; 101 | set trees.order=false; 102 | set trees.orderType="increasing"; 103 | set trees.rooting=false; 104 | set trees.rootingType="User Selection"; 105 | set trees.transform=false; 106 | set trees.transformType="cladogram"; 107 | end; 108 | 109 | -------------------------------------------------------------------------------- /test/tree.C2.MCC.trim.round.figtree.tree: -------------------------------------------------------------------------------- 1 | #NEXUS 2 | begin taxa; 3 | dimensions ntax=5; 4 | taxlabels 5 | D4ElSal94 6 | D4Indon77 7 | D4Mexico84 8 | D4PRico86 9 | D4Tahiti79 10 | ; 11 | end; 12 | 13 | begin trees; 14 | tree tree_1 = [&R] ((((D4Mexico84:5.0,D4ElSal94:15.0):1.0,D4PRico86:8.0):1.0,D4Tahiti79:2.0):5.0,D4Indon77:5.0); 15 | end; 16 | 17 | begin figtree; 18 | set appearance.backgroundColorAttribute="Default"; 19 | set appearance.backgroundColour=#ffffff; 20 | set appearance.branchColorAttribute="User selection"; 21 | set appearance.branchColorGradient=false; 22 | set appearance.branchLineWidth=2.0; 23 | set appearance.branchMinLineWidth=0.0; 24 | set appearance.branchWidthAttribute="Fixed"; 25 | set appearance.foregroundColour=#000000; 26 | set appearance.hilightingGradient=false; 27 | set appearance.selectionColour=#2d3680; 28 | set branchLabels.colorAttribute="User selection"; 29 | set branchLabels.displayAttribute="Branch lengths (raw)"; 30 | set branchLabels.fontName="sansserif"; 31 | set branchLabels.fontSize=8; 32 | set branchLabels.fontStyle=0; 33 | set branchLabels.isShown=true; 34 | set branchLabels.significantDigits=4; 35 | set layout.expansion=0; 36 | set layout.layoutType="RECTILINEAR"; 37 | set layout.zoom=0; 38 | set legend.attribute=null; 39 | set legend.fontSize=10.0; 40 | set legend.isShown=false; 41 | set legend.significantDigits=4; 42 | set nodeBars.barWidth=4.0; 43 | set nodeBars.displayAttribute=null; 44 | set nodeBars.isShown=false; 45 | set nodeLabels.colorAttribute="User selection"; 46 | set nodeLabels.displayAttribute="Node heights (raw)"; 47 | set nodeLabels.fontName="sansserif"; 48 | set nodeLabels.fontSize=10; 49 | set nodeLabels.fontStyle=0; 50 | set nodeLabels.isShown=true; 51 | set nodeLabels.significantDigits=4; 52 | set nodeShapeExternal.colourAttribute=null; 53 | set nodeShapeExternal.isShown=true; 54 | set nodeShapeExternal.minSize=10.0; 55 | set nodeShapeExternal.scaleType=Width; 56 | set nodeShapeExternal.shapeType=Circle; 57 | set nodeShapeExternal.size=10.0; 58 | set nodeShapeExternal.sizeAttribute=null; 59 | set nodeShapeInternal.colourAttribute=null; 60 | set nodeShapeInternal.isShown=false; 61 | set nodeShapeInternal.minSize=10.0; 62 | set nodeShapeInternal.scaleType=Width; 63 | set nodeShapeInternal.shapeType=Circle; 64 | set nodeShapeInternal.size=4.0; 65 | set nodeShapeInternal.sizeAttribute=null; 66 | set polarLayout.alignTipLabels=false; 67 | set polarLayout.angularRange=0; 68 | set polarLayout.rootAngle=0; 69 | set polarLayout.rootLength=100; 70 | set polarLayout.showRoot=true; 71 | set radialLayout.spread=0.0; 72 | set rectilinearLayout.alignTipLabels=true; 73 | set rectilinearLayout.curvature=0; 74 | set rectilinearLayout.rootLength=100; 75 | set scale.offsetAge=1994.0; 76 | set scale.rootAge=1.0; 77 | set scale.scaleFactor=1.0; 78 | set scale.scaleRoot=false; 79 | set scaleAxis.automaticScale=false; 80 | set scaleAxis.fontSize=12.0; 81 | set scaleAxis.isShown=true; 82 | set scaleAxis.lineWidth=1.0; 83 | set scaleAxis.majorTicks=5.0; 84 | set scaleAxis.minorTicks=1.0; 85 | set scaleAxis.origin=0.0; 86 | set scaleAxis.reverseAxis=true; 87 | set scaleAxis.showGrid=true; 88 | set scaleBar.automaticScale=true; 89 | set scaleBar.fontSize=10.0; 90 | set scaleBar.isShown=false; 91 | set scaleBar.lineWidth=1.0; 92 | set scaleBar.scaleRange=3.0; 93 | set tipLabels.colorAttribute="User selection"; 94 | set tipLabels.displayAttribute="Names"; 95 | set tipLabels.fontName="sansserif"; 96 | set tipLabels.fontSize=12; 97 | set tipLabels.fontStyle=0; 98 | set tipLabels.isShown=true; 99 | set tipLabels.significantDigits=4; 100 | set trees.order=true; 101 | set trees.orderType="decreasing"; 102 | set trees.rooting=false; 103 | set trees.rootingType="User Selection"; 104 | set trees.transform=false; 105 | set trees.transformType="cladogram"; 106 | end; 107 | 108 | -------------------------------------------------------------------------------- /version.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | --------------------------------------------------------------------------------