├── .DS_Store ├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ └── draft-pdf.yml ├── .gitignore ├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── NEWS.md ├── R ├── compute_linkage_groups.R ├── compute_macrosynteny.R ├── get_ideograms_coordinates.R ├── get_syntenic_genes.R ├── load_orthologs.R ├── plot_chord_diagram.R ├── plot_macrosynteny.R ├── plot_oxford_grid.R ├── reorder_macrosynteny.R ├── reorder_multiple_macrosyntenies.R ├── reverse_species_order.R └── subset_linkage_orthologs.R ├── README.md ├── inst ├── .DS_Store ├── CITATION ├── extdata │ ├── .DS_Store │ ├── Bflo.bed │ ├── Bflo_vs_Pech.tab │ ├── Bflo_vs_Pyes.tab │ ├── Pech.bed │ ├── Pyes.bed │ ├── Single_copy_orthologs.tsv │ └── my_orthologs.tab └── img │ ├── Chord_diagram_3species.png │ ├── example.png │ └── macrosyntR_logo.150pp.png ├── man ├── compute_linkage_groups.Rd ├── compute_macrosynteny.Rd ├── get_syntenic_genes.Rd ├── load_orthologs.Rd ├── plot_chord_diagram.Rd ├── plot_macrosynteny.Rd ├── plot_oxford_grid.Rd ├── reorder_macrosynteny.Rd ├── reorder_multiple_macrosyntenies.Rd ├── reverse_species_order.Rd └── subset_linkage_orthologs.Rd ├── paper ├── F1.large.jpeg ├── F1.large.jpg ├── paper.bib └── paper.md └── vignettes ├── .gitignore ├── macrosyntR.R └── macrosyntR.Rmd /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamiLhll/macrosyntR/a86189db19dafb15e78898e431f65df974618edc/.DS_Store -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.github$ 4 | ^paper* 5 | ^LICENSE -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/draft-pdf.yml: -------------------------------------------------------------------------------- 1 | on: [push] 2 | 3 | jobs: 4 | paper: 5 | runs-on: ubuntu-latest 6 | name: Paper Draft 7 | steps: 8 | - name: Checkout 9 | uses: actions/checkout@v3 10 | - name: Build draft PDF 11 | uses: openjournals/openjournals-draft-action@master 12 | with: 13 | journal: joss 14 | # This should be the path to the paper within your repo. 15 | paper-path: paper/paper.md 16 | - name: Upload 17 | uses: actions/upload-artifact@v1 18 | with: 19 | name: paper 20 | # This is the output path where Pandoc will write the compiled 21 | # PDF. Note, this should be the same directory as the input 22 | # paper.md 23 | path: paper/paper.pdf 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | *.DS_Store 6 | macrosyntR.Rproj 7 | inst/doc 8 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: macrosyntR 2 | Type: Package 3 | Title: Draw Ordered Oxford Grids 4 | Version: 0.3.4 5 | Authors@R: c(person(given="Sami", 6 | family ="El Hilali", 7 | email = "elhilali.sami@gmail.com", 8 | role = c("aut", "cre"), 9 | comment = c(ORCID = "0000-0003-4417-8399")), 10 | person(given="Richard", 11 | family="Copley", 12 | role = "aut", 13 | comment = c(ORCID = "0000-0001-7846-4954")) 14 | ) 15 | Maintainer: Sami El Hilali 16 | Depends: R (>= 4.1.0) 17 | Imports: 18 | stats, 19 | utils, 20 | ggplot2, 21 | igraph, 22 | tidyr, 23 | reshape2, 24 | dplyr, 25 | stringr, 26 | rlang 27 | Description: Use standard genomics file format (BED) and a table of orthologs to 28 | illustrate synteny conservation at the genome-wide scale. 29 | Significantly conserved linkage groups are identified as described in Simakov et al. (2020) 30 | and displayed on an Oxford Grid (Edwards (1991) ) or a chord diagram as in Simakov et al. (2022) . 31 | The package provides a function that uses a network-based greedy algorithm to find communities (Clauset et al. (2004) ) 32 | and so automatically order the chromosomes on the plot to improve interpretability. 33 | Encoding: UTF-8 34 | LazyData: true 35 | License: GPL-3 36 | URL: https://github.com/SamiLhll/macrosyntR 37 | BugReports: https://github.com/SamiLhll/macrosyntR/issues 38 | Roxygen: list(markdown = TRUE) 39 | RoxygenNote: 7.3.1 40 | Suggests: 41 | knitr, 42 | rmarkdown 43 | VignetteBuilder: knitr 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(compute_linkage_groups) 4 | export(compute_macrosynteny) 5 | export(get_syntenic_genes) 6 | export(load_orthologs) 7 | export(plot_chord_diagram) 8 | export(plot_macrosynteny) 9 | export(plot_oxford_grid) 10 | export(reorder_macrosynteny) 11 | export(reorder_multiple_macrosyntenies) 12 | export(reverse_species_order) 13 | export(subset_linkage_orthologs) 14 | import(ggplot2) 15 | import(tidyr) 16 | import(utils) 17 | importFrom(dplyr,arrange) 18 | importFrom(dplyr,desc) 19 | importFrom(dplyr,group_by) 20 | importFrom(dplyr,mutate) 21 | importFrom(dplyr,n) 22 | importFrom(dplyr,rename) 23 | importFrom(dplyr,row_number) 24 | importFrom(dplyr,select) 25 | importFrom(dplyr,setdiff) 26 | importFrom(dplyr,summarise) 27 | importFrom(dplyr,ungroup) 28 | importFrom(igraph,cluster_fast_greedy) 29 | importFrom(igraph,graph_from_data_frame) 30 | importFrom(igraph,groups) 31 | importFrom(rlang,":=") 32 | importFrom(rlang,sym) 33 | importFrom(stats,fisher.test) 34 | importFrom(stats,p.adjust) 35 | importFrom(stringr,str_replace) 36 | importFrom(stringr,str_subset) 37 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # macrosyntR 0.3.4 2 | 3 | ### Enhancements : 4 | 5 | * Add control over the spacing between ideograms in the function plot_chord_diagram() 6 | 7 | # macrosyntR 0.3.3 8 | 9 | ### Enhancements : 10 | 11 | * removed dependency on ggthemes package that is scheduled for archival. 12 | 13 | # macrosyntR 0.3.1 14 | 15 | ### New features : 16 | 17 | 18 | * Two species and more can now be visualized on a chord diagram using the function plot_chord_diagram() 19 | 20 | 21 | ### Enhancements : 22 | 23 | * Redundant chromosome names from one species to another are now accepted 24 | 25 | * load_orthologs now handles more than two species. It uses the argument 'bedfiles' instead of sp1_bed and sp2_bed which are still working when used together. 26 | 27 | # macrosyntR 0.2.21 28 | 29 | ### Enhancements : 30 | 31 | * added control when chromosome names are redundant in the 'orthologs_df' provided to 'reorder_macrosynteny()'. 32 | It now raises an error with explanations about what's wrong. 33 | 34 | # macrosyntR 0.2.19 35 | 36 | ### New features : 37 | 38 | * created the function get_syntenic_genes(). It takes an orthologs_df as input and 39 | outputs a table with the details of all detected blocks of two or more consecutive genes. 40 | 41 | * created the function reverse_species_order(). It takes an orthologs_df as input and 42 | outputs it with sp1 changed in sp2 and the other way around. It can be called in plot_oxford_grid(). 43 | 44 | * Added the argument keep_sp1_raw_order in reorder_macrosynteny(). When set to TRUE, it returns an orthologs_df with only the sp2.Chr reordered, and doesn't change the order of sp1.Chr compared with the input data. It can be also be called in plot_oxford_grid(). 45 | 46 | * 'plot_oxford_grid()' now features an option to (dis)able the coloring of orthologs depending on if they 47 | occur on significant linkage groups or not. By default, when setting a color_by argument, the orthologs that are located on non-significant linkage groups are displayed in grey. It is possible to disable this behavior by calling the function with setting argument *shade_non_significant* to *TRUE*. 48 | 49 | 50 | ### Bug fixes : 51 | 52 | * Corrected a bug that occurred when loading bed files with more than 3 fields in 'load_orthologs()'. 53 | This function now handles bed files that have fields after the 4th column (seqName). 54 | 55 | * Corrected a bug that happened when trying to set a custom color palette through the color_palette argument in 'plot_oxford_grid()'. It is now possible to set a custom color palette as a list of color names. 56 | 57 | 58 | ### Enhancements : 59 | 60 | * Added a `NEWS.md` file to track changes to the package. 61 | * Added documentation about how to customize the plots 62 | -------------------------------------------------------------------------------- /R/compute_linkage_groups.R: -------------------------------------------------------------------------------- 1 | # compute_linkage_groups 2 | # 3 | # This is a function to compute the linkage groups of an table of orthologs that includes two or more species. 4 | #' @title Compute Linkage groups 5 | #' @description This is a function to compute the conserved linkage groups shared between two or more species. 6 | #' It computes the significant associations between chromosomes of all species versus all (pairwise) 7 | #' using the fischer test implemented in compute_macrosynteny(). 8 | #' It outputs a dataframe shaped as following : 9 | #' sp1.Chr,sp2.Chr,..., spN.chr,n,LGs 10 | #' where n is the number of shared orthologs in the group and LGs are the IDs for the linkage groups 11 | #' 12 | #' @param orthologs_df dataframe. orthologs with genomic coordinates loaded with load_orthologs() 13 | #' 14 | #' @return A dataframe object 15 | #' 16 | #' @import tidyr 17 | #' @importFrom dplyr group_by summarise ungroup arrange n 18 | #' 19 | #' @examples 20 | #' # basic usage of compute_linkage_groups: 21 | #' 22 | #' orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 23 | #' 24 | #' my_orthologs <- read.table(orthologs_table,header=TRUE) 25 | #' 26 | #' my_macrosynteny <- compute_linkage_groups(my_orthologs) 27 | #' 28 | #' @export 29 | 30 | 31 | compute_linkage_groups <- function(orthologs_df) { 32 | 33 | 34 | sp1.Chr <- sp2.Chr <- significant <- n <- NULL 35 | 36 | amount_of_species <- length(which(colnames(orthologs_df) %in% paste0("sp",c(1:60),".Chr"))) 37 | 38 | options(dplyr.summarise.inform = FALSE) 39 | all_linkages <- NULL 40 | # Iterate and compare every species two by two : 41 | for (i in c(1:amount_of_species)) { 42 | if (i < amount_of_species) { 43 | departure_species <- paste0("sp",i) 44 | for (j in c((i+1):amount_of_species)) { 45 | arrival_species <- paste0("sp",j) 46 | # subset orthologs_df to get only the two species under study : 47 | departure_colnames <- colnames(orthologs_df)[grep(departure_species,colnames(orthologs_df))] 48 | arrival_colnames <- colnames(orthologs_df)[grep(arrival_species,colnames(orthologs_df))] 49 | subset_orthologs_df <- orthologs_df[c(departure_colnames,arrival_colnames)] 50 | # rename to sp1 and sp2 : 51 | colnames(subset_orthologs_df) <- gsub(departure_species,"sp1",colnames(subset_orthologs_df)) 52 | colnames(subset_orthologs_df) <- gsub(arrival_species,"sp2",colnames(subset_orthologs_df)) 53 | temp_macrosynteny <- compute_macrosynteny(subset_orthologs_df) %>% 54 | select(sp1.Chr,sp2.Chr,significant) 55 | temp_macrosynteny <- subset(temp_macrosynteny,significant == "yes") %>% 56 | select(-significant) 57 | colnames(temp_macrosynteny) <- c(paste0(departure_species,".Chr"),paste0(arrival_species,".Chr")) 58 | if (i == 1 & j == 2) { all_linkages <- temp_macrosynteny } 59 | else { all_linkages <- merge(all_linkages,temp_macrosynteny) } 60 | } 61 | } 62 | } 63 | # Compute amount of orthologs 64 | #colnames to group_by : 65 | grp_cols <- colnames(all_linkages) 66 | dots <- lapply(grp_cols, as.symbol) 67 | linkages_to_return <- merge(orthologs_df,all_linkages) %>% 68 | group_by(.groups = !!!syms(grp_cols)) %>% 69 | summarise(n = n()) %>% 70 | ungroup() %>% 71 | arrange(desc(n)) 72 | # mutate(linkage = as.character(dplyr::row_number())) 73 | letters702 <- c(letters, sapply(letters, function(x) paste0(x, letters))) 74 | linkages_to_return$LGs <- letters702[1:length(linkages_to_return$sp1.Chr)] 75 | 76 | 77 | options(dplyr.summarise.inform = TRUE) 78 | 79 | return(linkages_to_return) 80 | } -------------------------------------------------------------------------------- /R/compute_macrosynteny.R: -------------------------------------------------------------------------------- 1 | # compute_macrosynteny 2 | # 3 | # This is a function to generate the contingency table of an orthologs dataframe and apply fischer test to calculate the significant associations. 4 | #' @title Compute significant macrosynteny blocks 5 | #' @description This is a function to generate the contingency table of an orthologs dataframe and 6 | #' apply fischer test to calculate the significant associations. It outputs a dataframe shaped as following : 7 | #' sp1.Chr,sp2.Chr,a,pval,significant,pval_adj 8 | #' 9 | #' @param orthologs_df dataframe. orthologs with genomic coordinates loaded with load_orthologs() 10 | #' @param pvalue_threshold numeric. threshold for significancy. (default equals 0.001) 11 | #' 12 | #' @return A dataframe object 13 | #' 14 | #' @importFrom stats fisher.test p.adjust 15 | #' @import tidyr 16 | #' @importFrom dplyr rename mutate select 17 | #' 18 | #' @examples 19 | #' # basic usage of compute_macrosynteny : 20 | #' 21 | #' orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 22 | #' 23 | #' my_orthologs <- read.table(orthologs_table,header=TRUE) 24 | #' 25 | #' my_macrosynteny <- compute_macrosynteny(my_orthologs) 26 | #' 27 | #' @export 28 | 29 | 30 | compute_macrosynteny <- function(orthologs_df,pvalue_threshold = 0.001) { 31 | 32 | ### construct the contingency table : 33 | final_i <- final_j <- final_a <- final_b <- final_c <- final_d <- NULL 34 | sp1.Chr <- sp2.Chr <- value <- variable <- pvalues_value <- pvalues_adj <- odds <- a <- significant <-NULL 35 | # Error check : proper format for arguments : 36 | if (!(is.numeric(pvalue_threshold) & length(pvalue_threshold) == 1)) {stop("Wrong format for 'pvalue_threshold' argument. Must be a single value of type numeric")} 37 | # Error check : format of orthologs_df 38 | # required_fields <- c("sp1.ID","sp1.Index","sp1.Chr","sp2.ID","sp2.Index","sp2.Chr") 39 | required_fields <- c("sp1.ID","sp1.Chr","sp2.ID","sp2.Chr") 40 | for (i in required_fields) { 41 | if (isFALSE(i %in% colnames(orthologs_df))) { 42 | # stop("Missing fields in the provided orthologs_df. All the following columns are required : sp1.ID,sp1.Index,sp1.Chr,sp2.ID,sp2.Index,sp2.Chr") 43 | stop("Missing fields in the provided orthologs_df. All the following columns are required : sp1.ID,sp1.Chr,sp2.ID,sp2.Chr") 44 | } 45 | } 46 | # Error check : orthologs_df is empty 47 | if (length(orthologs_df$sp1.Chr) == 0) {stop("Table provided through the orthologs_df argument is empty")} 48 | # Warning check : when number of chromosomes is too high 49 | if (length(unique(orthologs_df$sp1.Chr)) >= 300) { 50 | warning(paste0("The first species in the orthologs_df has ",length(unique(orthologs_df$sp1.Chr))," chromosomes. Computational time can be very long on fragmented genomes")) 51 | } 52 | if (length(unique(orthologs_df$sp2.Chr)) >= 300) { 53 | warning(paste0("The second species in the orthologs_df has ",length(unique(orthologs_df$sp2.Chr))," chromosomes. Computational time can be very long on fragmented genomes")) 54 | } 55 | 56 | for (i in unique(orthologs_df$sp1.Chr)) { 57 | subsetted_orthologs_df_in <- subset(orthologs_df,sp1.Chr == i) 58 | subsetted_orthologs_df_out <- subset(orthologs_df,sp1.Chr != i) 59 | compared_specie_scaffs <- unique(subsetted_orthologs_df_in$sp2.Chr) 60 | for (j in compared_specie_scaffs) { 61 | cell_a <- length(subset(subsetted_orthologs_df_in, sp2.Chr == j)$sp1.Chr) 62 | final_a <- c(final_a,cell_a) 63 | cell_b <- length(subset(subsetted_orthologs_df_out, sp2.Chr == j)$sp1.Chr) 64 | final_b <- c(final_b,cell_b) 65 | cell_c <- length(subset(subsetted_orthologs_df_in, sp2.Chr != j)$sp1.Chr) 66 | final_c <- c(final_c,cell_c) 67 | cell_d <- length(subset(subsetted_orthologs_df_out, sp2.Chr != j)$sp1.Chr) 68 | final_d <- c(final_d,cell_d) 69 | final_j <- c(final_j,j) 70 | } 71 | final_i <- c(final_i,rep(i,times=length(compared_specie_scaffs))) 72 | } 73 | 74 | contingency_table <- data.frame(sp1 = final_i, 75 | sp2 = final_j, 76 | a = final_a,b = final_b, 77 | c = final_c,d = final_d) 78 | ### DONE 79 | 80 | rownames(contingency_table) <- paste(contingency_table$sp1, 81 | contingency_table$sp2,sep="-") 82 | contingency_table <- subset(contingency_table,select=c("a","b","c","d")) 83 | 84 | ### Calculate pvalues and odds : 85 | p_values <- apply(contingency_table, 1, 86 | function(x) { 87 | tbl <- matrix(as.numeric(x[1:4]), ncol=2, byrow=T) 88 | stats::fisher.test(tbl, alternative="greater")$p.value 89 | }) 90 | odds_values <- apply(contingency_table, 1, 91 | function(x) { 92 | tbl <- matrix(as.numeric(x[1:4]), ncol=2, byrow=T) 93 | stats::fisher.test(tbl, alternative="greater")$estimate[[1]] 94 | }) 95 | 96 | ### merge pvalues and odds with the contingency table : 97 | contingency_table$variable <- rownames(contingency_table) 98 | p_values.melted <- reshape2::melt(p_values) %>% 99 | dplyr::rename(pvalues_value = value) 100 | p_values.melted$variable <- rownames(p_values.melted) 101 | 102 | odds_values.melted <- reshape2::melt(odds_values) %>% 103 | dplyr::rename(odds_values = value) 104 | odds_values.melted$variable <- rownames(odds_values.melted) 105 | 106 | contingency_table <- merge(contingency_table,p_values.melted) %>% 107 | dplyr::mutate(pvalues_adj = stats::p.adjust(pvalues_value)) %>% 108 | dplyr::mutate(significant = "no", 109 | significant = replace(significant,pvalues_adj <= pvalue_threshold,"yes")) 110 | 111 | contingency_table <- merge(contingency_table,odds_values.melted) %>% 112 | dplyr::mutate(odds = "> 1", 113 | odds = replace(odds,odds_values < 1,"< 1")) %>% 114 | tidyr::separate(variable,c("sp1.Chr","sp2.Chr"),sep="-") 115 | 116 | ### reshape before returning : 117 | macrosynt_df <- contingency_table %>% 118 | dplyr::select(sp1.Chr,sp2.Chr,a,pvalues_value,significant,pvalues_adj) %>% 119 | dplyr::rename(orthologs = a,pval = pvalues_value,pval_adj = pvalues_adj) 120 | # copy the levels of orthologs_df to keep the same ordering when plotting : 121 | if (is.factor(orthologs_df$sp1.Chr)) { 122 | macrosynt_df$sp1.Chr <- factor(macrosynt_df$sp1.Chr,levels = levels(orthologs_df$sp1.Chr)) 123 | } 124 | else { 125 | macrosynt_df$sp1.Chr <- factor(macrosynt_df$sp1.Chr) 126 | } 127 | if (is.factor(orthologs_df$sp1.Chr)) { 128 | macrosynt_df$sp2.Chr <- factor(macrosynt_df$sp2.Chr,levels = levels(orthologs_df$sp2.Chr)) 129 | } 130 | else { 131 | macrosynt_df$sp2.Chr <- factor(macrosynt_df$sp2.Chr) 132 | } 133 | 134 | return(macrosynt_df) 135 | 136 | } -------------------------------------------------------------------------------- /R/get_ideograms_coordinates.R: -------------------------------------------------------------------------------- 1 | # get_ideograms_coordinates (internal) 2 | # 3 | # This is an internal function that is called by plot_chord_diagram() 4 | #' @title get the ideograms coordinates to plot chord diagrams (internal) 5 | #' @description This is an internal function to compute the ideograms coordinates to plot chord diagrams. 6 | #' 7 | #' @param orthologs_df dataframe. orthologs with genomic coordinates loaded with load_orthologs() 8 | #' @param species_number integer. the number of the species being processed. (default = 1) 9 | #' @param amount_of_species integer. the total amount of species in the orthologs_df (default = 2) 10 | #' @param ideogram_height integer. the height of the ideograms (default = 10) 11 | #' @param gap_size integer. the size of the gaps between ideograms (default = 40) 12 | #' 13 | #' 14 | #' @return A dataframe object 15 | #' 16 | #' @import tidyr 17 | #' @importFrom rlang sym 18 | #' @importFrom dplyr mutate select 19 | #' 20 | #' 21 | #' @noRd 22 | 23 | get_ideograms_coordinates <- function(orthologs_df, 24 | species_number = 1, 25 | amount_of_species = 2, 26 | ideogram_height = 10, 27 | gap_size = 40) { 28 | 29 | id_y <- starts <- stops <- NULL 30 | 31 | ### 1 - compute values based on number of orthologs per chromosome : 32 | species <- paste0("sp",species_number) 33 | Chr_column <- paste0(species,".Chr") 34 | Index_column <- paste0(species,".Index") 35 | ideograms_to_process <- orthologs_df %>% 36 | group_by(!!rlang::sym(Chr_column)) %>% 37 | arrange(!!rlang::sym(Index_column),.by_group = TRUE) %>% 38 | summarise(n = n()) %>% ungroup() 39 | # print(ideograms_to_process) 40 | ideograms_to_process$stops <- cumsum(ideograms_to_process$n) + 1 41 | ideograms_to_process$starts <- c(0,ideograms_to_process$stops[1:length(ideograms_to_process$stops) - 1]) 42 | # print(ideograms_to_process) 43 | ### 2 - Compute new starts and stops with adding a gap between the chromosomes : 44 | genome_gap <- 0 45 | temp_ideograms <- NULL 46 | 47 | for (i in ideograms_to_process[[Chr_column]]) { 48 | temp_ideogram <- ideograms_to_process[ideograms_to_process[[Chr_column]] == i,] 49 | temp_ideogram <- temp_ideogram %>% 50 | mutate(starts = replace(starts, TRUE, starts + genome_gap), 51 | stops = replace(stops, TRUE, stops + genome_gap)) 52 | temp_ideograms <- rbind(temp_ideograms,temp_ideogram) 53 | genome_gap <- genome_gap + gap_size 54 | 55 | } 56 | ### 3 - Compute mids that will be the x aes in the plot : 57 | ideograms_to_return <- temp_ideograms %>% 58 | mutate(mids = (starts + stops) / 2) %>% 59 | select(-n) 60 | 61 | ### 4 - Compute Y coordinates and add to the dataframe : 62 | ideograms_to_return <- ideograms_to_return %>% 63 | mutate(id_y = 100 - ((species_number -1) * (100 / amount_of_species)))%>% 64 | mutate(id_ymin = id_y - (ideogram_height / 2), 65 | id_ymax = id_y + (ideogram_height / 2)) 66 | 67 | ### 5 - rename the columns with species number : 68 | colnames_to_return <- c(Chr_column,paste0(species,c(".id_stops",".id_starts",".id_mids",".id_y",".id_ymin",".id_ymax"))) 69 | colnames(ideograms_to_return) <- colnames_to_return 70 | 71 | return(ideograms_to_return) 72 | } -------------------------------------------------------------------------------- /R/get_syntenic_genes.R: -------------------------------------------------------------------------------- 1 | # get_syntenic_genes 2 | # 3 | # This is a function to extract all the syntenic genes from an orthologs_df. 4 | #' @title get the syntenic genes as a table 5 | #' @description This is a function to extract all the syntenic genes from an orthologs_df. It requires as input an orthologs_df loaded by load_orthologs(). 6 | #' 7 | #' @param orthologs_df dataframe. orthologs with genomic coordinates loaded by load_orthologs() 8 | #' 9 | #' @importFrom dplyr select 10 | #' 11 | #' @return dataframe composed of details for each detected syntenic block of genes. It contains the following columns : sp1.Chr, sp1.Start, sp1.End, sp2.Chr, sp2.Start, sp2.End, size, sp1.IDs, sp2.IDs 12 | #' 13 | #' @seealso [load_orthologs()] 14 | #' 15 | #' @examples 16 | #' # basic usage of get_syntenic_genes : 17 | #' 18 | #' orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 19 | #' 20 | #' my_orthologs <- read.table(orthologs_table,header=TRUE) 21 | #' 22 | #' my_syntenic_block_of_genes <- get_syntenic_genes(my_orthologs) 23 | #' 24 | #' @export 25 | 26 | 27 | get_syntenic_genes <- function(orthologs_df) { 28 | 29 | ################################################## 30 | ####### ERROR CHECK : 31 | # Error check : format of orthologs_df 32 | required_fields <- c("sp1.ID","sp1.Index","sp1.Chr","sp2.ID","sp2.Index","sp2.Chr") 33 | for (i in required_fields) { 34 | if (isFALSE(i %in% colnames(orthologs_df))) { 35 | required_fields_character <- paste(required_fields,sep=",") 36 | stop("Missing fields in the provided orthologs_df. All the following columns are required : sp1.ID,sp1.Index,sp1.Chr,sp2.ID,sp2.Index,sp2.Chr") 37 | } 38 | } 39 | # Error check : orthologs_df is empty 40 | if (length(orthologs_df$sp1.Chr) == 0) {stop("Table provided through the orthologs_df argument is empty")} 41 | ################################################## 42 | 43 | Syntenic_blocks <- NULL 44 | size <- sp1.Chr <- sp1.End <- sp1.IDs <- sp1.Index <- sp1.Start <- sp2.Chr <- sp2.End <- sp2.IDs <- sp2.Start <- NULL 45 | 46 | chromosomes_sp1 <- unique(orthologs_df$sp1.Chr) 47 | # Iterate on all chromosomes from 1st species 48 | for (i in (chromosomes_sp1)) { 49 | chr_table <- subset(orthologs_df,sp1.Chr == i) 50 | chromosome_sp2 <- unique(chr_table$sp2.Chr) 51 | # Iterate on all chromosomes from 2nd species 52 | for (ii in (chromosome_sp2)) { 53 | # get the subset of orthologs df and arrange the genes by the relative order in species 1 : 54 | chr_table <- subset(orthologs_df,sp1.Chr == i & sp2.Chr == ii) %>% 55 | arrange(sp1.Index) 56 | # Compute the distance (relative) of genes in species 2 following the order in species 1 : 57 | distance_to_next_gene <- diff(chr_table$sp2.Index) 58 | distance_to_next_gene[abs(distance_to_next_gene) != 1] <- 0 59 | distance_to_next_gene <- abs(distance_to_next_gene) 60 | 61 | ### Start to walk through the list of distances to get all the syntenic genes 62 | Index_on_list <- 1 63 | while (Index_on_list < length(distance_to_next_gene)) { 64 | current_pair <- distance_to_next_gene[Index_on_list] 65 | if(current_pair == 1) { 66 | new_syntenic_block <- c(Index_on_list,Index_on_list + 1) 67 | Index_on_list <- Index_on_list + 1 68 | current_pair <- distance_to_next_gene[Index_on_list] 69 | while(current_pair == 1 & Index_on_list < length(distance_to_next_gene)) { 70 | new_syntenic_block <- c(new_syntenic_block, Index_on_list,Index_on_list + 1) 71 | Index_on_list <- Index_on_list + 1 72 | current_pair <- distance_to_next_gene[Index_on_list] 73 | } 74 | ## Build the piece of dataframe for the detected syntenic genes : 75 | new_syntenic_block <- unique(new_syntenic_block) 76 | genes_sp1_in_syntenic_block <- toString(chr_table$sp1.ID[new_syntenic_block],) 77 | genes_sp2_in_syntenic_block <- toString(chr_table$sp2.ID[new_syntenic_block],) 78 | start_sp1 <- min(chr_table$sp1.Start[new_syntenic_block]) 79 | stop_sp1 <- max(chr_table$sp1.End[new_syntenic_block]) 80 | start_sp2 <- min(chr_table$sp2.Start[new_syntenic_block]) 81 | stop_sp2 <- max(chr_table$sp2.End[new_syntenic_block]) 82 | temp_syntenic_df <- data.frame(sp1.IDs = genes_sp1_in_syntenic_block, 83 | sp2.IDs = genes_sp2_in_syntenic_block) %>% 84 | mutate(sp1.Chr = i, 85 | sp2.Chr = ii, 86 | sp1.Start = start_sp1, 87 | sp1.End = stop_sp1, 88 | sp2.Start = start_sp2, 89 | sp2.End = stop_sp2, 90 | size = length(chr_table$sp1.ID[new_syntenic_block])) 91 | Syntenic_blocks <- rbind(Syntenic_blocks,temp_syntenic_df) 92 | } 93 | else { 94 | Index_on_list <- Index_on_list +1 95 | } 96 | } 97 | 98 | Syntenic_blocks <- Syntenic_blocks %>% 99 | select(sp1.Chr,sp1.Start, sp1.End,sp2.Chr,sp2.Start,sp2.End,size,sp1.IDs,sp2.IDs) 100 | } 101 | } 102 | return(Syntenic_blocks) 103 | } -------------------------------------------------------------------------------- /R/load_orthologs.R: -------------------------------------------------------------------------------- 1 | # load_orthologs 2 | # 3 | # This is a function to load a table with orthologous genes between two or more species. 4 | #' @title load orthologs with their genomic coordinates. 5 | #' @description Puts together the table of orthologous genes with their genomic coordinates 6 | #' in the two or more species. It outputs a data.frame shaped as following : 7 | #' sp1.ID,sp1.Chr,sp1.Start,sp1.End,sp1.Index,sp2.ID,sp2.Chr,sp2.Start,sp2.End,sp2.Index,... 8 | #' 9 | #' @param orthologs_table character. Full path to the orthologs table (format : geneID_on_species1 geneID_on_species2 geneID_on_speciesN) 10 | #' @param sp1_bed (deprecated) character. Full path to the genomic coordinates of the genes on species1 11 | #' @param sp2_bed (deprecated) character. Full path to the genomic coordinates of the genes on species2 12 | #' @param bedfiles array. List of full paths to the genomic coordinates ordered as in the appearing order of the orthologs_table (BED format) 13 | 14 | #' @return dataframe composed of genomic coordinates and relative index of orthologs on both species 15 | #' 16 | #' @import utils 17 | #' @importFrom dplyr rename mutate group_by arrange ungroup select row_number 18 | #' 19 | #' @examples 20 | #' # basic usage of load_orthologs for two species : 21 | #' 22 | #' orthologs_file <- system.file("extdata","Bflo_vs_Pyes.tab",package="macrosyntR") 23 | #' bedfile_sp1 <- system.file("extdata","Bflo.bed",package="macrosyntR") 24 | #' bedfile_sp2 <- system.file("extdata","Pyes.bed",package="macrosyntR") 25 | #' 26 | #' 27 | #' my_orthologs <- load_orthologs(orthologs_table = orthologs_file, 28 | #' bedfiles = c(bedfile_sp1,bedfile_sp2)) 29 | #'# example with 3 species : 30 | #' orthologs_file <- system.file("extdata","Single_copy_orthologs.tsv",package="macrosyntR") 31 | #' bedfile_sp3 <- system.file("extdata","Pech.bed",package="macrosyntR") 32 | #' 33 | #' my_orthologs <- load_orthologs(orthologs_table = orthologs_file, 34 | #' bedfiles = c(bedfile_sp1,bedfile_sp2,bedfile_sp3)) 35 | #' 36 | #' 37 | #' @export 38 | 39 | 40 | load_orthologs <- function(orthologs_table, 41 | sp1_bed = NULL, 42 | sp2_bed = NULL, 43 | bedfiles = NULL) { 44 | 45 | V1 <- V2 <- V3 <- V4 <- NULL 46 | Start <- End <- Chr <- Loci <- Index <- ID <- NULL 47 | 48 | # Error check : 1 - species1_bed and species2_bed contains at least 4 fields (tab separated) 49 | # Error check : 2 - temp_orthologs_table contains two fields (tab separated) 50 | 51 | 52 | #### 1 - Open orthologs : 53 | orthologs_table_to_return <- utils::read.csv(orthologs_table,sep ="\t", header = FALSE) 54 | # Error check : the orthologs table must contain two columns 55 | if(length(orthologs_table_to_return) < 2) {stop("The table of orthologs must contain at least two columns separated by a \"\\t\"")} 56 | 57 | # rename columns with "spx.ID" 58 | number_of_species <- length(orthologs_table_to_return) 59 | colnames(orthologs_table_to_return) <- paste0("sp",c(1:number_of_species),".ID") 60 | #### 61 | 62 | #### 2 - Open bedfiles : 63 | 64 | ## When species1_bed and species2_bed are used : 65 | if (!is.null(sp1_bed)) { 66 | if (!is.null(sp2_bed)) { 67 | bedfiles <- c(sp1_bed,sp2_bed) 68 | } 69 | else { 70 | stop("Error. Arguments sp1_bed and sp2_bed are meant to be used together") 71 | } 72 | } 73 | else if (!is.null(sp2_bed)) { 74 | stop("Error. Arguments sp1_bed and sp2_bed are meant to be used together") 75 | } 76 | 77 | ## 78 | if (!is.null(bedfiles)) { 79 | current_species <- 0 80 | ## Check amount of bedfiles matchs amount of columns in orthologs_table : 81 | if (length(orthologs_table_to_return) != length(bedfiles)) { 82 | stop("Error. Amount of species in orthologs_table differs from the amount of provided bedfiles.") 83 | } 84 | ## 85 | for (current_bedfile_path in bedfiles) { 86 | current_species <- current_species + 1 87 | # open bedfile : 88 | current_bedfile <- utils::read.csv(current_bedfile_path,sep = "\t", header = FALSE) 89 | # check conformity of bedfile : 90 | if (length(current_bedfile) < 4) { stop(paste0("Error. Bedfiles must be tab separated containing at least 4 fields. Wrong format in : ",current_bedfile_path))} 91 | # compute indexes : 92 | current_bedfile <- current_bedfile %>% 93 | rename(Chr = V1, Start = V2, End = V3, ID = V4) %>% 94 | mutate(Loci = (Start + End)/2) %>% 95 | group_by(Chr) %>% 96 | arrange(Loci) %>% 97 | mutate(Index = dplyr::row_number()) %>% 98 | ungroup() %>% 99 | select(ID,Chr,Start,End,Index) 100 | # Convert Chr to factor 101 | current_bedfile$Chr <- factor(current_bedfile$Chr) 102 | # rename columns with species identifier : 103 | species_prefix <- paste0("sp",current_species,".") 104 | colnames(current_bedfile) <- paste0(species_prefix,colnames(current_bedfile)) 105 | # merge with table of orthologs 106 | orthologs_table_to_return <- merge(orthologs_table_to_return,current_bedfile) 107 | } 108 | } 109 | return(orthologs_table_to_return) 110 | } 111 | -------------------------------------------------------------------------------- /R/plot_chord_diagram.R: -------------------------------------------------------------------------------- 1 | # plot_chord_diagram 2 | # 3 | # This is a function to plot the orthology as chord diagrams 4 | #' @title plot the Macro-synteny as a chord diagram 5 | #' @description This is a function to plot the chord diagrams to compare the macro synteny of two or more species. 6 | #' It requires as input an orthologs_df loaded by load_orthologs() 7 | #' 8 | #' @param orthologs_df dataframe. orthologs with genomic coordinates loaded by the load_orthologs() 9 | #' @param species_labels list of characters. names of the species to display on the plot 10 | #' @param species_labels_size integer. size of the labels (default = 2) 11 | #' @param color_by string. name of the column in the orthologs_df to color the links by (default = "sp1.Chr") 12 | #' @param custom_color_palette list of characters. palette to use for the coloring of the links following the argument color_by 13 | #' @param reorder_chromosomes logical. (default = TRUE) tells whether to reorder the chromosomes in clusters as implemented in reorder_macrosynteny() 14 | #' @param remove_non_linkage_orthologs logical. (default = TRUE) tells wether to remove the orthologs that are not within significant linkage groups as calculated by compute_linkage_groups(). 15 | #' @param species_labels_hpos (default =-400) 16 | #' @param label_size integer. size of the labels to display on the ideograms (default = 2) 17 | #' @param ideogram_fill character. name of the colors to fill the ideograms with (default = "white") 18 | #' @param ideogram_color character. name of the colors to draw the borders of the ideograms with (default = "black") 19 | #' @param ideogram_height integer. height of the ideograms (default = 4) 20 | #' @param gap_size integer. Size of the gap separating the ideograms (default = 40) 21 | #' @param ribbons_curvature float. curvature of the ribbons (default = 0.1) 22 | #' @param ribbons_alpha float. alpha of the ribbons (default = 0.5) 23 | #' 24 | #' @seealso [load_orthologs()] 25 | #' @seealso [reorder_macrosynteny()] 26 | #' @seealso [compute_linkage_groups()] 27 | #' 28 | #' @return A ggplot2 object 29 | #' 30 | #' @import ggplot2 31 | #' @importFrom rlang sym := 32 | #' @importFrom dplyr arrange group_by mutate row_number ungroup 33 | #' 34 | #' @examples 35 | #' # basic usage of plot_oxford_grid : 36 | #' 37 | #' orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 38 | #' 39 | #' my_orthologs <- read.table(orthologs_table,header=TRUE) 40 | #' 41 | #' plot_chord_diagram(my_orthologs,species_labels = c("B. flo","P. ech")) 42 | #' 43 | #' @export 44 | 45 | plot_chord_diagram <- function(orthologs_df, 46 | species_labels = NULL, 47 | species_labels_size = 5, 48 | color_by = "sp1.Chr", 49 | custom_color_palette = NULL, 50 | reorder_chromosomes = TRUE, 51 | remove_non_linkage_orthologs = TRUE, 52 | species_labels_hpos = -400, 53 | label_size = 2, 54 | ideogram_fill = "white", 55 | ideogram_color = "black", 56 | ideogram_height = 4, 57 | gap_size = 40, 58 | ribbons_curvature = 0.1, 59 | ribbons_alpha = 0.5) { 60 | 61 | ### 1 - Compute the amount of species (max 60 species) and reorder Chromosomes : 62 | 63 | amount_of_species <- length(which(colnames(orthologs_df) %in% paste0("sp",c(1:60),".Chr"))) 64 | 65 | if (reorder_chromosomes) { 66 | orthologs_df_to_plot <- reorder_multiple_macrosyntenies(orthologs_df) 67 | } 68 | else { orthologs_df_to_plot <- orthologs_df} 69 | 70 | if (remove_non_linkage_orthologs){ 71 | orthologs_df_to_plot <- subset_linkage_orthologs(orthologs_df_to_plot) 72 | } 73 | 74 | ### 2 - Initialize plot : 75 | 76 | p <- ggplot() + ggplot2::theme_void() 77 | 78 | ################################################ 79 | ### Start for loop to compute ideogram and link coordinates 80 | 81 | for (i in c(1:amount_of_species)) { 82 | 83 | ### 3 - Compute Ideograms coordinates : 84 | species <- paste0("sp",i) 85 | 86 | # Compute X and Y coordinates for the ideograms of the species : 87 | species_ideograms_coordinates <- get_ideograms_coordinates(orthologs_df_to_plot, 88 | species_number = i, 89 | amount_of_species = amount_of_species, 90 | ideogram_height = ideogram_height, 91 | gap_size = gap_size) 92 | 93 | 94 | ### 4 - Compute links coordinates and plot : 95 | 96 | if (i+1 <= amount_of_species) { 97 | departure_species <- species 98 | arrival_species <- paste0("sp",i+1) 99 | # subset orthologs_df to have only departure and arrival species 100 | 101 | # merge with departure species : 102 | links_df <- merge(orthologs_df_to_plot,species_ideograms_coordinates, by = paste0(departure_species,".Chr")) 103 | # merge with arrival species : 104 | arrival_species_coordinates <- get_ideograms_coordinates(orthologs_df_to_plot, 105 | species_number = i + 1, 106 | amount_of_species = amount_of_species, 107 | ideogram_height = ideogram_height, 108 | gap_size = gap_size) 109 | links_df <- merge(links_df,arrival_species_coordinates,by = paste0(arrival_species,".Chr")) 110 | 111 | # recompute indexes by adding the id_starts to it : 112 | Chr_column <- paste0(departure_species,".Chr") 113 | Start_column <- paste0(departure_species,".Start") 114 | Index_column <- paste0(departure_species,".Index") 115 | links_df <- links_df %>% group_by(!!rlang::sym(Chr_column)) %>% arrange(!!rlang::sym(Index_column),.by_group = TRUE) %>% 116 | mutate( "{departure_species}.Index" := dplyr::row_number()) %>% ungroup() 117 | 118 | links_df[[paste0(departure_species,".Index")]] <- links_df[[paste0(departure_species,".Index")]] + links_df[[paste0(departure_species,".id_starts")]] 119 | 120 | Chr_column <- paste0(arrival_species,".Chr") 121 | Start_column <- paste0(arrival_species,".Start") 122 | Index_column <- paste0(arrival_species,".Index") 123 | links_df <- links_df %>% group_by(!!rlang::sym(Chr_column)) %>% arrange(!!rlang::sym(Index_column),.by_group = TRUE) %>% 124 | mutate( "{arrival_species}.Index" := dplyr::row_number()) %>% ungroup() 125 | 126 | links_df[[paste0(arrival_species,".Index")]] <- links_df[[paste0(arrival_species,".Index")]] + links_df[[paste0(arrival_species,".id_starts")]] 127 | # add X_center : 128 | links_df[[paste0(departure_species,"_",arrival_species,".Xcenter")]] <- (links_df[[paste0(departure_species,".Index")]] + links_df[[paste0(arrival_species,".Index")]]) / 2 129 | # add Y_center : 130 | links_df[[paste0(departure_species,"_",arrival_species,".Ycenter")]] <- (links_df[[paste0(departure_species,".id_y")]] + links_df[[paste0(arrival_species,".id_y")]]) / 2 131 | 132 | ## shuffle links order : 133 | random_rows_order <- sample(nrow(links_df)) 134 | links_df <- links_df[random_rows_order,] 135 | 136 | # PLOT links : 137 | color_by_sym <- ggplot2::ensym(color_by) 138 | p <- p + 139 | # First half of the links : 140 | geom_curve(data = links_df, 141 | aes(x = .data[[paste0(departure_species,".Index")]], 142 | xend = .data[[paste0(departure_species,"_",arrival_species,".Xcenter")]], 143 | y = .data[[paste0(departure_species,".id_ymin")]], 144 | yend = .data[[paste0(departure_species,"_",arrival_species,".Ycenter")]], 145 | color = !!color_by_sym), 146 | curvature = -ribbons_curvature, 147 | linewidth = .5, alpha = ribbons_alpha) + 148 | # Second half of the links : 149 | geom_curve(data = links_df, 150 | aes(x = .data[[paste0(departure_species,"_",arrival_species,".Xcenter")]], 151 | xend = .data[[paste0(arrival_species,".Index")]], 152 | y = .data[[paste0(departure_species,"_",arrival_species,".Ycenter")]], 153 | yend = .data[[paste0(arrival_species,".id_ymax")]], 154 | color = !!color_by_sym), 155 | curvature = ribbons_curvature, 156 | linewidth = .5, alpha = ribbons_alpha) 157 | } # END IF 158 | 159 | ### Plot ideograms : 160 | # Plot ideograms : 161 | p <- p + 162 | # draw ideograms : 163 | annotate("rect", 164 | xmin = species_ideograms_coordinates[[paste0(species,".id_starts")]], 165 | xmax = species_ideograms_coordinates[[paste0(species,".id_stops")]], 166 | ymin = species_ideograms_coordinates[[paste0(species,".id_ymin")]], 167 | ymax = species_ideograms_coordinates[[paste0(species,".id_ymax")]], 168 | alpha = 1,fill = ideogram_fill, color = ideogram_color) + 169 | # add chromosome labels : 170 | geom_point(data = species_ideograms_coordinates, 171 | aes(x=.data[[paste0(species,".id_mids")]], 172 | y=.data[[paste0(species,".id_y")]]), 173 | size = label_size + 1,color = "white",shape = 15) + 174 | annotate(geom="text", 175 | x=species_ideograms_coordinates[[paste0(species,".id_mids")]], 176 | y=species_ideograms_coordinates[[paste0(species,".id_y")]], 177 | label=species_ideograms_coordinates[[paste0(species,".Chr")]], 178 | size = label_size,angle = 0) 179 | # add species labels : 180 | if (! is.null(species_labels)) { 181 | p <- p + 182 | annotate(geom="text", 183 | x=species_labels_hpos, 184 | y=min(species_ideograms_coordinates[[paste0(species,".id_y")]]), 185 | label=species_labels[i], 186 | size = species_labels_size,angle = 0, 187 | fontface = 'italic') 188 | 189 | } 190 | } # END_FOR 191 | 192 | 193 | if (is.null(custom_color_palette)) { 194 | Ref_palette <- c("#89C5DA", "#DA5724", "#74D944", "#CE50CA", "#3F4921", "#C0717C", "#CBD588", "#5F7FC7", 195 | "#673770", "#D3D93E", "#38333E", "#508578", "#D7C1B1", "#689030", "#AD6F3B", "#CD9BCD", 196 | "#D14285", "#6DDE88", "#652926", "#7FDCC0", "#C84248", "#8569D5", "#5E738F", "#D1A33D", 197 | "#8A7C64", "#599861") 198 | custom_color_palette <- Ref_palette[1:length(unique(links_df[[color_by]]))] 199 | } 200 | 201 | 202 | p <- p + scale_color_manual(values = custom_color_palette) 203 | 204 | 205 | return(p) 206 | 207 | } -------------------------------------------------------------------------------- /R/plot_macrosynteny.R: -------------------------------------------------------------------------------- 1 | # plot_macrosynteny 2 | # 3 | # This is a function to plot the result of compute_macrosynteny() 4 | #' @title Plot Macro-synteny 5 | #' @description This is a function to generate the contingency table of an MBH dataframe and apply fischer test to calculate the significant associations. 6 | #' 7 | #' @param macrosynt_df dataframe of contingency table with p-values calculated by the compute_macrosynteny() function 8 | #' @param sp1_label character. The name of the species1 to display on the plot 9 | #' @param sp2_label character. The name of the species2 to put on the plot 10 | #' 11 | #' @seealso [compute_macrosynteny()] 12 | #' 13 | #' @return ggplot2 object 14 | #' 15 | #' @import ggplot2 16 | #' 17 | #' @examples 18 | #' # basic usage of plot_macrosynteny : 19 | #' 20 | #' orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 21 | #' 22 | #' my_orthologs <- read.table(orthologs_table,header=TRUE) 23 | #' 24 | #' my_macrosynteny <- compute_macrosynteny(my_orthologs) 25 | #' 26 | #' plot_macrosynteny(my_macrosynteny, 27 | #' sp1_label = "B. floridae", 28 | #' sp2_label = "P. yessoensis") 29 | #' 30 | #' @export 31 | 32 | 33 | plot_macrosynteny <- function(macrosynt_df, 34 | sp1_label="", 35 | sp2_label="") { 36 | 37 | sp1.Chr <- sp2.Chr <- orthologs <- significant <- NULL 38 | 39 | # Error check : proper format for arguments : 40 | if (!(is.character(sp1_label) & length(sp1_label) == 1)) { stop("Wrong format for argument 'sp1_label'. Must be a single value of type character")} 41 | if (!(is.character(sp2_label) & length(sp2_label) == 1)) { stop("Wrong format for argument 'sp2_label'. Must be a single value of type character")} 42 | # Error check : proper formatting of macrosynt_df 43 | required_fields <- c("sp1.Chr","sp2.Chr","orthologs","pval","significant","pval_adj") 44 | for (i in required_fields) { 45 | if (isFALSE(i %in% colnames(macrosynt_df))) { 46 | stop("Missing fields in the provided 'macrosynt_df'. All the following columns are required : sp1.Chr, sp2.Chr, orthologs, pval, significant, pval_adj") 47 | } 48 | } 49 | # Error check : macrosynt_df is empty 50 | if (length(macrosynt_df$sp1.Chr) == 0) {stop("Table provided through the 'macrosynt_df' argument is empty")} 51 | # Warning check : when number of chromosomes is too high 52 | if (length(unique(macrosynt_df$sp1.Chr)) >= 300) { 53 | warning(paste0("The first species in the 'macrosynt_df' has ",length(unique(macrosynt_df$sp1.Chr))," chromosomes. Computational time can be very long on fragmented genomes")) 54 | } 55 | if (length(unique(macrosynt_df$sp2.Chr)) >= 300) { 56 | warning(paste0("The second species in the 'macrosynt_df' has ",length(unique(macrosynt_df$sp2.Chr))," chromosomes. Computational time can be very long on fragmented genomes")) 57 | } 58 | 59 | macrosynt_df_to_plot <- macrosynt_df 60 | 61 | ### Plot : 62 | p <- ggplot2::ggplot(macrosynt_df_to_plot,aes(x=sp1.Chr,y=sp2.Chr)) + 63 | ggplot2::geom_point(aes(size=orthologs,color=significant)) + 64 | ggplot2::theme_bw() + 65 | ggplot2::scale_color_manual(values=c("#cf6b04","#4baaf2")) + 66 | ggplot2::scale_y_discrete(limits=rev) + 67 | ggplot2::scale_x_discrete(position = "top") + 68 | ggplot2::labs(x=sp1_label,y=sp2_label) 69 | 70 | 71 | p <- p + ggplot2::theme(axis.ticks = ggplot2::element_blank(),legend.position = "none", 72 | axis.title.x = ggplot2::element_text(family = "sans",size = 12), 73 | axis.text.x = ggplot2::element_text(family = "sans",size = 7,angle=90), 74 | axis.text.y = ggplot2::element_text(family = "sans",size = 7), 75 | axis.title = ggplot2::element_text(family = "sans",size = 12), 76 | legend.text = ggplot2::element_text(size = 8), 77 | legend.title = ggplot2::element_text(size = 10), 78 | plot.title = ggplot2::element_text(family = "sans",size=12,hjust = 0.5), 79 | plot.background = ggplot2::element_rect(fill = "white",colour = "white")) 80 | 81 | 82 | return(p) 83 | 84 | } -------------------------------------------------------------------------------- /R/plot_oxford_grid.R: -------------------------------------------------------------------------------- 1 | # plot_oxford_grid 2 | # 3 | # This is a function to plot the oxford grided plot to compare the macro synteny of two species 4 | #' @title plot the Macro-synteny as an oxford grid. 5 | #' @description This is a function to plot the oxford grided plot to compare the macro synteny of two species. It requires as input an orthologs_df loaded by load_orthologs() 6 | #' 7 | #' @param orthologs_df dataframe. orthologs with genomic coordinates loaded by the load_orthologs() 8 | #' @param sp1_label character. name of 1st species to display on the plot 9 | #' @param sp2_label character. name of 2nd species to display on the plot 10 | #' @param dot_size numeric. (default = 0.5) 11 | #' @param dot_alpha numeric. (default = 0.4) 12 | #' @param reorder logical. (default = FALSE) tells whether to reorder the chromosomes in clusters as implemented in reorder_macrosynteny() 13 | #' @param keep_only_significant logical. (default = FALSE) 14 | #' @param color_by string/variable name. (default = NULL) column of the orthologs_df to use to color the dots. 15 | #' @param pvalue_threshold numeric. (default = 0.001) 16 | #' @param color_palette vector. (default = NULL) list of colors (as string under double quote) for the clusters. The amount of colors must match the amount of clusters. 17 | #' @param shade_non_significant logical. (default = TRUE) When TRUE the orthologs located on non-significant linkage groups are displayed in "grey" 18 | #' @param reverse_species logical. (default = FALSE) When TRUE the x and y axis of the plot are reversed. sp1 is displayed on the y axis and sp2 is displayed on the x axis. 19 | #' @param keep_sp1_raw_order logical.(default equals FALSE) tells if the reordering should be constrained on the species1 and change just the order of the species2 20 | #' 21 | #' @seealso [load_orthologs()] 22 | #' @seealso [reorder_macrosynteny()] 23 | #' 24 | #' @return A ggplot2 object 25 | #' 26 | #' @import ggplot2 27 | #' 28 | #' @examples 29 | #' # basic usage of plot_oxford_grid : 30 | #' 31 | #' orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 32 | #' 33 | #' my_orthologs <- read.table(orthologs_table,header=TRUE) 34 | #' 35 | #' plot_oxford_grid(my_orthologs, 36 | #' sp1_label = "B. floridae", 37 | #' sp2_label = "P. echinospica") 38 | #' 39 | #' # plot a reordered Oxford Grid and color by cluster : 40 | #' \donttest{ 41 | #' plot_oxford_grid(my_orthologs, 42 | #' sp1_label = "B. floridae", 43 | #' sp2_label = "P. echinospica", 44 | #' reorder = TRUE, 45 | #' color_by = "clust") 46 | #' } 47 | #' @export 48 | 49 | 50 | plot_oxford_grid <- function(orthologs_df, 51 | sp1_label = "", 52 | sp2_label = "", 53 | dot_size = 0.5, 54 | dot_alpha = 0.4, 55 | reorder = FALSE, 56 | keep_only_significant = FALSE, 57 | color_by = NULL, 58 | pvalue_threshold= 0.001, 59 | color_palette = NULL, 60 | shade_non_significant = TRUE, 61 | reverse_species = FALSE, 62 | keep_sp1_raw_order = FALSE) { 63 | 64 | sp1.Index <- sp2.Index <- sp2.Chr <-significant <- clust <- NULL 65 | 66 | orthologs_df_to_plot <- orthologs_df 67 | # Error check : proper format for arguments : 68 | if (!(is.character(sp1_label) & length(sp1_label) == 1)) { stop("Wrong format for argument 'sp1_label'. Must be a single value of type character")} 69 | if (!(is.character(sp2_label) & length(sp2_label) == 1)) { stop("Wrong format for argument 'sp2_label'. Must be a single value of type character")} 70 | if (!(is.numeric(dot_size) & length(dot_size) == 1)) { stop("Wrong format for argument 'dot_size'. Must be a single value of type numeric")} 71 | if (!(is.numeric(dot_alpha) & length(dot_alpha) == 1)) { stop("Wrong format for argument 'dot_alpha'. Must be a single value of type numeric")} 72 | if (!(is.logical(reorder) & length(reorder) == 1)) { stop("Wrong format for argument 'reorder'. Must be a single value of type logical")} 73 | if (!(is.logical(keep_only_significant) & length(keep_only_significant) == 1)) { stop("Wrong format for argument 'keep_only_significant'. Must be of type logical")} 74 | if (!(is.logical(shade_non_significant) & length(shade_non_significant) == 1)) { stop("Wrong format for argument 'shade_non_significant'. Must be of type logical")} 75 | if (!(is.logical(reverse_species) & length(reverse_species) == 1)) { stop("Wrong format for argument 'reverse_species'. Must be of type logical")} 76 | if (!(is.logical(keep_sp1_raw_order) & length(keep_sp1_raw_order) == 1)) { stop("Wrong format for argument 'keep_sp1_raw_order'. Must be of type logical")} 77 | 78 | if(!(is.null(color_by))) { 79 | if (reorder) { 80 | if (!((color_by %in% colnames(orthologs_df) | color_by == "clust") & length(color_by) == 1 & is.character(color_by))) { 81 | stop("Wrong format for 'color_by' argument. Must be a single value of type character and correspond to the name of one column of the orthologs_df") 82 | } 83 | } 84 | else if (!(color_by %in% colnames(orthologs_df) & length(color_by) == 1 & is.character(color_by))) { 85 | stop("Wrong format for 'color_by' argument. Must be a single value of type character and correspond to the name of one column of the orthologs_df") 86 | } 87 | } 88 | if (!(is.numeric(pvalue_threshold) & length(pvalue_threshold) == 1)) {stop("Wrong format for 'pvalue_threshold' argument. Must be a single value of type numeric")} 89 | if (!(is.null(color_by))) { 90 | if (color_by != "clust") { 91 | if (!(is.null(color_palette)) & (length(color_palette) < length(unique(orthologs_df[[color_by]])))) {stop(paste("Wrong format in argument 'color_palette'. Must be a list of colors with as much values as the amount of unique elements in the column specified in the argument 'color_by'. color palette has ", 92 | length(color_palette)," elements, while the color_by column is ",length(unique(orthologs_df[[color_by]]))))} 93 | } 94 | } 95 | 96 | # Error check : format of orthologs_df 97 | required_fields <- c("sp1.ID","sp1.Index","sp1.Chr","sp2.ID","sp2.Index","sp2.Chr") 98 | for (i in required_fields) { 99 | if (isFALSE(i %in% colnames(orthologs_df))) { 100 | stop("Missing fields in the provided 'orthologs_df'. All the following columns are required : sp1.ID,sp1.Index,sp1.Chr,sp2.ID,sp2.Index,sp2.Chr") 101 | } 102 | } 103 | # Error check : orthologs_df is empty 104 | if (length(orthologs_df$sp1.Chr) == 0) {stop("Table provided through the 'orthologs_df' argument is empty")} 105 | # Warning check : when number of chromosomes is too high 106 | if (length(unique(orthologs_df$sp1.Chr)) >= 300) { 107 | warning(paste0("The first species in the 'orthologs_df' has ",length(unique(orthologs_df$sp1.Chr))," chromosomes. Computational time can be very long on fragmented genomes")) 108 | } 109 | if (length(unique(orthologs_df$sp2.Chr)) >= 300) { 110 | warning(paste0("The second species in the 'orthologs_df' has ",length(unique(orthologs_df$sp2.Chr))," chromosomes. Computational time can be very long on fragmented genomes")) 111 | } 112 | ### reverse species if needed : 113 | if (reverse_species) { 114 | orthologs_df <- reverse_species_order(orthologs_df) 115 | } 116 | 117 | ### reorder df first : 118 | if (reorder) { 119 | # calculate clusters and reordered synteny 120 | orthologs_reordered <- reorder_macrosynteny(orthologs_df,pvalue_threshold = pvalue_threshold, 121 | keep_only_significant = keep_only_significant, 122 | keep_sp1_raw_order = keep_sp1_raw_order) 123 | orthologs_df_to_plot <- orthologs_reordered 124 | } 125 | # separate dots not in clusters, and dots in clusters 126 | if (! is.null(color_by)) { 127 | # ### [Exception here] Check that orthologs_df_to_plot has the clust column 128 | # if (!(color_ %in% colnames(orthologs_df_to_plot))) { 129 | # stop("Asked to color the clusters but the clust column couldn't be found in the data. Make sure to set reorder = TRUE or use reorder_macrosynteny()") 130 | # } 131 | ### 132 | # convert to character for discrete values coloring : 133 | temp_macrosynt <- compute_macrosynteny(orthologs_df) 134 | temp_orthologs_and_macrosynt <- merge(orthologs_df_to_plot,temp_macrosynt) 135 | final_df_with_groups <- subset(temp_orthologs_and_macrosynt,significant == "yes") 136 | non_linkage_df <- subset(temp_orthologs_and_macrosynt, significant == "no") 137 | 138 | # initialize the plot with colors : 139 | color_by_sym <- ggplot2::ensym(color_by) 140 | p <- ggplot2::ggplot(final_df_with_groups,ggplot2::aes(x=sp1.Index,y=sp2.Index,color = !!color_by_sym)) + 141 | ggplot2::geom_point(size=dot_size,alpha=dot_alpha) 142 | # Check shade_non_significant: 143 | if (shade_non_significant) { 144 | p <- p + ggplot2::geom_point(data = non_linkage_df,ggplot2::aes(x=sp1.Index,y=sp2.Index), 145 | color="gray", 146 | size = dot_size, 147 | alpha = dot_alpha) 148 | } 149 | else { p <- p + ggplot2::geom_point(data = non_linkage_df,ggplot2::aes(x=sp1.Index,y=sp2.Index,color = !!color_by_sym), 150 | size = dot_size, 151 | alpha = dot_alpha) 152 | } 153 | 154 | if (! is.null(color_palette)) { 155 | #### [Exception here] : check that length(clusters_color_palette) == length(levels(final_df_with_groups$clust)) 156 | p <- p + 157 | ggplot2::scale_color_manual(values = color_palette) 158 | } 159 | } 160 | else { 161 | p <- ggplot2::ggplot(orthologs_df_to_plot,ggplot2::aes(x=sp1.Index,y=sp2.Index)) + ggplot2::geom_jitter(size=dot_size,alpha=dot_alpha) 162 | } 163 | ### build the plot : 164 | p <- p + ggplot2::theme_void() + 165 | ggplot2::facet_grid(sp2.Chr ~ sp1.Chr,scales = "free",space = "free") + 166 | ggplot2::theme(axis.text.y=ggplot2::element_blank(), 167 | axis.text.x=ggplot2::element_blank(), 168 | strip.text.x=ggplot2::element_text(family="sans",angle=90,size = 7), 169 | strip.text.y=ggplot2::element_text(family="sans",angle=0,size = 7), 170 | axis.title.x =ggplot2::element_text(family="sans",size=10), 171 | axis.title.y =ggplot2::element_text(family="sans",size=12), 172 | plot.subtitle =ggplot2::element_text(family="sans",size=12,hjust = 0.5), 173 | strip.background=ggplot2::element_rect(colour="white",fill="white"), 174 | plot.background = ggplot2::element_rect(fill = "white",colour = "white"), 175 | axis.ticks = ggplot2::element_blank(), 176 | legend.position = "none", 177 | panel.spacing = ggplot2::unit(0.01, "lines"), 178 | panel.grid = ggplot2::element_blank(), 179 | panel.border = ggplot2::element_rect(fill = NA, color = "gray",size=0.1), 180 | panel.background = ggplot2::element_rect(fill = "white", colour = "white")) + 181 | ggplot2::labs(y=sp2_label, x= paste0("(",length(orthologs_df_to_plot$sp1.ID)," orthologs)"),subtitle = sp1_label) 182 | 183 | return(p) 184 | 185 | } -------------------------------------------------------------------------------- /R/reorder_macrosynteny.R: -------------------------------------------------------------------------------- 1 | # reorder_macrosynteny 2 | # 3 | # This is a function to reorder an orthologs_df, that was generated with load_orthologs(). It retrieves communities using igraph::cluster_fast_greedy. 4 | #' @title Reorder the mbh_df before plotting 5 | #' @description This is a function to reorder an orthologs_df, that was generated with load_orthologs(). It retrieves communities using igraph::cluster_fast_greedy. 6 | #' 7 | #' @param orthologs_df dataframe. mutual best hits with genomic coordinates loaded with load_orthologs() 8 | #' @param pvalue_threshold numeric. threshold for significancy. (default equals 0.001) 9 | #' @param keep_only_significant logical. (default equals FALSE) tells if the non significant linkage groups should be removed. It drastically speeds up the computation when using one highly fragmented genome. 10 | #' @param keep_sp1_raw_order logical. (default equals FALSE) tells if the reordering should be constrained on the species1 and change just the order of the species2 11 | #' 12 | #' @return A dataframe object 13 | #' @seealso [load_orthologs()] 14 | #' @seealso [compute_macrosynteny()] 15 | #' 16 | #' @importFrom igraph graph_from_data_frame cluster_fast_greedy groups 17 | #' @importFrom dplyr select rename arrange group_by summarise ungroup mutate setdiff desc 18 | #' @importFrom stringr str_subset str_replace 19 | #' 20 | #'@examples 21 | #' # basic usage of reorder_macrosynteny : 22 | #' 23 | #' orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 24 | #' 25 | #' my_orthologs <- read.table(orthologs_table,header=TRUE) 26 | #' 27 | #' my_orthologs_reordered <- reorder_macrosynteny(my_orthologs) 28 | #' 29 | #' @export 30 | 31 | 32 | reorder_macrosynteny <- function(orthologs_df, 33 | pvalue_threshold = 0.001, 34 | keep_only_significant = FALSE, 35 | keep_sp1_raw_order = FALSE) { 36 | 37 | contingency_table <- significant_entries <- significant_entries_for_graph <- NULL 38 | significant_entries_for_graph <- significant_association_undirected_graph <- clusters <- cluster_df <- NULL 39 | sp1_amounts <- sp2_amounts <- NULL 40 | final_levels_sp1 <- final_levels_sp2 <- NULL 41 | significant <- pval <- orthologs <- sp1.Chr <- sp2.Chr <- amounts <- clust <- n <- weight <- NULL 42 | 43 | # Error check : 44 | # Error check : proper format for arguments : 45 | if (!(is.numeric(pvalue_threshold) & length(pvalue_threshold) == 1)) {stop("Wrong format for 'pvalue_threshold' argument. Must be a single value of type numeric")} 46 | if (!(is.logical(keep_only_significant) & length(keep_only_significant) == 1)) { stop("Wrong format for argument 'keep_only_significant'. Must be of type logical")} 47 | if (!(is.logical(keep_sp1_raw_order) & length(keep_sp1_raw_order) == 1)) { stop("Wrong format for argument 'keep_sp1_raw_order'. Must be of type logical")} 48 | # Error check : proper formatting of macrosynt_df 49 | # Error check : format of orthologs_df 50 | required_fields <- c("sp1.ID","sp1.Index","sp1.Chr","sp2.ID","sp2.Index","sp2.Chr") 51 | for (i in required_fields) { 52 | if (isFALSE(i %in% colnames(orthologs_df))) { 53 | stop("Missing fields in the provided 'orthologs_df'. All the following columns are required : sp1.ID,sp1.Index,sp1.Chr,sp2.ID,sp2.Index,sp2.Chr") 54 | } 55 | } 56 | # Error check : orthologs_df is empty 57 | if (length(orthologs_df$sp1.Chr) == 0) {stop("Table provided through the 'orthologs_df' argument is empty")} 58 | # Warning check : when number of chromosomes is too high 59 | if (length(unique(orthologs_df$sp1.Chr)) >= 300) { 60 | warning(paste0("The first species in the 'orthologs_df' has ",length(unique(orthologs_df$sp1.Chr))," chromosomes. Computational time can be very long on fragmented genomes")) 61 | } 62 | if (length(unique(orthologs_df$sp2.Chr)) >= 300) { 63 | warning(paste0("The second species in the 'orthologs_df' has ",length(unique(orthologs_df$sp2.Chr))," chromosomes. Computational time can be very long on fragmented genomes")) 64 | } 65 | 66 | ##### 1 - Build an undirected and unweighted graph of connected chromosomes (significant amount of orthologs) 67 | # rename_chromosomes to ensure uniqueness of names in graph : 68 | levels(orthologs_df$sp1.Chr) <- paste0("sp1_Chr_",levels(orthologs_df$sp1.Chr)) 69 | levels(orthologs_df$sp2.Chr) <- paste0("sp2_Chr_",levels(orthologs_df$sp2.Chr)) 70 | # These prefix are removed at the end of the function 71 | 72 | # Get a table with only significant association using compute_macrosynteny from this package : 73 | contingency_table <- compute_macrosynteny(orthologs_df,pvalue_threshold) 74 | if (keep_only_significant) { 75 | significant_entries <- subset(contingency_table,significant == "yes") 76 | } 77 | else { 78 | significant_entries <- contingency_table 79 | } 80 | 81 | 82 | # build an Undirected weighted graph between sp1.chr and sp2.chr containing all significant edges : 83 | significant_entries_for_graph <- significant_entries %>% dplyr::select(-significant,-pval,) %>% dplyr::rename(from = sp1.Chr,to = sp2.Chr, weight = orthologs) 84 | # compute clusters of sp1.Chr and sp2.Chr that are directly or indirectly connected in the graph : 85 | significant_association_undirected_graph <- igraph::graph_from_data_frame(significant_entries_for_graph, directed = F) 86 | clusters <- igraph::cluster_fast_greedy(significant_association_undirected_graph) 87 | 88 | ##### DONE : Built the graph 89 | 90 | ##### 2 - Compute amounts of orthologs in each cluster and order them by attributing them an index from 1 to n (1 being the larger cluster) : 91 | chroms_in_cluster_as_string <- NULL 92 | ortholog_amount_in_cluster <- NULL 93 | for (list_of_chrom_in_cluster in igraph::groups(clusters)) { 94 | temp_amounts <- subset(significant_entries,(sp1.Chr %in% list_of_chrom_in_cluster) & (sp2.Chr %in% list_of_chrom_in_cluster)) 95 | chroms_in_cluster_as_string <- c(chroms_in_cluster_as_string,paste(list_of_chrom_in_cluster,collapse = ",")) 96 | ortholog_amount_in_cluster <- c(ortholog_amount_in_cluster,sum(temp_amounts$orthologs)) 97 | } 98 | cluster_df <- data.frame(clust = chroms_in_cluster_as_string, 99 | amounts = ortholog_amount_in_cluster) %>% 100 | dplyr::arrange(dplyr::desc(amounts)) 101 | cluster_df$num_clust <- letters[1:length(cluster_df$amounts)] 102 | ##### DONE : Computed order of clusters 103 | 104 | ##### 3 - Compute order of chromosomes by recomputing the levels of the factor. sorting by descending cluster size then descencding chromosome size. 105 | # get a table with number of orthologs for each chromosome 106 | if (keep_sp1_raw_order) { 107 | final_levels_sp1 <- levels(orthologs_df$sp1.Chr) 108 | final_levels_sp2 <- NULL 109 | sp1_amounts <- significant_entries %>% dplyr::group_by(sp1.Chr) %>% dplyr::summarise(n=sum(orthologs)) %>% dplyr::ungroup() 110 | sp2_amounts <- significant_entries %>% dplyr::group_by(sp2.Chr) %>% dplyr::summarise(n=sum(orthologs)) %>% dplyr::ungroup() 111 | chrom_clusters_reordered <- cluster_df$clust 112 | for (i in final_levels_sp1) { 113 | matching_clusters <- stringr::str_subset(chrom_clusters_reordered,paste0(i,",")) 114 | chrom_cluster_list <- strsplit(matching_clusters,",")[[1]] 115 | for (chrom in chrom_cluster_list) { 116 | if (!(chrom %in% final_levels_sp1)) { 117 | if (!(chrom %in% final_levels_sp2)) { 118 | final_levels_sp2 <- c(final_levels_sp2,chrom) 119 | } 120 | } 121 | } 122 | } 123 | } 124 | else { 125 | sp1_amounts <- significant_entries %>% dplyr::group_by(sp1.Chr) %>% dplyr::summarise(n=sum(orthologs)) %>% dplyr::ungroup() 126 | sp2_amounts <- significant_entries %>% dplyr::group_by(sp2.Chr) %>% dplyr::summarise(n=sum(orthologs)) %>% dplyr::ungroup() 127 | chrom_clusters_reordered <- cluster_df$clust 128 | for(chrom_cluster in chrom_clusters_reordered) { 129 | chrom_cluster_list <- strsplit(chrom_cluster,",")[[1]] 130 | cluster_levels_sp1 <- NULL 131 | cluster_levels_sp2 <- NULL 132 | for (chrom in chrom_cluster_list) { 133 | if (chrom %in% orthologs_df$sp1.Chr) { 134 | cluster_levels_sp1 <- c(cluster_levels_sp1,chrom) 135 | } 136 | else { 137 | cluster_levels_sp2 <- c(cluster_levels_sp2,chrom) 138 | } 139 | } 140 | # order the chromosomes from larger to smaller (in amount of orthologs) : 141 | cluster_levels_sp1_df <- subset(sp1_amounts,sp1.Chr %in% cluster_levels_sp1) %>% 142 | dplyr::arrange(dplyr::desc(n)) 143 | final_levels_sp1 <- c(final_levels_sp1,as.character(cluster_levels_sp1_df$sp1.Chr)) 144 | cluster_levels_sp2_df <- subset(sp2_amounts,sp2.Chr %in% cluster_levels_sp2) %>% 145 | dplyr::arrange(dplyr::desc(n)) 146 | final_levels_sp2 <- c(final_levels_sp2,as.character(cluster_levels_sp2_df$sp2.Chr)) 147 | 148 | }} 149 | orthologs_df_to_return <- subset(orthologs_df, (sp1.Chr %in% final_levels_sp1) & (sp2.Chr %in% final_levels_sp2)) 150 | orthologs_df_to_return$sp1.Chr <- factor(orthologs_df_to_return$sp1.Chr,levels = final_levels_sp1) 151 | orthologs_df_to_return$sp2.Chr <- factor(orthologs_df_to_return$sp2.Chr,levels = final_levels_sp2) 152 | ##### DONE : Computed order of chromosomes 153 | 154 | ##### 4 - Add an additional column with clusters number : 155 | final_df_with_groups <- NULL 156 | cluster_num <- 0 157 | # cluster_df calculated in part 2 of this function 158 | chrom_clusters_reordered <- cluster_df$clust 159 | for (i in chrom_clusters_reordered){ 160 | chrom_cluster_list <- strsplit(i,",")[[1]] 161 | cluster_num <- cluster_num + 1 162 | temp <- subset(orthologs_df_to_return,((sp1.Chr %in% chrom_cluster_list) & (sp2.Chr %in% chrom_cluster_list))) %>% 163 | dplyr::mutate(clust = letters[cluster_num]) 164 | final_df_with_groups <- rbind(final_df_with_groups,temp) 165 | } 166 | # convert to character for discrete values coloring : 167 | # final_df_with_groups$clust <- as.character(final_df_with_groups$clust) 168 | # build a second dataframe with dots not on linkage groups to display in grey : 169 | non_linkage_df <- final_df_with_groups %>% dplyr::select(-clust) 170 | # check that the clust column doesn't exist : 171 | if ("clust" %in% colnames(orthologs_df_to_return)) { 172 | orthologs_df_to_return <- orthologs_df_to_return %>% 173 | dplyr::select(-clust) 174 | } 175 | non_linkage_df <- dplyr::setdiff(orthologs_df_to_return,non_linkage_df) %>% 176 | dplyr::mutate(clust = "0") 177 | final_df_with_groups <- rbind(final_df_with_groups,non_linkage_df) 178 | orthologs_df_to_return <- merge(orthologs_df_to_return,final_df_with_groups) 179 | 180 | # Remove prefix that granted uniqueness of chromosome names : 181 | levels(orthologs_df_to_return$sp1.Chr) <- stringr::str_replace(levels(orthologs_df_to_return$sp1.Chr),"sp1_Chr_","") 182 | levels(orthologs_df_to_return$sp2.Chr) <- stringr::str_replace(levels(orthologs_df_to_return$sp2.Chr),"sp2_Chr_","") 183 | 184 | return(orthologs_df_to_return) 185 | } -------------------------------------------------------------------------------- /R/reorder_multiple_macrosyntenies.R: -------------------------------------------------------------------------------- 1 | # reorder_multiple_macrosyntenies 2 | # 3 | # This is a function to reorder an orthologs_df, that was generated with load_orthologs(). 4 | # It retrieves communities using igraph::cluster_fast_greedy 5 | 6 | #' @title Reorder the chromosomes of two or more species before plotting 7 | #' @description This is a function to reorder an orthologs_df, same as reorder_macrosynteny, 8 | #' but it handles tables with more than 2 species. 9 | #' 10 | #' @param orthologs_df dataframe. orthologs with genomic coordinates loaded with load_orthologs() 11 | #' 12 | #' @return A dataframe object 13 | #' @seealso [load_orthologs()] 14 | #' @seealso [compute_macrosynteny()] 15 | #' @seealso [reorder_macrosynteny()] 16 | #' 17 | #' 18 | #'@examples 19 | #' # basic usage of reorder_macrosynteny : 20 | #' 21 | #' orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 22 | #' 23 | #' my_orthologs <- read.table(orthologs_table,header=TRUE) 24 | #' 25 | #' my_orthologs_reordered <- reorder_multiple_macrosyntenies(my_orthologs) 26 | #' 27 | #' @export 28 | 29 | 30 | reorder_multiple_macrosyntenies <- function(orthologs_df) { 31 | 32 | amount_of_species <- length(which(colnames(orthologs_df) %in% paste0("sp",c(1:60),".Chr"))) 33 | orthologs_df_to_return <- orthologs_df 34 | 35 | for (i in c(1:(amount_of_species-1))) { 36 | departure_species <- paste0("sp",i) 37 | arrival_species <- paste0("sp",i+1) 38 | # subset the dataframe to have only the two species under study : 39 | departure_colnames <- colnames(orthologs_df)[grep(departure_species,colnames(orthologs_df))] 40 | arrival_colnames <- colnames(orthologs_df)[grep(arrival_species,colnames(orthologs_df))] 41 | subset_orthologs_df <- orthologs_df_to_return[c(departure_colnames,arrival_colnames)] 42 | 43 | # rename departure_species into sp1 and arrival_species into sp2 : 44 | temp_colnames <- gsub(departure_species,"sp1",colnames(subset_orthologs_df)) 45 | temp_colnames <- gsub(arrival_species,"sp2",temp_colnames) 46 | 47 | colnames(subset_orthologs_df) <- temp_colnames 48 | # use reorder_macrosynteny to reorder pairwise (keep_sp1_raw_order after the first run) 49 | if (i > 1) { keep_sp1_raw_order <- TRUE } 50 | else { keep_sp1_raw_order <- FALSE } 51 | subset_orthologs_reordered <- reorder_macrosynteny(subset_orthologs_df, 52 | keep_sp1_raw_order = keep_sp1_raw_order) 53 | 54 | # get only the resulting levels to apply on the spX.Chr of orthologs_df 55 | reordered_levels_departure <- levels(subset_orthologs_reordered$sp1.Chr) 56 | reordered_levels_arrival <- levels(subset_orthologs_reordered$sp2.Chr) 57 | 58 | orthologs_df_to_return[[paste0(departure_species,".Chr")]] <- factor(orthologs_df_to_return[[paste0(departure_species,".Chr")]], levels = reordered_levels_departure) 59 | orthologs_df_to_return[[paste0(arrival_species,".Chr")]] <- factor(orthologs_df_to_return[[paste0(arrival_species,".Chr")]],levels = reordered_levels_arrival) 60 | 61 | 62 | } 63 | 64 | return(orthologs_df_to_return) 65 | } -------------------------------------------------------------------------------- /R/reverse_species_order.R: -------------------------------------------------------------------------------- 1 | # reverse_species_order 2 | # 3 | # This is a function to reverse the species order in an orthologs_df. 4 | #' @title Reverse order of the species in an orthologs_df. 5 | #' @description Returns an orthologs_df (data.frame) with reversed species order compared to the inputted orthologs_df. 6 | #' sp1 becomes sp2 and the otherway around. It intends at facilitating the integration of more than just two datasets. 7 | #' It outputs a data.frame shaped as following : 8 | #' sp1.ID,sp1.Chr,sp1.Start,sp1.End,sp1.Index,sp2.ID,sp2.Chr,sp2.Start,sp2.End,sp2.Index 9 | #' 10 | #' @param orthologs_df orthologs_df dataframe. mutual best hits with genomic coordinates loaded with load_orthologs() 11 | 12 | #' @return dataframe composed of genomic coordinates and relative index of orthologs on both species 13 | #' 14 | #' @seealso [load_orthologs()] 15 | #' 16 | #' 17 | #' @examples 18 | #' # basic usage of reverse_species_order : 19 | #' 20 | #' orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 21 | #' 22 | #' my_orthologs <- read.table(orthologs_table,header=TRUE) 23 | #' 24 | #' my_orthologs_reversed <- reverse_species_order(my_orthologs) 25 | #' 26 | #' @export 27 | 28 | 29 | reverse_species_order <- function(orthologs_df) { 30 | 31 | temp_colnames <- orthologs_df_to_return <- NULL 32 | 33 | #### Error check : format of orthologs_df 34 | required_fields <- c("sp1.ID","sp1.Index","sp1.Chr","sp2.ID","sp2.Index","sp2.Chr") 35 | for (i in required_fields) { 36 | if (isFALSE(i %in% colnames(orthologs_df))) { 37 | stop("Missing fields in the provided 'orthologs_df'. All the following columns are required : sp1.ID,sp1.Index,sp1.Chr,sp2.ID,sp2.Index,sp2.Chr") 38 | } 39 | } 40 | # Error check : orthologs_df is empty 41 | if (length(orthologs_df$sp1.Chr) == 0) {stop("Table provided through the 'orthologs_df' argument is empty")} 42 | 43 | ### RUN 44 | # replace sp1 by sp2 and sp2 by sp1 in colnames : 45 | temp_colnames <- colnames(orthologs_df) 46 | temp_colnames <- gsub("sp1","spx",temp_colnames) 47 | temp_colnames <- gsub("sp2","sp1",temp_colnames) 48 | temp_colnames <- gsub("spx","sp2",temp_colnames) 49 | 50 | # copy the orthologs_df and assign the modified colnames in the new table : 51 | orthologs_df_to_return <- orthologs_df 52 | colnames(orthologs_df_to_return) <- temp_colnames 53 | 54 | return(orthologs_df_to_return) 55 | } -------------------------------------------------------------------------------- /R/subset_linkage_orthologs.R: -------------------------------------------------------------------------------- 1 | # subset_linkage_orthologs 2 | # 3 | # This is a function to subset_the orthologs that are contained in the linkage groups of an orthologs_df 4 | #' @title Subset Orthologs contained in conserved linkage groups 5 | #' @description This is a function to subset an orthologs_df and keep only the orthologs that are within significant 6 | #' linkage groups computed by the function compute_linkage_groups(). 7 | #' 8 | #' @param orthologs_df dataframe. orthologs with genomic coordinates loaded with load_orthologs() 9 | #' @param linkages dataframe. table listing the linkage groups as returned by the function compute_linkage_groups() 10 | #' 11 | #' @seealso [load_orthologs()] 12 | #' @seealso [compute_linkage_groups()] 13 | #' 14 | #' @return A dataframe object 15 | #' 16 | #' @import tidyr 17 | #' @importFrom dplyr group_by arrange mutate row_number ungroup 18 | #' 19 | #' @examples 20 | #' # basic usage of compute_linkage_groups: 21 | #' 22 | #' orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 23 | #' 24 | #' my_orthologs <- read.table(orthologs_table,header=TRUE) 25 | #' 26 | #' my_macrosynteny <- compute_linkage_groups(my_orthologs) 27 | #' 28 | #' @export 29 | 30 | 31 | 32 | subset_linkage_orthologs <- function(orthologs_df, 33 | linkages=NULL) { 34 | 35 | sp1.Chr <- sp1.Start <- sp2.Chr <- sp2.Start <- NULL 36 | 37 | if (is.null(linkages)) { 38 | linkages <- compute_linkage_groups(orthologs_df) 39 | } 40 | 41 | orthologs_df_to_return <- merge(orthologs_df,linkages) 42 | 43 | # recompute indexes : 44 | orthologs_df_to_return <- orthologs_df_to_return %>% 45 | group_by(sp1.Chr) %>% arrange(sp1.Start) %>% mutate(sp1.Index = dplyr::row_number()) %>% ungroup() %>% 46 | group_by(sp2.Chr) %>% arrange(sp2.Start) %>% mutate(sp2.Index = dplyr::row_number()) %>% ungroup() 47 | 48 | 49 | return(orthologs_df_to_return) 50 | } 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # macrosyntR 2 | 3 | 4 | An R package for evaluation of synteny conservation at the genome-wide scale. 5 | It takes a table of orthologs and genome annotation files formatted as BED to automatically 6 | infer significantly conserved linkage groups, and order them on an Oxford grid or a chord diagram using a network based greedy algorithm. 7 | 8 | 9 | [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) 10 | [![CRAN](http://www.r-pkg.org/badges/version/macrosyntR)](https://cran.r-project.org/package=macrosyntR) 11 | [![downloads](https://cranlogs.r-pkg.org/badges/grand-total/macrosyntR)](https://cran.r-project.org/package=macrosyntR) 12 | [![bioRxiv:10.1101/2023.01.26.525673](https://img.shields.io/badge/bioRxiv-10.1101/2023.01.26.525673-abcfed.svg)](https://doi.org/10.1101/2023.01.26.525673) 13 | 14 | 15 | ----------------------------------------------------------------------- 16 | 17 | 18 | # Installation 19 | 20 | ```{r} 21 | 22 | # A stable version is available on CRAN and can be downloaded using : 23 | install.packages("macrosyntR") 24 | # get the development version from GitHub using devtools : 25 | # install.packages("devtools") 26 | devtools::install_github("SamiLhll/macrosyntR",build_vignettes = TRUE) 27 | # building the vignette makes the installation a bit longer but its mandatory so ou can access it by doing : 28 | vignette("macrosyntR") 29 | 30 | ``` 31 | 32 | 33 | # Usage 34 | 35 | Check out the vignette for a comprehensive step-by-step tutorial illustrating how the package works using publicly available data, and how to customize the analysis. 36 | 37 | ### Preparing input data : 38 | 39 | To start comparing species, you'll need two types of files : 40 | * 1 - A two columns table of orthologous genes between species to compare as generated by [rbhxpress](https://github.com/SamiLhll/rbhXpress), or derived from OrthoFinder (see Vignette) 41 | * 2 - A bed file listing the genomic coordinates and sequence names of all the orthologs of all the species (with names matching the columns of file 1) 42 | 43 | ### Get an automatically ordered and colored Oxford grid : 44 | 45 | To illustrate the results of the package we compare the publicly available data from the lancelet Branchiostoma floridae ([Simakov et al. 2020](https://doi.org/10.1038/s41559-020-1156-z)) with the Siboglinidae Paraescarpia echinospica ([Sun et al. 2021](https://doi.org/10.1093/molbev/msab203)) 46 | Once you have your pairs of orthologs, getting an ordered Oxford grid using this package is achieved as following : 47 | 48 | ```{r} 49 | 50 | library(macrosyntR) 51 | 52 | # Load table of orthologs and integrate with genomic coordinates : 53 | my_orthologs_table <- load_orthologs(orthologs_table = system.file("extdata","Bflo_vs_Pech.tab",package="macrosyntR"), 54 | bedfiles = c(system.file("extdata","Bflo.bed",package="macrosyntR"), 55 | system.file("extdata","Pech.bed",package="macrosyntR"))) 56 | 57 | # Draw an oxford grid : 58 | p1 <- plot_oxford_grid(my_orthologs, 59 | sp1_label = "B.floridae", 60 | sp2_label = "P.echinospica") 61 | p1 62 | 63 | # Automatically reorder the Oxford grid and color the detected clusters (communities): 64 | p2 <- plot_oxford_grid(my_orthologs, 65 | sp1_label = "B.floridae", 66 | sp2_label = "P.echinospica", 67 | reorder = TRUE, 68 | color_by = "clust") 69 | p2 70 | 71 | # Plot the significant linkage groups : 72 | my_macrosynteny <- compute_macrosynteny(my_orthologs) 73 | p3 <- plot_macrosynteny(my_macrosynteny) 74 | p3 75 | 76 | 77 | # Call the reordering function, test significance and plot it : 78 | my_orthologs_reordered <- reorder_macrosynteny(my_orthologs) 79 | my_macrosynteny <- compute_macrosynteny(my_orthologs_reordered) 80 | p4 <- plot_macrosynteny(my_macrosynteny) 81 | p4 82 | 83 | ``` 84 | 85 | 86 | 87 | 88 | ## Compute linkage groups between three species and plot on a chord diagram : 89 | 90 | You can have compute the conserved linkage groups for two (or more species) and display them on a chord diagram. 91 | Here, I'm showing how it looks like when adding the data from the scallop Patinopecten yessoensis (Wang et al. (2017)). 92 | The content of the orthologs_table is now derived from OrthoFinder (Emms and Kelly (2019)) and the single copy orthologs were extracted with a command line such as : 93 | 94 | ```{bash} 95 | 96 | fgrep -f /Orthogroups/Orthogroups_SingleCopyOrthologues.txt \ 97 | /Orthogroups/Orthogroups.tsv > Single_copy_orthologs.tab 98 | 99 | # On linux and MacOS, if the result of 100 | file Single_copy_orthologs.tab 101 | # is ASCII text, with CRLF line terminators 102 | # then you should replace the line terminators by regular "\n" with a command such as : 103 | tr '\015\012/' '\n' < Single_copy_orthologs.tab | awk '($0 != "") {print}' > Single_copy_orthologs.tsv 104 | 105 | ``` 106 | 107 | Then you can draw a chord diagram displaying the conserved linkage groups such as : 108 | 109 | ```{r} 110 | # load data 111 | my_orthologs_with_3_sp <- load_orthologs(orthologs_table = system.file("extdata","Single_copy_orthologs.tsv",package="macrosyntR"), 112 | bedfiles = c(system.file("extdata","Bflo.bed",package="macrosyntR"), 113 | system.file("extdata","Pech.bed",package="macrosyntR"), 114 | system.file("extdata","Pyes.bed",package="macrosyntR"))) 115 | 116 | # Change the chromosome names to keep only numbers 117 | levels(my_orthologs_with_3_sp$sp1.Chr) <- stringr::str_replace(levels(my_orthologs_with_3_sp$sp1.Chr),"BFL","") 118 | levels(my_orthologs_with_3_sp$sp2.Chr) <- stringr::str_replace(levels(my_orthologs_with_3_sp$sp2.Chr),"PEC","") 119 | levels(my_orthologs_with_3_sp$sp3.Chr) <- stringr::str_replace(levels(my_orthologs_with_3_sp$sp3.Chr),"chr","") 120 | 121 | # Plot an automatically ordered chord diagram colored by the linkage groups : 122 | plot_chord_diagram(my_orthologs_with_3_sp, 123 | species_labels = c("B. flo","P. ech", "P. yes"), 124 | color_by = "LGs") + 125 | theme(legend.position = "none") 126 | 127 | # The linkage groups were automatically computed but you can also get them as a table using : 128 | my_linkage_groups <- compute_linkage_groups(my_orthologs_with_3_sp) 129 | 130 | ``` 131 | 132 | 133 | 134 | 135 | # Additional ressources 136 | 137 | ### Computing orthologs as reciprocal best hits : 138 | If you don't know how to do it, I implemented rbhXpress. It uses Diamond blast to generate an output compatible with macrosyntR. 139 | Please find more details in the following repository : [rbhXpress](https://github.com/SamiLhll/rbhXpress) 140 | 141 | # Getting help 142 | 143 | Need help, Identified a bug, or want to see other features implemented ? 144 | Feel free to open an issue here or send an email at : 145 | elhilali.sami@gmail.com 146 | 147 | # Citation 148 | 149 | If used in your research, please cite : 150 | 151 | * El Hilali, S., Copley R., "macrosyntR : Drawing automatically ordered Oxford Grids from standard genomic files in R", bioRxiv (2023). [doi:10.1101/2023.01.26.525673](https://doi.org/10.1101/2023.01.26.525673) 152 | 153 | -------------------------------------------------------------------------------- /inst/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamiLhll/macrosyntR/a86189db19dafb15e78898e431f65df974618edc/inst/.DS_Store -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | bibentry( 2 | key = "macrosyntR", 3 | bibtype = "Unpublished", 4 | title = "macrosyntR : Drawing automatically ordered Oxford Grids from standard genomic files in R", 5 | author = c( 6 | person(c("Sami"),"El Hilali", role = c("aut", "cre"), 7 | email = "elhilali.sami@gmail.com"), 8 | person(c("Richard", "R."), "Copley", role = "aut")), 9 | year = "2023", 10 | note = "R package version 0.2.19", 11 | url = "https://www.biorxiv.org/content/10.1101/2023.01.26.525673v1", 12 | textVersion = paste( 13 | "El Hilali, S., Copley, R.", 14 | "macrosyntR : Drawing automatically ordered Oxford Grids from standard genomic files in R.", 15 | "BioRxiv (2023). https://doi.org/10.1101/2023.01.26.525673" 16 | ) 17 | ) -------------------------------------------------------------------------------- /inst/extdata/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamiLhll/macrosyntR/a86189db19dafb15e78898e431f65df974618edc/inst/extdata/.DS_Store -------------------------------------------------------------------------------- /inst/img/Chord_diagram_3species.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamiLhll/macrosyntR/a86189db19dafb15e78898e431f65df974618edc/inst/img/Chord_diagram_3species.png -------------------------------------------------------------------------------- /inst/img/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamiLhll/macrosyntR/a86189db19dafb15e78898e431f65df974618edc/inst/img/example.png -------------------------------------------------------------------------------- /inst/img/macrosyntR_logo.150pp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamiLhll/macrosyntR/a86189db19dafb15e78898e431f65df974618edc/inst/img/macrosyntR_logo.150pp.png -------------------------------------------------------------------------------- /man/compute_linkage_groups.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/compute_linkage_groups.R 3 | \name{compute_linkage_groups} 4 | \alias{compute_linkage_groups} 5 | \title{Compute Linkage groups} 6 | \usage{ 7 | compute_linkage_groups(orthologs_df) 8 | } 9 | \arguments{ 10 | \item{orthologs_df}{dataframe. orthologs with genomic coordinates loaded with load_orthologs()} 11 | } 12 | \value{ 13 | A dataframe object 14 | } 15 | \description{ 16 | This is a function to compute the conserved linkage groups shared between two or more species. 17 | It computes the significant associations between chromosomes of all species versus all (pairwise) 18 | using the fischer test implemented in compute_macrosynteny(). 19 | It outputs a dataframe shaped as following : 20 | sp1.Chr,sp2.Chr,..., spN.chr,n,LGs 21 | where n is the number of shared orthologs in the group and LGs are the IDs for the linkage groups 22 | } 23 | \examples{ 24 | # basic usage of compute_linkage_groups: 25 | 26 | orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 27 | 28 | my_orthologs <- read.table(orthologs_table,header=TRUE) 29 | 30 | my_macrosynteny <- compute_linkage_groups(my_orthologs) 31 | 32 | } 33 | -------------------------------------------------------------------------------- /man/compute_macrosynteny.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/compute_macrosynteny.R 3 | \name{compute_macrosynteny} 4 | \alias{compute_macrosynteny} 5 | \title{Compute significant macrosynteny blocks} 6 | \usage{ 7 | compute_macrosynteny(orthologs_df, pvalue_threshold = 0.001) 8 | } 9 | \arguments{ 10 | \item{orthologs_df}{dataframe. orthologs with genomic coordinates loaded with load_orthologs()} 11 | 12 | \item{pvalue_threshold}{numeric. threshold for significancy. (default equals 0.001)} 13 | } 14 | \value{ 15 | A dataframe object 16 | } 17 | \description{ 18 | This is a function to generate the contingency table of an orthologs dataframe and 19 | apply fischer test to calculate the significant associations. It outputs a dataframe shaped as following : 20 | sp1.Chr,sp2.Chr,a,pval,significant,pval_adj 21 | } 22 | \examples{ 23 | # basic usage of compute_macrosynteny : 24 | 25 | orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 26 | 27 | my_orthologs <- read.table(orthologs_table,header=TRUE) 28 | 29 | my_macrosynteny <- compute_macrosynteny(my_orthologs) 30 | 31 | } 32 | -------------------------------------------------------------------------------- /man/get_syntenic_genes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/get_syntenic_genes.R 3 | \name{get_syntenic_genes} 4 | \alias{get_syntenic_genes} 5 | \title{get the syntenic genes as a table} 6 | \usage{ 7 | get_syntenic_genes(orthologs_df) 8 | } 9 | \arguments{ 10 | \item{orthologs_df}{dataframe. orthologs with genomic coordinates loaded by load_orthologs()} 11 | } 12 | \value{ 13 | dataframe composed of details for each detected syntenic block of genes. It contains the following columns : sp1.Chr, sp1.Start, sp1.End, sp2.Chr, sp2.Start, sp2.End, size, sp1.IDs, sp2.IDs 14 | } 15 | \description{ 16 | This is a function to extract all the syntenic genes from an orthologs_df. It requires as input an orthologs_df loaded by load_orthologs(). 17 | } 18 | \examples{ 19 | # basic usage of get_syntenic_genes : 20 | 21 | orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 22 | 23 | my_orthologs <- read.table(orthologs_table,header=TRUE) 24 | 25 | my_syntenic_block_of_genes <- get_syntenic_genes(my_orthologs) 26 | 27 | } 28 | \seealso{ 29 | \code{\link[=load_orthologs]{load_orthologs()}} 30 | } 31 | -------------------------------------------------------------------------------- /man/load_orthologs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/load_orthologs.R 3 | \name{load_orthologs} 4 | \alias{load_orthologs} 5 | \title{load orthologs with their genomic coordinates.} 6 | \usage{ 7 | load_orthologs( 8 | orthologs_table, 9 | sp1_bed = NULL, 10 | sp2_bed = NULL, 11 | bedfiles = NULL 12 | ) 13 | } 14 | \arguments{ 15 | \item{orthologs_table}{character. Full path to the orthologs table (format : geneID_on_species1 geneID_on_species2 geneID_on_speciesN)} 16 | 17 | \item{sp1_bed}{(deprecated) character. Full path to the genomic coordinates of the genes on species1} 18 | 19 | \item{sp2_bed}{(deprecated) character. Full path to the genomic coordinates of the genes on species2} 20 | 21 | \item{bedfiles}{array. List of full paths to the genomic coordinates ordered as in the appearing order of the orthologs_table (BED format)} 22 | } 23 | \value{ 24 | dataframe composed of genomic coordinates and relative index of orthologs on both species 25 | } 26 | \description{ 27 | Puts together the table of orthologous genes with their genomic coordinates 28 | in the two or more species. It outputs a data.frame shaped as following : 29 | sp1.ID,sp1.Chr,sp1.Start,sp1.End,sp1.Index,sp2.ID,sp2.Chr,sp2.Start,sp2.End,sp2.Index,... 30 | } 31 | \examples{ 32 | # basic usage of load_orthologs for two species : 33 | 34 | orthologs_file <- system.file("extdata","Bflo_vs_Pyes.tab",package="macrosyntR") 35 | bedfile_sp1 <- system.file("extdata","Bflo.bed",package="macrosyntR") 36 | bedfile_sp2 <- system.file("extdata","Pyes.bed",package="macrosyntR") 37 | 38 | 39 | my_orthologs <- load_orthologs(orthologs_table = orthologs_file, 40 | bedfiles = c(bedfile_sp1,bedfile_sp2)) 41 | # example with 3 species : 42 | orthologs_file <- system.file("extdata","Single_copy_orthologs.tsv",package="macrosyntR") 43 | bedfile_sp3 <- system.file("extdata","Pech.bed",package="macrosyntR") 44 | 45 | my_orthologs <- load_orthologs(orthologs_table = orthologs_file, 46 | bedfiles = c(bedfile_sp1,bedfile_sp2,bedfile_sp3)) 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /man/plot_chord_diagram.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_chord_diagram.R 3 | \name{plot_chord_diagram} 4 | \alias{plot_chord_diagram} 5 | \title{plot the Macro-synteny as a chord diagram} 6 | \usage{ 7 | plot_chord_diagram( 8 | orthologs_df, 9 | species_labels = NULL, 10 | species_labels_size = 5, 11 | color_by = "sp1.Chr", 12 | custom_color_palette = NULL, 13 | reorder_chromosomes = TRUE, 14 | remove_non_linkage_orthologs = TRUE, 15 | species_labels_hpos = -400, 16 | label_size = 2, 17 | ideogram_fill = "white", 18 | ideogram_color = "black", 19 | ideogram_height = 4, 20 | gap_size = 40, 21 | ribbons_curvature = 0.1, 22 | ribbons_alpha = 0.5 23 | ) 24 | } 25 | \arguments{ 26 | \item{orthologs_df}{dataframe. orthologs with genomic coordinates loaded by the load_orthologs()} 27 | 28 | \item{species_labels}{list of characters. names of the species to display on the plot} 29 | 30 | \item{species_labels_size}{integer. size of the labels (default = 2)} 31 | 32 | \item{color_by}{string. name of the column in the orthologs_df to color the links by (default = "sp1.Chr")} 33 | 34 | \item{custom_color_palette}{list of characters. palette to use for the coloring of the links following the argument color_by} 35 | 36 | \item{reorder_chromosomes}{logical. (default = TRUE) tells whether to reorder the chromosomes in clusters as implemented in reorder_macrosynteny()} 37 | 38 | \item{remove_non_linkage_orthologs}{logical. (default = TRUE) tells wether to remove the orthologs that are not within significant linkage groups as calculated by compute_linkage_groups().} 39 | 40 | \item{species_labels_hpos}{(default =-400)} 41 | 42 | \item{label_size}{integer. size of the labels to display on the ideograms (default = 2)} 43 | 44 | \item{ideogram_fill}{character. name of the colors to fill the ideograms with (default = "white")} 45 | 46 | \item{ideogram_color}{character. name of the colors to draw the borders of the ideograms with (default = "black")} 47 | 48 | \item{ideogram_height}{integer. height of the ideograms (default = 4)} 49 | 50 | \item{gap_size}{integer. Size of the gap separating the ideograms (default = 40)} 51 | 52 | \item{ribbons_curvature}{float. curvature of the ribbons (default = 0.1)} 53 | 54 | \item{ribbons_alpha}{float. alpha of the ribbons (default = 0.5)} 55 | } 56 | \value{ 57 | A ggplot2 object 58 | } 59 | \description{ 60 | This is a function to plot the chord diagrams to compare the macro synteny of two or more species. 61 | It requires as input an orthologs_df loaded by load_orthologs() 62 | } 63 | \examples{ 64 | # basic usage of plot_oxford_grid : 65 | 66 | orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 67 | 68 | my_orthologs <- read.table(orthologs_table,header=TRUE) 69 | 70 | plot_chord_diagram(my_orthologs,species_labels = c("B. flo","P. ech")) 71 | 72 | } 73 | \seealso{ 74 | \code{\link[=load_orthologs]{load_orthologs()}} 75 | 76 | \code{\link[=reorder_macrosynteny]{reorder_macrosynteny()}} 77 | 78 | \code{\link[=compute_linkage_groups]{compute_linkage_groups()}} 79 | } 80 | -------------------------------------------------------------------------------- /man/plot_macrosynteny.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_macrosynteny.R 3 | \name{plot_macrosynteny} 4 | \alias{plot_macrosynteny} 5 | \title{Plot Macro-synteny} 6 | \usage{ 7 | plot_macrosynteny(macrosynt_df, sp1_label = "", sp2_label = "") 8 | } 9 | \arguments{ 10 | \item{macrosynt_df}{dataframe of contingency table with p-values calculated by the compute_macrosynteny() function} 11 | 12 | \item{sp1_label}{character. The name of the species1 to display on the plot} 13 | 14 | \item{sp2_label}{character. The name of the species2 to put on the plot} 15 | } 16 | \value{ 17 | ggplot2 object 18 | } 19 | \description{ 20 | This is a function to generate the contingency table of an MBH dataframe and apply fischer test to calculate the significant associations. 21 | } 22 | \examples{ 23 | # basic usage of plot_macrosynteny : 24 | 25 | orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 26 | 27 | my_orthologs <- read.table(orthologs_table,header=TRUE) 28 | 29 | my_macrosynteny <- compute_macrosynteny(my_orthologs) 30 | 31 | plot_macrosynteny(my_macrosynteny, 32 | sp1_label = "B. floridae", 33 | sp2_label = "P. yessoensis") 34 | 35 | } 36 | \seealso{ 37 | \code{\link[=compute_macrosynteny]{compute_macrosynteny()}} 38 | } 39 | -------------------------------------------------------------------------------- /man/plot_oxford_grid.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plot_oxford_grid.R 3 | \name{plot_oxford_grid} 4 | \alias{plot_oxford_grid} 5 | \title{plot the Macro-synteny as an oxford grid.} 6 | \usage{ 7 | plot_oxford_grid( 8 | orthologs_df, 9 | sp1_label = "", 10 | sp2_label = "", 11 | dot_size = 0.5, 12 | dot_alpha = 0.4, 13 | reorder = FALSE, 14 | keep_only_significant = FALSE, 15 | color_by = NULL, 16 | pvalue_threshold = 0.001, 17 | color_palette = NULL, 18 | shade_non_significant = TRUE, 19 | reverse_species = FALSE, 20 | keep_sp1_raw_order = FALSE 21 | ) 22 | } 23 | \arguments{ 24 | \item{orthologs_df}{dataframe. orthologs with genomic coordinates loaded by the load_orthologs()} 25 | 26 | \item{sp1_label}{character. name of 1st species to display on the plot} 27 | 28 | \item{sp2_label}{character. name of 2nd species to display on the plot} 29 | 30 | \item{dot_size}{numeric. (default = 0.5)} 31 | 32 | \item{dot_alpha}{numeric. (default = 0.4)} 33 | 34 | \item{reorder}{logical. (default = FALSE) tells whether to reorder the chromosomes in clusters as implemented in reorder_macrosynteny()} 35 | 36 | \item{keep_only_significant}{logical. (default = FALSE)} 37 | 38 | \item{color_by}{string/variable name. (default = NULL) column of the orthologs_df to use to color the dots.} 39 | 40 | \item{pvalue_threshold}{numeric. (default = 0.001)} 41 | 42 | \item{color_palette}{vector. (default = NULL) list of colors (as string under double quote) for the clusters. The amount of colors must match the amount of clusters.} 43 | 44 | \item{shade_non_significant}{logical. (default = TRUE) When TRUE the orthologs located on non-significant linkage groups are displayed in "grey"} 45 | 46 | \item{reverse_species}{logical. (default = FALSE) When TRUE the x and y axis of the plot are reversed. sp1 is displayed on the y axis and sp2 is displayed on the x axis.} 47 | 48 | \item{keep_sp1_raw_order}{logical.(default equals FALSE) tells if the reordering should be constrained on the species1 and change just the order of the species2} 49 | } 50 | \value{ 51 | A ggplot2 object 52 | } 53 | \description{ 54 | This is a function to plot the oxford grided plot to compare the macro synteny of two species. It requires as input an orthologs_df loaded by load_orthologs() 55 | } 56 | \examples{ 57 | # basic usage of plot_oxford_grid : 58 | 59 | orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 60 | 61 | my_orthologs <- read.table(orthologs_table,header=TRUE) 62 | 63 | plot_oxford_grid(my_orthologs, 64 | sp1_label = "B. floridae", 65 | sp2_label = "P. echinospica") 66 | 67 | # plot a reordered Oxford Grid and color by cluster : 68 | \donttest{ 69 | plot_oxford_grid(my_orthologs, 70 | sp1_label = "B. floridae", 71 | sp2_label = "P. echinospica", 72 | reorder = TRUE, 73 | color_by = "clust") 74 | } 75 | } 76 | \seealso{ 77 | \code{\link[=load_orthologs]{load_orthologs()}} 78 | 79 | \code{\link[=reorder_macrosynteny]{reorder_macrosynteny()}} 80 | } 81 | -------------------------------------------------------------------------------- /man/reorder_macrosynteny.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reorder_macrosynteny.R 3 | \name{reorder_macrosynteny} 4 | \alias{reorder_macrosynteny} 5 | \title{Reorder the mbh_df before plotting} 6 | \usage{ 7 | reorder_macrosynteny( 8 | orthologs_df, 9 | pvalue_threshold = 0.001, 10 | keep_only_significant = FALSE, 11 | keep_sp1_raw_order = FALSE 12 | ) 13 | } 14 | \arguments{ 15 | \item{orthologs_df}{dataframe. mutual best hits with genomic coordinates loaded with load_orthologs()} 16 | 17 | \item{pvalue_threshold}{numeric. threshold for significancy. (default equals 0.001)} 18 | 19 | \item{keep_only_significant}{logical. (default equals FALSE) tells if the non significant linkage groups should be removed. It drastically speeds up the computation when using one highly fragmented genome.} 20 | 21 | \item{keep_sp1_raw_order}{logical. (default equals FALSE) tells if the reordering should be constrained on the species1 and change just the order of the species2} 22 | } 23 | \value{ 24 | A dataframe object 25 | } 26 | \description{ 27 | This is a function to reorder an orthologs_df, that was generated with load_orthologs(). It retrieves communities using igraph::cluster_fast_greedy. 28 | } 29 | \examples{ 30 | # basic usage of reorder_macrosynteny : 31 | 32 | orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 33 | 34 | my_orthologs <- read.table(orthologs_table,header=TRUE) 35 | 36 | my_orthologs_reordered <- reorder_macrosynteny(my_orthologs) 37 | 38 | } 39 | \seealso{ 40 | \code{\link[=load_orthologs]{load_orthologs()}} 41 | 42 | \code{\link[=compute_macrosynteny]{compute_macrosynteny()}} 43 | } 44 | -------------------------------------------------------------------------------- /man/reorder_multiple_macrosyntenies.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reorder_multiple_macrosyntenies.R 3 | \name{reorder_multiple_macrosyntenies} 4 | \alias{reorder_multiple_macrosyntenies} 5 | \title{Reorder the chromosomes of two or more species before plotting} 6 | \usage{ 7 | reorder_multiple_macrosyntenies(orthologs_df) 8 | } 9 | \arguments{ 10 | \item{orthologs_df}{dataframe. orthologs with genomic coordinates loaded with load_orthologs()} 11 | } 12 | \value{ 13 | A dataframe object 14 | } 15 | \description{ 16 | This is a function to reorder an orthologs_df, same as reorder_macrosynteny, 17 | but it handles tables with more than 2 species. 18 | } 19 | \examples{ 20 | # basic usage of reorder_macrosynteny : 21 | 22 | orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 23 | 24 | my_orthologs <- read.table(orthologs_table,header=TRUE) 25 | 26 | my_orthologs_reordered <- reorder_multiple_macrosyntenies(my_orthologs) 27 | 28 | } 29 | \seealso{ 30 | \code{\link[=load_orthologs]{load_orthologs()}} 31 | 32 | \code{\link[=compute_macrosynteny]{compute_macrosynteny()}} 33 | 34 | \code{\link[=reorder_macrosynteny]{reorder_macrosynteny()}} 35 | } 36 | -------------------------------------------------------------------------------- /man/reverse_species_order.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reverse_species_order.R 3 | \name{reverse_species_order} 4 | \alias{reverse_species_order} 5 | \title{Reverse order of the species in an orthologs_df.} 6 | \usage{ 7 | reverse_species_order(orthologs_df) 8 | } 9 | \arguments{ 10 | \item{orthologs_df}{orthologs_df dataframe. mutual best hits with genomic coordinates loaded with load_orthologs()} 11 | } 12 | \value{ 13 | dataframe composed of genomic coordinates and relative index of orthologs on both species 14 | } 15 | \description{ 16 | Returns an orthologs_df (data.frame) with reversed species order compared to the inputted orthologs_df. 17 | sp1 becomes sp2 and the otherway around. It intends at facilitating the integration of more than just two datasets. 18 | It outputs a data.frame shaped as following : 19 | sp1.ID,sp1.Chr,sp1.Start,sp1.End,sp1.Index,sp2.ID,sp2.Chr,sp2.Start,sp2.End,sp2.Index 20 | } 21 | \examples{ 22 | # basic usage of reverse_species_order : 23 | 24 | orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 25 | 26 | my_orthologs <- read.table(orthologs_table,header=TRUE) 27 | 28 | my_orthologs_reversed <- reverse_species_order(my_orthologs) 29 | 30 | } 31 | \seealso{ 32 | \code{\link[=load_orthologs]{load_orthologs()}} 33 | } 34 | -------------------------------------------------------------------------------- /man/subset_linkage_orthologs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/subset_linkage_orthologs.R 3 | \name{subset_linkage_orthologs} 4 | \alias{subset_linkage_orthologs} 5 | \title{Subset Orthologs contained in conserved linkage groups} 6 | \usage{ 7 | subset_linkage_orthologs(orthologs_df, linkages = NULL) 8 | } 9 | \arguments{ 10 | \item{orthologs_df}{dataframe. orthologs with genomic coordinates loaded with load_orthologs()} 11 | 12 | \item{linkages}{dataframe. table listing the linkage groups as returned by the function compute_linkage_groups()} 13 | } 14 | \value{ 15 | A dataframe object 16 | } 17 | \description{ 18 | This is a function to subset an orthologs_df and keep only the orthologs that are within significant 19 | linkage groups computed by the function compute_linkage_groups(). 20 | } 21 | \examples{ 22 | # basic usage of compute_linkage_groups: 23 | 24 | orthologs_table <- system.file("extdata","my_orthologs.tab",package="macrosyntR") 25 | 26 | my_orthologs <- read.table(orthologs_table,header=TRUE) 27 | 28 | my_macrosynteny <- compute_linkage_groups(my_orthologs) 29 | 30 | } 31 | \seealso{ 32 | \code{\link[=load_orthologs]{load_orthologs()}} 33 | 34 | \code{\link[=compute_linkage_groups]{compute_linkage_groups()}} 35 | } 36 | -------------------------------------------------------------------------------- /paper/F1.large.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamiLhll/macrosyntR/a86189db19dafb15e78898e431f65df974618edc/paper/F1.large.jpeg -------------------------------------------------------------------------------- /paper/F1.large.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SamiLhll/macrosyntR/a86189db19dafb15e78898e431f65df974618edc/paper/F1.large.jpg -------------------------------------------------------------------------------- /paper/paper.bib: -------------------------------------------------------------------------------- 1 | 2 | @MISC{El_Hilali:2022, 3 | title = "{SamiLhll/rbhXpress}: v1.2.3", 4 | author = "El Hilali, Sami", 5 | month = nov, 6 | year = 2022, 7 | url = "https://zenodo.org/record/7324400", 8 | doi = "10.5281/zenodo.7324400" 9 | } 10 | 11 | @ARTICLE{Sun:2021, 12 | title = "Genomic Signatures Supporting the Symbiosis and Formation of 13 | Chitinous Tube in the {Deep-Sea} Tubeworm Paraescarpia 14 | echinospica", 15 | author = "Sun, Yanan and Sun, Jin and Yang, Yi and Lan, Yi and Ip, Jack 16 | Chi-Ho and Wong, Wai Chuen and Kwan, Yick Hang and Zhang, Yanjie 17 | and Han, Zhuang and Qiu, Jian-Wen and Qian, Pei-Yuan", 18 | journal = "Mol. Biol. Evol.", 19 | volume = 38, 20 | number = 10, 21 | pages = "4116--4134", 22 | month = sep, 23 | year = 2021, 24 | url = "http://dx.doi.org/10.1093/molbev/msab203", 25 | language = "en", 26 | issn = "0737-4038, 1537-1719", 27 | pmid = "34255082", 28 | doi = "10.1093/molbev/msab203", 29 | pmc = "PMC8476170" 30 | } 31 | 32 | 33 | @ARTICLE{Wang:2017, 34 | title = "Scallop genome provides insights into evolution of bilaterian 35 | karyotype and development", 36 | author = "Wang, Shi and Zhang, Jinbo and Jiao, Wenqian and Li, Ji and Xun, 37 | Xiaogang and Sun, Yan and Guo, Ximing and Huan, Pin and Dong, Bo 38 | and Zhang, Lingling and Hu, Xiaoli and Sun, Xiaoqing and Wang, 39 | Jing and Zhao, Chengtian and Wang, Yangfan and Wang, Dawei and 40 | Huang, Xiaoting and Wang, Ruijia and Lv, Jia and Li, Yuli and 41 | Zhang, Zhifeng and Liu, Baozhong and Lu, Wei and Hui, Yuanyuan 42 | and Liang, Jun and Zhou, Zunchun and Hou, Rui and Li, Xue and 43 | Liu, Yunchao and Li, Hengde and Ning, Xianhui and Lin, Yu and 44 | Zhao, Liang and Xing, Qiang and Dou, Jinzhuang and Li, Yangping 45 | and Mao, Junxia and Guo, Haobing and Dou, Huaiqian and Li, Tianqi 46 | and Mu, Chuang and Jiang, Wenkai and Fu, Qiang and Fu, Xiaoteng 47 | and Miao, Yan and Liu, Jian and Yu, Qian and Li, Ruojiao and 48 | Liao, Huan and Li, Xuan and Kong, Yifan and Jiang, Zhi and 49 | Chourrout, Daniel and Li, Ruiqiang and Bao, Zhenmin", 50 | journal = "Nat Ecol Evol", 51 | volume = 1, 52 | number = 5, 53 | pages = "120", 54 | month = apr, 55 | year = 2017, 56 | url = "http://dx.doi.org/10.1038/s41559-017-0120", 57 | language = "en", 58 | issn = "2397-334X", 59 | pmid = "28812685", 60 | doi = "10.1038/s41559-017-0120" 61 | } 62 | 63 | 64 | @ARTICLE{Lewin:2018, 65 | title = "Earth {BioGenome} Project: Sequencing life for the future of life", 66 | author = "Lewin, Harris A and Robinson, Gene E and Kress, W John and Baker, 67 | William J and Coddington, Jonathan and Crandall, Keith A and 68 | Durbin, Richard and Edwards, Scott V and Forest, F{\'e}lix and 69 | Gilbert, M Thomas P and Goldstein, Melissa M and Grigoriev, Igor V 70 | and Hackett, Kevin J and Haussler, David and Jarvis, Erich D and 71 | Johnson, Warren E and Patrinos, Aristides and Richards, Stephen 72 | and Castilla-Rubio, Juan Carlos and van Sluys, Marie-Anne and 73 | Soltis, Pamela S and Xu, Xun and Yang, Huanming and Zhang, Guojie", 74 | journal = "Proceedings of the National Academy of Sciences", 75 | volume = 115, 76 | number = 17, 77 | pages = "4325--4333", 78 | year = 2018, 79 | url = "https://www.pnas.org/doi/abs/10.1073/pnas.1720115115", 80 | eprint = "https://www.pnas.org/doi/pdf/10.1073/pnas.1720115115", 81 | doi = "10.1073/pnas.1720115115" 82 | } 83 | 84 | @ARTICLE{Simakov:2022, 85 | title = "Deeply conserved synteny and the evolution of metazoan chromosomes", 86 | author = "Simakov, Oleg and Bredeson, Jessen and Berkoff, Kodiak and 87 | Marletaz, Ferdinand and Mitros, Therese and Schultz, Darrin T and 88 | O'Connell, Brendan L and Dear, Paul and Martinez, Daniel E and 89 | Steele, Robert E and Green, Richard E and David, Charles N and 90 | Rokhsar, Daniel S", 91 | journal = "Science Advances", 92 | volume = 8, 93 | number = 5, 94 | pages = "eabi5884", 95 | year = 2022, 96 | url = "https://www.science.org/doi/abs/10.1126/sciadv.abi5884", 97 | eprint = "https://www.science.org/doi/pdf/10.1126/sciadv.abi5884", 98 | doi = "10.1126/sciadv.abi5884" 99 | } 100 | 101 | @ARTICLE{Clauset:2004, 102 | title = "Finding community structure in very large networks", 103 | author = "Clauset, Aaron and Newman, M E J and Moore, Cristopher", 104 | journal = "Phys. Rev. E Stat. Nonlin. Soft Matter Phys.", 105 | volume = 70, 106 | number = "6 Pt 2", 107 | pages = "066111", 108 | month = dec, 109 | year = 2004, 110 | url = "http://dx.doi.org/10.1103/PhysRevE.70.066111", 111 | language = "en", 112 | issn = "1539-3755", 113 | pmid = "15697438", 114 | doi = "10.1103/PhysRevE.70.066111" 115 | } 116 | 117 | @ARTICLE{Edwards:1991, 118 | title = "The Oxford Grid", 119 | author = "Edwards, J H", 120 | journal = "Ann. Hum. Genet.", 121 | volume = 55, 122 | number = 1, 123 | pages = "17--31", 124 | month = jan, 125 | year = 1991, 126 | url = "http://dx.doi.org/10.1111/j.1469-1809.1991.tb00394.x", 127 | language = "en", 128 | issn = "0003-4800", 129 | pmid = "2042932", 130 | doi = "10.1111/j.1469-1809.1991.tb00394.x" 131 | } 132 | 133 | @ARTICLE{Lallemand:2020, 134 | title = "An Overview of Duplicated Gene Detection Methods: Why the 135 | Duplication Mechanism Has to Be Accounted for in Their Choice", 136 | author = "Lallemand, Tanguy and Leduc, Martin and Land{\`e}s, Claudine and 137 | Rizzon, Car{\`e}ne and Lerat, Emmanuelle", 138 | journal = "Genes", 139 | volume = 11, 140 | number = 9, 141 | month = sep, 142 | year = 2020, 143 | url = "http://dx.doi.org/10.3390/genes11091046", 144 | language = "en", 145 | issn = "2073-4425", 146 | pmid = "32899740", 147 | doi = "10.3390/genes11091046", 148 | pmc = "PMC7565063" 149 | } 150 | 151 | @ARTICLE{Braso-Vives:2022, 152 | title = "Parallel evolution of amphioxus and vertebrate small-scale gene 153 | duplications", 154 | author = "Bras{\'o}-Vives, Marina and Marl{\'e}taz, Ferdinand and Echchiki, 155 | Amina and Mantica, Federica and Acemel, Rafael D and 156 | G{\'o}mez-Skarmeta, Jos{\'e} L and Hartas{\'a}nchez, Diego A and 157 | Le Targa, Lorlane and Pontarotti, Pierre and Tena, Juan J and 158 | Maeso, Ignacio and Escriva, Hector and Irimia, Manuel and 159 | Robinson-Rechavi, Marc", 160 | journal = "Genome Biol.", 161 | volume = 23, 162 | number = 1, 163 | pages = "243", 164 | month = nov, 165 | year = 2022, 166 | url = "http://dx.doi.org/10.1186/s13059-022-02808-6", 167 | language = "en", 168 | issn = "1465-6906", 169 | pmid = "36401278", 170 | doi = "10.1186/s13059-022-02808-6", 171 | pmc = "PMC9673378" 172 | } 173 | 174 | @ARTICLE{Csardi:2006, 175 | title = "The igraph software package for complex network research", 176 | author = "Csardi, Gabor and Nepusz, Tamas and {Others}", 177 | journal = "InterJournal, complex systems", 178 | publisher = "researchgate.net", 179 | volume = 1695, 180 | number = 5, 181 | pages = "1--9", 182 | year = 2006, 183 | url = "https://www.researchgate.net/profile/Gabor-Csardi/publication/221995787_The_Igraph_Software_Package_for_Complex_Network_Research/links/0c96051d301a30f265000000/The-Igraph-Software-Package-for-Complex-Network-Research.pdf" 184 | } 185 | 186 | @ARTICLE{Putnam:2007, 187 | title = "Sea anemone genome reveals ancestral eumetazoan gene repertoire 188 | and genomic organization", 189 | author = "Putnam, Nicholas H and Srivastava, Mansi and Hellsten, Uffe and 190 | Dirks, Bill and Chapman, Jarrod and Salamov, Asaf and Terry, 191 | Astrid and Shapiro, Harris and Lindquist, Erika and Kapitonov, 192 | Vladimir V and Jurka, Jerzy and Genikhovich, Grigory and 193 | Grigoriev, Igor V and Lucas, Susan M and Steele, Robert E and 194 | Finnerty, John R and Technau, Ulrich and Martindale, Mark Q and 195 | Rokhsar, Daniel S", 196 | journal = "Science", 197 | volume = 317, 198 | number = 5834, 199 | pages = "86--94", 200 | month = jul, 201 | year = 2007, 202 | url = "http://dx.doi.org/10.1126/science.1139158", 203 | language = "en", 204 | issn = "0036-8075, 1095-9203", 205 | pmid = "17615350", 206 | doi = "10.1126/science.1139158" 207 | } 208 | 209 | @ARTICLE{Buchfink:2021, 210 | title = "Sensitive protein alignments at tree-of-life scale using 211 | {DIAMOND}", 212 | author = "Buchfink, Benjamin and Reuter, Klaus and Drost, Hajk-Georg", 213 | journal = "Nat. Methods", 214 | publisher = "nature.com", 215 | volume = 18, 216 | number = 4, 217 | pages = "366--368", 218 | month = apr, 219 | year = 2021, 220 | url = "http://dx.doi.org/10.1038/s41592-021-01101-x", 221 | language = "en", 222 | issn = "1548-7091, 1548-7105", 223 | pmid = "33828273", 224 | doi = "10.1038/s41592-021-01101-x", 225 | pmc = "PMC8026399" 226 | } 227 | 228 | @ARTICLE{Martin-Duran:2020, 229 | title = "Conservative route to genome compaction in a miniature annelid", 230 | author = "Mart{\'\i}n-Dur{\'a}n, Jos{\'e} M and Vellutini, Bruno C and 231 | Marl{\'e}taz, Ferdinand and Cetrangolo, Viviana and Cvetesic, 232 | Nevena and Thiel, Daniel and Henriet, Simon and Grau-Bov{\'e}, 233 | Xavier and Carrillo-Baltodano, Allan M and Gu, Wenjia and Kerbl, 234 | Alexandra and Marquez, Yamile and Bekkouche, Nicolas and 235 | Chourrout, Daniel and G{\'o}mez-Skarmeta, Jose Luis and Irimia, 236 | Manuel and Lenhard, Boris and Worsaae, Katrine and Hejnol, 237 | Andreas", 238 | journal = "Nature Ecology \& Evolution", 239 | publisher = "Nature Publishing Group", 240 | volume = 5, 241 | number = 2, 242 | pages = "231--242", 243 | month = nov, 244 | year = 2020, 245 | url = "https://www.nature.com/articles/s41559-020-01327-6", 246 | language = "en", 247 | issn = "2397-334X, 2397-334X", 248 | doi = "10.1038/s41559-020-01327-6" 249 | } 250 | 251 | @ARTICLE{Simakov:2020, 252 | title = "Deeply conserved synteny resolves early events in vertebrate 253 | evolution", 254 | author = "Simakov, Oleg and Marl{\'e}taz, Ferdinand and Yue, Jia-Xing and 255 | O'Connell, Brendan and Jenkins, Jerry and Brandt, Alexander and 256 | Calef, Robert and Tung, Che-Huang and Huang, Tzu-Kai and 257 | Schmutz, Jeremy and Satoh, Nori and Yu, Jr-Kai and Putnam, 258 | Nicholas H and Green, Richard E and Rokhsar, Daniel S", 259 | journal = "Nature Ecology \& Evolution", 260 | publisher = "Nature Publishing Group", 261 | volume = 4, 262 | number = 6, 263 | pages = "820--830", 264 | month = apr, 265 | year = 2020, 266 | url = "https://www.nature.com/articles/s41559-020-1156-z", 267 | language = "en", 268 | issn = "2397-334X, 2397-334X", 269 | doi = "10.1038/s41559-020-1156-z" 270 | } 271 | 272 | @ARTICLE{Tang:2008, 273 | title = "Synteny and Collinearity in Plant Genomes", 274 | author = "Tang, Haibao and Bowers, John E and Wang, Xiyin and Ming, Ray and 275 | Alam, Maqsudul and Paterson, Andrew H", 276 | journal = "Science", 277 | volume = 320, 278 | number = 5875, 279 | pages = "486--488", 280 | year = 2008, 281 | url = "https://www.science.org/doi/abs/10.1126/science.1153917", 282 | eprint = "https://www.science.org/doi/pdf/10.1126/science.1153917", 283 | issn = "0036-8075", 284 | doi = "10.1126/science.1153917" 285 | } 286 | 287 | @ARTICLE{Simakov:2020, 288 | title = "Deeply conserved synteny resolves early events in vertebrate 289 | evolution", 290 | author = "Simakov, Oleg and Marl{\'e}taz, Ferdinand and Yue, Jia-Xing and 291 | O'Connell, Brendan and Jenkins, Jerry and Brandt, Alexander and 292 | Calef, Robert and Tung, Che-Huang and Huang, Tzu-Kai and Schmutz, 293 | Jeremy and Satoh, Nori and Yu, Jr-Kai and Putnam, Nicholas H and 294 | Green, Richard E and Rokhsar, Daniel S", 295 | journal = "Nat Ecol Evol", 296 | volume = 4, 297 | number = 6, 298 | pages = "820--830", 299 | month = jun, 300 | year = 2020, 301 | url = "http://dx.doi.org/10.1038/s41559-020-1156-z", 302 | language = "en", 303 | issn = "2397-334X", 304 | pmid = "32313176", 305 | doi = "10.1038/s41559-020-1156-z", 306 | pmc = "PMC7269912" 307 | } 308 | -------------------------------------------------------------------------------- /paper/paper.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'macrosyntR : Drawing automatically ordered Oxford grids from standard genomic files in R' 3 | tags: 4 | - R 5 | - genomics 6 | - bioinformatics 7 | - evolution 8 | - visualization 9 | authors: 10 | - name: Sami {El Hilali} 11 | orcid: 0000-0003-4417-8399 12 | affiliation: 1 13 | corresponding: true 14 | - name: Richard R. Copley 15 | orcid: 0000-0001-7846-4954 16 | affiliation: 1 17 | affiliations: 18 | - name: Laboratoire de Biologie du Développement de Villefranche-sur-mer (LBDV), Sorbonne Université, CNRS, 06230 Villefranche-sur-mer, France 19 | index: 1 20 | 21 | date: 18 May 2023 22 | bibliography: paper.bib 23 | 24 | --- 25 | 26 | # Summary 27 | 28 | Macrosynteny refers to the conservation of chromosomal to sub-chromosomal domains across species and its conservation can provide insight on the evolution of animal genomes. Pairwise comparison of de-novo assembled genomes based on predicted protein sequences often use a graphical visualization called an Oxford grid. We implemented an R package to draw Oxford grids from standard genomic file formats. The package can automatically order the chromosomes, to improve interpretability, and is thus helpful for both exploratory data analysis and production of publication quality graphics. 29 | 30 | # Background 31 | 32 | Rearrangements of ancestral metazoan chromosomes have shaped the karyotypes of current animals. Studies based on distantly related animals have suggested good conservation of macrosynteny, that is, conservation of gene content within chromosomal or sub-chromosomal domains, but not necessarily conservation of precise gene order [@Simakov:2022]. Synteny analyses are becoming increasingly common in comparative genomics studies of eukaryotes [@Tang:2008; @Wang:2017]. 33 | 34 | In the context of efforts like the Earth BioGenome Project [@Lewin:2018] newly released genome assemblies of non-model organisms are reaching chromosomal scales. These data will provide a valuable resource to build a comprehensive framework of the evolution of metazoan chromosomes. At the same time many computational tools (reviewed in [@Lallemand:2020]) have been implemented to allow for the analysis of the macro and microsynteny conservation. 35 | 36 | # Statement of need 37 | 38 | In Metazoa, the pairwise comparison syntenic relationships often uses a graphical visualization called an Oxford Grid, a two-dimensional dot plot showing genomic loci of two species, each being assigned an axis, and every dot representing a correspondence in DNA content [@Edwards:1991]. More recently, this concept has been used to show the chromosomal correspondences of inferred gene ortholog pairs [@Wang:2017;@Simakov:2020;@Martin-Duran:2020; @Braso-Vives:2022]. 39 | 40 | The Oxford Grid is a straightforward visualization tool to compare the genome-wide distribution of orthologous genes in high quality genomes. We have implemented macrosyntR, an open source R package to automatically identify, order and plot the relative spatial arrangement of orthologous genes on Oxford Grids. It features an option to use a network-based greedy algorithm to cluster the sequences that are likely to originate from the same ancestral chromosome. 41 | 42 | # Description 43 | 44 | macrosyntR is an R package that features 5 functions covering all actions needed to go from input files to the drawing of Oxford Grids. A stable version is available on CRAN [https://CRAN.R-project.org/package=macrosyntR](https://CRAN.R-project.org/package=macrosyntR) and the developmental version is hosted on github at : [https://github.com/SamiLhll/macrosyntR](https://github.com/SamiLhll/macrosyntR) 45 | 46 | ### Input DATA 47 | 48 | The data required are a table of orthologous genes, that is a two column table containing sequence names of pairs of orthologous genes in the two species, and one BED file [https://www.ensembl.org/info/website/upload/bed.html](https://www.ensembl.org/info/website/upload/bed.html) per species to specify gene order, each composed of the three mandatory fields Chrom, ChromStart, ChromEnd and the additional field seqName. The sequence names of the two files must match with sequence names of the first and second column of the table of orthologs. 49 | 50 | BED files can be easily generated from other common formats such as GTF and GFF available on public databases or output by gene prediction software. 51 | 52 | ### Computing the significantly conserved macrosynteny blocks 53 | 54 | The function 'compute_macrosynteny()' builds a contingency table of the number of shared orthologs in each possible chromosome pairing. The significant associations are computed using Fisher’s exact test as described in [@Simakov:2020]. The result is a data.frame object containing the number of orthologs, multiple-testing adjusted p-values that can be visualized using the function 'plot_macrosynteny()' (Figure 1A). 55 | 56 | ### Visualizing the orthologs on an Oxford grid 57 | 58 | The Oxford grid is drawn using the function 'plot_oxford_grid()'. Each dot corresponds to an orthologous pair (from the function 'load_orthologs()') with x and y coordinates being the relative order index on the chromosomes taken from the BED files. The dots are organized in squared facets, corresponding to the chromosomes (entry Chrom from the BED files). The limits of these squares are proportional to the total amount of genes on each scale. Many features are customizable, such as the labels, the color, size and transparency of the dots. 59 | 60 | ### Clustering the conserved macrosynteny blocks 61 | 62 | It is helpful to reorder the facets to interpret the results especially when analyzing fragmented genomes. Network-based methods such as hierarchical clustering have been proposed in previous studies [@Putnam:2007; @Martin-Duran:2020]. 63 | 64 | We implemented a clustering algorithm that allows for a good interpretability of the results in a limited amount of computational time (Figure 1B). Data are modeled in a network where every chromosome from the two species is modeled as a node, and weighted edges are created between every pair of nodes. The weights correspond to the number of shared orthologs between the two nodes that they connect. The linkage groups are retrieved by organizing the chromosomes into communities using the greedy algorithm implemented in the function 'cluster_fast_greedy()' from igraph v.1.3.0 [@Csardi:2006] It finds the local optimal communities at each step and is designed to handle large networks with an approximate linear complexity [@Clauset:2004]. 65 | 66 | The ordering is then performed by decreasing size of both the "communities", and the chromosomes (in amount of orthologs) from left to right (species 1) and top to bottom (species 2). This algorithm performs well even when comparing a chromosomal level genome assembly with a more fragmented one. Computation time can be reduced by using the argument 'keep_only_significant'. 67 | 68 | ![A. macrosyntR workflow for the drawing of an oxford Grid and a macrosynteny plot. B. Detection of communities to order the chromosomes. Each vertice corresponds to a chromosome from one of the two species. The edges are weighted by the amount of shared orthologs. A fast greedy algorithm is applied to detect the communities before plotting a reordered Oxford Grid.](F1.large.jpg){ width=80% } 69 | 70 | ### Example using public datasets 71 | 72 | To demonstrate the use of the package, we compare two publicly available datasets. We selected the gene predictions of the lancelet Branchiostoma floridae [@Simakov:2020] and the deep-sea tubeworm Paraescarpia echinospica [@Sun:2021]. Orthologs were calculated as reciprocal best hits using Diamond Blast [@Buchfink:2021] called through rbhXpress [@El_Hilali:2022]. Two R command lines are then enough to draw an Oxford Grid (Figure 1A). The default order is the chromosomal alphabetical order. We can improve the interpretability by using the clustering method (Figure 1B) and track the chromosomal fusions that have shaped the karyotypes of these species. 73 | 74 | # Availability 75 | 76 | A stable version is available on CRAN [(https://CRAN.R-project.org/package=macrosyntR)](https://CRAN.R-project.org/package=macrosyntR) and can be installed using the command 'install.packages("macrosyntR")'. A developmental version is hosted on github at : [https://github.com/SamiLhll/macrosyntR](https://github.com/SamiLhll/macrosyntR) 77 | 78 | # Acknowledgements 79 | 80 | This work was supported by the HFSP grant RGP0028/2018. We thank Aida Verdes for giving constructive feedback on the package and Mohamed Khamla (LBDV) for drawing of the Hex Logo. 81 | 82 | # References 83 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html -------------------------------------------------------------------------------- /vignettes/macrosyntR.R: -------------------------------------------------------------------------------- 1 | ## ---- include = FALSE--------------------------------------------------------- 2 | knitr::opts_chunk$set( 3 | collapse = TRUE, 4 | comment = "#>" 5 | ) 6 | 7 | ## ----setup-------------------------------------------------------------------- 8 | library(macrosyntR) 9 | 10 | ## ----------------------------------------------------------------------------- 11 | 12 | my_orthologs_table <- load_orthologs(orthologs_table = system.file("extdata","Bflo_vs_Pech.tab",package="macrosyntR"), 13 | bedfiles = c(system.file("extdata","Bflo.bed",package="macrosyntR"), 14 | system.file("extdata","Pech.bed",package="macrosyntR"))) 15 | 16 | head(my_orthologs_table) 17 | 18 | 19 | ## ----------------------------------------------------------------------------- 20 | 21 | my_orthologs_with_3_sp <- load_orthologs(orthologs_table = system.file("extdata","Single_copy_orthologs.tsv",package="macrosyntR"), 22 | bedfiles = c(system.file("extdata","Bflo.bed",package="macrosyntR"), 23 | system.file("extdata","Pech.bed",package="macrosyntR"), 24 | system.file("extdata","Pyes.bed",package="macrosyntR"))) 25 | 26 | head(my_orthologs_with_3_sp) 27 | 28 | 29 | ## ----------------------------------------------------------------------------- 30 | 31 | # compute significance : 32 | macrosynteny_df <- compute_macrosynteny(my_orthologs_table) 33 | head(macrosynteny_df) 34 | 35 | 36 | ## ----eval = FALSE, out.width = '450px'---------------------------------------- 37 | # 38 | # # visualize the loaded data on a oxford grid : 39 | # plot_oxford_grid(my_orthologs_table, 40 | # sp1_label = "B.floridae", 41 | # sp2_label = "P.echinospica") 42 | # 43 | # # Visualize the results of the test of significance : 44 | # plot_macrosynteny(macrosynteny_df, 45 | # sp1_label = "B.floridae", 46 | # sp2_label = "P.echinospica") 47 | # 48 | 49 | ## ----echo = FALSE,out.width = c('300px','300px')------------------------------ 50 | 51 | # visualize the loaded data on a oxford grid : 52 | plot_oxford_grid(my_orthologs_table, 53 | sp1_label = "B.floridae", 54 | sp2_label = "P.echinospica") 55 | 56 | # Visualize the results of the test of significance : 57 | plot_macrosynteny(macrosynteny_df, 58 | sp1_label = "B.floridae", 59 | sp2_label = "P.echinospica") 60 | 61 | 62 | ## ----eval = FALSE------------------------------------------------------------- 63 | # my_linkage_groups <- compute_linkage_groups(my_orthologs_with_3_sp) 64 | # head(my_linkage_groups) 65 | # 66 | 67 | ## ----echo = FALSE------------------------------------------------------------- 68 | 69 | my_linkage_groups <- compute_linkage_groups(my_orthologs_with_3_sp) 70 | head(my_linkage_groups) 71 | 72 | 73 | ## ----eval = FALSE------------------------------------------------------------- 74 | # 75 | # # visualize the loaded data on a oxford grid : 76 | # my_orthologs_table_reordered <- reorder_macrosynteny(my_orthologs_table) 77 | # plot_oxford_grid(my_orthologs_table_reordered, 78 | # sp1_label = "B.floridae", 79 | # sp2_label = "P.echinospica") 80 | # 81 | # # compute significance and visualize on a dotplot : 82 | # macrosynteny_df_reordered <- compute_macrosynteny(my_orthologs_table_reordered) 83 | # plot_macrosynteny(macrosynteny_df_reordered, 84 | # sp1_label = "B.floridae", 85 | # sp2_label = "P.echinospica") 86 | # 87 | 88 | ## ----echo = FALSE------------------------------------------------------------- 89 | # visualize the loaded data on a oxford grid : 90 | my_orthologs_table_reordered <- reorder_macrosynteny(my_orthologs_table) 91 | plot_oxford_grid(my_orthologs_table_reordered, 92 | sp1_label = "B.floridae", 93 | sp2_label = "P.echinospica") 94 | # compute significance and visualize on a dotplot : 95 | macrosynteny_df_reordered <- compute_macrosynteny(my_orthologs_table_reordered) 96 | plot_macrosynteny(macrosynteny_df_reordered, 97 | sp1_label = "B.floridae", 98 | sp2_label = "P.echinospica") 99 | 100 | 101 | ## ----eval = FALSE------------------------------------------------------------- 102 | # # select only the orthologs falling in the chromosomes of interest and plot: 103 | # subset_of_orthologs <- subset(my_orthologs_table, sp1.Chr %in% c("BFL13","BFL15","BFL2","BFL3") & sp2.Chr %in% c("PEC2","PEC5","PEC11")) 104 | # 105 | # plot_oxford_grid(subset_of_orthologs, 106 | # sp1_label = "B.floridae", 107 | # sp2_label = "P.echinospica") 108 | # 109 | # # reorder : 110 | # subset_of_orthologs$sp2.Chr <- factor(subset_of_orthologs$sp2.Chr,levels = c("PEC5","PEC11","PEC2")) 111 | # plot_oxford_grid(subset_of_orthologs, 112 | # sp1_label = "B.floridae", 113 | # sp2_label = "P.echinospica") 114 | # 115 | # # Compute and plot macrosynteny : 116 | # macrosynteny_of_subset <- compute_macrosynteny(subset_of_orthologs) 117 | # plot_macrosynteny(macrosynteny_of_subset, 118 | # sp1_label = "B.floridae", 119 | # sp2_label = "P.echinospica") 120 | # 121 | 122 | ## ----echo = FALSE,out.width = c('300px','300px')------------------------------ 123 | # select only the orthologs falling in the chromosomes of interest and plot: 124 | subset_of_orthologs <- subset(my_orthologs_table, sp1.Chr %in% c("BFL13","BFL15","BFL2","BFL3") & sp2.Chr %in% c("PEC2","PEC5","PEC11")) 125 | 126 | plot_oxford_grid(subset_of_orthologs, 127 | sp1_label = "B.floridae", 128 | sp2_label = "P.echinospica") 129 | 130 | # reorder : 131 | subset_of_orthologs$sp2.Chr <- factor(subset_of_orthologs$sp2.Chr,levels = c("PEC5","PEC11","PEC2")) 132 | plot_oxford_grid(subset_of_orthologs, 133 | sp1_label = "B.floridae", 134 | sp2_label = "P.echinospica") 135 | 136 | 137 | 138 | ## ----eval = FALSE------------------------------------------------------------- 139 | # 140 | # # visualize the loaded data on a oxford grid with reordering and coloring by cluster : 141 | # plot_oxford_grid(my_orthologs_table, 142 | # sp1_label = "B.floridae", 143 | # sp2_label = "P.echinospica", 144 | # reorder = TRUE, 145 | # color_by = "clust") 146 | # 147 | # # redo and color by sp1.Chr instead : 148 | # plot_oxford_grid(my_orthologs_table, 149 | # sp1_label = "B.floridae", 150 | # sp2_label = "P.echinospica", 151 | # reorder = TRUE, 152 | # color_by = "sp1.Chr") 153 | # 154 | 155 | ## ----echo = FALSE,out.width = c('300px','300px')------------------------------ 156 | 157 | # visualize the loaded data on a oxford grid with reordering and coloring by cluster : 158 | plot_oxford_grid(my_orthologs_table, 159 | sp1_label = "B.floridae", 160 | sp2_label = "P.echinospica", 161 | reorder = TRUE, 162 | color_by = "clust") 163 | 164 | # redo and color by sp2.Chr instead : 165 | plot_oxford_grid(my_orthologs_table, 166 | sp1_label = "B.floridae", 167 | sp2_label = "P.echinospica", 168 | reorder = TRUE, 169 | color_by = "sp2.Chr") 170 | 171 | 172 | ## ----------------------------------------------------------------------------- 173 | 174 | library(ggplot2) 175 | 176 | # legend on right (works also with "top" and "left") : 177 | plot_macrosynteny(macrosynteny_df_reordered) + 178 | theme(legend.position = "right") 179 | 180 | 181 | ## ----------------------------------------------------------------------------- 182 | 183 | # Check how many colors are necessary : 184 | print(length(unique(my_orthologs_table_reordered$sp2.Chr))) 185 | 186 | # change color_palette using plot_oxford_grid option color_palette : 187 | color_palette_Pechinospica_chromosomes <- c("#A52A2A", "#FFD39B", "#66CDAA", "#8EE5EE", "#7FFF00", "#FFD700", "#FF7F00", "#474747", "#6495ED", "#FF3030", "#0000EE", "#FF1493", "#8A2BE2", "#080808") 188 | 189 | 190 | plot_oxford_grid(my_orthologs_table_reordered, 191 | color_by = "sp2.Chr", 192 | color_palette = color_palette_Pechinospica_chromosomes) 193 | 194 | 195 | ## ----------------------------------------------------------------------------- 196 | 197 | # change the colors in plot_macrosynteny using ggplot2 functions : 198 | 199 | plot_macrosynteny(macrosynteny_df_reordered) + 200 | scale_color_manual(values = c("gray45","darkgreen")) + 201 | theme(legend.position = "right") 202 | 203 | 204 | ## ----------------------------------------------------------------------------- 205 | 206 | library(dplyr) 207 | 208 | # Let's color only the orthologs that were previously selected in the part 3.2 : 209 | my_orthologs_table_modified <- my_orthologs_table_reordered %>% 210 | mutate(selected = "no") %>% 211 | mutate(selected = replace(selected,sp1.ID %in% subset_of_orthologs$sp1.ID,"yes")) 212 | 213 | plot_oxford_grid(my_orthologs_table_modified, 214 | color_by = "selected", 215 | color_palette = c("black","firebrick")) 216 | 217 | # set the argument shade_non_significant to FALSE to have colors on all the genes of interest : 218 | 219 | plot_oxford_grid(my_orthologs_table_modified, 220 | color_by = "selected", 221 | shade_non_significant = FALSE, 222 | color_palette = c("black","firebrick")) 223 | 224 | 225 | 226 | ## ----------------------------------------------------------------------------- 227 | 228 | plot_chord_diagram(my_orthologs_with_3_sp, 229 | species_labels = c("B. flo","P. ech", "P. yes"), 230 | color_by = "LGs") + 231 | theme(legend.position = "none") 232 | 233 | 234 | ## ----eval=FALSE--------------------------------------------------------------- 235 | # 236 | # # Change the chromosome names to keep only numbers 237 | # levels(my_orthologs_with_3_sp$sp1.Chr) <- stringr::str_replace(levels(my_orthologs_with_3_sp$sp1.Chr),"BFL","") 238 | # levels(my_orthologs_with_3_sp$sp2.Chr) <- stringr::str_replace(levels(my_orthologs_with_3_sp$sp2.Chr),"PEC","") 239 | # levels(my_orthologs_with_3_sp$sp3.Chr) <- stringr::str_replace(levels(my_orthologs_with_3_sp$sp3.Chr),"chr","") 240 | # 241 | # 242 | # plot_chord_diagram(my_orthologs_with_3_sp, 243 | # species_labels = c("B. flo","P. ech", "P. yes"), 244 | # color_by = "LGs") + 245 | # theme(legend.position = "none") 246 | # 247 | 248 | -------------------------------------------------------------------------------- /vignettes/macrosyntR.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "macrosyntR" 3 | author: "Sami El Hilali" 4 | date: "2022/11/09" 5 | output: rmarkdown::html_vignette 6 | vignette: > 7 | %\VignetteIndexEntry{macrosyntR} 8 | %\VignetteEngine{knitr::rmarkdown} 9 | %\VignetteEncoding{UTF-8} 10 | --- 11 | 12 | ```{r, include = FALSE} 13 | knitr::opts_chunk$set( 14 | collapse = TRUE, 15 | comment = "#>" 16 | ) 17 | ``` 18 | 19 | 20 | An R package for evaluation of pair-wise synteny conservation at the genome-wide scale. It takes a table of orthologs and genome annotation files formatted as BED to automatically infer significantly conserved linkage groups, and order them on an oxford grid. 21 | 22 | # Overview : 23 | 24 | It has 7 functions : 25 | 26 | 27 | | Function | description | 28 | |-----------------------|--------------------------------------------------------------------------------------------------------------| 29 | | load_orthologs() | integrates genomic coordinates (bedfiles) of the orthologs of the species to compare | 30 | | compute_macrosynteny() | compares all the chromosomes to each other and identifies the significantly conserved linkage groups | 31 | | reorder_macrosynteny() | takes an orthologs_df (from load_orthologs()) and outputs an orthologs_df with chromosome levels reordered by cluster and amount of orthologs (run alone or by setting plot_oxford_grid(...,auto_order_clusters = TRUE) )| 32 | | plot_macrosynteny() | draws a dotplot displaying the significant linkage groups with their relative amount of orthologs | 33 | | plot_oxford_grid() | draws an Oxford grid from an orthologs_df (output of either load_orthologs() or reorder_macrosynteny() | 34 | | reverse_species_order() | returns an orthologs_df where sp1 became sp2 and the other way around | 35 | | get_syntenic_genes() | compute all blocks containing at least two consecutive genes (relative order) in both species and returns the details as a table | 36 | | reorder_multiple_macrosyntenies() | takes an orthologs_df and reorder like reorder_macrosynteny() but for more than two species | 37 | | plot_chord_diagram() | takes an orthologs_df with two or more species and draws the orthologs as lines in a chord diagram | 38 | | compute_linkage_groups() | takes an orthologs_df and computes the conserved linkage groups | 39 | 40 | # Step-by-step tutorial : 41 | 42 | We demonstrate the usage of the package using a subset of publicly available data (samples attached to the package). 43 | 44 | * Branchiostoma floridae (Simakov et al. 2020) 45 | 46 | * Patinopecten yessoensis (Wang et al. 2017) 47 | 48 | * Paraescarpia echinospica (Sun et al. 2021) 49 | 50 | 51 | ### 1 - Pre-processing : 52 | 53 | #### 1.1 - Foreword : 54 | 55 | This package doesn't compute the orthologs. I recommend to compute pairwise orthology as reciprocal best hits using [rbhxpress](https://github.com/SamiLhll/rbhXpress). It is fast and accurate as it uses diamond blast. 56 | 57 | To use more than 2 species, I recommend using OrthoFinder (Emms and Kelly 2019) as it's easy to derive single copy orthologs from it's output. 58 | 59 | Drawing the plots using this package require to have the following data : 60 | 61 | * A two (or more) columns table of orthologs (reciprocal best hits). Each gene must appear only once in the table. 62 | * genomic coordinates on each species for all the orthologs 63 | 64 | let's say I have the following orthologs : 65 | 66 | ```{bash, eval = FALSE} 67 | sp1.gene.x1 sp2.gene.y1 68 | sp1.gene.X2 sp2.gene.y2 69 | ... 70 | sp1.gene.xn sp2.gene.yn 71 | ``` 72 | 73 | then, the genomic coordinates files must look like (BED format) : 74 | 75 | * species1 : 76 | ```{bash, eval = FALSE} 77 | chr4 200 600 sp1.gene.x1 78 | chr8 10 400 sp1.gene.x2 79 | ... 80 | chr12 900 980 sp1.gene.xn 81 | ``` 82 | 83 | * species2 : 84 | ```{bash, eval = FALSE} 85 | chr1 100 200 sp2.gene.y1 86 | chr6 50 200 sp2.gene.y2 87 | ... 88 | chr8 300 480 sp2.gene.yn 89 | ``` 90 | 91 | 92 | #### 1.2 - Example using two species (rbhXpress) : 93 | 94 | I'm going to show usage of this package by comparing the data of the lancelet Branchiostoma floridae ([Simakov et al. 2020](https://doi.org/10.1038/s41559-020-1156-z)) with the data of the vestimentifera (giant tubeworm) Paraescarpia echinospica ([Sun et al. 2021](https://doi.org/10.1093/molbev/msab203)). 95 | 96 | Download the sequences of proteins (fasta format) and their genomic coordinates : 97 | 98 | - B.floridae : 99 | The data are available on ncbi at https://www.ncbi.nlm.nih.gov/genome/?term=txid7739 100 | get the protein sequences at by clicking the "Download sequences in FASTA format for protein". 101 | get the genomic coordinates by clicking "Download genome annotation in tabular format" and further click download as csv. 102 | 103 | - P.echinospica : 104 | The data are available on figshare under the doi : [10.6084/m9.figshare.15050478](https://doi.org/10.6084/m9.figshare.15050478) 105 | 106 | 107 | Compute the reciprocal best hits of the fasta sequences. Using [rbhXpress](https://github.com/SamiLhll/rbhXpress) you can achieve it by typing the following in your terminal : 108 | 109 | ```{bash,eval = FALSE} 110 | # In the terminal : 111 | # call rbhXpress with using 6 threads : 112 | bash rbhXpress -a GCF_000003815.2_Bfl_VNyyK_protein.faa -b Pec_ragoo_v1.0.pep.fasta -o Bflo_vs_Pech.tab -t 6 113 | 114 | ``` 115 | 116 | To convert the genome annotation to the [bed file format](https://www.ensembl.org/info/website/upload/bed.html), I'm using the following command lines (if unfamiliar with this you can use a spreadsheet software). The concept is to keep the chrom, chromStart, chromEnd mandatory fields plus the name optional field that links the genomic region with the protein product : 117 | 118 | ```{bash, eval = FALSE} 119 | # In the terminal : 120 | # B.floridae CSV file to bed 121 | tail -n +2 proteins_75_971579.csv | cut -d "," -f1,3,4,9 | \ 122 | sed -e 's/\"//g' -e 's/,/\t/g' -e 's/chromosome /BFL/g' > Bflo.bed 123 | 124 | # P.echinospica gff file to bed 125 | fgrep "gene" Pec_genes.ragoo_v1.0.gff | cut -f1,4,5,9 | cut -d ";" -f 1 | \ 126 | fgrep "Superscaffold" | sed -e 's/ID=//g' -e 's/Superscaffold/PEC/g' > Pech.bed 127 | 128 | ``` 129 | 130 | **Please note that the example dataset attached to this package is a subset. I kept only 2500 ortholog pairs to lower the compilation time**. 131 | 132 | #### 1.3 - Example using 3 species (Orthofinder) : 133 | 134 | If we wanted to add one species to the previous study, we would need to get the data and compute the single copy orthologs. 135 | We will use here the data for the scallop Patinopecten yessoensis ([Wang et al. 2017](https://doi.org/10.1038/s41559-017-0120)). 136 | These data were shared by the authors upon request and a sample is attached with the package. 137 | 138 | The first step is to compute the orthologs using orthofinder (Emms and Kelly 2019). 139 | When done, you can extract the Single copy orthologs using the following command line : 140 | 141 | ```{bash, eval = FALSE} 142 | 143 | fgrep -f /Orthogroups/Orthogroups_SingleCopyOrthologues.txt \ 144 | /Orthogroups/Orthogroups.tsv > Single_copy_orthologs.tab 145 | 146 | ``` 147 | 148 | One important thing about orthofinder's output is the encoding that will create issues when loaded in R. 149 | 150 | If for the encoding you have like me : 151 | 152 | ```{bash, eval = FALSE} 153 | 154 | file Single_copy_orthologs.tab 155 | # ASCII text, with CRLF line terminators 156 | 157 | ``` 158 | 159 | These CRLF line terminators are a problem and you should replace it by regular "\n" as line terminator. 160 | It can be achieved using the following command : 161 | 162 | ```{bash, eval = FALSE} 163 | 164 | tr '\015\012/' '\n' < Single_copy_orthologs.tab | awk '($0 != "") {print}' > Single_copy_orthologs.tsv 165 | 166 | ``` 167 | 168 | ### 2 - Load the data : 169 | 170 | Now the data are ready to be loaded into R using macrosyntR : 171 | 172 | ```{r setup} 173 | library(macrosyntR) 174 | ``` 175 | 176 | ```{r} 177 | 178 | my_orthologs_table <- load_orthologs(orthologs_table = system.file("extdata","Bflo_vs_Pech.tab",package="macrosyntR"), 179 | bedfiles = c(system.file("extdata","Bflo.bed",package="macrosyntR"), 180 | system.file("extdata","Pech.bed",package="macrosyntR"))) 181 | 182 | head(my_orthologs_table) 183 | 184 | ``` 185 | 186 | or alternatively : 187 | 188 | ```{r} 189 | 190 | my_orthologs_with_3_sp <- load_orthologs(orthologs_table = system.file("extdata","Single_copy_orthologs.tsv",package="macrosyntR"), 191 | bedfiles = c(system.file("extdata","Bflo.bed",package="macrosyntR"), 192 | system.file("extdata","Pech.bed",package="macrosyntR"), 193 | system.file("extdata","Pyes.bed",package="macrosyntR"))) 194 | 195 | head(my_orthologs_with_3_sp) 196 | 197 | ``` 198 | 199 | 200 | ### 3 - Compute linkage groups : 201 | 202 | Let's vizualize the pairs of chromosomes that have a significant amount of orthologs using compute_macrosynteny(). 203 | We can visualize the results on a dot plot using plot_macrosnyteny() and see the distributions of orthologs on an oxford grid using plot_oxford_grid() 204 | 205 | ```{r} 206 | 207 | # compute significance : 208 | macrosynteny_df <- compute_macrosynteny(my_orthologs_table) 209 | head(macrosynteny_df) 210 | 211 | ``` 212 | 213 | 214 | ```{r,eval = FALSE, out.width = '450px'} 215 | 216 | # visualize the loaded data on a oxford grid : 217 | plot_oxford_grid(my_orthologs_table, 218 | sp1_label = "B.floridae", 219 | sp2_label = "P.echinospica") 220 | 221 | # Visualize the results of the test of significance : 222 | plot_macrosynteny(macrosynteny_df, 223 | sp1_label = "B.floridae", 224 | sp2_label = "P.echinospica") 225 | 226 | ``` 227 | 228 | ```{r,echo = FALSE,out.width = c('300px','300px')} 229 | 230 | # visualize the loaded data on a oxford grid : 231 | plot_oxford_grid(my_orthologs_table, 232 | sp1_label = "B.floridae", 233 | sp2_label = "P.echinospica") 234 | 235 | # Visualize the results of the test of significance : 236 | plot_macrosynteny(macrosynteny_df, 237 | sp1_label = "B.floridae", 238 | sp2_label = "P.echinospica") 239 | 240 | ``` 241 | 242 | 243 | To get these (sub)chromosomal associations of two or more species, we can use the function compute_linkage_groups() 244 | 245 | ```{r,eval = FALSE} 246 | my_linkage_groups <- compute_linkage_groups(my_orthologs_with_3_sp) 247 | head(my_linkage_groups) 248 | 249 | ``` 250 | 251 | 252 | ```{r,echo = FALSE} 253 | 254 | my_linkage_groups <- compute_linkage_groups(my_orthologs_with_3_sp) 255 | head(my_linkage_groups) 256 | 257 | ``` 258 | 259 | ### 4 - Reorder chromosome levels to group the linkage groups in clusters : 260 | 261 | #### 4.1 - Automatic reordering using a network-based greedy algorithm : 262 | 263 | Reordering the chromosomes using a network based greedy algorithm can be performed by calling the function reorder_macrosynteny. 264 | It returns an orthologs_df with reordered levels in sp1.Chr and sp2.Chr. These columns are factors where the levels determine the plotting order. 265 | You'll see the results of the clustering, when drawing the oxford grid of this newly generated orthologs data.frame 266 | 267 | ```{r,eval = FALSE} 268 | 269 | # visualize the loaded data on a oxford grid : 270 | my_orthologs_table_reordered <- reorder_macrosynteny(my_orthologs_table) 271 | plot_oxford_grid(my_orthologs_table_reordered, 272 | sp1_label = "B.floridae", 273 | sp2_label = "P.echinospica") 274 | 275 | # compute significance and visualize on a dotplot : 276 | macrosynteny_df_reordered <- compute_macrosynteny(my_orthologs_table_reordered) 277 | plot_macrosynteny(macrosynteny_df_reordered, 278 | sp1_label = "B.floridae", 279 | sp2_label = "P.echinospica") 280 | 281 | ``` 282 | 283 | ```{r,echo = FALSE} 284 | # visualize the loaded data on a oxford grid : 285 | my_orthologs_table_reordered <- reorder_macrosynteny(my_orthologs_table) 286 | plot_oxford_grid(my_orthologs_table_reordered, 287 | sp1_label = "B.floridae", 288 | sp2_label = "P.echinospica") 289 | # compute significance and visualize on a dotplot : 290 | macrosynteny_df_reordered <- compute_macrosynteny(my_orthologs_table_reordered) 291 | plot_macrosynteny(macrosynteny_df_reordered, 292 | sp1_label = "B.floridae", 293 | sp2_label = "P.echinospica") 294 | 295 | ``` 296 | 297 | #### 4.2 - Manually reorder/subset the Chromosomes : 298 | 299 | If you would like to subset some chromosomes of interest and manually reorder them you can still take advantage of functions implemented to handle data.frames. 300 | This task is out of the scope of this package, and can achieved using base R : 301 | 302 | ```{r,eval = FALSE} 303 | # select only the orthologs falling in the chromosomes of interest and plot: 304 | subset_of_orthologs <- subset(my_orthologs_table, sp1.Chr %in% c("BFL13","BFL15","BFL2","BFL3") & sp2.Chr %in% c("PEC2","PEC5","PEC11")) 305 | 306 | plot_oxford_grid(subset_of_orthologs, 307 | sp1_label = "B.floridae", 308 | sp2_label = "P.echinospica") 309 | 310 | # reorder : 311 | subset_of_orthologs$sp2.Chr <- factor(subset_of_orthologs$sp2.Chr,levels = c("PEC5","PEC11","PEC2")) 312 | plot_oxford_grid(subset_of_orthologs, 313 | sp1_label = "B.floridae", 314 | sp2_label = "P.echinospica") 315 | 316 | # Compute and plot macrosynteny : 317 | macrosynteny_of_subset <- compute_macrosynteny(subset_of_orthologs) 318 | plot_macrosynteny(macrosynteny_of_subset, 319 | sp1_label = "B.floridae", 320 | sp2_label = "P.echinospica") 321 | 322 | ``` 323 | 324 | ```{r,echo = FALSE,out.width = c('300px','300px')} 325 | # select only the orthologs falling in the chromosomes of interest and plot: 326 | subset_of_orthologs <- subset(my_orthologs_table, sp1.Chr %in% c("BFL13","BFL15","BFL2","BFL3") & sp2.Chr %in% c("PEC2","PEC5","PEC11")) 327 | 328 | plot_oxford_grid(subset_of_orthologs, 329 | sp1_label = "B.floridae", 330 | sp2_label = "P.echinospica") 331 | 332 | # reorder : 333 | subset_of_orthologs$sp2.Chr <- factor(subset_of_orthologs$sp2.Chr,levels = c("PEC5","PEC11","PEC2")) 334 | plot_oxford_grid(subset_of_orthologs, 335 | sp1_label = "B.floridae", 336 | sp2_label = "P.echinospica") 337 | 338 | 339 | ``` 340 | 341 | 342 | ### 5 - Plot directly with reordering the linkage groups and coloring : 343 | 344 | The reordering can be performed on the row when calling plot_oxford_grid() by setting the reorder argument to TRUE. 345 | 346 | ```{r,eval = FALSE} 347 | 348 | # visualize the loaded data on a oxford grid with reordering and coloring by cluster : 349 | plot_oxford_grid(my_orthologs_table, 350 | sp1_label = "B.floridae", 351 | sp2_label = "P.echinospica", 352 | reorder = TRUE, 353 | color_by = "clust") 354 | 355 | # redo and color by sp1.Chr instead : 356 | plot_oxford_grid(my_orthologs_table, 357 | sp1_label = "B.floridae", 358 | sp2_label = "P.echinospica", 359 | reorder = TRUE, 360 | color_by = "sp1.Chr") 361 | 362 | ``` 363 | 364 | ```{r,echo = FALSE,out.width = c('300px','300px')} 365 | 366 | # visualize the loaded data on a oxford grid with reordering and coloring by cluster : 367 | plot_oxford_grid(my_orthologs_table, 368 | sp1_label = "B.floridae", 369 | sp2_label = "P.echinospica", 370 | reorder = TRUE, 371 | color_by = "clust") 372 | 373 | # redo and color by sp2.Chr instead : 374 | plot_oxford_grid(my_orthologs_table, 375 | sp1_label = "B.floridae", 376 | sp2_label = "P.echinospica", 377 | reorder = TRUE, 378 | color_by = "sp2.Chr") 379 | 380 | ``` 381 | 382 | ### 6 - Customize the plots : 383 | 384 | Plots returned from both plot_oxford_grid() and plot_macrosynteny() are ggplot objects and it is possible to further customizing them using the vocabulary from the ggplot2 package. 385 | 386 | #### 6.1 - customize the legend : 387 | 388 | As the functions plot_oxford_grid(), plot_macrosynteny() and plot_chord_diagram() return a ggplot2 object, you can customize the plots using ggplot2::theme() function. 389 | For example, if you want to display the legend on the right of the plot you can do : 390 | ```{r} 391 | 392 | library(ggplot2) 393 | 394 | # legend on right (works also with "top" and "left") : 395 | plot_macrosynteny(macrosynteny_df_reordered) + 396 | theme(legend.position = "right") 397 | 398 | ``` 399 | 400 | 401 | #### 6.2 - change the color palette : 402 | 403 | plot_oxford_grid() features an option color_palette, but it is also possible to set it using scale_color_manual() from ggplot2 : 404 | 405 | ```{r} 406 | 407 | # Check how many colors are necessary : 408 | print(length(unique(my_orthologs_table_reordered$sp2.Chr))) 409 | 410 | # change color_palette using plot_oxford_grid option color_palette : 411 | color_palette_Pechinospica_chromosomes <- c("#A52A2A", "#FFD39B", "#66CDAA", "#8EE5EE", "#7FFF00", "#FFD700", "#FF7F00", "#474747", "#6495ED", "#FF3030", "#0000EE", "#FF1493", "#8A2BE2", "#080808") 412 | 413 | 414 | plot_oxford_grid(my_orthologs_table_reordered, 415 | color_by = "sp2.Chr", 416 | color_palette = color_palette_Pechinospica_chromosomes) 417 | 418 | ``` 419 | 420 | ```{r} 421 | 422 | # change the colors in plot_macrosynteny using ggplot2 functions : 423 | 424 | plot_macrosynteny(macrosynteny_df_reordered) + 425 | scale_color_manual(values = c("gray45","darkgreen")) + 426 | theme(legend.position = "right") 427 | 428 | ``` 429 | 430 | # 7 - Integrate additional information using colors : 431 | 432 | The data returned by load_orthologs(), reorder_macrosynteny(), and compute_macrosynteny() are data.frame objects. I can thus add external information based on protein IDs by merging it with another dataframe, and then take advantage of using colors to display the new information on the plot : 433 | 434 | 435 | ```{r} 436 | 437 | library(dplyr) 438 | 439 | # Let's color only the orthologs that were previously selected in the part 3.2 : 440 | my_orthologs_table_modified <- my_orthologs_table_reordered %>% 441 | mutate(selected = "no") %>% 442 | mutate(selected = replace(selected,sp1.ID %in% subset_of_orthologs$sp1.ID,"yes")) 443 | 444 | plot_oxford_grid(my_orthologs_table_modified, 445 | color_by = "selected", 446 | color_palette = c("black","firebrick")) 447 | 448 | # set the argument shade_non_significant to FALSE to have colors on all the genes of interest : 449 | 450 | plot_oxford_grid(my_orthologs_table_modified, 451 | color_by = "selected", 452 | shade_non_significant = FALSE, 453 | color_palette = c("black","firebrick")) 454 | 455 | 456 | ``` 457 | 458 | # 8 - plot a chord diagram : 459 | 460 | To plot the conservation of macrosynteny accross two or more species (here 3) on a chord diagram and coloring according to linkage groups we use 461 | the function plot_chord_diagram() : 462 | 463 | ```{r} 464 | 465 | plot_chord_diagram(my_orthologs_with_3_sp, 466 | species_labels = c("B. flo","P. ech", "P. yes"), 467 | color_by = "LGs") + 468 | theme(legend.position = "none") 469 | 470 | ``` 471 | 472 | We can change the chromosome names to improve the readability of the plot using stringr::str_replace() and factor levels as following : 473 | 474 | ```{r,eval=FALSE} 475 | 476 | # Change the chromosome names to keep only numbers 477 | levels(my_orthologs_with_3_sp$sp1.Chr) <- stringr::str_replace(levels(my_orthologs_with_3_sp$sp1.Chr),"BFL","") 478 | levels(my_orthologs_with_3_sp$sp2.Chr) <- stringr::str_replace(levels(my_orthologs_with_3_sp$sp2.Chr),"PEC","") 479 | levels(my_orthologs_with_3_sp$sp3.Chr) <- stringr::str_replace(levels(my_orthologs_with_3_sp$sp3.Chr),"chr","") 480 | 481 | 482 | plot_chord_diagram(my_orthologs_with_3_sp, 483 | species_labels = c("B. flo","P. ech", "P. yes"), 484 | color_by = "LGs") + 485 | theme(legend.position = "none") 486 | 487 | ``` 488 | 489 | ![](../inst/img/Chord_diagram_3species.png) 490 | --------------------------------------------------------------------------------