diff --git a/.Rbuildignore b/.Rbuildignore
index fd68cd8..c35c30e 100644
--- a/.Rbuildignore
+++ b/.Rbuildignore
@@ -4,3 +4,4 @@
^README-.*\.png$
^data-raw/$
^TODO\.md$
+^LICENSE\.md$
diff --git a/DESCRIPTION b/DESCRIPTION
index 0fd9fc0..a7f30b6 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,27 +1,24 @@
Package: PAMES
-Date: 2021-12-01
-Type: Package
Title: Purity Assessment from clonal MEthylation Sites
-Description: Exploiting data from DNA methylation, this package provides the operations
- required to evaluate the purity of tumor samples.
-Version: 2.7.2
+Description: Exploiting data from DNA methylation, this package provides the
+ operations required to evaluate the purity of tumor samples.
+Version: 3.0.0
Authors@R: c(person("Dario", "Romagnoli", role=c("aut", "cre"),
email="dario.romagnoli87@gmail.com"),
person("Matteo", "Benelli", role="aut"),
person("Francesca", "Demichelis", role="aut"))
-Depends: R (>= 3.5.0)
+Depends: R (>= 4.0.0)
Imports:
- parallel,
- S4Vectors,
+ assertthat,
GenomicRanges,
IRanges,
- assertthat,
- dplyr
+ parallel,
+ S4Vectors,
Suggests:
knitr,
rmarkdown,
testthat
-License: GPL-3 | file LICENSE
+License: GPL (>= 3)
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.0
diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index 9cecc1d..0000000
--- a/LICENSE
+++ /dev/null
@@ -1,674 +0,0 @@
- GNU GENERAL PUBLIC LICENSE
- Version 3, 29 June 2007
-
- Copyright (C) 2007 Free Software Foundation, Inc.
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
- Preamble
-
- The GNU General Public License is a free, copyleft license for
-software and other kinds of works.
-
- The licenses for most software and other practical works are designed
-to take away your freedom to share and change the works. By contrast,
-the GNU General Public License is intended to guarantee your freedom to
-share and change all versions of a program--to make sure it remains free
-software for all its users. We, the Free Software Foundation, use the
-GNU General Public License for most of our software; it applies also to
-any other work released this way by its authors. You can apply it to
-your programs, too.
-
- When we speak of free software, we are referring to freedom, not
-price. Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-them if you wish), that you receive source code or can get it if you
-want it, that you can change the software or use pieces of it in new
-free programs, and that you know you can do these things.
-
- To protect your rights, we need to prevent others from denying you
-these rights or asking you to surrender the rights. Therefore, you have
-certain responsibilities if you distribute copies of the software, or if
-you modify it: responsibilities to respect the freedom of others.
-
- For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must pass on to the recipients the same
-freedoms that you received. You must make sure that they, too, receive
-or can get the source code. And you must show them these terms so they
-know their rights.
-
- Developers that use the GNU GPL protect your rights with two steps:
-(1) assert copyright on the software, and (2) offer you this License
-giving you legal permission to copy, distribute and/or modify it.
-
- For the developers' and authors' protection, the GPL clearly explains
-that there is no warranty for this free software. For both users' and
-authors' sake, the GPL requires that modified versions be marked as
-changed, so that their problems will not be attributed erroneously to
-authors of previous versions.
-
- Some devices are designed to deny users access to install or run
-modified versions of the software inside them, although the manufacturer
-can do so. This is fundamentally incompatible with the aim of
-protecting users' freedom to change the software. The systematic
-pattern of such abuse occurs in the area of products for individuals to
-use, which is precisely where it is most unacceptable. Therefore, we
-have designed this version of the GPL to prohibit the practice for those
-products. If such problems arise substantially in other domains, we
-stand ready to extend this provision to those domains in future versions
-of the GPL, as needed to protect the freedom of users.
-
- Finally, every program is threatened constantly by software patents.
-States should not allow patents to restrict development and use of
-software on general-purpose computers, but in those that do, we wish to
-avoid the special danger that patents applied to a free program could
-make it effectively proprietary. To prevent this, the GPL assures that
-patents cannot be used to render the program non-free.
-
- The precise terms and conditions for copying, distribution and
-modification follow.
-
- TERMS AND CONDITIONS
-
- 0. Definitions.
-
- "This License" refers to version 3 of the GNU General Public License.
-
- "Copyright" also means copyright-like laws that apply to other kinds of
-works, such as semiconductor masks.
-
- "The Program" refers to any copyrightable work licensed under this
-License. Each licensee is addressed as "you". "Licensees" and
-"recipients" may be individuals or organizations.
-
- To "modify" a work means to copy from or adapt all or part of the work
-in a fashion requiring copyright permission, other than the making of an
-exact copy. The resulting work is called a "modified version" of the
-earlier work or a work "based on" the earlier work.
-
- A "covered work" means either the unmodified Program or a work based
-on the Program.
-
- To "propagate" a work means to do anything with it that, without
-permission, would make you directly or secondarily liable for
-infringement under applicable copyright law, except executing it on a
-computer or modifying a private copy. Propagation includes copying,
-distribution (with or without modification), making available to the
-public, and in some countries other activities as well.
-
- To "convey" a work means any kind of propagation that enables other
-parties to make or receive copies. Mere interaction with a user through
-a computer network, with no transfer of a copy, is not conveying.
-
- An interactive user interface displays "Appropriate Legal Notices"
-to the extent that it includes a convenient and prominently visible
-feature that (1) displays an appropriate copyright notice, and (2)
-tells the user that there is no warranty for the work (except to the
-extent that warranties are provided), that licensees may convey the
-work under this License, and how to view a copy of this License. If
-the interface presents a list of user commands or options, such as a
-menu, a prominent item in the list meets this criterion.
-
- 1. Source Code.
-
- The "source code" for a work means the preferred form of the work
-for making modifications to it. "Object code" means any non-source
-form of a work.
-
- A "Standard Interface" means an interface that either is an official
-standard defined by a recognized standards body, or, in the case of
-interfaces specified for a particular programming language, one that
-is widely used among developers working in that language.
-
- The "System Libraries" of an executable work include anything, other
-than the work as a whole, that (a) is included in the normal form of
-packaging a Major Component, but which is not part of that Major
-Component, and (b) serves only to enable use of the work with that
-Major Component, or to implement a Standard Interface for which an
-implementation is available to the public in source code form. A
-"Major Component", in this context, means a major essential component
-(kernel, window system, and so on) of the specific operating system
-(if any) on which the executable work runs, or a compiler used to
-produce the work, or an object code interpreter used to run it.
-
- The "Corresponding Source" for a work in object code form means all
-the source code needed to generate, install, and (for an executable
-work) run the object code and to modify the work, including scripts to
-control those activities. However, it does not include the work's
-System Libraries, or general-purpose tools or generally available free
-programs which are used unmodified in performing those activities but
-which are not part of the work. For example, Corresponding Source
-includes interface definition files associated with source files for
-the work, and the source code for shared libraries and dynamically
-linked subprograms that the work is specifically designed to require,
-such as by intimate data communication or control flow between those
-subprograms and other parts of the work.
-
- The Corresponding Source need not include anything that users
-can regenerate automatically from other parts of the Corresponding
-Source.
-
- The Corresponding Source for a work in source code form is that
-same work.
-
- 2. Basic Permissions.
-
- All rights granted under this License are granted for the term of
-copyright on the Program, and are irrevocable provided the stated
-conditions are met. This License explicitly affirms your unlimited
-permission to run the unmodified Program. The output from running a
-covered work is covered by this License only if the output, given its
-content, constitutes a covered work. This License acknowledges your
-rights of fair use or other equivalent, as provided by copyright law.
-
- You may make, run and propagate covered works that you do not
-convey, without conditions so long as your license otherwise remains
-in force. You may convey covered works to others for the sole purpose
-of having them make modifications exclusively for you, or provide you
-with facilities for running those works, provided that you comply with
-the terms of this License in conveying all material for which you do
-not control copyright. Those thus making or running the covered works
-for you must do so exclusively on your behalf, under your direction
-and control, on terms that prohibit them from making any copies of
-your copyrighted material outside their relationship with you.
-
- Conveying under any other circumstances is permitted solely under
-the conditions stated below. Sublicensing is not allowed; section 10
-makes it unnecessary.
-
- 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
-
- No covered work shall be deemed part of an effective technological
-measure under any applicable law fulfilling obligations under article
-11 of the WIPO copyright treaty adopted on 20 December 1996, or
-similar laws prohibiting or restricting circumvention of such
-measures.
-
- When you convey a covered work, you waive any legal power to forbid
-circumvention of technological measures to the extent such circumvention
-is effected by exercising rights under this License with respect to
-the covered work, and you disclaim any intention to limit operation or
-modification of the work as a means of enforcing, against the work's
-users, your or third parties' legal rights to forbid circumvention of
-technological measures.
-
- 4. Conveying Verbatim Copies.
-
- You may convey verbatim copies of the Program's source code as you
-receive it, in any medium, provided that you conspicuously and
-appropriately publish on each copy an appropriate copyright notice;
-keep intact all notices stating that this License and any
-non-permissive terms added in accord with section 7 apply to the code;
-keep intact all notices of the absence of any warranty; and give all
-recipients a copy of this License along with the Program.
-
- You may charge any price or no price for each copy that you convey,
-and you may offer support or warranty protection for a fee.
-
- 5. Conveying Modified Source Versions.
-
- You may convey a work based on the Program, or the modifications to
-produce it from the Program, in the form of source code under the
-terms of section 4, provided that you also meet all of these conditions:
-
- a) The work must carry prominent notices stating that you modified
- it, and giving a relevant date.
-
- b) The work must carry prominent notices stating that it is
- released under this License and any conditions added under section
- 7. This requirement modifies the requirement in section 4 to
- "keep intact all notices".
-
- c) You must license the entire work, as a whole, under this
- License to anyone who comes into possession of a copy. This
- License will therefore apply, along with any applicable section 7
- additional terms, to the whole of the work, and all its parts,
- regardless of how they are packaged. This License gives no
- permission to license the work in any other way, but it does not
- invalidate such permission if you have separately received it.
-
- d) If the work has interactive user interfaces, each must display
- Appropriate Legal Notices; however, if the Program has interactive
- interfaces that do not display Appropriate Legal Notices, your
- work need not make them do so.
-
- A compilation of a covered work with other separate and independent
-works, which are not by their nature extensions of the covered work,
-and which are not combined with it such as to form a larger program,
-in or on a volume of a storage or distribution medium, is called an
-"aggregate" if the compilation and its resulting copyright are not
-used to limit the access or legal rights of the compilation's users
-beyond what the individual works permit. Inclusion of a covered work
-in an aggregate does not cause this License to apply to the other
-parts of the aggregate.
-
- 6. Conveying Non-Source Forms.
-
- You may convey a covered work in object code form under the terms
-of sections 4 and 5, provided that you also convey the
-machine-readable Corresponding Source under the terms of this License,
-in one of these ways:
-
- a) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by the
- Corresponding Source fixed on a durable physical medium
- customarily used for software interchange.
-
- b) Convey the object code in, or embodied in, a physical product
- (including a physical distribution medium), accompanied by a
- written offer, valid for at least three years and valid for as
- long as you offer spare parts or customer support for that product
- model, to give anyone who possesses the object code either (1) a
- copy of the Corresponding Source for all the software in the
- product that is covered by this License, on a durable physical
- medium customarily used for software interchange, for a price no
- more than your reasonable cost of physically performing this
- conveying of source, or (2) access to copy the
- Corresponding Source from a network server at no charge.
-
- c) Convey individual copies of the object code with a copy of the
- written offer to provide the Corresponding Source. This
- alternative is allowed only occasionally and noncommercially, and
- only if you received the object code with such an offer, in accord
- with subsection 6b.
-
- d) Convey the object code by offering access from a designated
- place (gratis or for a charge), and offer equivalent access to the
- Corresponding Source in the same way through the same place at no
- further charge. You need not require recipients to copy the
- Corresponding Source along with the object code. If the place to
- copy the object code is a network server, the Corresponding Source
- may be on a different server (operated by you or a third party)
- that supports equivalent copying facilities, provided you maintain
- clear directions next to the object code saying where to find the
- Corresponding Source. Regardless of what server hosts the
- Corresponding Source, you remain obligated to ensure that it is
- available for as long as needed to satisfy these requirements.
-
- e) Convey the object code using peer-to-peer transmission, provided
- you inform other peers where the object code and Corresponding
- Source of the work are being offered to the general public at no
- charge under subsection 6d.
-
- A separable portion of the object code, whose source code is excluded
-from the Corresponding Source as a System Library, need not be
-included in conveying the object code work.
-
- A "User Product" is either (1) a "consumer product", which means any
-tangible personal property which is normally used for personal, family,
-or household purposes, or (2) anything designed or sold for incorporation
-into a dwelling. In determining whether a product is a consumer product,
-doubtful cases shall be resolved in favor of coverage. For a particular
-product received by a particular user, "normally used" refers to a
-typical or common use of that class of product, regardless of the status
-of the particular user or of the way in which the particular user
-actually uses, or expects or is expected to use, the product. A product
-is a consumer product regardless of whether the product has substantial
-commercial, industrial or non-consumer uses, unless such uses represent
-the only significant mode of use of the product.
-
- "Installation Information" for a User Product means any methods,
-procedures, authorization keys, or other information required to install
-and execute modified versions of a covered work in that User Product from
-a modified version of its Corresponding Source. The information must
-suffice to ensure that the continued functioning of the modified object
-code is in no case prevented or interfered with solely because
-modification has been made.
-
- If you convey an object code work under this section in, or with, or
-specifically for use in, a User Product, and the conveying occurs as
-part of a transaction in which the right of possession and use of the
-User Product is transferred to the recipient in perpetuity or for a
-fixed term (regardless of how the transaction is characterized), the
-Corresponding Source conveyed under this section must be accompanied
-by the Installation Information. But this requirement does not apply
-if neither you nor any third party retains the ability to install
-modified object code on the User Product (for example, the work has
-been installed in ROM).
-
- The requirement to provide Installation Information does not include a
-requirement to continue to provide support service, warranty, or updates
-for a work that has been modified or installed by the recipient, or for
-the User Product in which it has been modified or installed. Access to a
-network may be denied when the modification itself materially and
-adversely affects the operation of the network or violates the rules and
-protocols for communication across the network.
-
- Corresponding Source conveyed, and Installation Information provided,
-in accord with this section must be in a format that is publicly
-documented (and with an implementation available to the public in
-source code form), and must require no special password or key for
-unpacking, reading or copying.
-
- 7. Additional Terms.
-
- "Additional permissions" are terms that supplement the terms of this
-License by making exceptions from one or more of its conditions.
-Additional permissions that are applicable to the entire Program shall
-be treated as though they were included in this License, to the extent
-that they are valid under applicable law. If additional permissions
-apply only to part of the Program, that part may be used separately
-under those permissions, but the entire Program remains governed by
-this License without regard to the additional permissions.
-
- When you convey a copy of a covered work, you may at your option
-remove any additional permissions from that copy, or from any part of
-it. (Additional permissions may be written to require their own
-removal in certain cases when you modify the work.) You may place
-additional permissions on material, added by you to a covered work,
-for which you have or can give appropriate copyright permission.
-
- Notwithstanding any other provision of this License, for material you
-add to a covered work, you may (if authorized by the copyright holders of
-that material) supplement the terms of this License with terms:
-
- a) Disclaiming warranty or limiting liability differently from the
- terms of sections 15 and 16 of this License; or
-
- b) Requiring preservation of specified reasonable legal notices or
- author attributions in that material or in the Appropriate Legal
- Notices displayed by works containing it; or
-
- c) Prohibiting misrepresentation of the origin of that material, or
- requiring that modified versions of such material be marked in
- reasonable ways as different from the original version; or
-
- d) Limiting the use for publicity purposes of names of licensors or
- authors of the material; or
-
- e) Declining to grant rights under trademark law for use of some
- trade names, trademarks, or service marks; or
-
- f) Requiring indemnification of licensors and authors of that
- material by anyone who conveys the material (or modified versions of
- it) with contractual assumptions of liability to the recipient, for
- any liability that these contractual assumptions directly impose on
- those licensors and authors.
-
- All other non-permissive additional terms are considered "further
-restrictions" within the meaning of section 10. If the Program as you
-received it, or any part of it, contains a notice stating that it is
-governed by this License along with a term that is a further
-restriction, you may remove that term. If a license document contains
-a further restriction but permits relicensing or conveying under this
-License, you may add to a covered work material governed by the terms
-of that license document, provided that the further restriction does
-not survive such relicensing or conveying.
-
- If you add terms to a covered work in accord with this section, you
-must place, in the relevant source files, a statement of the
-additional terms that apply to those files, or a notice indicating
-where to find the applicable terms.
-
- Additional terms, permissive or non-permissive, may be stated in the
-form of a separately written license, or stated as exceptions;
-the above requirements apply either way.
-
- 8. Termination.
-
- You may not propagate or modify a covered work except as expressly
-provided under this License. Any attempt otherwise to propagate or
-modify it is void, and will automatically terminate your rights under
-this License (including any patent licenses granted under the third
-paragraph of section 11).
-
- However, if you cease all violation of this License, then your
-license from a particular copyright holder is reinstated (a)
-provisionally, unless and until the copyright holder explicitly and
-finally terminates your license, and (b) permanently, if the copyright
-holder fails to notify you of the violation by some reasonable means
-prior to 60 days after the cessation.
-
- Moreover, your license from a particular copyright holder is
-reinstated permanently if the copyright holder notifies you of the
-violation by some reasonable means, this is the first time you have
-received notice of violation of this License (for any work) from that
-copyright holder, and you cure the violation prior to 30 days after
-your receipt of the notice.
-
- Termination of your rights under this section does not terminate the
-licenses of parties who have received copies or rights from you under
-this License. If your rights have been terminated and not permanently
-reinstated, you do not qualify to receive new licenses for the same
-material under section 10.
-
- 9. Acceptance Not Required for Having Copies.
-
- You are not required to accept this License in order to receive or
-run a copy of the Program. Ancillary propagation of a covered work
-occurring solely as a consequence of using peer-to-peer transmission
-to receive a copy likewise does not require acceptance. However,
-nothing other than this License grants you permission to propagate or
-modify any covered work. These actions infringe copyright if you do
-not accept this License. Therefore, by modifying or propagating a
-covered work, you indicate your acceptance of this License to do so.
-
- 10. Automatic Licensing of Downstream Recipients.
-
- Each time you convey a covered work, the recipient automatically
-receives a license from the original licensors, to run, modify and
-propagate that work, subject to this License. You are not responsible
-for enforcing compliance by third parties with this License.
-
- An "entity transaction" is a transaction transferring control of an
-organization, or substantially all assets of one, or subdividing an
-organization, or merging organizations. If propagation of a covered
-work results from an entity transaction, each party to that
-transaction who receives a copy of the work also receives whatever
-licenses to the work the party's predecessor in interest had or could
-give under the previous paragraph, plus a right to possession of the
-Corresponding Source of the work from the predecessor in interest, if
-the predecessor has it or can get it with reasonable efforts.
-
- You may not impose any further restrictions on the exercise of the
-rights granted or affirmed under this License. For example, you may
-not impose a license fee, royalty, or other charge for exercise of
-rights granted under this License, and you may not initiate litigation
-(including a cross-claim or counterclaim in a lawsuit) alleging that
-any patent claim is infringed by making, using, selling, offering for
-sale, or importing the Program or any portion of it.
-
- 11. Patents.
-
- A "contributor" is a copyright holder who authorizes use under this
-License of the Program or a work on which the Program is based. The
-work thus licensed is called the contributor's "contributor version".
-
- A contributor's "essential patent claims" are all patent claims
-owned or controlled by the contributor, whether already acquired or
-hereafter acquired, that would be infringed by some manner, permitted
-by this License, of making, using, or selling its contributor version,
-but do not include claims that would be infringed only as a
-consequence of further modification of the contributor version. For
-purposes of this definition, "control" includes the right to grant
-patent sublicenses in a manner consistent with the requirements of
-this License.
-
- Each contributor grants you a non-exclusive, worldwide, royalty-free
-patent license under the contributor's essential patent claims, to
-make, use, sell, offer for sale, import and otherwise run, modify and
-propagate the contents of its contributor version.
-
- In the following three paragraphs, a "patent license" is any express
-agreement or commitment, however denominated, not to enforce a patent
-(such as an express permission to practice a patent or covenant not to
-sue for patent infringement). To "grant" such a patent license to a
-party means to make such an agreement or commitment not to enforce a
-patent against the party.
-
- If you convey a covered work, knowingly relying on a patent license,
-and the Corresponding Source of the work is not available for anyone
-to copy, free of charge and under the terms of this License, through a
-publicly available network server or other readily accessible means,
-then you must either (1) cause the Corresponding Source to be so
-available, or (2) arrange to deprive yourself of the benefit of the
-patent license for this particular work, or (3) arrange, in a manner
-consistent with the requirements of this License, to extend the patent
-license to downstream recipients. "Knowingly relying" means you have
-actual knowledge that, but for the patent license, your conveying the
-covered work in a country, or your recipient's use of the covered work
-in a country, would infringe one or more identifiable patents in that
-country that you have reason to believe are valid.
-
- If, pursuant to or in connection with a single transaction or
-arrangement, you convey, or propagate by procuring conveyance of, a
-covered work, and grant a patent license to some of the parties
-receiving the covered work authorizing them to use, propagate, modify
-or convey a specific copy of the covered work, then the patent license
-you grant is automatically extended to all recipients of the covered
-work and works based on it.
-
- A patent license is "discriminatory" if it does not include within
-the scope of its coverage, prohibits the exercise of, or is
-conditioned on the non-exercise of one or more of the rights that are
-specifically granted under this License. You may not convey a covered
-work if you are a party to an arrangement with a third party that is
-in the business of distributing software, under which you make payment
-to the third party based on the extent of your activity of conveying
-the work, and under which the third party grants, to any of the
-parties who would receive the covered work from you, a discriminatory
-patent license (a) in connection with copies of the covered work
-conveyed by you (or copies made from those copies), or (b) primarily
-for and in connection with specific products or compilations that
-contain the covered work, unless you entered into that arrangement,
-or that patent license was granted, prior to 28 March 2007.
-
- Nothing in this License shall be construed as excluding or limiting
-any implied license or other defenses to infringement that may
-otherwise be available to you under applicable patent law.
-
- 12. No Surrender of Others' Freedom.
-
- If conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot convey a
-covered work so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you may
-not convey it at all. For example, if you agree to terms that obligate you
-to collect a royalty for further conveying from those to whom you convey
-the Program, the only way you could satisfy both those terms and this
-License would be to refrain entirely from conveying the Program.
-
- 13. Use with the GNU Affero General Public License.
-
- Notwithstanding any other provision of this License, you have
-permission to link or combine any covered work with a work licensed
-under version 3 of the GNU Affero General Public License into a single
-combined work, and to convey the resulting work. The terms of this
-License will continue to apply to the part which is the covered work,
-but the special requirements of the GNU Affero General Public License,
-section 13, concerning interaction through a network will apply to the
-combination as such.
-
- 14. Revised Versions of this License.
-
- The Free Software Foundation may publish revised and/or new versions of
-the GNU General Public License from time to time. Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
- Each version is given a distinguishing version number. If the
-Program specifies that a certain numbered version of the GNU General
-Public License "or any later version" applies to it, you have the
-option of following the terms and conditions either of that numbered
-version or of any later version published by the Free Software
-Foundation. If the Program does not specify a version number of the
-GNU General Public License, you may choose any version ever published
-by the Free Software Foundation.
-
- If the Program specifies that a proxy can decide which future
-versions of the GNU General Public License can be used, that proxy's
-public statement of acceptance of a version permanently authorizes you
-to choose that version for the Program.
-
- Later license versions may give you additional or different
-permissions. However, no additional obligations are imposed on any
-author or copyright holder as a result of your choosing to follow a
-later version.
-
- 15. Disclaimer of Warranty.
-
- THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
-APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
-HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
-OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
-IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
-ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
-
- 16. Limitation of Liability.
-
- IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
-THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
-GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
-USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
-DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
-PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
-EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
-SUCH DAMAGES.
-
- 17. Interpretation of Sections 15 and 16.
-
- If the disclaimer of warranty and limitation of liability provided
-above cannot be given local legal effect according to their terms,
-reviewing courts shall apply local law that most closely approximates
-an absolute waiver of all civil liability in connection with the
-Program, unless a warranty or assumption of liability accompanies a
-copy of the Program in return for a fee.
-
- END OF TERMS AND CONDITIONS
-
- How to Apply These Terms to Your New Programs
-
- If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
- To do so, attach the following notices to the program. It is safest
-to attach them to the start of each source file to most effectively
-state the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
- {one line to give the program's name and a brief idea of what it does.}
- Copyright (C) {year} {name of author}
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-
-Also add information on how to contact you by electronic and paper mail.
-
- If the program does terminal interaction, make it output a short
-notice like this when it starts in an interactive mode:
-
- {project} Copyright (C) {year} {fullname}
- This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
- This is free software, and you are welcome to redistribute it
- under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, your program's commands
-might be different; for a GUI interface, you would use an "about box".
-
- You should also get your employer (if you work as a programmer) or school,
-if any, to sign a "copyright disclaimer" for the program, if necessary.
-For more information on this, and how to apply and follow the GNU GPL, see
-.
-
- The GNU General Public License does not permit incorporating your program
-into proprietary programs. If your program is a subroutine library, you
-may consider it more useful to permit linking proprietary applications with
-the library. If this is what you want to do, use the GNU Lesser General
-Public License instead of this License. But first, please read
-.
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 0000000..175443c
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,595 @@
+GNU General Public License
+==========================
+
+_Version 3, 29 June 2007_
+_Copyright © 2007 Free Software Foundation, Inc. <>_
+
+Everyone is permitted to copy and distribute verbatim copies of this license
+document, but changing it is not allowed.
+
+## Preamble
+
+The GNU General Public License is a free, copyleft license for software and other
+kinds of works.
+
+The licenses for most software and other practical works are designed to take away
+your freedom to share and change the works. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change all versions of a
+program--to make sure it remains free software for all its users. We, the Free
+Software Foundation, use the GNU General Public License for most of our software; it
+applies also to any other work released this way by its authors. You can apply it to
+your programs, too.
+
+When we speak of free software, we are referring to freedom, not price. Our General
+Public Licenses are designed to make sure that you have the freedom to distribute
+copies of free software (and charge for them if you wish), that you receive source
+code or can get it if you want it, that you can change the software or use pieces of
+it in new free programs, and that you know you can do these things.
+
+To protect your rights, we need to prevent others from denying you these rights or
+asking you to surrender the rights. Therefore, you have certain responsibilities if
+you distribute copies of the software, or if you modify it: responsibilities to
+respect the freedom of others.
+
+For example, if you distribute copies of such a program, whether gratis or for a fee,
+you must pass on to the recipients the same freedoms that you received. You must make
+sure that they, too, receive or can get the source code. And you must show them these
+terms so they know their rights.
+
+Developers that use the GNU GPL protect your rights with two steps: **(1)** assert
+copyright on the software, and **(2)** offer you this License giving you legal permission
+to copy, distribute and/or modify it.
+
+For the developers' and authors' protection, the GPL clearly explains that there is
+no warranty for this free software. For both users' and authors' sake, the GPL
+requires that modified versions be marked as changed, so that their problems will not
+be attributed erroneously to authors of previous versions.
+
+Some devices are designed to deny users access to install or run modified versions of
+the software inside them, although the manufacturer can do so. This is fundamentally
+incompatible with the aim of protecting users' freedom to change the software. The
+systematic pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we have designed
+this version of the GPL to prohibit the practice for those products. If such problems
+arise substantially in other domains, we stand ready to extend this provision to
+those domains in future versions of the GPL, as needed to protect the freedom of
+users.
+
+Finally, every program is threatened constantly by software patents. States should
+not allow patents to restrict development and use of software on general-purpose
+computers, but in those that do, we wish to avoid the special danger that patents
+applied to a free program could make it effectively proprietary. To prevent this, the
+GPL assures that patents cannot be used to render the program non-free.
+
+The precise terms and conditions for copying, distribution and modification follow.
+
+## TERMS AND CONDITIONS
+
+### 0. Definitions
+
+“This License” refers to version 3 of the GNU General Public License.
+
+“Copyright” also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+“The Program” refers to any copyrightable work licensed under this
+License. Each licensee is addressed as “you”. “Licensees” and
+“recipients” may be individuals or organizations.
+
+To “modify” a work means to copy from or adapt all or part of the work in
+a fashion requiring copyright permission, other than the making of an exact copy. The
+resulting work is called a “modified version” of the earlier work or a
+work “based on” the earlier work.
+
+A “covered work” means either the unmodified Program or a work based on
+the Program.
+
+To “propagate” a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for infringement under
+applicable copyright law, except executing it on a computer or modifying a private
+copy. Propagation includes copying, distribution (with or without modification),
+making available to the public, and in some countries other activities as well.
+
+To “convey” a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through a computer
+network, with no transfer of a copy, is not conveying.
+
+An interactive user interface displays “Appropriate Legal Notices” to the
+extent that it includes a convenient and prominently visible feature that **(1)**
+displays an appropriate copyright notice, and **(2)** tells the user that there is no
+warranty for the work (except to the extent that warranties are provided), that
+licensees may convey the work under this License, and how to view a copy of this
+License. If the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+### 1. Source Code
+
+The “source code” for a work means the preferred form of the work for
+making modifications to it. “Object code” means any non-source form of a
+work.
+
+A “Standard Interface” means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of interfaces
+specified for a particular programming language, one that is widely used among
+developers working in that language.
+
+The “System Libraries” of an executable work include anything, other than
+the work as a whole, that **(a)** is included in the normal form of packaging a Major
+Component, but which is not part of that Major Component, and **(b)** serves only to
+enable use of the work with that Major Component, or to implement a Standard
+Interface for which an implementation is available to the public in source code form.
+A “Major Component”, in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system (if any) on which
+the executable work runs, or a compiler used to produce the work, or an object code
+interpreter used to run it.
+
+The “Corresponding Source” for a work in object code form means all the
+source code needed to generate, install, and (for an executable work) run the object
+code and to modify the work, including scripts to control those activities. However,
+it does not include the work's System Libraries, or general-purpose tools or
+generally available free programs which are used unmodified in performing those
+activities but which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for the work, and
+the source code for shared libraries and dynamically linked subprograms that the work
+is specifically designed to require, such as by intimate data communication or
+control flow between those subprograms and other parts of the work.
+
+The Corresponding Source need not include anything that users can regenerate
+automatically from other parts of the Corresponding Source.
+
+The Corresponding Source for a work in source code form is that same work.
+
+### 2. Basic Permissions
+
+All rights granted under this License are granted for the term of copyright on the
+Program, and are irrevocable provided the stated conditions are met. This License
+explicitly affirms your unlimited permission to run the unmodified Program. The
+output from running a covered work is covered by this License only if the output,
+given its content, constitutes a covered work. This License acknowledges your rights
+of fair use or other equivalent, as provided by copyright law.
+
+You may make, run and propagate covered works that you do not convey, without
+conditions so long as your license otherwise remains in force. You may convey covered
+works to others for the sole purpose of having them make modifications exclusively
+for you, or provide you with facilities for running those works, provided that you
+comply with the terms of this License in conveying all material for which you do not
+control copyright. Those thus making or running the covered works for you must do so
+exclusively on your behalf, under your direction and control, on terms that prohibit
+them from making any copies of your copyrighted material outside their relationship
+with you.
+
+Conveying under any other circumstances is permitted solely under the conditions
+stated below. Sublicensing is not allowed; section 10 makes it unnecessary.
+
+### 3. Protecting Users' Legal Rights From Anti-Circumvention Law
+
+No covered work shall be deemed part of an effective technological measure under any
+applicable law fulfilling obligations under article 11 of the WIPO copyright treaty
+adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention
+of such measures.
+
+When you convey a covered work, you waive any legal power to forbid circumvention of
+technological measures to the extent such circumvention is effected by exercising
+rights under this License with respect to the covered work, and you disclaim any
+intention to limit operation or modification of the work as a means of enforcing,
+against the work's users, your or third parties' legal rights to forbid circumvention
+of technological measures.
+
+### 4. Conveying Verbatim Copies
+
+You may convey verbatim copies of the Program's source code as you receive it, in any
+medium, provided that you conspicuously and appropriately publish on each copy an
+appropriate copyright notice; keep intact all notices stating that this License and
+any non-permissive terms added in accord with section 7 apply to the code; keep
+intact all notices of the absence of any warranty; and give all recipients a copy of
+this License along with the Program.
+
+You may charge any price or no price for each copy that you convey, and you may offer
+support or warranty protection for a fee.
+
+### 5. Conveying Modified Source Versions
+
+You may convey a work based on the Program, or the modifications to produce it from
+the Program, in the form of source code under the terms of section 4, provided that
+you also meet all of these conditions:
+
+* **a)** The work must carry prominent notices stating that you modified it, and giving a
+relevant date.
+* **b)** The work must carry prominent notices stating that it is released under this
+License and any conditions added under section 7. This requirement modifies the
+requirement in section 4 to “keep intact all notices”.
+* **c)** You must license the entire work, as a whole, under this License to anyone who
+comes into possession of a copy. This License will therefore apply, along with any
+applicable section 7 additional terms, to the whole of the work, and all its parts,
+regardless of how they are packaged. This License gives no permission to license the
+work in any other way, but it does not invalidate such permission if you have
+separately received it.
+* **d)** If the work has interactive user interfaces, each must display Appropriate Legal
+Notices; however, if the Program has interactive interfaces that do not display
+Appropriate Legal Notices, your work need not make them do so.
+
+A compilation of a covered work with other separate and independent works, which are
+not by their nature extensions of the covered work, and which are not combined with
+it such as to form a larger program, in or on a volume of a storage or distribution
+medium, is called an “aggregate” if the compilation and its resulting
+copyright are not used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work in an aggregate
+does not cause this License to apply to the other parts of the aggregate.
+
+### 6. Conveying Non-Source Forms
+
+You may convey a covered work in object code form under the terms of sections 4 and
+5, provided that you also convey the machine-readable Corresponding Source under the
+terms of this License, in one of these ways:
+
+* **a)** Convey the object code in, or embodied in, a physical product (including a
+physical distribution medium), accompanied by the Corresponding Source fixed on a
+durable physical medium customarily used for software interchange.
+* **b)** Convey the object code in, or embodied in, a physical product (including a
+physical distribution medium), accompanied by a written offer, valid for at least
+three years and valid for as long as you offer spare parts or customer support for
+that product model, to give anyone who possesses the object code either **(1)** a copy of
+the Corresponding Source for all the software in the product that is covered by this
+License, on a durable physical medium customarily used for software interchange, for
+a price no more than your reasonable cost of physically performing this conveying of
+source, or **(2)** access to copy the Corresponding Source from a network server at no
+charge.
+* **c)** Convey individual copies of the object code with a copy of the written offer to
+provide the Corresponding Source. This alternative is allowed only occasionally and
+noncommercially, and only if you received the object code with such an offer, in
+accord with subsection 6b.
+* **d)** Convey the object code by offering access from a designated place (gratis or for
+a charge), and offer equivalent access to the Corresponding Source in the same way
+through the same place at no further charge. You need not require recipients to copy
+the Corresponding Source along with the object code. If the place to copy the object
+code is a network server, the Corresponding Source may be on a different server
+(operated by you or a third party) that supports equivalent copying facilities,
+provided you maintain clear directions next to the object code saying where to find
+the Corresponding Source. Regardless of what server hosts the Corresponding Source,
+you remain obligated to ensure that it is available for as long as needed to satisfy
+these requirements.
+* **e)** Convey the object code using peer-to-peer transmission, provided you inform
+other peers where the object code and Corresponding Source of the work are being
+offered to the general public at no charge under subsection 6d.
+
+A separable portion of the object code, whose source code is excluded from the
+Corresponding Source as a System Library, need not be included in conveying the
+object code work.
+
+A “User Product” is either **(1)** a “consumer product”, which
+means any tangible personal property which is normally used for personal, family, or
+household purposes, or **(2)** anything designed or sold for incorporation into a
+dwelling. In determining whether a product is a consumer product, doubtful cases
+shall be resolved in favor of coverage. For a particular product received by a
+particular user, “normally used” refers to a typical or common use of
+that class of product, regardless of the status of the particular user or of the way
+in which the particular user actually uses, or expects or is expected to use, the
+product. A product is a consumer product regardless of whether the product has
+substantial commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+“Installation Information” for a User Product means any methods,
+procedures, authorization keys, or other information required to install and execute
+modified versions of a covered work in that User Product from a modified version of
+its Corresponding Source. The information must suffice to ensure that the continued
+functioning of the modified object code is in no case prevented or interfered with
+solely because modification has been made.
+
+If you convey an object code work under this section in, or with, or specifically for
+use in, a User Product, and the conveying occurs as part of a transaction in which
+the right of possession and use of the User Product is transferred to the recipient
+in perpetuity or for a fixed term (regardless of how the transaction is
+characterized), the Corresponding Source conveyed under this section must be
+accompanied by the Installation Information. But this requirement does not apply if
+neither you nor any third party retains the ability to install modified object code
+on the User Product (for example, the work has been installed in ROM).
+
+The requirement to provide Installation Information does not include a requirement to
+continue to provide support service, warranty, or updates for a work that has been
+modified or installed by the recipient, or for the User Product in which it has been
+modified or installed. Access to a network may be denied when the modification itself
+materially and adversely affects the operation of the network or violates the rules
+and protocols for communication across the network.
+
+Corresponding Source conveyed, and Installation Information provided, in accord with
+this section must be in a format that is publicly documented (and with an
+implementation available to the public in source code form), and must require no
+special password or key for unpacking, reading or copying.
+
+### 7. Additional Terms
+
+“Additional permissions” are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions. Additional
+permissions that are applicable to the entire Program shall be treated as though they
+were included in this License, to the extent that they are valid under applicable
+law. If additional permissions apply only to part of the Program, that part may be
+used separately under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+When you convey a copy of a covered work, you may at your option remove any
+additional permissions from that copy, or from any part of it. (Additional
+permissions may be written to require their own removal in certain cases when you
+modify the work.) You may place additional permissions on material, added by you to a
+covered work, for which you have or can give appropriate copyright permission.
+
+Notwithstanding any other provision of this License, for material you add to a
+covered work, you may (if authorized by the copyright holders of that material)
+supplement the terms of this License with terms:
+
+* **a)** Disclaiming warranty or limiting liability differently from the terms of
+sections 15 and 16 of this License; or
+* **b)** Requiring preservation of specified reasonable legal notices or author
+attributions in that material or in the Appropriate Legal Notices displayed by works
+containing it; or
+* **c)** Prohibiting misrepresentation of the origin of that material, or requiring that
+modified versions of such material be marked in reasonable ways as different from the
+original version; or
+* **d)** Limiting the use for publicity purposes of names of licensors or authors of the
+material; or
+* **e)** Declining to grant rights under trademark law for use of some trade names,
+trademarks, or service marks; or
+* **f)** Requiring indemnification of licensors and authors of that material by anyone
+who conveys the material (or modified versions of it) with contractual assumptions of
+liability to the recipient, for any liability that these contractual assumptions
+directly impose on those licensors and authors.
+
+All other non-permissive additional terms are considered “further
+restrictions” within the meaning of section 10. If the Program as you received
+it, or any part of it, contains a notice stating that it is governed by this License
+along with a term that is a further restriction, you may remove that term. If a
+license document contains a further restriction but permits relicensing or conveying
+under this License, you may add to a covered work material governed by the terms of
+that license document, provided that the further restriction does not survive such
+relicensing or conveying.
+
+If you add terms to a covered work in accord with this section, you must place, in
+the relevant source files, a statement of the additional terms that apply to those
+files, or a notice indicating where to find the applicable terms.
+
+Additional terms, permissive or non-permissive, may be stated in the form of a
+separately written license, or stated as exceptions; the above requirements apply
+either way.
+
+### 8. Termination
+
+You may not propagate or modify a covered work except as expressly provided under
+this License. Any attempt otherwise to propagate or modify it is void, and will
+automatically terminate your rights under this License (including any patent licenses
+granted under the third paragraph of section 11).
+
+However, if you cease all violation of this License, then your license from a
+particular copyright holder is reinstated **(a)** provisionally, unless and until the
+copyright holder explicitly and finally terminates your license, and **(b)** permanently,
+if the copyright holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+Moreover, your license from a particular copyright holder is reinstated permanently
+if the copyright holder notifies you of the violation by some reasonable means, this
+is the first time you have received notice of violation of this License (for any
+work) from that copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+Termination of your rights under this section does not terminate the licenses of
+parties who have received copies or rights from you under this License. If your
+rights have been terminated and not permanently reinstated, you do not qualify to
+receive new licenses for the same material under section 10.
+
+### 9. Acceptance Not Required for Having Copies
+
+You are not required to accept this License in order to receive or run a copy of the
+Program. Ancillary propagation of a covered work occurring solely as a consequence of
+using peer-to-peer transmission to receive a copy likewise does not require
+acceptance. However, nothing other than this License grants you permission to
+propagate or modify any covered work. These actions infringe copyright if you do not
+accept this License. Therefore, by modifying or propagating a covered work, you
+indicate your acceptance of this License to do so.
+
+### 10. Automatic Licensing of Downstream Recipients
+
+Each time you convey a covered work, the recipient automatically receives a license
+from the original licensors, to run, modify and propagate that work, subject to this
+License. You are not responsible for enforcing compliance by third parties with this
+License.
+
+An “entity transaction” is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an organization, or
+merging organizations. If propagation of a covered work results from an entity
+transaction, each party to that transaction who receives a copy of the work also
+receives whatever licenses to the work the party's predecessor in interest had or
+could give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if the predecessor
+has it or can get it with reasonable efforts.
+
+You may not impose any further restrictions on the exercise of the rights granted or
+affirmed under this License. For example, you may not impose a license fee, royalty,
+or other charge for exercise of rights granted under this License, and you may not
+initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging
+that any patent claim is infringed by making, using, selling, offering for sale, or
+importing the Program or any portion of it.
+
+### 11. Patents
+
+A “contributor” is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The work thus
+licensed is called the contributor's “contributor version”.
+
+A contributor's “essential patent claims” are all patent claims owned or
+controlled by the contributor, whether already acquired or hereafter acquired, that
+would be infringed by some manner, permitted by this License, of making, using, or
+selling its contributor version, but do not include claims that would be infringed
+only as a consequence of further modification of the contributor version. For
+purposes of this definition, “control” includes the right to grant patent
+sublicenses in a manner consistent with the requirements of this License.
+
+Each contributor grants you a non-exclusive, worldwide, royalty-free patent license
+under the contributor's essential patent claims, to make, use, sell, offer for sale,
+import and otherwise run, modify and propagate the contents of its contributor
+version.
+
+In the following three paragraphs, a “patent license” is any express
+agreement or commitment, however denominated, not to enforce a patent (such as an
+express permission to practice a patent or covenant not to sue for patent
+infringement). To “grant” such a patent license to a party means to make
+such an agreement or commitment not to enforce a patent against the party.
+
+If you convey a covered work, knowingly relying on a patent license, and the
+Corresponding Source of the work is not available for anyone to copy, free of charge
+and under the terms of this License, through a publicly available network server or
+other readily accessible means, then you must either **(1)** cause the Corresponding
+Source to be so available, or **(2)** arrange to deprive yourself of the benefit of the
+patent license for this particular work, or **(3)** arrange, in a manner consistent with
+the requirements of this License, to extend the patent license to downstream
+recipients. “Knowingly relying” means you have actual knowledge that, but
+for the patent license, your conveying the covered work in a country, or your
+recipient's use of the covered work in a country, would infringe one or more
+identifiable patents in that country that you have reason to believe are valid.
+
+If, pursuant to or in connection with a single transaction or arrangement, you
+convey, or propagate by procuring conveyance of, a covered work, and grant a patent
+license to some of the parties receiving the covered work authorizing them to use,
+propagate, modify or convey a specific copy of the covered work, then the patent
+license you grant is automatically extended to all recipients of the covered work and
+works based on it.
+
+A patent license is “discriminatory” if it does not include within the
+scope of its coverage, prohibits the exercise of, or is conditioned on the
+non-exercise of one or more of the rights that are specifically granted under this
+License. You may not convey a covered work if you are a party to an arrangement with
+a third party that is in the business of distributing software, under which you make
+payment to the third party based on the extent of your activity of conveying the
+work, and under which the third party grants, to any of the parties who would receive
+the covered work from you, a discriminatory patent license **(a)** in connection with
+copies of the covered work conveyed by you (or copies made from those copies), or **(b)**
+primarily for and in connection with specific products or compilations that contain
+the covered work, unless you entered into that arrangement, or that patent license
+was granted, prior to 28 March 2007.
+
+Nothing in this License shall be construed as excluding or limiting any implied
+license or other defenses to infringement that may otherwise be available to you
+under applicable patent law.
+
+### 12. No Surrender of Others' Freedom
+
+If conditions are imposed on you (whether by court order, agreement or otherwise)
+that contradict the conditions of this License, they do not excuse you from the
+conditions of this License. If you cannot convey a covered work so as to satisfy
+simultaneously your obligations under this License and any other pertinent
+obligations, then as a consequence you may not convey it at all. For example, if you
+agree to terms that obligate you to collect a royalty for further conveying from
+those to whom you convey the Program, the only way you could satisfy both those terms
+and this License would be to refrain entirely from conveying the Program.
+
+### 13. Use with the GNU Affero General Public License
+
+Notwithstanding any other provision of this License, you have permission to link or
+combine any covered work with a work licensed under version 3 of the GNU Affero
+General Public License into a single combined work, and to convey the resulting work.
+The terms of this License will continue to apply to the part which is the covered
+work, but the special requirements of the GNU Affero General Public License, section
+13, concerning interaction through a network will apply to the combination as such.
+
+### 14. Revised Versions of this License
+
+The Free Software Foundation may publish revised and/or new versions of the GNU
+General Public License from time to time. Such new versions will be similar in spirit
+to the present version, but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program specifies that
+a certain numbered version of the GNU General Public License “or any later
+version” applies to it, you have the option of following the terms and
+conditions either of that numbered version or of any later version published by the
+Free Software Foundation. If the Program does not specify a version number of the GNU
+General Public License, you may choose any version ever published by the Free
+Software Foundation.
+
+If the Program specifies that a proxy can decide which future versions of the GNU
+General Public License can be used, that proxy's public statement of acceptance of a
+version permanently authorizes you to choose that version for the Program.
+
+Later license versions may give you additional or different permissions. However, no
+additional obligations are imposed on any author or copyright holder as a result of
+your choosing to follow a later version.
+
+### 15. Disclaimer of Warranty
+
+THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER
+EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE
+QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
+DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+### 16. Limitation of Liability
+
+IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY
+COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS
+PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL,
+INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE
+OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
+WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+### 17. Interpretation of Sections 15 and 16
+
+If the disclaimer of warranty and limitation of liability provided above cannot be
+given local legal effect according to their terms, reviewing courts shall apply local
+law that most closely approximates an absolute waiver of all civil liability in
+connection with the Program, unless a warranty or assumption of liability accompanies
+a copy of the Program in return for a fee.
+
+_END OF TERMS AND CONDITIONS_
+
+## How to Apply These Terms to Your New Programs
+
+If you develop a new program, and you want it to be of the greatest possible use to
+the public, the best way to achieve this is to make it free software which everyone
+can redistribute and change under these terms.
+
+To do so, attach the following notices to the program. It is safest to attach them
+to the start of each source file to most effectively state the exclusion of warranty;
+and each file should have at least the “copyright” line and a pointer to
+where the full notice is found.
+
+
+ Copyright (C)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program does terminal interaction, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Copyright (C)
+ This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type 'show c' for details.
+
+The hypothetical commands `show w` and `show c` should show the appropriate parts of
+the General Public License. Of course, your program's commands might be different;
+for a GUI interface, you would use an “about box”.
+
+You should also get your employer (if you work as a programmer) or school, if any, to
+sign a “copyright disclaimer” for the program, if necessary. For more
+information on this, and how to apply and follow the GNU GPL, see
+<>.
+
+The GNU General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may consider it
+more useful to permit linking proprietary applications with the library. If this is
+what you want to do, use the GNU Lesser General Public License instead of this
+License. But first, please read
+<>.
diff --git a/NAMESPACE b/NAMESPACE
index f4bdde6..7a13e85 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,12 +1,13 @@
# Generated by roxygen2: do not edit by hand
-export(compute_AUC)
-export(compute_purity)
+export(find_informative_regions)
+export(find_informative_sites)
+export(get_AUC)
+export(get_purity)
export(reduce_to_regions)
-export(select_informative_regions)
-export(select_informative_regions_ext)
-export(select_informative_sites)
-export(select_informative_sites_ext)
-importFrom(dplyr,"%>%")
+importFrom(stats,dist)
importFrom(stats,median)
+importFrom(stats,quantile)
importFrom(stats,setNames)
+importFrom(utils,adist)
+importFrom(utils,head)
diff --git a/NEWS.md b/NEWS.md
index aaabb1a..663cb11 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,3 +1,11 @@
+# PAMES v3.0.0 aka PAMES2
+PAMES has been completely rewritten to work in with our new framework [MiMeSis](https://github.com/cgplab/MIMESIS)
+Major changes:
+- all functions now return a data.frame instead of a vector: according to our experience, data.frames works integrate better with pipelines;
+- `get_AUC` replace `compute_AUC` and takes as input a matrix of beta-values as originally produced by Illumina Beadchips (instead of rounded percentages);
+- `find_informative_sites` and `find_informative_regions` replace `select_informative_sites` and `select_informative_regions`, respectively, and integrate the new `control_constraints` parameter;
+- `get_purity` replace `compute_purity` and as input a data.frame (generated by `find_informative_sites`/`find_informative_regions`).
+
# PAMES v2.7.2
- rename `median_of_regions`: `reduce_region`
- add `method` parameter to `reduce_to_regions`: allow choice between "median" (default) or mean
diff --git a/R/PAMES.R b/R/PAMES.R
index 121a56d..eea4b84 100644
--- a/R/PAMES.R
+++ b/R/PAMES.R
@@ -1,16 +1,16 @@
#' PAMES: Purity Assessment from clonal MEthylation Sites
#'
#' The PAMES package provides a set of functions to estimate
-#' the level of purity of tumor samples.
+#' the level of purity or the tumor content of tumor samples.
#'
-#' The basic workflow of PAMES requires to \code{\link{compute_AUC}} (to evaluate tumor-control methylation differences),
-#' \code{\link{select_informative_sites}} (to retrieve sites of interest),
-#' and \code{\link{compute_purity}} of tumor samples.
+#' The basic workflow of PAMES requires to \code{\link{get_AUC}} (to evaluate tumor-control methylation differences),
+#' \code{\link{find_informative_sites}} (to retrieve sites of interest),
+#' and \code{\link{get_purity}} of tumor samples.
#' When working with methylation data obtained with other technologies (such as Bisulphite Sequencing),
#' users should must map their set of CpG sites to differentially methylated regions
#' (such as CpG islands) using data \code{\link{reduce_to_regions}}, then
-#' \code{\link{compute_AUC}}, \code{\link{select_informative_regions}} and finally
-#' \code{\link{compute_purity}}.
+#' \code{\link{get_AUC}}, \code{\link{find_informative_regions}} and finally
+#' \code{\link{get_purity}}.
#
#' @docType package
#' @name PAMES
diff --git a/R/compute_AUC.R b/R/compute_AUC.R
deleted file mode 100644
index 52c7095..0000000
--- a/R/compute_AUC.R
+++ /dev/null
@@ -1,93 +0,0 @@
-#' Compute Area Under Curve for a matrix of samples
-#'
-#' This function computes the Area Under Curve used to define the segregation
-#' between tumor and control samples accordingly to their methylation (beta)
-#' values.
-#'
-#' @param tumor_table A matrix of beta-values (percentage) from tumor samples.
-#' @param control_table A matrix of beta-values (percentage) from normal/control samples.
-#' @param ncores Number of parallel processes to use for parallel computing.
-#' @param min_samples_frac Fraction of samples (independently in tumor and
-#' control samples) that are not NA required to analyze a site (range=0-1, default=1).
-#' @param return_info If TRUE (default) return a vector else compute all AUC and return a data.frame
-#' reporting fraction of NAs in tumor and control tables.
-#' @param na_threshold (DEPRECATED) Fraction of NAs (considered independently in tumor and
-#' control samples) above which a site will not be selected (default=0).
-#' @return A vector of AUC scores (NA if not analyzed) or a data.frame with AUC scores
-#' and the fraction of non-NA samples in tumor and control tables.
-#' @examples
-#' auc_data <- compute_AUC(tumor_toy_data, control_toy_data)
-#' @importFrom stats setNames
-#' @export
-compute_AUC <- function(tumor_table, control_table, ncores=1, na_threshold, return_info=FALSE, min_samples_frac=1) {
- message(sprintf("[%s] # Compute AUC #", Sys.time()))
- # check parameters
- if (!missing(na_threshold)){
- warning("'na_threshold' is deprecated, use 'min_samples_frac' instead.")
- assertthat::assert_that(is.numeric(na_threshold))
- assertthat::assert_that(dplyr::between(na_threshold, 0, 1))
- min_samples_frac <- 1-na_threshold
- }
-
- assertthat::assert_that(nrow(tumor_table) == nrow(control_table))
- if (!is.null(rownames(tumor_table)) & !is.null(rownames(control_table))){
- if (any(rownames(tumor_table) != rownames(control_table))){
- warning("tumor_table and control_table have different rownames")
- }
- }
-
- assertthat::assert_that(is.numeric(ncores))
- ncores <- min(max(ncores, 1), parallel::detectCores())
- assertthat::assert_that(is.numeric(min_samples_frac), dplyr::between(min_samples_frac, 0, 1))
- assertthat::assert_that(is.logical(return_info))
-
- beta_table <- as.matrix(cbind(tumor_table, control_table))
- beta_table <- round(beta_table)
- storage.mode(beta_table) <- "integer"
-
- is_tumor <- c(rep(TRUE, ncol(tumor_table)), rep(FALSE, ncol(control_table)))
-
- cl <- parallel::makeCluster(ncores)
- if (isFALSE(return_info)){
- # select rows by NAs
- message(sprintf("[%s] Filter sites with fraction of available beta-scores greater than or equal to %.2f...", Sys.time(), min_samples_frac))
- tumor_available_sites <- which(rowSums(!is.na(beta_table[,is_tumor]))/sum(is_tumor) >= min_samples_frac)
- control_available_sites <- which(rowSums(!is.na(beta_table[,!is_tumor]))/sum(!is_tumor) >= min_samples_frac)
- available_sites <- intersect(tumor_available_sites, control_available_sites)
-
- message(sprintf("[%s] Computing...", Sys.time()))
- auc <- setNames(rep(NA_real_, nrow(beta_table)), rownames(beta_table))
- auc[available_sites] <- parallel::parApply(cl, beta_table[available_sites,,drop=FALSE], 1, single_AUC, is_tumor=is_tumor)
-
- } else {
- message(sprintf("[%s] Computing...", Sys.time()))
- auc_scores <- parallel::parApply(cl, beta_table, 1, single_AUC, is_tumor = is_tumor)
- auc <- data.frame(auc = auc_scores,
- tumor_nonNA_frac = rowSums(!is.na(beta_table[,is_tumor]))/sum(is_tumor),
- control_nonNA_frac = rowSums(!is.na(beta_table[,!is_tumor]))/sum(!is_tumor))
- }
- parallel::stopCluster(cl)
- message(sprintf("[%s] Done", Sys.time()))
- return(auc)
-}
-
-#' Compute AUC
-#'
-#' Use Wilcoxon method to compute AUC.
-#'
-#' @param scores integer vector (range 1-100)
-#' @param is_tumor logical vector (class labels)
-#' @keywords internal
-#' \href{http://blog.revolutionanalytics.com/2017/03/auc-meets-u-stat.html}{http://blog.revolutionanalytics.com}
-single_AUC <- function(scores, is_tumor) {
- assertthat::assert_that(is.integer(scores))
- assertthat::assert_that(is.logical(is_tumor))
- na_idx <- is.na(scores)
- scores <- scores[!na_idx]
- is_tumor <- is_tumor[!na_idx]
- n1 <- sum(is_tumor)
- n2 <- sum(!is_tumor)
- R1 <- sum(rank(scores)[is_tumor])
- U1 <- R1 - n1*(n1+1)/2
- return(U1/(n1*n2))
-}
diff --git a/R/compute_purity.R b/R/compute_purity.R
deleted file mode 100644
index f9d50fa..0000000
--- a/R/compute_purity.R
+++ /dev/null
@@ -1,33 +0,0 @@
-#' Compute Purity of Tumor Samples
-#'
-#' Estimate the proportion of cancer cells in the admixture of cells
-#' forming tumor microenvironment.
-#'
-#' @param tumor_table A matrix of beta-values from tumor samples.
-#' @param list_of_sites A list of indexes generated by
-#' \code{\link{select_informative_sites}} or
-#' \code{\link{select_informative_regions}}.
-#' @param ref_table Reference table used to find sites.
-#' @return A vector of purity estimates.
-#' @importFrom stats median
-#' @export
-#' @examples
-#' purity <- compute_purity(tumor_toy_data,
-#' list_of_sites=list(hyper=c(1, 10, 20), hypo=c(15,30,45),
-#' ref_table=illumina27k_hg19[3:4]))
-compute_purity <- function(tumor_table, list_of_sites, ref_table) {
- message(sprintf("[%s] # Compute purity #", Sys.time()))
- # check parameters
- assertthat::assert_that(nrow(tumor_table) == nrow(ref_table))
- assertthat::assert_that(is.list(list_of_sites))
- assertthat::assert_that(any(c("hyper", "hypo") %in% names(list_of_sites)))
- message(sprintf("- Using %i hyper- and %i hypo-methylated sites",
- length(list_of_sites[["hyper"]]),
- length(list_of_sites[["hypo"]])))
-
- beta_values <- rbind(tumor_table[list_of_sites[["hyper"]],],
- 100 - tumor_table[list_of_sites[["hypo"]],])
- purity <- apply(beta_values, 2, median, na.rm = TRUE)
- message(sprintf("[%s] Done", Sys.time()))
- return(purity)
-}
diff --git a/R/data.R b/R/data.R
index 4225ef0..9565655 100644
--- a/R/data.R
+++ b/R/data.R
@@ -38,12 +38,12 @@
#' @source \url{https://genome.ucsc.edu/}
"cpg_islands"
-#' BS Toy data
+#' BS-Seq Toy data
#'
#' Example of tumor and control beta values from Bisulphite Sequencing
-"bs_toy_matrix"
+"bs_seq_toy_matrix"
-#' BS Toy sites
+#' BS-Seq Toy sites
#'
#' Example of data.frame with location of CpG sites
-"bs_toy_sites"
+"bs_seq_toy_sites"
diff --git a/R/find_informative_regions.R b/R/find_informative_regions.R
new file mode 100644
index 0000000..3b57bd8
--- /dev/null
+++ b/R/find_informative_regions.R
@@ -0,0 +1,136 @@
+#' Select informative regions (extended)
+#'
+#' This function generates a list of informative regions to estimate the purity
+#' or the tumor content of a set of tumor samples.
+#'
+#' A new parameter, named \code{control_costraints}, is required force
+#' selection of sites where upper/lower quartiles of control scores are below
+#' beta-values given by \code{control_costraints}. Regions are divided into
+#' \code{hyper} and \code{hypo} depending on their level of methylation with
+#' respect to the average beta-score of normal samples.
+#'
+#' @param tumor_table A matrix of beta-values of tumor samples.
+#' @param control_table A matrix of beta-values of control/normal samples.
+#' @param auc A data.frame with AUC scores generated by \code{get_AUC}.
+#' @param cores Number of parallel processes.
+#' @param max_regions Maximum number of regions to retrieve (half hyper-, half
+#' hypo-methylated) (default=20).
+#' @param percentiles A vector of length 2. Min and max percentiles to
+#' select sites with beta values outside hypo- and hyper-ranges (default = c(0,100);
+#' i.e. only min and max beta should be outside of ranges).
+#' @param hyper_range A vector of length 2 with minimum lower and upper values
+#' required to select hyper-methylated informative sites.
+#' @param hypo_range A vector of length 2 with minimum lower and upper values
+#' required to select hypo-methylated informative sites.
+#' @param method How to select sites: "even" (half hyper-, half hypo-methylated sites),
+#' "top" (highest AUC irregardless of hyper or hypomethylation), "hyper" (hyper-methylated sites only),
+#' "hypo" (hypo-methylated, sites only).
+#' @param control_costraints To select a site, "first quartile"/"third quartile" of control data must be above/below these beta-values.
+#' @param full_info Return all informative sites (for debugging purposes).
+#' @return A data.frame reporing region names (chr_position) and type ("hyper" and "hypo") of informative regions.
+#' @importFrom stats quantile
+#' @export
+#' @examples
+#' reduced_data <- reduce_to_regions(bs_seq_toy_matrix, bs_seq_toy_sites, cpg_islands[1:1000,])
+#' auc_data <- get_AUC(reduced_data[,1:10], reduced_data[,11:20])
+#' info_regions <- find_informative_regions(reduced_data[,1:10], reduced_data[,11:20], auc_data)
+find_informative_regions <- function(tumor_table, control_table, auc, cores=1,
+ max_regions = 20, percentiles = c(0,100),
+ hyper_range = c(min = .40, max = .90), hypo_range = c(min = .10, max = .60),
+ control_costraints = c(.30, .70),
+ method = c("even", "top", "hyper", "hypo"), full_info=FALSE){
+
+ message(sprintf("[%s] # Find informative regions #", Sys.time()))
+
+ # check parameters
+ assertthat::assert_that(is.matrix(tumor_table))
+ assertthat::assert_that(is.matrix(control_table))
+ assertthat::assert_that(!is.null(rownames(tumor_table)))
+ assertthat::assert_that(identical(rownames(tumor_table), rownames(control_table)))
+ assertthat::assert_that(nrow(tumor_table) == nrow(auc))
+
+ assertthat::assert_that(is.matrix(tumor_table))
+ assertthat::assert_that(is.matrix(control_table))
+ assertthat::assert_that(nrow(tumor_table) == nrow(auc))
+
+ assertthat::assert_that(is.numeric(cores))
+ assertthat::assert_that(is.numeric(max_regions))
+ assertthat::assert_that(is.numeric(hyper_range))
+ assertthat::assert_that(is.numeric(hypo_range))
+ assertthat::assert_that(is.numeric(control_costraints))
+ assertthat::assert_that(is.numeric(percentiles))
+
+ assertthat::assert_that(length(hyper_range) == 2)
+ assertthat::assert_that(length(hypo_range) == 2)
+ assertthat::assert_that(length(control_costraints) == 2)
+ assertthat::assert_that(length(percentiles) == 2)
+
+ method <- match.arg(method)
+ if (method == "even")
+ assertthat::assert_that(max_regions %% 2 == 0, msg="method is set to 'even' but max_regions is not even")
+
+ assertthat::assert_that(is.logical(full_info))
+
+ message(sprintf("- Method: %s", method))
+ message(sprintf("- Number of regions to retrieve: %i", max_regions))
+ message(sprintf("- Hyper-methylated regions range: %.2f-%.2f", hyper_range[1], hyper_range[2]))
+ message(sprintf("- Hypo-methylated regions range: %.2f-%.2f", hypo_range[1], hypo_range[2]))
+ message(sprintf("- Control constraints: %.2f-%.2f", control_costraints[1], control_costraints[2]))
+ message(sprintf("- Percentiles: %g-%g", percentiles[1], percentiles[2]))
+
+ # minimum and maximum beta per region
+ cl <- parallel::makeCluster(cores)
+ message(sprintf("[%s] Compute min-/max- beta scores...", Sys.time()))
+ min_beta <- suppressWarnings(parallel::parApply(cl, tumor_table, 1, quantile, probs = percentiles[1]/100, na.rm = TRUE))
+ max_beta <- suppressWarnings(parallel::parApply(cl, tumor_table, 1, quantile, probs = percentiles[2]/100, na.rm = TRUE))
+
+ message(sprintf("[%s] Compute control interquartiles...", Sys.time()))
+ lower_quart <- suppressWarnings(parallel::parApply(cl, control_table, 1, quantile, probs = .25, na.rm = TRUE))
+ upper_quart <- suppressWarnings(parallel::parApply(cl, control_table, 1, quantile, probs = .75, na.rm = TRUE))
+
+ message(sprintf("[%s] Select regions...", Sys.time()))
+ diff_meth_regions_df <- cbind(auc,
+ data.frame(Max_beta = max_beta,
+ Min_beta = min_beta,
+ Lower_Quart = lower_quart,
+ Upper_Quart = upper_quart))
+ hyper_regions_idx <- with(diff_meth_regions_df, which(AUC > .80 & Min_beta < hyper_range[1] & Max_beta > hyper_range[2] & Upper_Quart < control_costraints[1]))
+ hypo_regions_idx <- with(diff_meth_regions_df, which(AUC < .20 & Min_beta < hypo_range[1] & Max_beta > hypo_range[2] & Lower_Quart > control_costraints[2]))
+ regions_type <- rep("no_differences", nrow(auc))
+ regions_type[hyper_regions_idx] <- "hyper"
+ regions_type[hypo_regions_idx] <- "hypo"
+ diff_meth_regions_df$Region_type <- regions_type
+ diff_meth_regions_df$AUC[diff_meth_regions_df$eegions_type == "Hypo"] <- 1-diff_meth_regions_df$AUC
+ diff_meth_regions_df <- diff_meth_regions_df[order(diff_meth_regions_df$AUC, decreasing = TRUE),]
+
+ hyper_regions_df <- diff_meth_regions_df[diff_meth_regions_df$Region_type == "hyper",]
+ hypo_regions_df <- diff_meth_regions_df[diff_meth_regions_df$Region_type == "hypo",]
+ message(sprintf("* Total hyper-methylated regions = %i", nrow(hyper_regions_df)))
+ message(sprintf("* Total hypo-methylated regions = %i", nrow(hypo_regions_df)))
+
+ if (full_info) {
+ regions <- rbind(hyper_regions_df, hypo_regions_df)
+ columns <- c("Probe", "Region_type",
+ "AUC", "Max_beta", "Min_beta", "Upper_Quart", "Lower_Quart")
+ regions <- regions[,columns]
+ } else {
+ if (method == "even") {
+ regions <- rbind(head(hyper_regions_df[hyper_regions_df$Keep_site,],max_regions/2),
+ head(hypo_regions_df[hypo_regions_df$Keep_site,],max_regions/2))
+ } else if (method == "top") {
+ regions <- rbind(hyper_regions_df, hypo_regions_df)
+ regions <- regions[order(regions$AUC, decreasing = TRUE),]
+ regions <- head(regions,max_regions)
+ } else if (method == "hyper") {
+ regions <- head(hyper_regions_df,max_regions)
+ } else if (method == "hypo") {
+ regions <- head(hypo_regions_df,max_regions)
+ }
+ regions <- regions[c("Probe", "Region_type")]
+ message(sprintf("* Retrieved hyper-methylated regions = %i", sum(regions$Region_type=="hyper")))
+ message(sprintf("* Retrieved hypo-methylated regions = %i", sum(regions$Region_type=="hypo")))
+ }
+ rownames(regions) <- NULL
+ message(sprintf("[%s] Done", Sys.time()))
+ return(regions)
+}
diff --git a/R/find_informative_sites.R b/R/find_informative_sites.R
new file mode 100644
index 0000000..af6dd21
--- /dev/null
+++ b/R/find_informative_sites.R
@@ -0,0 +1,181 @@
+#' Discover informative CpG sites
+#'
+#' This function generates a set of informative CpG sites to estimate
+#' the purity or the tumor content of a set of tumor samples.
+#'
+#' A new parameter, named \code{control_costraints}, is required to force the
+#' selection of sites with upper/lower quartiles of control scores are below
+#' beta-values given by \code{control_costraints}. Sites are divided into
+#' \code{hyper} and \code{hypo} depending on their level of methylation with
+#' respect to the average beta-score of normal samples.
+#'
+#' @param tumor_table A matrix of beta-values of tumor samples.
+#' @param control_table A matrix of beta-values of control/normal samples.
+#' @param auc A data.frame with AUC scores generated by \code{get_AUC}.
+#' @param ref_table A data.frame with first two columns reporting genomic location (chromosome, genomic_coordinates).
+#' @param cores Number of parallel processes.
+#' @param max_sites Maximum number of sites to retrieve (half hyper-, half
+#' hypo-methylated) (default=20).
+#' @param min_distance Exclude sites located at less than `min_distance` from higher-ranking site (default = 1e6 bps).
+#' @param percentiles A vector of length 2. Min and max percentiles to
+#' select sites with beta values outside hypo- and hyper-ranges (default = c(0,100);
+#' i.e. only min and max beta should be outside of ranges).
+#' @param hyper_range A vector of length 2 with minimum lower and upper values
+#' required to select hyper-methylated informative sites.
+#' @param hypo_range A vector of length 2 with minimum lower and upper values
+#' required to select hypo-methylated informative sites.
+#' @param method How to select sites: "even" (half hyper-, half hypo-methylated sites),
+#' "top" (highest AUC irregardless of hyper or hypomethylation), "hyper" (hyper-methylated sites only),
+#' "hypo" (hypo-methylated, sites only).
+#' @param control_costraints To select a site, "first quartile"/"third quartile" of control data must be above/below these beta-values.
+#' @param full_info Return all informative sites with a column reporting wether to use a site or not (for debugging purposes).
+#' @return A data.frame reporting probe names and type ("hyper" and "hypo") of informative sites.
+#' @importFrom stats quantile
+#' @importFrom utils head
+#' @export
+#' @examples
+#' ## WARNING: The following code doesn't retrieve any informative site
+#' ## It just shows how to use the tool
+#' auc_data <- get_AUC(tumor_toy_data, control_toy_data)
+#' info_sites <- find_informative_sites(tumor_toy_data, control_toy_data, auc_data, illumina27k_hg19)
+find_informative_sites <- function(tumor_table, control_table, auc, ref_table, cores=1,
+ max_sites = 20, min_distance = 1e6, percentiles = c(0, 100),
+ hyper_range = c(min = .40, max = .90), hypo_range = c(min = .10, max = .60),
+ control_costraints = c(.30, .70),
+ method = c("even", "top", "hyper", "hypo"), full_info=FALSE){
+
+ message(sprintf("[%s] # Find informative sites #", Sys.time()))
+
+ # check parameters
+ assertthat::assert_that(is.matrix(tumor_table))
+ assertthat::assert_that(is.matrix(control_table))
+ assertthat::assert_that(is.data.frame(auc))
+ assertthat::assert_that(!is.null(rownames(tumor_table)))
+ assertthat::assert_that(identical(rownames(tumor_table), rownames(control_table)))
+ assertthat::assert_that(nrow(tumor_table) == nrow(auc))
+ assertthat::assert_that(ncol(ref_table) >= 2)
+ assertthat::assert_that(nrow(tumor_table) == nrow(ref_table))
+
+ assertthat::assert_that(is.numeric(cores))
+ assertthat::assert_that(is.numeric(max_sites))
+ assertthat::assert_that(is.numeric(min_distance))
+ assertthat::assert_that(is.logical(full_info))
+ assertthat::assert_that(is.numeric(hyper_range))
+ assertthat::assert_that(is.numeric(hypo_range))
+ assertthat::assert_that(is.numeric(control_costraints))
+ assertthat::assert_that(is.numeric(percentiles))
+
+ assertthat::assert_that(length(hyper_range) == 2)
+ assertthat::assert_that(length(hypo_range) == 2)
+ assertthat::assert_that(length(control_costraints) == 2)
+ assertthat::assert_that(length(percentiles) == 2)
+
+ method <- match.arg(method)
+ if (method == "even")
+ assertthat::assert_that(max_sites %% 2 == 0, msg="method is set to 'even' but 'max_sites' is not even")
+
+ message(sprintf("- Method: %s", method))
+ message(sprintf("- Minimum distance between sites: %g bps", min_distance))
+ message(sprintf("- Number of sites to retrieve: %i", max_sites))
+ message(sprintf("- Hyper-methylated sites range: %.2f-%.2f", hyper_range[1], hyper_range[2]))
+ message(sprintf("- Hypo-methylated sites range: %.2f-%.2f", hypo_range[1], hypo_range[2]))
+ message(sprintf("- Control constraints: %.2f-%.2f", control_costraints[1], control_costraints[2]))
+ message(sprintf("- Percentiles: %g-%g", percentiles[1], percentiles[2]))
+
+ # minimum and maximum beta per site
+ cl <- parallel::makeCluster(cores)
+ message(sprintf("[%s] Compute min-/max- beta scores...", Sys.time()))
+ min_beta <- suppressWarnings(parallel::parApply(cl, tumor_table, 1, quantile, probs = percentiles[1]/100, na.rm = TRUE))
+ max_beta <- suppressWarnings(parallel::parApply(cl, tumor_table, 1, quantile, probs = percentiles[2]/100, na.rm = TRUE))
+
+ message(sprintf("[%s] Compute control interquartiles...", Sys.time()))
+ lower_quart <- suppressWarnings(parallel::parApply(cl, control_table, 1, quantile, probs = .25, na.rm = TRUE))
+ upper_quart <- suppressWarnings(parallel::parApply(cl, control_table, 1, quantile, probs = .75, na.rm = TRUE))
+ parallel::stopCluster(cl)
+
+ message(sprintf("[%s] Find sites...", Sys.time()))
+ diff_meth_sites_df <- cbind(auc,
+ data.frame(Max_beta = max_beta,
+ Min_beta = min_beta,
+ Upper_Quart = upper_quart,
+ Lower_Quart = lower_quart,
+ Chromosome = ref_table[[1]],
+ Genomic_Coordinate = ref_table[[2]]))
+ hyper_sites_idx <- with(diff_meth_sites_df, which(AUC > .80 & Min_beta < hyper_range[1] & Max_beta > hyper_range[2] & Upper_Quart < control_costraints[1]))
+ hypo_sites_idx <- with(diff_meth_sites_df, which(AUC < .20 & Min_beta < hypo_range[1] & Max_beta > hypo_range[2] & Lower_Quart > control_costraints[2]))
+ site_type <- rep("no_differences", nrow(auc))
+ site_type[hyper_sites_idx] <- "hyper"
+ site_type[hypo_sites_idx] <- "hypo"
+ diff_meth_sites_df$Site_type <- site_type
+ diff_meth_sites_df$AUC[diff_meth_sites_df$Site_type == "Hypo"] <- 1-diff_meth_sites_df$AUC
+ diff_meth_sites_df <- diff_meth_sites_df[order(diff_meth_sites_df$AUC, decreasing = TRUE),]
+
+ hyper_sites_df <- diff_meth_sites_df[diff_meth_sites_df$Site_type == "hyper",]
+ hypo_sites_df <- diff_meth_sites_df[diff_meth_sites_df$Site_type == "hypo",]
+ message(sprintf("* Total hyper-methylated sites = %i", nrow(hyper_sites_df)))
+ message(sprintf("* Total hypo-methylated sites = %i", nrow(hypo_sites_df)))
+
+ # avoid sites too close to previously selected sites
+ hyper_sites_df$Keep_site <- remove_close_sites(hyper_sites_df, max_sites, min_distance)
+ hypo_sites_df$Keep_site <- remove_close_sites(hypo_sites_df, max_sites, min_distance)
+
+ if (full_info) {
+ sites <- rbind(hyper_sites_df, hypo_sites_df)
+ columns <- c("Probe", "Site_type", "Chromosome", "Genomic_Coordinate",
+ "AUC", "Max_beta", "Min_beta", "Upper_Quart",
+ "Lower_Quart","Keep_site")
+ sites <- sites[,columns]
+ } else {
+ # filter sites and take selected number
+ if (method == "even") {
+ sites <- rbind(head(hyper_sites_df[hyper_sites_df$Keep_site,],max_sites/2),
+ head(hypo_sites_df[hypo_sites_df$Keep_site,],max_sites/2))
+ } else if (method == "top") {
+ sites <- rbind(hyper_sites_df, hypo_sites_df)
+ sites <- sites[order(sites$AUC, decreasing = TRUE),]
+ sites <- head(sites,max_sites)
+ } else if (method == "hyper") {
+ sites <- head(hyper_sites_df,max_sites)
+ } else if (method == "hypo") {
+ sites <- head(hypo_sites_df,max_sites)
+ }
+ sites <- sites[c("Probe", "Site_type", "Chromosome", "Genomic_Coordinate")]
+ message(sprintf("* Retrieved hyper-methylated sites = %i", sum(sites$Site_type=="hyper")))
+ message(sprintf("* Retrieved hypo-methylated sites = %i", sum(sites$Site_type=="hypo")))
+ }
+ rownames(sites) <- NULL
+ message(sprintf("[%s] Done", Sys.time()))
+ return(sites)
+}
+
+#' Remove close sites
+#'
+#' @param sites_df A data.frame
+#' @param min_distanc A number
+#' @keywords internal
+#' @importFrom stats dist
+#' @importFrom utils adist
+remove_close_sites <- function(sites_df, max_sites, min_distance){
+
+ keep_sites <- logical(nrow(sites_df))
+ kept_sites <- 0
+ i <- 1
+ if (nrow(sites_df) > 0){
+ diff_chr <- as.matrix(adist(sites_df$Chromosome)) > 0
+ above_distance <- as.matrix(dist(sites_df$Genomic_Coordinate)) >= min_distance
+
+ keep_sites[1] <- TRUE
+ kept_sites <- kept_sites + 1
+ i <- i + 1
+ }
+ while (kept_sites < max_sites & i <= nrow(sites_df)){
+ check_all <- all(diff_chr[i, seq_len(i-1)] | above_distance[i, seq_len(i-1)])
+ check_all <- check_all[!is.na(check_all)]
+ if (length(check_all) > 0 & isTRUE(all(check_all))) {
+ keep_sites[i] <- TRUE
+ kept_sites <- kept_sites + 1
+ }
+ i <- i + 1
+ }
+ return(keep_sites)
+}
diff --git a/R/get_AUC.R b/R/get_AUC.R
new file mode 100644
index 0000000..4e3075b
--- /dev/null
+++ b/R/get_AUC.R
@@ -0,0 +1,86 @@
+#' Calculate Area Under Curve comparing tumor and control samples
+#'
+#' This function calculates the Area Under Curve that define the segregation
+#' between tumor and control samples accordingly to their methylation (beta)
+#' values.
+#'
+#' @param tumor_table A matrix of beta-values from tumor samples.
+#' @param control_table A matrix of beta-values from normal/control samples.
+#' @param cores Number of cores for parallel computing.
+#' @param max_NA_data At most this fraction of NAs (in tumor and control data
+#' independently) is permitted to calculate AUC of a site (default=1, i.e. only
+#' sites without NAs).
+#' @param full_info If TRUE (default=FALSE) returns also sites infos (fraction
+#' of NAs in tumor and control tables) without skipping probes with missing values.
+#' @return A data.frame with AUC scores and probes names
+#' @examples
+#' auc_data <- get_AUC(tumor_toy_data, control_toy_data)
+#' @importFrom stats setNames
+#' @export
+get_AUC <- function(tumor_table, control_table, max_NA_data=0, cores=1, full_info=FALSE) {
+ message(sprintf("[%s] # Calculate AUC #", Sys.time()))
+
+ # check parameters
+ assertthat::assert_that(is.matrix(tumor_table))
+ assertthat::assert_that(is.matrix(control_table))
+ assertthat::assert_that(!is.null(rownames(tumor_table)))
+ assertthat::assert_that(identical(rownames(tumor_table), rownames(control_table)))
+ assertthat::assert_that(is.numeric(max_NA_data))
+ assertthat::assert_that(is.numeric(cores))
+ assertthat::assert_that(is.logical(full_info))
+ assertthat::assert_that(max_NA_data>=0 & max_NA_data<=1)
+
+ cores <- min(round(cores), parallel::detectCores())
+
+ beta_table <- cbind(tumor_table, control_table)
+
+ is_tumor <- c(rep(TRUE, ncol(tumor_table)), rep(FALSE, ncol(control_table)))
+
+ cl <- parallel::makeCluster(cores)
+ if (isFALSE(full_info)){
+ # identify non-valid sites
+ message(sprintf("[%s] Skip sites with proportion of missing beta-scores greater than %.2f...", Sys.time(), max_NA_data))
+ tumor_available_sites <- which(rowSums(is.na(tumor_table))/ncol(tumor_table) >= max_NA_data)
+ control_available_sites <- which(rowSums(is.na(control_table))/ncol(control_table) >= max_NA_data)
+ available_sites <- intersect(tumor_available_sites, control_available_sites)
+
+ message(sprintf("[%s] Calculating...", Sys.time()))
+ auc_scores <- rep(NA_real_, nrow(beta_table))
+ auc_scores[available_sites] <- parallel::parApply(cl, beta_table[available_sites,,drop=FALSE], 1, single_AUC, is_tumor=is_tumor)
+
+ AUC_df <- data.frame(Probe=rownames(tumor_table),
+ AUC = auc_scores)
+
+ } else {
+ message(sprintf("[%s] Calculating...", Sys.time()))
+ auc_scores <- parallel::parApply(cl, beta_table, 1, single_AUC, is_tumor = is_tumor)
+ AUC_df <- data.frame(Probe=rownames(tumor_table),
+ AUC = auc_scores,
+ tumor_NA_fraction = rowSums(is.na(tumor_table))/ncol(tumor_table),
+ control_NA_fraction = rowSums(is.na(control_table))/ncol(control_table))
+ }
+ parallel::stopCluster(cl)
+ message(sprintf("[%s] Done", Sys.time()))
+ return(AUC_df)
+}
+
+#' Calculate AUC
+#'
+#' Use Wilcoxon method to calculate AUC.
+#'
+#' @param scores integer vector (range 1-100)
+#' @param is_tumor logical vector (class labels)
+#' @keywords internal
+#' \href{http://blog.revolutionanalytics.com/2017/03/auc-meets-u-stat.html}{http://blog.revolutionanalytics.com}
+single_AUC <- function(scores, is_tumor) {
+ assertthat::assert_that(is.numeric(scores))
+ assertthat::assert_that(is.logical(is_tumor))
+ na_idx <- is.na(scores)
+ scores <- scores[!na_idx]
+ is_tumor <- is_tumor[!na_idx]
+ n1 <- sum(is_tumor)
+ n2 <- sum(!is_tumor)
+ R1 <- sum(rank(scores)[is_tumor])
+ U1 <- R1 - n1*(n1+1)/2
+ return(U1/(n1*n2))
+}
diff --git a/R/get_purity.R b/R/get_purity.R
new file mode 100644
index 0000000..dabc242
--- /dev/null
+++ b/R/get_purity.R
@@ -0,0 +1,36 @@
+#' Calculate purity or tumor content samples
+#'
+#' Estimate the proportion of cancer cells in the admixture of cells
+#' forming the tumor microenvironment or the fraction of ctDNA in cfDNA samples.
+#'
+#' @param tumor_table A matrix of beta-values
+#' @param info_sites A data.frame reporting a set of informative sites
+#' generated by \code{\link{find_informative_sites}} or
+#' \code{\link{find_informative_regions}}.
+#' @return A data.frame with purity scores.
+#' @importFrom stats median
+#' @export
+#' @examples
+#' purity <- get_purity(tumor_toy_data,
+#' info_sites=data.frame(Probe=c("CpG_00001","CpG_00010","CpG_00020",
+#' "CpG_00015","CpG_00030","CpG_00045"), Site_type=rep(c("hyper","hypo"), each=3)))
+get_purity <- function(tumor_table, info_sites) {
+ # check parameters
+ assertthat::assert_that(is.matrix(tumor_table))
+ assertthat::assert_that(is.data.frame(info_sites))
+
+ message(sprintf("[%s] # Calculate purity #", Sys.time()))
+
+ hyper_sites <- info_sites$Probe[info_sites$Site_type=="hyper"]
+ hypo_sites <- info_sites$Probe[info_sites$Site_type=="hypo"]
+ hyper_sites <- intersect(hyper_sites, rownames(tumor_table))
+ hypo_sites <- intersect(hypo_sites, rownames(tumor_table))
+
+ message(sprintf("- Using %i hyper- and %i hypo-methylated sites",
+ length(hyper_sites), length(hypo_sites)))
+ beta_values <- rbind(tumor_table[hyper_sites,], 1-tumor_table[hypo_sites,])
+ Purity <- apply(beta_values, 2, median, na.rm = TRUE)
+ purity_df <- data.frame(Sample=colnames(tumor_table), Purity)
+ message(sprintf("[%s] Done", Sys.time()))
+ return(purity_df)
+}
diff --git a/R/reduce_to_regions.R b/R/reduce_to_regions.R
index d84347b..168f93e 100644
--- a/R/reduce_to_regions.R
+++ b/R/reduce_to_regions.R
@@ -1,28 +1,27 @@
#' Reduce beta values from CpG sites to genomic regions
#'
-#' Reduce several beta values from different CpG sites to single beta values
-#' associated to one genomic region (such as CpG islands) where CpG sites are located.
+#' Reduce several beta values from different CpG sites to a single beta value
+#' associated to one genomic region (such as CpG islands).
#' Different technologies retrieve DNA methylation levels of
-#' different CpG sites. This function makes a direct comparison possible.
+#' different CpG sites. This function makes possible a direct comparison.
#'
-#' @param beta_table A matrix of beta-values (percentage).
+#' @param beta_table A matrix of beta-values.
#' @param cpg_sites A data.frame reporting the genomic location of CpG sites.
#' @param cpg_regions A data.frame reporting the genomic location of genomic regions.
-#' @param min_CpGs An integer (default to 3). Minimum number of CpG sites
-#' within a single genomic region required to compute the reduced beta value
-#' (return NA otherwise).
-#' @param method Take `median` or `mean`of CpG sites.
-#' @return A matrix of beta values (nrow == length(cpg_indexes)).
+#' @param min_CpGs An integer (default=3). Minimum number of CpG sites
+#' within a single genomic region (return NA otherwise).
+#' @param method Function to summarise a region: either `median` or `mean` (default=median).
+#' @return A matrix of beta values, each row corresponding to one region.
#' @importFrom stats median
#' @export
#' @examples
-#' reduced_data <- reduce_to_regions(bs_toy_matrix, bs_toy_sites, cpg_islands[1:10,])
+#' reduced_data <- reduce_to_regions(bs_seq_toy_matrix, bs_seq_toy_sites, cpg_islands[1:10,])
reduce_to_regions <- function(beta_table, cpg_sites, cpg_regions, min_CpGs = 3, method=c("median", "mean")){
message(sprintf("[%s] # Reduce to regions #", Sys.time()))
# check parameters
method <- match.arg(method)
- min_CpGs <- as.integer(min_CpGs)
+ assertthat::assert_that(is.numeric(min_CpGs))
assertthat::assert_that(min_CpGs > 0)
assertthat::assert_that(ncol(cpg_sites) >= 2)
assertthat::assert_that(ncol(cpg_regions) >= 3)
@@ -55,7 +54,8 @@ reduce_to_regions <- function(beta_table, cpg_sites, cpg_regions, min_CpGs = 3,
subject_hits <- S4Vectors::subjectHits(overlaps)
query_hits <- S4Vectors::queryHits(overlaps)
idx_list <- tapply(subject_hits, query_hits, function(idx) return(idx))
- above_thr_regions <- which(sapply(idx_list, length) >= min_CpGs) # skip regions with not enough sites
+ # skip regions with not enough sites
+ above_thr_regions <- which(sapply(idx_list, length) >= min_CpGs)
if (length(above_thr_regions) == 0){
message(sprintf("[%s] No region overlaps enough sites", Sys.time()))
diff --git a/R/select_informative_regions.R b/R/select_informative_regions.R
deleted file mode 100644
index f637f50..0000000
--- a/R/select_informative_regions.R
+++ /dev/null
@@ -1,114 +0,0 @@
-#' Select informative regions
-#'
-#' This function generates a list of informative regions to be used to estimate
-#' the purity of a set of tumor samples.
-#'
-#' Informative regions are divided into \code{hyper} and \code{hypo} depending
-#' on their level of methylation with respect to the average beta-score of
-#' normal samples. Both sets will be used to compute purity.
-#'
-#' @param tumor_table A matrix of beta-values (percentage) from tumor samples.
-#' @param auc A vector of AUC scores generated by \code{compute_AUC}.
-#' @param max_sites Maximum number of regions to retrieve (half hyper-, half
-#' hypo-methylated) (default = 20).
-#' @param hyper_range A vector of length 2 with minimum lower and upper values
-#' required to select hyper-methylated informative sites.
-#' @param hypo_range A vector of length 2 with minimum lower and upper values
-#' required to select hypo-methylated informative sites.
-#' @param method How to select sites: "even" (half hyper-, half hypo-methylated sites),
-#' "top" (highest AUC irregardless of hyper or hypomethylation), "hyper" (hyper-methylated sites only),
-#' "hypo" (hypo-methylated, sites only).
-#' @param percentiles Vector of length 2: lower and upper percentiles to
-#' select sites with beta values outside hypo- and hyper-ranges (default =
-#' 0,100; 0th and 100th percentiles, i.e. only min and max beta should be outside of ranges).
-#' @param return_info Return also a data.frame of all informative sites (for debug purpose).
-#' @return A named list of indexes of informative regions ("hyper-" and "hypo-methylated").
-#' @importFrom dplyr "%>%"
-#' @export
-#' @examples
-#' reduced_data <- reduce_to_regions(bs_toy_matrix, bs_toy_sites, cpg_islands[1:1000,])
-#' auc_data <- compute_AUC(reduced_data[,1:10], reduced_data[,11:20])
-#' info_regions <- select_informative_regions(reduced_data[,1:10], auc_data)
-select_informative_regions <- function(tumor_table, auc, max_sites = 20,
- hyper_range = c(min = 40, max = 90), hypo_range = c(min = 10, max = 60),
- method = c("even", "top", "hyper", "hypo"), percentiles = c(0, 100), return_info=FALSE){
-
- message(sprintf("[%s] # Select informative regions #", Sys.time()))
- # check parameters
-
- tumor_table <- as.matrix(tumor_table)
- tumor_table <- round(tumor_table)
- storage.mode(tumor_table) <- "integer"
-
- assertthat::assert_that(nrow(tumor_table) == length(auc))
-
- assertthat::assert_that(is.numeric(max_sites))
-
- assertthat::assert_that(is.numeric(hyper_range))
- assertthat::assert_that(is.numeric(hypo_range))
- assertthat::assert_that(is.numeric(percentiles))
-
- assertthat::assert_that(length(hyper_range) == 2)
- assertthat::assert_that(length(hypo_range) == 2)
- assertthat::assert_that(length(percentiles) == 2)
-
- assertthat::assert_that(all(dplyr::between(hyper_range, 0, 100)))
- assertthat::assert_that(all(dplyr::between(hypo_range, 0, 100)))
- assertthat::assert_that(all(dplyr::between(percentiles, 0, 100)))
-
- method <- match.arg(method)
- if (method == "even")
- assertthat::assert_that(max_sites %% 2 == 0, msg="method is set to 'even' but max_sites is not even")
-
- assertthat::assert_that(is.logical(return_info))
-
- message(sprintf("- Method: %s", method))
- message(sprintf("- Number of regions to retrieve: %i", max_sites))
- message(sprintf("- Hyper-methylated regions range: %i-%i", hyper_range[1], hyper_range[2]))
- message(sprintf("- Hypo-methylated regions range: %i-%i", hypo_range[1], hypo_range[2]))
- message(sprintf("- Percentiles: %g-%g", percentiles[1], percentiles[2]))
-
- # minimum and maximum beta per region
- message(sprintf("[%s] Compute min-/max- beta scores...", Sys.time()))
- min_beta <- suppressWarnings(apply(tumor_table, 1, quantile, probs = percentiles[1]/100, na.rm = TRUE))
- max_beta <- suppressWarnings(apply(tumor_table, 1, quantile, probs = percentiles[2]/100, na.rm = TRUE))
-
- diff_meth_regions <- dplyr::tibble(Index = seq_along(auc),
- AUC = auc,
- Max_beta = max_beta,
- Min_beta = min_beta) %>%
- dplyr::mutate(Type = dplyr::case_when(AUC > .80 & Min_beta < hyper_range[1] & Max_beta > hyper_range[2] ~ "Hyper",
- AUC < .20 & Min_beta < hypo_range[1] & Max_beta > hypo_range[2] ~ "Hypo",
- TRUE ~ "No_diff")) %>%
- dplyr::filter(Type != "No_diff") %>%
- dplyr::mutate(AUC = dplyr::if_else(Type == "Hypo", 1-AUC, AUC)) %>%
- dplyr::arrange(-AUC)
-
- regions_hyper <- dplyr::filter(diff_meth_regions, Type == "Hyper")
- regions_hypo <- dplyr::filter(diff_meth_regions, Type == "Hypo")
- message(sprintf("* Total hyper-methylated regions = %i", nrow(regions_hyper)))
- message(sprintf("* Total hypo-methylated regions = %i", nrow(regions_hypo)))
-
- if (method == "even") {
- regions <- list(hyper = regions_hyper %>% dplyr::slice(seq_len(max_sites/2)) %>% dplyr::pull(Index),
- hypo = regions_hypo %>% dplyr::slice(seq_len(max_sites/2)) %>% dplyr::pull(Index))
- } else if (method == "top") {
- top_regions <- dplyr::bind_rows(regions_hyper, regions_hypo) %>% dplyr::arrange(-AUC) %>% dplyr::slice(seq_len(max_sites))
- regions <- list(hyper = top_regions %>% dplyr::filter(Type == "Hyper") %>% dplyr::pull(Index),
- hypo = top_regions %>% dplyr::filter(Type == "Hypo") %>% dplyr::pull(Index))
- } else if (method == "hyper") {
- regions <- list(hyper = regions_hyper %>% dplyr::slice(seq_len(max_sites)) %>% dplyr::pull(Index))
- } else if (method == "hypo") {
- regions <- list(hypo = regions_hypo %>% dplyr::slice(seq_len(max_sites)) %>% dplyr::pull(Index))
- }
-
- message(sprintf("* Retrieved hyper-methylated regions = %i", length(regions$hyper)))
- message(sprintf("* Retrieved hypo-methylated regions = %i", length(regions$hypo)))
-
- message(sprintf("[%s] Done", Sys.time()))
- if (return_info) {
- return(list(regions, diff_meth_regions))
- } else {
- return(regions)
- }
-}
diff --git a/R/select_informative_regions_ext.R b/R/select_informative_regions_ext.R
deleted file mode 100644
index b16fa46..0000000
--- a/R/select_informative_regions_ext.R
+++ /dev/null
@@ -1,143 +0,0 @@
-#' Select informative regions (extended)
-#'
-#' This function generates a list of informative regions to be used to estimate
-#' the purity of a set of tumor samples.
-#'
-#' The EXTENDED version was added to introduce the new parameter, named
-#' \code{control_costraints}, to force selection of sites where upper/lower
-#' quartiles of control scores are below beta-values given by
-#' \code{control_costraints}. Informative regions are divided into
-#' \code{hyper} and \code{hypo} depending on their level of methylation with
-#' respect to the average beta-score of normal samples. Both sets will be used
-#' to compute purity.
-#'
-#' @param tumor_table A matrix of beta-values (percentage) from tumor samples.
-#' @param control_table A matrix of beta-values (percentage) from normal/control samples.
-#' @param auc A vector of AUC scores generated by \code{compute_AUC}.
-#' @param max_sites Maximum number of regions to retrieve (half hyper-, half
-#' hypo-methylated) (default = 20).
-#' @param hyper_range A vector of length 2 with minimum lower and upper values
-#' required to select hyper-methylated informative sites.
-#' @param hypo_range A vector of length 2 with minimum lower and upper values
-#' required to select hypo-methylated informative sites.
-#' @param method How to select sites: "even" (half hyper-, half hypo-methylated sites),
-#' "top" (highest AUC irregardless of hyper or hypomethylation), "hyper" (hyper-methylated sites only),
-#' "hypo" (hypo-methylated, sites only).
-#' @param percentiles Vector of length 2: lower and upper percentiles to
-#' select sites with beta values outside hypo- and hyper-ranges (default =
-#' 0,100; 0th and 100th percentiles, i.e. only min and max beta should be outside of ranges).
-#' @param control_costraints To select a site, "first quartile"/"third quartile" of control data must be above/below these beta-values.
-#' @param return_info Return also a data.frame of all informative sites (for debug purpose).
-#' @return A named list of indexes of informative regions ("hyper-" and "hypo-methylated").
-#' @importFrom dplyr "%>%"
-#' @export
-#' @examples
-#' reduced_data <- reduce_to_regions(bs_toy_matrix, bs_toy_sites, cpg_islands[1:1000,])
-#' auc_data <- compute_AUC(reduced_data[,1:10], reduced_data[,11:20])
-#' info_regions <- select_informative_regions(reduced_data[,1:10], auc_data)
-select_informative_regions_ext <- function(tumor_table, control_table, auc,
- max_sites = 20, percentiles = c(0,100),
- hyper_range = c(min = 40, max = 90), hypo_range = c(min = 10, max = 60),
- control_costraints = c(30,70),
- method = c("even", "top", "hyper", "hypo"), return_info=FALSE){
-
- message(sprintf("[%s] # Select informative regions #", Sys.time()))
- # check parameters
- diff_range_t <- diff(range(tumor_table, na.rm = TRUE))
- diff_range_c <- diff(range(control_table, na.rm = TRUE))
- assertthat::assert_that(diff_range_t > 1, diff_range_t <= 100, msg="For computation efficiency convert tumor_table to percentage values.")
- assertthat::assert_that(diff_range_c > 1, diff_range_c <= 100, msg="For computation efficiency convert control_table to percentage values.")
-
- tumor_table <- as.matrix(tumor_table)
- tumor_table <- round(tumor_table)
- storage.mode(tumor_table) <- "integer"
-
- assertthat::assert_that(nrow(tumor_table) == length(auc))
-
- assertthat::assert_that(is.numeric(max_sites))
-
- assertthat::assert_that(is.numeric(hyper_range))
- assertthat::assert_that(is.numeric(hypo_range))
- assertthat::assert_that(is.numeric(control_costraints))
- assertthat::assert_that(is.numeric(percentiles))
-
- assertthat::assert_that(length(hyper_range) == 2)
- assertthat::assert_that(length(hypo_range) == 2)
- assertthat::assert_that(length(control_costraints) == 2)
- assertthat::assert_that(length(percentiles) == 2)
-
- assertthat::assert_that(all(dplyr::between(hyper_range, 0, 100)))
- assertthat::assert_that(all(dplyr::between(hypo_range, 0, 100)))
- assertthat::assert_that(all(dplyr::between(control_costraints, 0, 100)))
- assertthat::assert_that(all(dplyr::between(percentiles, 0, 100)))
-
- method <- match.arg(method)
- if (method == "even")
- assertthat::assert_that(max_sites %% 2 == 0, msg="method is set to 'even' but max_sites is not even")
-
- assertthat::assert_that(is.logical(return_info))
-
- message(sprintf("- Method: %s", method))
- message(sprintf("- Number of regions to retrieve: %i", max_sites))
- message(sprintf("- Hyper-methylated regions range: %i-%i", hyper_range[1], hyper_range[2]))
- message(sprintf("- Hypo-methylated regions range: %i-%i", hypo_range[1], hypo_range[2]))
- message(sprintf("- Control constraints: %i-%i", control_costraints[1], control_costraints[2]))
- message(sprintf("- Percentiles: %g-%g", percentiles[1], percentiles[2]))
-
- # minimum and maximum beta per region
- message(sprintf("[%s] Compute min-/max- beta scores...", Sys.time()))
- min_beta <- suppressWarnings(apply(tumor_table, 1, quantile, probs = percentiles[1]/100, na.rm = TRUE))
- max_beta <- suppressWarnings(apply(tumor_table, 1, quantile, probs = percentiles[2]/100, na.rm = TRUE))
-
- message(sprintf("[%s] Compute control interquartiles...", Sys.time()))
- lower_quart <- suppressWarnings(apply(control_table, 1, quantile, probs = .25, na.rm = TRUE))
- upper_quart <- suppressWarnings(apply(control_table, 1, quantile, probs = .75, na.rm = TRUE))
-
- if (is.null(names(auc)))
- names(auc) <- sprintf("CpG_%06d", seq_along(auc))
-
- message(sprintf("[%s] Select regions...", Sys.time()))
- diff_meth_regions <- dplyr::tibble(Probe = names(auc),
- Index = seq_along(auc),
- AUC = auc,
- Max_beta = max_beta,
- Min_beta = min_beta,
- Lower_Quart = lower_quart,
- Upper_Quart = upper_quart)
- diff_meth_regions <- dplyr::mutate(diff_meth_regions,
- Type = dplyr::case_when(AUC > .80 & Min_beta < hyper_range[1] & Max_beta > hyper_range[2] & Upper_Quart < control_costraints[1] ~ "Hyper",
- AUC < .20 & Min_beta < hypo_range[1] & Max_beta > hypo_range[2] & Lower_Quart > control_costraints[2] ~ "Hypo",
- TRUE ~ "No_diff"))
- diff_meth_regions <- dplyr::mutate(diff_meth_regions, AUC = dplyr::if_else(Type == "Hypo", 1-AUC, AUC))
- diff_meth_regions <- dplyr::arrange(diff_meth_regions, -AUC)
-
- regions_hyper <- dplyr::filter(diff_meth_regions, Type == "Hyper")
- regions_hypo <- dplyr::filter(diff_meth_regions, Type == "Hypo")
- message(sprintf("* Total hyper-methylated regions = %i", nrow(regions_hyper)))
- message(sprintf("* Total hypo-methylated regions = %i", nrow(regions_hypo)))
-
- if (method == "even") {
- regions <- list(hyper = regions_hyper %>% dplyr::slice(seq_len(max_sites/2)) %>% dplyr::pull(Index),
- hypo = regions_hypo %>% dplyr::slice(seq_len(max_sites/2)) %>% dplyr::pull(Index))
- } else if (method == "top") {
- top_regions <- dplyr::bind_rows(regions_hyper, regions_hypo) %>% dplyr::arrange(-AUC) %>% dplyr::slice(seq_len(max_sites))
- regions <- list(hyper = top_regions %>% dplyr::filter(Type == "Hyper") %>% dplyr::pull(Index),
- hypo = top_regions %>% dplyr::filter(Type == "Hypo") %>% dplyr::pull(Index))
- } else if (method == "hyper") {
- regions <- list(hyper = regions_hyper %>% dplyr::slice(seq_len(max_sites)) %>% dplyr::pull(Index))
- } else if (method == "hypo") {
- regions <- list(hypo = regions_hypo %>% dplyr::slice(seq_len(max_sites)) %>% dplyr::pull(Index))
- }
-
- names(regions$hyper) <- names(auc)[regions$hyper]
- names(regions$hypo) <- names(auc)[regions$hypo]
- message(sprintf("* Retrieved hyper-methylated regions = %i", length(regions$hyper)))
- message(sprintf("* Retrieved hypo-methylated regions = %i", length(regions$hypo)))
-
- message(sprintf("[%s] Done", Sys.time()))
- if (return_info) {
- return(c(regions, list(info=diff_meth_regions)))
- } else {
- return(regions)
- }
-}
diff --git a/R/select_informative_sites.R b/R/select_informative_sites.R
deleted file mode 100644
index e45b086..0000000
--- a/R/select_informative_sites.R
+++ /dev/null
@@ -1,177 +0,0 @@
-#' Select informative CpG sites
-#'
-#' This function generates a list of informative CpG sites to be used to estimate
-#' the purity of a set of tumor samples.
-#'
-#' Informative sites are divided into \code{hyper} and \code{hypo} depending on
-#' their level of methylation with respect to the average beta-score of normal
-#' samples. Both sets are used to compute purity.
-#'
-#' @param tumor_table A matrix of beta-values (percentage) from tumor samples.
-#' @param auc A vector of AUC scores generated by \code{compute_AUC}.
-#' @param ref_table A data.frame with two columns (chromosome, genomic_coordinates).
-#' @param max_sites Maximum number of sites to retrieve (half hyper-, half
-#' hypo-methylated) (default = 20).
-#' @param min_distance Avoid selection of CpG sites located within this
-#' distance from one another (default = 1e6 bps).
-#' @param hyper_range A vector of length 2 with minimum lower and upper values
-#' required to select hyper-methylated informative sites.
-#' @param hypo_range A vector of length 2 with minimum lower and upper values
-#' required to select hypo-methylated informative sites.
-#' @param method How to select sites: "even" (half hyper-, half hypo-methylated sites),
-#' "top" (highest AUC irregardless of hyper or hypomethylation), "hyper" (hyper-methylated sites only),
-#' "hypo" (hypo-methylated, sites only).
-#' @param percentiles Vector of length 2: lower and upper percentiles to
-#' select sites with beta values outside hypo- and hyper-ranges
-#' (default = 0,100; 0th and 100th percentiles,
-#' i.e. only min and max beta should be outside of ranges).
-#' @param return_info Return also a data.frame of all informative sites (for debug purpose).
-#' @return A named list of indexes of informative sites ("hyper-" and "hypo-methylated").
-#' @importFrom dplyr "%>%"
-#' @export
-#' @examples
-#' ## WARNING: The following code doesn't retrieve any informative site
-#' ## Its purpose is to show how to use the tool
-#' auc_data <- compute_AUC(tumor_toy_data, control_toy_data)
-#' info_sites <- select_informative_sites(tumor_toy_data, auc_data, illumina27k_hg19[3:4])
-select_informative_sites <- function(tumor_table, auc, ref_table,
- max_sites = 20, min_distance = 1e6, percentiles = c(0, 100),
- hyper_range = c(min = 40, max = 90), hypo_range = c(min = 10, max = 60),
- method = c("even", "top", "hyper", "hypo"), return_info=FALSE){
-
- message(sprintf("[%s] # Select informative sites #", Sys.time()))
- # check parameters
-
- tumor_table <- as.matrix(tumor_table)
- tumor_table <- round(tumor_table)
- storage.mode(tumor_table) <- "integer"
-
-
- assertthat::assert_that(nrow(tumor_table) == length(auc))
- assertthat::assert_that(ncol(ref_table) >= 2)
- assertthat::assert_that(is.character(ref_table[[1]]))
- assertthat::assert_that(is.numeric(ref_table[[2]]))
- assertthat::assert_that(nrow(tumor_table) == nrow(ref_table), msg="Number of rows of tumor_table is not equal to the number of rows of ref_table")
-
- assertthat::assert_that(is.numeric(max_sites))
- assertthat::assert_that(is.numeric(min_distance), min_distance > 0)
-
- assertthat::assert_that(is.numeric(hyper_range))
- assertthat::assert_that(is.numeric(hypo_range))
- assertthat::assert_that(is.numeric(percentiles))
-
- assertthat::assert_that(length(hyper_range) == 2)
- assertthat::assert_that(length(hypo_range) == 2)
- assertthat::assert_that(length(percentiles) == 2)
-
- assertthat::assert_that(all(dplyr::between(hyper_range, 0, 100)))
- assertthat::assert_that(all(dplyr::between(hypo_range, 0, 100)))
- assertthat::assert_that(all(dplyr::between(percentiles, 0, 100)))
-
- method <- match.arg(method)
- if (method == "even")
- assertthat::assert_that(max_sites %% 2 == 0, msg="method is set to 'even' but max_sites is not even")
-
- assertthat::assert_that(is.logical(return_info))
-
- message(sprintf("- Method: %s", method))
- message(sprintf("- Minimum distance between sites: %g bps", min_distance))
- message(sprintf("- Number of sites to retrieve: %i", max_sites))
- message(sprintf("- Hyper-methylated sites range: %i-%i", hyper_range[1], hyper_range[2]))
- message(sprintf("- Hypo-methylated sites range: %i-%i", hypo_range[1], hypo_range[2]))
- message(sprintf("- Percentiles: %g-%g", percentiles[1], percentiles[2]))
-
- # minimum and maximum beta per site
- message(sprintf("[%s] Compute min-/max- beta scores...", Sys.time()))
- min_beta <- suppressWarnings(apply(tumor_table, 1, quantile, probs = percentiles[1]/100, na.rm = TRUE))
- max_beta <- suppressWarnings(apply(tumor_table, 1, quantile, probs = percentiles[2]/100, na.rm = TRUE))
-
- message(sprintf("[%s] Select sites...", Sys.time()))
- diff_meth_sites <- dplyr::tibble(Index = seq_along(auc),
- AUC = auc,
- Max_beta = max_beta,
- Min_beta = min_beta,
- Chromosome = ref_table[[1]],
- Position = ref_table[[2]])
- diff_meth_sites <- dplyr::mutate(diff_meth_sites,
- Type = dplyr::case_when(AUC > .80 & Min_beta < hyper_range[1] & Max_beta > hyper_range[2] ~ "Hyper",
- AUC < .20 & Min_beta < hypo_range[1] & Max_beta > hypo_range[2] ~ "Hypo",
- TRUE ~ "No_diff"))
- diff_meth_sites <- dplyr::mutate(diff_meth_sites, AUC = dplyr::if_else(Type == "Hypo", 1-AUC, AUC))
- diff_meth_sites <- dplyr::arrange(diff_meth_sites, -AUC)
-
- sites_hyper <- dplyr::filter(diff_meth_sites, Type == "Hyper")
- sites_hypo <- dplyr::filter(diff_meth_sites, Type == "Hypo")
- message(sprintf("* Total hyper-methylated sites = %i", nrow(sites_hyper)))
- message(sprintf("* Total hypo-methylated sites = %i", nrow(sites_hypo)))
-
- # skip sites too close to previously selected sites
- keep_site_hyper <- logical(nrow(sites_hyper))
- kept_sites <- 0
- i <- 1
- if (nrow(sites_hyper) > 0){
- diff_chr <- as.matrix(adist(sites_hyper$Chromosome)) > 0
- above_distance <- as.matrix(dist(sites_hyper$Position)) >= min_distance
-
- keep_site_hyper[1] <- TRUE
- kept_sites <- kept_sites + 1
- i <- i + 1
- }
- while (kept_sites < max_sites & i <= nrow(sites_hyper)){
- check_all <- all(diff_chr[i, seq_len(i-1)] | above_distance[i, seq_len(i-1)])
- check_all <- check_all[!is.na(check_all)]
- if (length(check_all) > 0 & isTRUE(all(check_all))) {
- keep_site_hyper[i] <- TRUE
- kept_sites <- kept_sites + 1
- }
- i <- i + 1
- }
- top_hyper_sites <- sites_hyper[keep_site_hyper, ]
-
- keep_site_hypo <- logical(nrow(sites_hypo))
- kept_sites <- 0
- i <- 1
- if (nrow(sites_hypo) > 0){
- diff_chr <- as.matrix(adist(sites_hypo$Chromosome)) > 0
- above_distance <- as.matrix(dist(sites_hypo$Position)) >= min_distance
-
- keep_site_hypo[1] <- TRUE
- kept_sites <- kept_sites + 1
- i <- i + 1
- }
- while (kept_sites < max_sites & i <= nrow(sites_hypo)){
- check_all <- all(diff_chr[i, seq_len(i-1)] | above_distance[i, seq_len(i-1)])
- if (isTRUE(check_all)) {
- keep_site_hypo[i] <- TRUE
- kept_sites <- kept_sites + 1
- }
- i <- i + 1
- }
- top_hypo_sites <- sites_hypo[keep_site_hypo, ]
-
- if (method == "even") {
- sites <- list(hyper = top_hyper_sites %>% dplyr::slice(seq_len(max_sites/2)) %>% dplyr::pull(Index),
- hypo = top_hypo_sites %>% dplyr::slice(seq_len(max_sites/2)) %>% dplyr::pull(Index))
- } else if (method == "top") {
- top_sites <- dplyr::bind_rows(top_hyper_sites, top_hypo_sites) %>% dplyr::arrange(-AUC) %>% dplyr::slice(seq_len(max_sites))
- sites <- list(hyper = top_sites %>% dplyr::filter(Type == "Hyper") %>% dplyr::pull(Index),
- hypo = top_sites %>% dplyr::filter(Type == "Hypo") %>% dplyr::pull(Index))
- } else if (method == "hyper") {
- sites <- list(hyper = dplyr::slice(top_hyper_sites, seq_len(max_sites)) %>% dplyr::pull(Index))
- } else if (method == "hypo") {
- sites <- list(hypo = dplyr::slice(top_hypo_sites, seq_len(max_sites)) %>% dplyr::pull(Index))
- }
- names(sites$hyper) <- names(auc)[sites$hyper]
- names(sites$hypo) <- names(auc)[sites$hypo]
- message(sprintf("* Retrieved hyper-methylated sites = %i", length(sites$hyper)))
- message(sprintf("* Retrieved hypo-methylated sites = %i", length(sites$hypo)))
-
- message(sprintf("[%s] Done", Sys.time()))
- if (return_info) {
- sites_hyper$Keep <- keep_site_hyper
- sites_hypo$Keep <- keep_site_hypo
- return(c(sites, list(info=rbind(sites_hyper, sites_hypo))))
- } else {
- return(sites)
- }
-}
diff --git a/R/select_informative_sites_ext.R b/R/select_informative_sites_ext.R
deleted file mode 100644
index 0762605..0000000
--- a/R/select_informative_sites_ext.R
+++ /dev/null
@@ -1,200 +0,0 @@
-#' Select informative CpG sites (extended)
-#'
-#' This function generates a list of informative CpG sites to be used to estimate
-#' the purity of a set of tumor samples.
-#'
-#' The EXTENDED version was added to introduce the new parameter, named
-#' \code{control_costraints}, to force selection of sites where upper/lower
-#' quartiles of control scores are below beta-values given by
-#' \code{control_costraints}. Informative regions are divided into
-#' \code{hyper} and \code{hypo} depending on their level of methylation with
-#' respect to the average beta-score of normal samples. Both sets will be used
-#' to compute purity.
-#'
-#' @param tumor_table A matrix of beta-values (percentage) from tumor samples.
-#' @param control_table A matrix of beta-values (percentage) from normal/control samples.
-#' @param auc A vector of AUC scores generated by \code{compute_AUC}.
-#' @param ref_table A data.frame with two columns (chromosome, genomic_coordinates).
-#' @param max_sites Maximum number of sites to retrieve (half hyper-, half
-#' hypo-methylated) (default = 20).
-#' @param min_distance Avoid selection of CpG sites located within this
-#' distance from one another (default = 1e6 bps).
-#' @param percentiles Vector of length 2: lower and upper percentiles to
-#' select sites with beta values outside hypo- and hyper-ranges
-#' (default = 0,100; 0th and 100th percentiles,
-#' i.e. only min and max beta should be outside of ranges).
-#' @param hyper_range A vector of length 2 with minimum lower and upper values
-#' required to select hyper-methylated informative sites.
-#' @param hypo_range A vector of length 2 with minimum lower and upper values
-#' required to select hypo-methylated informative sites.
-#' @param method How to select sites: "even" (half hyper-, half hypo-methylated sites),
-#' "top" (highest AUC irregardless of hyper or hypomethylation), "hyper" (hyper-methylated sites only),
-#' "hypo" (hypo-methylated, sites only).
-#' @param control_costraints To select a site, "first quartile"/"third quartile" of control data must be above/below these beta-values.
-#' @param return_info Return also a data.frame of all informative sites (for debug purpose).
-#' @return A named list of indexes of informative sites ("hyper-" and "hypo-methylated").
-#' @importFrom dplyr "%>%"
-#' @export
-#' @examples
-#' ## WARNING: The following code doesn't retrieve any informative site
-#' ## Its purpose is to show how to use the tool
-#' auc_data <- compute_AUC(tumor_toy_data, control_toy_data)
-#' info_sites <- select_informative_sites(tumor_toy_data, auc_data, illumina27k_hg19[3:4])
-select_informative_sites_ext <- function(tumor_table, control_table, auc, ref_table,
- max_sites = 20, min_distance = 1e6, percentiles = c(0, 100),
- hyper_range = c(min = 40, max = 90), hypo_range = c(min = 10, max = 60),
- control_costraints = c(30,70),
- method = c("even", "top", "hyper", "hypo"), return_info=FALSE){
-
- message(sprintf("[%s] # Select informative sites #", Sys.time()))
- # check parameters
-
- tumor_table <- as.matrix(tumor_table)
- tumor_table <- round(tumor_table)
- storage.mode(tumor_table) <- "integer"
-
- control_table <- as.matrix(control_table)
- control_table <- round(control_table)
- storage.mode(control_table) <- "integer"
-
- assertthat::assert_that(nrow(tumor_table) == nrow(control_table))
- assertthat::assert_that(nrow(tumor_table) == length(auc))
- assertthat::assert_that(ncol(ref_table) >= 2)
- assertthat::assert_that(nrow(tumor_table) == nrow(ref_table), msg="Number of rows of tumor_table is not equal to the number of rows of ref_table")
-
- assertthat::assert_that(is.numeric(max_sites))
- assertthat::assert_that(is.numeric(min_distance), min_distance > 0)
-
- assertthat::assert_that(is.numeric(hyper_range))
- assertthat::assert_that(is.numeric(hypo_range))
- assertthat::assert_that(is.numeric(control_costraints))
- assertthat::assert_that(is.numeric(percentiles))
-
- assertthat::assert_that(length(hyper_range) == 2)
- assertthat::assert_that(length(hypo_range) == 2)
- assertthat::assert_that(length(control_costraints) == 2)
- assertthat::assert_that(length(percentiles) == 2)
-
- assertthat::assert_that(all(dplyr::between(hyper_range, 0, 100)))
- assertthat::assert_that(all(dplyr::between(hypo_range, 0, 100)))
- assertthat::assert_that(all(dplyr::between(control_costraints, 0, 100)))
- assertthat::assert_that(all(dplyr::between(percentiles, 0, 100)))
-
- method <- match.arg(method)
- if (method == "even")
- assertthat::assert_that(max_sites %% 2 == 0, msg="method is set to 'even' but max_sites is not even")
-
- assertthat::assert_that(is.logical(return_info))
-
- message(sprintf("- Method: %s", method))
- message(sprintf("- Minimum distance between sites: %g bps", min_distance))
- message(sprintf("- Number of sites to retrieve: %i", max_sites))
- message(sprintf("- Hyper-methylated sites range: %i-%i", hyper_range[1], hyper_range[2]))
- message(sprintf("- Hypo-methylated sites range: %i-%i", hypo_range[1], hypo_range[2]))
- message(sprintf("- Control constraints: %i-%i", control_costraints[1], control_costraints[2]))
- message(sprintf("- Percentiles: %g-%g", percentiles[1], percentiles[2]))
-
- # minimum and maximum beta per site
- message(sprintf("[%s] Compute min-/max- beta scores...", Sys.time()))
- min_beta <- suppressWarnings(apply(tumor_table, 1, quantile, probs = percentiles[1]/100, na.rm = TRUE))
- max_beta <- suppressWarnings(apply(tumor_table, 1, quantile, probs = percentiles[2]/100, na.rm = TRUE))
-
- message(sprintf("[%s] Compute control interquartiles...", Sys.time()))
- lower_quart <- suppressWarnings(apply(control_table, 1, quantile, probs = .25, na.rm = TRUE))
- upper_quart <- suppressWarnings(apply(control_table, 1, quantile, probs = .75, na.rm = TRUE))
-
- if (is.null(names(auc)))
- names(auc) <- sprintf("CpG_%06d", seq_along(auc))
-
- message(sprintf("[%s] Select sites...", Sys.time()))
- diff_meth_sites <- dplyr::tibble(Probe = names(auc),
- Index = seq_along(auc),
- AUC = auc,
- Max_beta = max_beta,
- Min_beta = min_beta,
- Lower_Quart = lower_quart,
- Upper_Quart = upper_quart,
- Chromosome = ref_table[[1]],
- Position = ref_table[[2]])
- diff_meth_sites <- dplyr::mutate(diff_meth_sites,
- Type = dplyr::case_when(AUC > .80 & Min_beta < hyper_range[1] & Max_beta > hyper_range[2] & Upper_Quart < control_costraints[1] ~ "Hyper",
- AUC < .20 & Min_beta < hypo_range[1] & Max_beta > hypo_range[2] & Lower_Quart > control_costraints[2] ~ "Hypo",
- TRUE ~ "No_diff"))
- diff_meth_sites <- dplyr::mutate(diff_meth_sites, AUC = dplyr::if_else(Type == "Hypo", 1-AUC, AUC))
- diff_meth_sites <- dplyr::arrange(diff_meth_sites, -AUC)
-
- sites_hyper <- dplyr::filter(diff_meth_sites, Type == "Hyper")
- sites_hypo <- dplyr::filter(diff_meth_sites, Type == "Hypo")
- message(sprintf("* Total hyper-methylated sites = %i", nrow(sites_hyper)))
- message(sprintf("* Total hypo-methylated sites = %i", nrow(sites_hypo)))
-
- # skip sites too close to previously selected sites
- keep_site_hyper <- logical(nrow(sites_hyper))
- kept_sites <- 0
- i <- 1
- if (nrow(sites_hyper) > 0){
- diff_chr <- as.matrix(adist(sites_hyper$Chromosome)) > 0
- above_distance <- as.matrix(dist(sites_hyper$Position)) >= min_distance
-
- keep_site_hyper[1] <- TRUE
- kept_sites <- kept_sites + 1
- i <- i + 1
- }
- while (kept_sites < max_sites & i <= nrow(sites_hyper)){
- check_all <- all(diff_chr[i, seq_len(i-1)] | above_distance[i, seq_len(i-1)])
- check_all <- check_all[!is.na(check_all)]
- if (length(check_all) > 0 & isTRUE(all(check_all))) {
- keep_site_hyper[i] <- TRUE
- kept_sites <- kept_sites + 1
- }
- i <- i + 1
- }
- top_hyper_sites <- sites_hyper[keep_site_hyper, ]
-
- keep_site_hypo <- logical(nrow(sites_hypo))
- kept_sites <- 0
- i <- 1
- if (nrow(sites_hypo) > 0){
- diff_chr <- as.matrix(adist(sites_hypo$Chromosome)) > 0
- above_distance <- as.matrix(dist(sites_hypo$Position)) >= min_distance
-
- keep_site_hypo[1] <- TRUE
- kept_sites <- kept_sites + 1
- i <- i + 1
- }
- while (kept_sites < max_sites & i <= nrow(sites_hypo)){
- check_all <- all(diff_chr[i, seq_len(i-1)] | above_distance[i, seq_len(i-1)])
- if (isTRUE(check_all)) {
- keep_site_hypo[i] <- TRUE
- kept_sites <- kept_sites + 1
- }
- i <- i + 1
- }
- top_hypo_sites <- sites_hypo[keep_site_hypo, ]
-
- if (method == "even") {
- sites <- list(hyper = top_hyper_sites %>% dplyr::slice(seq_len(max_sites/2)) %>% dplyr::pull(Index),
- hypo = top_hypo_sites %>% dplyr::slice(seq_len(max_sites/2)) %>% dplyr::pull(Index))
- } else if (method == "top") {
- top_sites <- dplyr::bind_rows(top_hyper_sites, top_hypo_sites) %>% dplyr::arrange(-AUC) %>% dplyr::slice(seq_len(max_sites))
- sites <- list(hyper = top_sites %>% dplyr::filter(Type == "Hyper") %>% dplyr::pull(Index),
- hypo = top_sites %>% dplyr::filter(Type == "Hypo") %>% dplyr::pull(Index))
- } else if (method == "hyper") {
- sites <- list(hyper = dplyr::slice(top_hyper_sites, seq_len(max_sites)) %>% dplyr::pull(Index))
- } else if (method == "hypo") {
- sites <- list(hypo = dplyr::slice(top_hypo_sites, seq_len(max_sites)) %>% dplyr::pull(Index))
- }
- names(sites$hyper) <- names(auc)[sites$hyper]
- names(sites$hypo) <- names(auc)[sites$hypo]
- message(sprintf("* Retrieved hyper-methylated sites = %i", length(sites$hyper)))
- message(sprintf("* Retrieved hypo-methylated sites = %i", length(sites$hypo)))
-
- message(sprintf("[%s] Done", Sys.time()))
- if (return_info) {
- sites_hyper$Keep <- keep_site_hyper
- sites_hypo$Keep <- keep_site_hypo
- return(c(sites, list(info=rbind(sites_hyper, sites_hypo))))
- } else {
- return(sites)
- }
-}
diff --git a/README.Rmd b/README.Rmd
index 225d543..a0900e5 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -18,14 +18,14 @@ Purity Assessment from DNA MEthylation Sites
## Installation
-You can install PAMES from github with:
-
+You can install PAMES version 3 (aka PAMES2) with:
```{r gh-installation, eval = FALSE}
# install.packages("devtools")
devtools::install_github("cgplab/PAMES")
```
-To include vignette use:
-```{r eval = FALSE}
+
+To install a previous version of PAMES use:
+```{r gh-installation, eval = FALSE}
# install.packages("devtools")
-devtools::install_github("cgplab/PAMES", build_vignettes = T)
+devtools::install_github("cgplab/PAMES", ref='v2.7.2')
```
diff --git a/data-raw/raw.R b/data-raw/raw.R
index 67e3fbd..40c97b4 100644
--- a/data-raw/raw.R
+++ b/data-raw/raw.R
@@ -1,26 +1,37 @@
library(readr)
library(dplyr)
+library(magrittr)
library(devtools)
-# illumina27k_hg19 <- read_tsv("data-raw/illumina27k_hg19.txt.gz") %>%
-# select(-Beta_value) %>%
-# mutate(Genomic_Coordinate=ifelse(Genomic_Coordinate == 0, NA, Genomic_Coordinate))
-# illumina27k_hg38 <- read_tsv("data-raw/illumina27k_hg38.txt.gz") %>%
-# select(-Beta_value)
-# illumina450k_hg19 <- read_tsv("data-raw/illumina450k_hg19.txt.gz") %>%
-# select(-Beta_value) %>% filter(startsWith(`Composite Element REF`, "cg"))
-# illumina450k_hg38 <- read_tsv("data-raw/illumina450k_hg38.txt.gz") %>%
-# select(-Beta_value) %>% filter(startsWith(`Composite Element REF`, "cg"))
-#
-# use_data(illumina27k_hg19, overwrite=T)
-# use_data(illumina450k_hg19, overwrite=T)
-# use_data(illumina27k_hg38, overwrite=T)
-# use_data(illumina450k_hg38, overwrite=T)
+illumina27k_hg19 <- read_tsv("illumina27k_hg19.txt.gz")
+illumina27k_hg19 %<>% select(Chromosome, Genomic_Coordinate, Probe=`Composite Element REF`, Gene_Symbol)
+illumina27k_hg19$Genomic_Coordinate[illumina27k_hg19$Genomic_Coordinate==0] <- NA
+illumina27k_hg19 <- illumina27k_hg19[startsWith(illumina27k_hg19$Probe, "cg"),]
+
+illumina450k_hg19 <- read_tsv("illumina450k_hg19.txt.gz")
+illumina450k_hg19 %<>% select(Chromosome, Genomic_Coordinate, Probe=`Composite Element REF`, Gene_Symbol)
+illumina450k_hg19$Genomic_Coordinate[illumina450k_hg19$Genomic_Coordinate==0] <- NA
+illumina450k_hg19 <- illumina450k_hg19[startsWith(illumina450k_hg19$Probe, "cg"),]
+
+illumina27k_hg38 <- read_tsv("illumina27k_hg38.txt.gz")
+illumina27k_hg38 %<>% select(Chromosome, Genomic_Coordinate=Start, Probe=`Composite Element REF`, Gene_Symbol:Feature_Type)
+illumina27k_hg38$Genomic_Coordinate[illumina27k_hg38$Genomic_Coordinate==0] <- NA
+illumina27k_hg38 <- illumina27k_hg38[startsWith(illumina27k_hg38$Probe, "cg"),]
+
+illumina450k_hg38 <- read_tsv("illumina450k_hg38.txt.gz")
+illumina450k_hg38 %<>% select(Chromosome, Genomic_Coordinate=Start, Probe=`Composite Element REF`, Gene_Symbol:Feature_Type)
+illumina450k_hg38$Genomic_Coordinate[illumina450k_hg38$Genomic_Coordinate==0] <- NA
+illumina450k_hg38 <- illumina450k_hg38[startsWith(illumina450k_hg38$Probe, "cg"),]
+
+use_data(illumina27k_hg19, overwrite=T)
+use_data(illumina450k_hg19, overwrite=T)
+use_data(illumina27k_hg38, overwrite=T)
+use_data(illumina450k_hg38, overwrite=T)
load("../data/cpg_islands.rda")
N <- 1000 # first N islands
-bs_tumor_toy_matrix <- c()
-bs_control_toy_matrix <- c()
+bs_seq_tumor_toy_matrix <- c()
+bs_seq_control_toy_matrix <- c()
cpg_sites <- c()
nsamples <- 10 # columns
cpg_islands_names <- c()
@@ -42,13 +53,13 @@ for (i in seq_len(N)){
m <- sample(c(0.1, 0.2, 0.5, 0.8, 0.9), 1)
set.seed(i*-1)
controls <- matrix(abs(runif(nsamples*nrows, m-0.05, m+0.05)), nrow = nrows)
- bs_tumor_toy_matrix <- rbind(bs_tumor_toy_matrix, tumors)
- bs_control_toy_matrix <- rbind(bs_control_toy_matrix, controls)
+ bs_seq_tumor_toy_matrix <- rbind(bs_seq_tumor_toy_matrix, tumors)
+ bs_seq_control_toy_matrix <- rbind(bs_seq_control_toy_matrix, controls)
cpg_sites <- c(cpg_sites, pos)
}
-bs_toy_sites <- tibble(chr = "1", pos = cpg_sites)
-dimnames(bs_tumor_toy_matrix) <- list(paste0("chr1_", cpg_sites), paste0("tumor", seq_len(nsamples)))
-dimnames(bs_control_toy_matrix) <- list(paste0("chr1_", cpg_sites), paste0("control", seq_len(nsamples)))
-bs_toy_matrix <- round(cbind(bs_tumor_toy_matrix, bs_control_toy_matrix)*100)
-use_data(bs_toy_matrix, bs_toy_sites, overwrite = TRUE)
+bs_seq_toy_sites <- tibble(chr = "1", pos = cpg_sites)
+dimnames(bs_seq_tumor_toy_matrix) <- list(paste0("chr1_", cpg_sites), paste0("tumor", seq_len(nsamples)))
+dimnames(bs_seq_control_toy_matrix) <- list(paste0("chr1_", cpg_sites), paste0("control", seq_len(nsamples)))
+bs_seq_toy_matrix <- round(cbind(bs_seq_tumor_toy_matrix, bs_seq_control_toy_matrix)*100)
+use_data(bs_seq_toy_matrix, bs_seq_toy_sites, overwrite = TRUE)
diff --git a/data/bs_seq_toy_matrix.rda b/data/bs_seq_toy_matrix.rda
new file mode 100644
index 0000000..77b81a9
Binary files /dev/null and b/data/bs_seq_toy_matrix.rda differ
diff --git a/data/bs_seq_toy_sites.rda b/data/bs_seq_toy_sites.rda
new file mode 100644
index 0000000..1f5104d
Binary files /dev/null and b/data/bs_seq_toy_sites.rda differ
diff --git a/data/bs_toy_matrix.rda b/data/bs_toy_matrix.rda
deleted file mode 100644
index b53de88..0000000
Binary files a/data/bs_toy_matrix.rda and /dev/null differ
diff --git a/data/bs_toy_sites.rda b/data/bs_toy_sites.rda
deleted file mode 100644
index 69c13eb..0000000
Binary files a/data/bs_toy_sites.rda and /dev/null differ
diff --git a/data/control_toy_data.rda b/data/control_toy_data.rda
index aa20423..1a7c8a2 100644
Binary files a/data/control_toy_data.rda and b/data/control_toy_data.rda differ
diff --git a/data/illumina27k_hg19.rda b/data/illumina27k_hg19.rda
index f981183..f120169 100644
Binary files a/data/illumina27k_hg19.rda and b/data/illumina27k_hg19.rda differ
diff --git a/data/illumina27k_hg38.rda b/data/illumina27k_hg38.rda
index 8ada8fe..242ddaf 100644
Binary files a/data/illumina27k_hg38.rda and b/data/illumina27k_hg38.rda differ
diff --git a/data/illumina450k_hg19.rda b/data/illumina450k_hg19.rda
index 4f303b8..837e383 100644
Binary files a/data/illumina450k_hg19.rda and b/data/illumina450k_hg19.rda differ
diff --git a/data/illumina450k_hg38.rda b/data/illumina450k_hg38.rda
index 794dce5..043e0d2 100644
Binary files a/data/illumina450k_hg38.rda and b/data/illumina450k_hg38.rda differ
diff --git a/data/tumor_toy_data.rda b/data/tumor_toy_data.rda
index 007b94d..3a094ea 100644
Binary files a/data/tumor_toy_data.rda and b/data/tumor_toy_data.rda differ
diff --git a/man/PAMES.Rd b/man/PAMES.Rd
index 8b563bd..2043c46 100644
--- a/man/PAMES.Rd
+++ b/man/PAMES.Rd
@@ -6,15 +6,15 @@
\title{PAMES: Purity Assessment from clonal MEthylation Sites}
\description{
The PAMES package provides a set of functions to estimate
-the level of purity of tumor samples.
+the level of purity or the tumor content of tumor samples.
}
\details{
-The basic workflow of PAMES requires to \code{\link{compute_AUC}} (to evaluate tumor-control methylation differences),
-\code{\link{select_informative_sites}} (to retrieve sites of interest),
-and \code{\link{compute_purity}} of tumor samples.
+The basic workflow of PAMES requires to \code{\link{get_AUC}} (to evaluate tumor-control methylation differences),
+\code{\link{find_informative_sites}} (to retrieve sites of interest),
+and \code{\link{get_purity}} of tumor samples.
When working with methylation data obtained with other technologies (such as Bisulphite Sequencing),
users should must map their set of CpG sites to differentially methylated regions
(such as CpG islands) using data \code{\link{reduce_to_regions}}, then
-\code{\link{compute_AUC}}, \code{\link{select_informative_regions}} and finally
-\code{\link{compute_purity}}.
+\code{\link{get_AUC}}, \code{\link{find_informative_regions}} and finally
+\code{\link{get_purity}}.
}
diff --git a/man/bs_toy_matrix.Rd b/man/bs_seq_toy_matrix.Rd
similarity index 77%
rename from man/bs_toy_matrix.Rd
rename to man/bs_seq_toy_matrix.Rd
index ad9a711..94c6cb6 100644
--- a/man/bs_toy_matrix.Rd
+++ b/man/bs_seq_toy_matrix.Rd
@@ -1,14 +1,14 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.R
\docType{data}
-\name{bs_toy_matrix}
-\alias{bs_toy_matrix}
-\title{BS Toy data}
+\name{bs_seq_toy_matrix}
+\alias{bs_seq_toy_matrix}
+\title{BS-Seq Toy data}
\format{
An object of class \code{matrix} (inherits from \code{array}) with 4510 rows and 20 columns.
}
\usage{
-bs_toy_matrix
+bs_seq_toy_matrix
}
\description{
Example of tumor and control beta values from Bisulphite Sequencing
diff --git a/man/bs_toy_sites.Rd b/man/bs_seq_toy_sites.Rd
similarity index 77%
rename from man/bs_toy_sites.Rd
rename to man/bs_seq_toy_sites.Rd
index 820bd7c..c55c1ba 100644
--- a/man/bs_toy_sites.Rd
+++ b/man/bs_seq_toy_sites.Rd
@@ -1,14 +1,14 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.R
\docType{data}
-\name{bs_toy_sites}
-\alias{bs_toy_sites}
-\title{BS Toy sites}
+\name{bs_seq_toy_sites}
+\alias{bs_seq_toy_sites}
+\title{BS-Seq Toy sites}
\format{
An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 4510 rows and 2 columns.
}
\usage{
-bs_toy_sites
+bs_seq_toy_sites
}
\description{
Example of data.frame with location of CpG sites
diff --git a/man/compute_AUC.Rd b/man/compute_AUC.Rd
deleted file mode 100644
index 913c71a..0000000
--- a/man/compute_AUC.Rd
+++ /dev/null
@@ -1,43 +0,0 @@
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/compute_AUC.R
-\name{compute_AUC}
-\alias{compute_AUC}
-\title{Compute Area Under Curve for a matrix of samples}
-\usage{
-compute_AUC(
- tumor_table,
- control_table,
- ncores = 1,
- na_threshold,
- return_info = FALSE,
- min_samples_frac = 1
-)
-}
-\arguments{
-\item{tumor_table}{A matrix of beta-values (percentage) from tumor samples.}
-
-\item{control_table}{A matrix of beta-values (percentage) from normal/control samples.}
-
-\item{ncores}{Number of parallel processes to use for parallel computing.}
-
-\item{na_threshold}{(DEPRECATED) Fraction of NAs (considered independently in tumor and
-control samples) above which a site will not be selected (default=0).}
-
-\item{return_info}{If TRUE (default) return a vector else compute all AUC and return a data.frame
-reporting fraction of NAs in tumor and control tables.}
-
-\item{min_samples_frac}{Fraction of samples (independently in tumor and
-control samples) that are not NA required to analyze a site (range=0-1, default=1).}
-}
-\value{
-A vector of AUC scores (NA if not analyzed) or a data.frame with AUC scores
-and the fraction of non-NA samples in tumor and control tables.
-}
-\description{
-This function computes the Area Under Curve used to define the segregation
-between tumor and control samples accordingly to their methylation (beta)
-values.
-}
-\examples{
-auc_data <- compute_AUC(tumor_toy_data, control_toy_data)
-}
diff --git a/man/compute_purity.Rd b/man/compute_purity.Rd
deleted file mode 100644
index 0ebaa65..0000000
--- a/man/compute_purity.Rd
+++ /dev/null
@@ -1,29 +0,0 @@
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/compute_purity.R
-\name{compute_purity}
-\alias{compute_purity}
-\title{Compute Purity of Tumor Samples}
-\usage{
-compute_purity(tumor_table, list_of_sites, ref_table)
-}
-\arguments{
-\item{tumor_table}{A matrix of beta-values from tumor samples.}
-
-\item{list_of_sites}{A list of indexes generated by
-\code{\link{select_informative_sites}} or
-\code{\link{select_informative_regions}}.}
-
-\item{ref_table}{Reference table used to find sites.}
-}
-\value{
-A vector of purity estimates.
-}
-\description{
-Estimate the proportion of cancer cells in the admixture of cells
-forming tumor microenvironment.
-}
-\examples{
-purity <- compute_purity(tumor_toy_data,
- list_of_sites=list(hyper=c(1, 10, 20), hypo=c(15,30,45),
- ref_table=illumina27k_hg19[3:4]))
-}
diff --git a/man/find_informative_regions.Rd b/man/find_informative_regions.Rd
new file mode 100644
index 0000000..8aab9d6
--- /dev/null
+++ b/man/find_informative_regions.Rd
@@ -0,0 +1,69 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/find_informative_regions.R
+\name{find_informative_regions}
+\alias{find_informative_regions}
+\title{Select informative regions (extended)}
+\usage{
+find_informative_regions(
+ tumor_table,
+ control_table,
+ auc,
+ cores = 1,
+ max_regions = 20,
+ percentiles = c(0, 100),
+ hyper_range = c(min = 0.4, max = 0.9),
+ hypo_range = c(min = 0.1, max = 0.6),
+ control_costraints = c(0.3, 0.7),
+ method = c("even", "top", "hyper", "hypo"),
+ full_info = FALSE
+)
+}
+\arguments{
+\item{tumor_table}{A matrix of beta-values of tumor samples.}
+
+\item{control_table}{A matrix of beta-values of control/normal samples.}
+
+\item{auc}{A data.frame with AUC scores generated by \code{get_AUC}.}
+
+\item{cores}{Number of parallel processes.}
+
+\item{max_regions}{Maximum number of regions to retrieve (half hyper-, half
+hypo-methylated) (default=20).}
+
+\item{percentiles}{A vector of length 2. Min and max percentiles to
+select sites with beta values outside hypo- and hyper-ranges (default = c(0,100);
+i.e. only min and max beta should be outside of ranges).}
+
+\item{hyper_range}{A vector of length 2 with minimum lower and upper values
+required to select hyper-methylated informative sites.}
+
+\item{hypo_range}{A vector of length 2 with minimum lower and upper values
+required to select hypo-methylated informative sites.}
+
+\item{control_costraints}{To select a site, "first quartile"/"third quartile" of control data must be above/below these beta-values.}
+
+\item{method}{How to select sites: "even" (half hyper-, half hypo-methylated sites),
+"top" (highest AUC irregardless of hyper or hypomethylation), "hyper" (hyper-methylated sites only),
+"hypo" (hypo-methylated, sites only).}
+
+\item{full_info}{Return all informative sites (for debugging purposes).}
+}
+\value{
+A data.frame reporing region names (chr_position) and type ("hyper" and "hypo") of informative regions.
+}
+\description{
+This function generates a list of informative regions to estimate the purity
+or the tumor content of a set of tumor samples.
+}
+\details{
+A new parameter, named \code{control_costraints}, is required force
+selection of sites where upper/lower quartiles of control scores are below
+beta-values given by \code{control_costraints}. Regions are divided into
+\code{hyper} and \code{hypo} depending on their level of methylation with
+respect to the average beta-score of normal samples.
+}
+\examples{
+reduced_data <- reduce_to_regions(bs_seq_toy_matrix, bs_seq_toy_sites, cpg_islands[1:1000,])
+auc_data <- get_AUC(reduced_data[,1:10], reduced_data[,11:20])
+info_regions <- find_informative_regions(reduced_data[,1:10], reduced_data[,11:20], auc_data)
+}
diff --git a/man/find_informative_sites.Rd b/man/find_informative_sites.Rd
new file mode 100644
index 0000000..27c7bd1
--- /dev/null
+++ b/man/find_informative_sites.Rd
@@ -0,0 +1,76 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/find_informative_sites.R
+\name{find_informative_sites}
+\alias{find_informative_sites}
+\title{Discover informative CpG sites}
+\usage{
+find_informative_sites(
+ tumor_table,
+ control_table,
+ auc,
+ ref_table,
+ cores = 1,
+ max_sites = 20,
+ min_distance = 1000000,
+ percentiles = c(0, 100),
+ hyper_range = c(min = 0.4, max = 0.9),
+ hypo_range = c(min = 0.1, max = 0.6),
+ control_costraints = c(0.3, 0.7),
+ method = c("even", "top", "hyper", "hypo"),
+ full_info = FALSE
+)
+}
+\arguments{
+\item{tumor_table}{A matrix of beta-values of tumor samples.}
+
+\item{control_table}{A matrix of beta-values of control/normal samples.}
+
+\item{auc}{A data.frame with AUC scores generated by \code{get_AUC}.}
+
+\item{ref_table}{A data.frame with first two columns reporting genomic location (chromosome, genomic_coordinates).}
+
+\item{cores}{Number of parallel processes.}
+
+\item{max_sites}{Maximum number of sites to retrieve (half hyper-, half
+hypo-methylated) (default=20).}
+
+\item{min_distance}{Exclude sites located at less than `min_distance` from higher-ranking site (default = 1e6 bps).}
+
+\item{percentiles}{A vector of length 2. Min and max percentiles to
+select sites with beta values outside hypo- and hyper-ranges (default = c(0,100);
+i.e. only min and max beta should be outside of ranges).}
+
+\item{hyper_range}{A vector of length 2 with minimum lower and upper values
+required to select hyper-methylated informative sites.}
+
+\item{hypo_range}{A vector of length 2 with minimum lower and upper values
+required to select hypo-methylated informative sites.}
+
+\item{control_costraints}{To select a site, "first quartile"/"third quartile" of control data must be above/below these beta-values.}
+
+\item{method}{How to select sites: "even" (half hyper-, half hypo-methylated sites),
+"top" (highest AUC irregardless of hyper or hypomethylation), "hyper" (hyper-methylated sites only),
+"hypo" (hypo-methylated, sites only).}
+
+\item{full_info}{Return all informative sites with a column reporting wether to use a site or not (for debugging purposes).}
+}
+\value{
+A data.frame reporting probe names and type ("hyper" and "hypo") of informative sites.
+}
+\description{
+This function generates a set of informative CpG sites to estimate
+the purity or the tumor content of a set of tumor samples.
+}
+\details{
+A new parameter, named \code{control_costraints}, is required to force the
+selection of sites with upper/lower quartiles of control scores are below
+beta-values given by \code{control_costraints}. Sites are divided into
+\code{hyper} and \code{hypo} depending on their level of methylation with
+respect to the average beta-score of normal samples.
+}
+\examples{
+## WARNING: The following code doesn't retrieve any informative site
+## It just shows how to use the tool
+auc_data <- get_AUC(tumor_toy_data, control_toy_data)
+info_sites <- find_informative_sites(tumor_toy_data, control_toy_data, auc_data, illumina27k_hg19)
+}
diff --git a/man/get_AUC.Rd b/man/get_AUC.Rd
new file mode 100644
index 0000000..c034acd
--- /dev/null
+++ b/man/get_AUC.Rd
@@ -0,0 +1,39 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/get_AUC.R
+\name{get_AUC}
+\alias{get_AUC}
+\title{Calculate Area Under Curve comparing tumor and control samples}
+\usage{
+get_AUC(
+ tumor_table,
+ control_table,
+ max_NA_data = 0,
+ cores = 1,
+ full_info = FALSE
+)
+}
+\arguments{
+\item{tumor_table}{A matrix of beta-values from tumor samples.}
+
+\item{control_table}{A matrix of beta-values from normal/control samples.}
+
+\item{max_NA_data}{At most this fraction of NAs (in tumor and control data
+independently) is permitted to calculate AUC of a site (default=1, i.e. only
+sites without NAs).}
+
+\item{cores}{Number of cores for parallel computing.}
+
+\item{full_info}{If TRUE (default=FALSE) returns also sites infos (fraction
+of NAs in tumor and control tables) without skipping probes with missing values.}
+}
+\value{
+A data.frame with AUC scores and probes names
+}
+\description{
+This function calculates the Area Under Curve that define the segregation
+between tumor and control samples accordingly to their methylation (beta)
+values.
+}
+\examples{
+auc_data <- get_AUC(tumor_toy_data, control_toy_data)
+}
diff --git a/man/get_purity.Rd b/man/get_purity.Rd
new file mode 100644
index 0000000..368f871
--- /dev/null
+++ b/man/get_purity.Rd
@@ -0,0 +1,27 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/get_purity.R
+\name{get_purity}
+\alias{get_purity}
+\title{Calculate purity or tumor content samples}
+\usage{
+get_purity(tumor_table, info_sites)
+}
+\arguments{
+\item{tumor_table}{A matrix of beta-values}
+
+\item{info_sites}{A data.frame reporting a set of informative sites
+generated by \code{\link{find_informative_sites}} or
+\code{\link{find_informative_regions}}.}
+}
+\value{
+A data.frame with purity scores.
+}
+\description{
+Estimate the proportion of cancer cells in the admixture of cells
+forming the tumor microenvironment or the fraction of ctDNA in cfDNA samples.
+}
+\examples{
+purity <- get_purity(tumor_toy_data,
+ info_sites=data.frame(Probe=c("CpG_00001","CpG_00010","CpG_00020",
+ "CpG_00015","CpG_00030","CpG_00045"), Site_type=rep(c("hyper","hypo"), each=3)))
+}
diff --git a/man/illumina27k_hg38.Rd b/man/illumina27k_hg38.Rd
index c94cb38..c59fad6 100644
--- a/man/illumina27k_hg38.Rd
+++ b/man/illumina27k_hg38.Rd
@@ -5,7 +5,7 @@
\alias{illumina27k_hg38}
\title{Illumina 27k BeadChip mapped to Genome Reference hg38}
\format{
-An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 27578 rows and 10 columns.
+An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 27578 rows and 9 columns.
}
\source{
\url{https://support.illumina.com/array/array_kits/infinium_humanmethylation27_beadchip_kit.html.html}
diff --git a/man/illumina450k_hg38.Rd b/man/illumina450k_hg38.Rd
index 786d94a..1999412 100644
--- a/man/illumina450k_hg38.Rd
+++ b/man/illumina450k_hg38.Rd
@@ -5,7 +5,7 @@
\alias{illumina450k_hg38}
\title{Illumina 450k BeadChip mapped to Genome Reference hg38}
\format{
-An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 482421 rows and 10 columns.
+An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 482421 rows and 9 columns.
}
\source{
\url{https://support.illumina.com/array/array_kits/infinium_humanmethylation27_beadchip_kit.html.html}
diff --git a/man/reduce_to_regions.Rd b/man/reduce_to_regions.Rd
index cdc3fd2..1e1328b 100644
--- a/man/reduce_to_regions.Rd
+++ b/man/reduce_to_regions.Rd
@@ -13,27 +13,26 @@ reduce_to_regions(
)
}
\arguments{
-\item{beta_table}{A matrix of beta-values (percentage).}
+\item{beta_table}{A matrix of beta-values.}
\item{cpg_sites}{A data.frame reporting the genomic location of CpG sites.}
\item{cpg_regions}{A data.frame reporting the genomic location of genomic regions.}
-\item{min_CpGs}{An integer (default to 3). Minimum number of CpG sites
-within a single genomic region required to compute the reduced beta value
-(return NA otherwise).}
+\item{min_CpGs}{An integer (default=3). Minimum number of CpG sites
+within a single genomic region (return NA otherwise).}
-\item{method}{Take `median` or `mean`of CpG sites.}
+\item{method}{Function to summarise a region: either `median` or `mean` (default=median).}
}
\value{
-A matrix of beta values (nrow == length(cpg_indexes)).
+A matrix of beta values, each row corresponding to one region.
}
\description{
-Reduce several beta values from different CpG sites to single beta values
-associated to one genomic region (such as CpG islands) where CpG sites are located.
+Reduce several beta values from different CpG sites to a single beta value
+associated to one genomic region (such as CpG islands).
Different technologies retrieve DNA methylation levels of
-different CpG sites. This function makes a direct comparison possible.
+different CpG sites. This function makes possible a direct comparison.
}
\examples{
-reduced_data <- reduce_to_regions(bs_toy_matrix, bs_toy_sites, cpg_islands[1:10,])
+reduced_data <- reduce_to_regions(bs_seq_toy_matrix, bs_seq_toy_sites, cpg_islands[1:10,])
}
diff --git a/man/remove_close_sites.Rd b/man/remove_close_sites.Rd
new file mode 100644
index 0000000..7dc951f
--- /dev/null
+++ b/man/remove_close_sites.Rd
@@ -0,0 +1,17 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/find_informative_sites.R
+\name{remove_close_sites}
+\alias{remove_close_sites}
+\title{Remove close sites}
+\usage{
+remove_close_sites(sites_df, max_sites, min_distance)
+}
+\arguments{
+\item{sites_df}{A data.frame}
+
+\item{min_distanc}{A number}
+}
+\description{
+Remove close sites
+}
+\keyword{internal}
diff --git a/man/select_informative_regions.Rd b/man/select_informative_regions.Rd
deleted file mode 100644
index 5a4857f..0000000
--- a/man/select_informative_regions.Rd
+++ /dev/null
@@ -1,58 +0,0 @@
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/select_informative_regions.R
-\name{select_informative_regions}
-\alias{select_informative_regions}
-\title{Select informative regions}
-\usage{
-select_informative_regions(
- tumor_table,
- auc,
- max_sites = 20,
- hyper_range = c(min = 40, max = 90),
- hypo_range = c(min = 10, max = 60),
- method = c("even", "top", "hyper", "hypo"),
- percentiles = c(0, 100),
- return_info = FALSE
-)
-}
-\arguments{
-\item{tumor_table}{A matrix of beta-values (percentage) from tumor samples.}
-
-\item{auc}{A vector of AUC scores generated by \code{compute_AUC}.}
-
-\item{max_sites}{Maximum number of regions to retrieve (half hyper-, half
-hypo-methylated) (default = 20).}
-
-\item{hyper_range}{A vector of length 2 with minimum lower and upper values
-required to select hyper-methylated informative sites.}
-
-\item{hypo_range}{A vector of length 2 with minimum lower and upper values
-required to select hypo-methylated informative sites.}
-
-\item{method}{How to select sites: "even" (half hyper-, half hypo-methylated sites),
-"top" (highest AUC irregardless of hyper or hypomethylation), "hyper" (hyper-methylated sites only),
-"hypo" (hypo-methylated, sites only).}
-
-\item{percentiles}{Vector of length 2: lower and upper percentiles to
-select sites with beta values outside hypo- and hyper-ranges (default =
-0,100; 0th and 100th percentiles, i.e. only min and max beta should be outside of ranges).}
-
-\item{return_info}{Return also a data.frame of all informative sites (for debug purpose).}
-}
-\value{
-A named list of indexes of informative regions ("hyper-" and "hypo-methylated").
-}
-\description{
-This function generates a list of informative regions to be used to estimate
-the purity of a set of tumor samples.
-}
-\details{
-Informative regions are divided into \code{hyper} and \code{hypo} depending
-on their level of methylation with respect to the average beta-score of
-normal samples. Both sets will be used to compute purity.
-}
-\examples{
-reduced_data <- reduce_to_regions(bs_toy_matrix, bs_toy_sites, cpg_islands[1:1000,])
-auc_data <- compute_AUC(reduced_data[,1:10], reduced_data[,11:20])
-info_regions <- select_informative_regions(reduced_data[,1:10], auc_data)
-}
diff --git a/man/select_informative_regions_ext.Rd b/man/select_informative_regions_ext.Rd
deleted file mode 100644
index 45dd73d..0000000
--- a/man/select_informative_regions_ext.Rd
+++ /dev/null
@@ -1,68 +0,0 @@
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/select_informative_regions_ext.R
-\name{select_informative_regions_ext}
-\alias{select_informative_regions_ext}
-\title{Select informative regions (extended)}
-\usage{
-select_informative_regions_ext(
- tumor_table,
- control_table,
- auc,
- max_sites = 20,
- percentiles = c(0, 100),
- hyper_range = c(min = 40, max = 90),
- hypo_range = c(min = 10, max = 60),
- control_costraints = c(30, 70),
- method = c("even", "top", "hyper", "hypo"),
- return_info = FALSE
-)
-}
-\arguments{
-\item{tumor_table}{A matrix of beta-values (percentage) from tumor samples.}
-
-\item{control_table}{A matrix of beta-values (percentage) from normal/control samples.}
-
-\item{auc}{A vector of AUC scores generated by \code{compute_AUC}.}
-
-\item{max_sites}{Maximum number of regions to retrieve (half hyper-, half
-hypo-methylated) (default = 20).}
-
-\item{percentiles}{Vector of length 2: lower and upper percentiles to
-select sites with beta values outside hypo- and hyper-ranges (default =
-0,100; 0th and 100th percentiles, i.e. only min and max beta should be outside of ranges).}
-
-\item{hyper_range}{A vector of length 2 with minimum lower and upper values
-required to select hyper-methylated informative sites.}
-
-\item{hypo_range}{A vector of length 2 with minimum lower and upper values
-required to select hypo-methylated informative sites.}
-
-\item{control_costraints}{To select a site, "first quartile"/"third quartile" of control data must be above/below these beta-values.}
-
-\item{method}{How to select sites: "even" (half hyper-, half hypo-methylated sites),
-"top" (highest AUC irregardless of hyper or hypomethylation), "hyper" (hyper-methylated sites only),
-"hypo" (hypo-methylated, sites only).}
-
-\item{return_info}{Return also a data.frame of all informative sites (for debug purpose).}
-}
-\value{
-A named list of indexes of informative regions ("hyper-" and "hypo-methylated").
-}
-\description{
-This function generates a list of informative regions to be used to estimate
-the purity of a set of tumor samples.
-}
-\details{
-The EXTENDED version was added to introduce the new parameter, named
-\code{control_costraints}, to force selection of sites where upper/lower
-quartiles of control scores are below beta-values given by
-\code{control_costraints}. Informative regions are divided into
-\code{hyper} and \code{hypo} depending on their level of methylation with
-respect to the average beta-score of normal samples. Both sets will be used
-to compute purity.
-}
-\examples{
-reduced_data <- reduce_to_regions(bs_toy_matrix, bs_toy_sites, cpg_islands[1:1000,])
-auc_data <- compute_AUC(reduced_data[,1:10], reduced_data[,11:20])
-info_regions <- select_informative_regions(reduced_data[,1:10], auc_data)
-}
diff --git a/man/select_informative_sites.Rd b/man/select_informative_sites.Rd
deleted file mode 100644
index 089c457..0000000
--- a/man/select_informative_sites.Rd
+++ /dev/null
@@ -1,67 +0,0 @@
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/select_informative_sites.R
-\name{select_informative_sites}
-\alias{select_informative_sites}
-\title{Select informative CpG sites}
-\usage{
-select_informative_sites(
- tumor_table,
- auc,
- ref_table,
- max_sites = 20,
- min_distance = 1000000,
- percentiles = c(0, 100),
- hyper_range = c(min = 40, max = 90),
- hypo_range = c(min = 10, max = 60),
- method = c("even", "top", "hyper", "hypo"),
- return_info = FALSE
-)
-}
-\arguments{
-\item{tumor_table}{A matrix of beta-values (percentage) from tumor samples.}
-
-\item{auc}{A vector of AUC scores generated by \code{compute_AUC}.}
-
-\item{ref_table}{A data.frame with two columns (chromosome, genomic_coordinates).}
-
-\item{max_sites}{Maximum number of sites to retrieve (half hyper-, half
-hypo-methylated) (default = 20).}
-
-\item{min_distance}{Avoid selection of CpG sites located within this
-distance from one another (default = 1e6 bps).}
-
-\item{percentiles}{Vector of length 2: lower and upper percentiles to
-select sites with beta values outside hypo- and hyper-ranges
-(default = 0,100; 0th and 100th percentiles,
-i.e. only min and max beta should be outside of ranges).}
-
-\item{hyper_range}{A vector of length 2 with minimum lower and upper values
-required to select hyper-methylated informative sites.}
-
-\item{hypo_range}{A vector of length 2 with minimum lower and upper values
-required to select hypo-methylated informative sites.}
-
-\item{method}{How to select sites: "even" (half hyper-, half hypo-methylated sites),
-"top" (highest AUC irregardless of hyper or hypomethylation), "hyper" (hyper-methylated sites only),
-"hypo" (hypo-methylated, sites only).}
-
-\item{return_info}{Return also a data.frame of all informative sites (for debug purpose).}
-}
-\value{
-A named list of indexes of informative sites ("hyper-" and "hypo-methylated").
-}
-\description{
-This function generates a list of informative CpG sites to be used to estimate
-the purity of a set of tumor samples.
-}
-\details{
-Informative sites are divided into \code{hyper} and \code{hypo} depending on
-their level of methylation with respect to the average beta-score of normal
-samples. Both sets are used to compute purity.
-}
-\examples{
-## WARNING: The following code doesn't retrieve any informative site
-## Its purpose is to show how to use the tool
-auc_data <- compute_AUC(tumor_toy_data, control_toy_data)
-info_sites <- select_informative_sites(tumor_toy_data, auc_data, illumina27k_hg19[3:4])
-}
diff --git a/man/select_informative_sites_ext.Rd b/man/select_informative_sites_ext.Rd
deleted file mode 100644
index 42077b4..0000000
--- a/man/select_informative_sites_ext.Rd
+++ /dev/null
@@ -1,77 +0,0 @@
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/select_informative_sites_ext.R
-\name{select_informative_sites_ext}
-\alias{select_informative_sites_ext}
-\title{Select informative CpG sites (extended)}
-\usage{
-select_informative_sites_ext(
- tumor_table,
- control_table,
- auc,
- ref_table,
- max_sites = 20,
- min_distance = 1000000,
- percentiles = c(0, 100),
- hyper_range = c(min = 40, max = 90),
- hypo_range = c(min = 10, max = 60),
- control_costraints = c(30, 70),
- method = c("even", "top", "hyper", "hypo"),
- return_info = FALSE
-)
-}
-\arguments{
-\item{tumor_table}{A matrix of beta-values (percentage) from tumor samples.}
-
-\item{control_table}{A matrix of beta-values (percentage) from normal/control samples.}
-
-\item{auc}{A vector of AUC scores generated by \code{compute_AUC}.}
-
-\item{ref_table}{A data.frame with two columns (chromosome, genomic_coordinates).}
-
-\item{max_sites}{Maximum number of sites to retrieve (half hyper-, half
-hypo-methylated) (default = 20).}
-
-\item{min_distance}{Avoid selection of CpG sites located within this
-distance from one another (default = 1e6 bps).}
-
-\item{percentiles}{Vector of length 2: lower and upper percentiles to
-select sites with beta values outside hypo- and hyper-ranges
-(default = 0,100; 0th and 100th percentiles,
-i.e. only min and max beta should be outside of ranges).}
-
-\item{hyper_range}{A vector of length 2 with minimum lower and upper values
-required to select hyper-methylated informative sites.}
-
-\item{hypo_range}{A vector of length 2 with minimum lower and upper values
-required to select hypo-methylated informative sites.}
-
-\item{control_costraints}{To select a site, "first quartile"/"third quartile" of control data must be above/below these beta-values.}
-
-\item{method}{How to select sites: "even" (half hyper-, half hypo-methylated sites),
-"top" (highest AUC irregardless of hyper or hypomethylation), "hyper" (hyper-methylated sites only),
-"hypo" (hypo-methylated, sites only).}
-
-\item{return_info}{Return also a data.frame of all informative sites (for debug purpose).}
-}
-\value{
-A named list of indexes of informative sites ("hyper-" and "hypo-methylated").
-}
-\description{
-This function generates a list of informative CpG sites to be used to estimate
-the purity of a set of tumor samples.
-}
-\details{
-The EXTENDED version was added to introduce the new parameter, named
-\code{control_costraints}, to force selection of sites where upper/lower
-quartiles of control scores are below beta-values given by
-\code{control_costraints}. Informative regions are divided into
-\code{hyper} and \code{hypo} depending on their level of methylation with
-respect to the average beta-score of normal samples. Both sets will be used
-to compute purity.
-}
-\examples{
-## WARNING: The following code doesn't retrieve any informative site
-## Its purpose is to show how to use the tool
-auc_data <- compute_AUC(tumor_toy_data, control_toy_data)
-info_sites <- select_informative_sites(tumor_toy_data, auc_data, illumina27k_hg19[3:4])
-}
diff --git a/man/single_AUC.Rd b/man/single_AUC.Rd
index 8d37033..1c8d470 100644
--- a/man/single_AUC.Rd
+++ b/man/single_AUC.Rd
@@ -1,8 +1,8 @@
% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/compute_AUC.R
+% Please edit documentation in R/get_AUC.R
\name{single_AUC}
\alias{single_AUC}
-\title{Compute AUC}
+\title{Calculate AUC}
\usage{
single_AUC(scores, is_tumor)
}
@@ -12,7 +12,7 @@ single_AUC(scores, is_tumor)
\item{is_tumor}{logical vector (class labels)}
}
\description{
-Use Wilcoxon method to compute AUC.
+Use Wilcoxon method to calculate AUC.
}
\keyword{\href{http://blog.revolutionanalytics.com/2017/03/auc-meets-u-stat.html}{http://blog.revolutionanalytics.com}}
\keyword{internal}
diff --git a/man/summarise_region.Rd b/man/summarise_region.Rd
new file mode 100644
index 0000000..90d6e0c
--- /dev/null
+++ b/man/summarise_region.Rd
@@ -0,0 +1,22 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/reduce_to_regions.R
+\name{summarise_region}
+\alias{summarise_region}
+\title{Reduce many CpG sites to one CpG region}
+\usage{
+summarise_region(x, n, method)
+}
+\arguments{
+\item{x}{A subset matrix.}
+
+\item{n}{Minimum required number of sites per region (return NA otherwise).}
+
+\item{method}{Either `median` or `mean`.}
+}
+\value{
+A vector
+}
+\description{
+If the number of sites is sufficient, take the median/mean value else return NA.
+}
+\keyword{internal}
diff --git a/tests/testthat/test-PAMES.R b/tests/testthat/test-PAMES.R
deleted file mode 100644
index b8af340..0000000
--- a/tests/testthat/test-PAMES.R
+++ /dev/null
@@ -1,79 +0,0 @@
-context("AUC") ##################################################
-test_that("'compute_AUC' works", {
- auc <- compute_AUC(tumor_toy_data, control_toy_data)
- expect_type(auc, "double")
- auc <- compute_AUC(tumor_toy_data, control_toy_data, return_info=TRUE)
- expect_type(auc, "list")
-})
-
-context("selection of sites") ##################################################
-test_that("'selection_of_sites' errors and warnings", {
- auc <- runif(nrow(tumor_toy_data))
- expect_error(select_informative_sites(tumor_toy_data, auc, max_sites = 19, illumina27k_hg19[3:4]), "method is set to 'even'")
- expect_error(select_informative_sites(tumor_toy_data, auc, percentiles = c(0,1000), illumina27k_hg19[3:4]), "not true")
-})
-test_that("'selection_of_sites' works", {
- set.seed(252)
- auc <- runif(nrow(tumor_toy_data))
- site_list <- select_informative_sites(tumor_toy_data, auc, illumina27k_hg19[3:4], method = "even")
- expect_type(site_list, "list")
- site_list <- select_informative_sites(tumor_toy_data, auc, illumina27k_hg19[3:4], method = "top")
- expect_type(site_list, "list")
- site_list <- select_informative_sites(tumor_toy_data, auc, illumina27k_hg19[3:4], method = "hyper")
- expect_length(site_list$hyper, 18)
- site_list <- select_informative_sites(tumor_toy_data, auc, illumina27k_hg19[3:4], method = "hypo")
- expect_length(site_list$hypo, 14)
- site_list <- select_informative_sites(tumor_toy_data, auc, illumina27k_hg19[3:4], percentiles=c(5,95))
- expect_length(site_list$hyper, 10)
- site_list <- select_informative_sites_ext(tumor_toy_data, control_toy_data, auc, illumina27k_hg19[3:4], return_info = TRUE)
- expect_length(site_list, 3)
-})
-
-context("CpG regions") ##################################################
-test_that("median of regions", {
- x <- rbind(rep(NA, 10), sample(100, 10), sample(100, 10))
- x[,3] <- NA
- expect_type(summarise_region(x, 2, "median"), "double")
- expect_true(all(is.na(summarise_region(x, 3, "mean"))))
-})
-test_that("reduce_to_regions works", {
- expect_error(reduce_to_regions(tumor_toy_data, illumina27k_hg38[3:4], cpg_islands), "No shared chromosomes")
- reduced_data <- reduce_to_regions(bs_toy_matrix, bs_toy_sites, cpg_islands)
- expect_is(reduced_data, "matrix")
- expect_equal(nrow(reduced_data), nrow(cpg_islands))
-})
-test_that("select_informative_regions works", {
- reduced_data <- round(reduce_to_regions(bs_toy_matrix, bs_toy_sites, cpg_islands))
- reduced_tumor <- reduced_data[,1:10]
- reduced_control <- reduced_data[,11:20]
- set.seed(252)
- auc_bs <- runif(nrow(reduced_data))
- region_list <- select_informative_regions(reduced_data, auc_bs)
- expect_type(region_list, "list")
- region_list <- select_informative_regions(reduced_data, auc_bs, method="top")
- expect_type(region_list, "list")
- region_list <- select_informative_regions(reduced_data, auc_bs, method="hyper")
- # expect_length(region_list$hyper, 20)
- expect_type(region_list, "list")
- region_list <- select_informative_regions(reduced_data, auc_bs, method="hypo")
- # expect_length(region_list$hypo, 20)
- expect_type(region_list, "list")
- region_list <- select_informative_regions(reduced_data, auc_bs, percentiles=c(5,95))
- # expect_length(region_list$hypo, 10)
- expect_type(region_list, "list")
- region_list <- select_informative_regions_ext(reduced_tumor, reduced_control,
- auc_bs, hyper_range = c(90,90),
- hypo_range = c(10,10),
- control_costraints = c(100,0), return_info = FALSE)
- # expect_length(region_list$hypo, 10)
- expect_type(region_list, "list")
-})
-
-context("Compute purity") ##################################################
-test_that("compute_purity works", {
- set.seed(252)
- auc <- runif(nrow(tumor_toy_data))
- site_list <- select_informative_sites(tumor_toy_data, auc, illumina27k_hg19[3:4])
- purity <- compute_purity(tumor_toy_data, site_list, illumina27k_hg19[3:4])
- expect_length(purity, ncol(tumor_toy_data))
-})
diff --git a/tests/testthat/test-find_informative_regions.R b/tests/testthat/test-find_informative_regions.R
new file mode 100644
index 0000000..4d3df37
--- /dev/null
+++ b/tests/testthat/test-find_informative_regions.R
@@ -0,0 +1,8 @@
+test_that("select_informative_regions works", {
+ reduced_data <- round(reduce_to_regions(bs_seq_toy_matrix, bs_seq_toy_sites, cpg_islands))
+ reduced_tumor <- reduced_data[,1:10]
+ reduced_control <- reduced_data[,11:20]
+ auc_bs_seq <- get_AUC(reduced_tumor, reduced_control, cores = 2)
+ region_list <- find_informative_regions(reduced_tumor, reduced_control, auc_bs_seq, cores=2, percentiles=c(5,95))
+ expect_type(region_list, "list")
+})
diff --git a/tests/testthat/test-find_informative_sites.R b/tests/testthat/test-find_informative_sites.R
new file mode 100644
index 0000000..e8ae995
--- /dev/null
+++ b/tests/testthat/test-find_informative_sites.R
@@ -0,0 +1,6 @@
+test_that("'find_informative_sites' works", {
+ set.seed(252)
+ auc1 <- get_AUC(tumor_toy_data, control_toy_data, cores = 2)
+ info_sites <- find_informative_sites(tumor_toy_data, control_toy_data, auc1, illumina27k_hg19, cores=2, percentiles=c(5,95), full_info = FALSE)
+ expect_type(info_sites, "list")
+})
diff --git a/tests/testthat/test-get_AUC.R b/tests/testthat/test-get_AUC.R
new file mode 100644
index 0000000..911069a
--- /dev/null
+++ b/tests/testthat/test-get_AUC.R
@@ -0,0 +1,6 @@
+test_that("'get_AUC' works", {
+ auc <- get_AUC(tumor_toy_data, control_toy_data, cores=2)
+ expect_type(auc, "list")
+ auc <- get_AUC(tumor_toy_data, control_toy_data, cores=2, full_info=TRUE)
+ expect_length(auc, 4)
+})
diff --git a/tests/testthat/test-get_purity.R b/tests/testthat/test-get_purity.R
new file mode 100644
index 0000000..bb91d1a
--- /dev/null
+++ b/tests/testthat/test-get_purity.R
@@ -0,0 +1,6 @@
+test_that("compute_purity works", {
+ auc <- get_AUC(tumor_toy_data, control_toy_data, cores=2)
+ site_list <- find_informative_sites(tumor_toy_data, control_toy_data, auc, illumina27k_hg19, cores=2)
+ purity <- get_purity(tumor_toy_data, site_list)
+ expect_type(purity, "list")
+})
diff --git a/tests/testthat/test-reduce_to_regions.R b/tests/testthat/test-reduce_to_regions.R
new file mode 100644
index 0000000..b914ebd
--- /dev/null
+++ b/tests/testthat/test-reduce_to_regions.R
@@ -0,0 +1,12 @@
+test_that("summarise_region works", {
+ x <- rbind(rep(NA, 10), sample(100, 10), sample(100, 10))
+ x[,3] <- NA
+ expect_type(summarise_region(x, 2, "median"), "double")
+ expect_true(all(is.na(summarise_region(x, 3, "mean"))))
+})
+test_that("reduce_to_regions works", {
+ expect_error(reduce_to_regions(tumor_toy_data, illumina27k_hg38, cpg_islands), "No shared chromosomes")
+ reduced_data <- reduce_to_regions(bs_seq_toy_matrix, bs_seq_toy_sites, cpg_islands)
+ expect_is(reduced_data, "matrix")
+ expect_equal(nrow(reduced_data), nrow(cpg_islands))
+})
diff --git a/vignettes/PAMES.Rmd b/vignettes/PAMES.Rmd
deleted file mode 100644
index 646a64f..0000000
--- a/vignettes/PAMES.Rmd
+++ /dev/null
@@ -1,63 +0,0 @@
----
-title: "PAMES"
-author: "Dario Romagnoli, Matteo Benelli"
-date: "`r Sys.Date()`"
-output: rmarkdown::html_vignette
-vignette: >
- %\VignetteIndexEntry{PAMES}
- %\VignetteEngine{knitr::rmarkdown}
- %\VignetteEncoding{UTF-8}
----
-
-**PAMES** (*Purity Assessment from MEthylation Sites*) is a tool developed
-for estimating purity of tumor samples.
-The default process for data obtained with Illumina BeadChip
-(450k or 27k) is divided into three steps:
-
-1. computation of AUC (`compute_AUC`)
-2. selection of informative CpG __sites__ (`select_informative_sites`/`select_informative_sites_ext`)
-3. estimation of purity (`compute_purity`)
-
-For data generated by other technologies (such as Bisulphite Sequencing), the
-purity estimation requires one preceding additional step:
-
-- reducing the data to CpG regions (`reduce_to_regions`)
-
-Two `data.frames` are required, one reporting the location of each CpG site
-(chromosome, position)
-and one reporting the location of each genomic regions (chromosome, start, end, optional_name).
-These steps convert beta values from several CpG sites
-to a single beta value associated to the genomic regions which CpG sites belong
-to (CpG sites located outside regions are discarded).
-
-From now on the analysis proceeds as previously described (notice the different `select` function):
-
-1. computation of AUC (`compute_AUC`)
-2. selection of informative CpG __regions__ (`select_informative_regions`/`select_informative_regions_ext`)
-3. estimation of purity (`compute_purity`)
-
-A set of pre-computed CpG sites (for Illumina 450k) and CpG regions for 14 cancer
-types are available with our [PAMESdata](https://github.com/cgplab/PAMESdata) package.
-
-## Examples
-
-Below are showed examples of the steps required to run different kind of analyses.
-
-### Pre-computed informative CpG sites (BRCA_sites) -- 450k, hg19
-
- BRCA_purity <- compute_purity(BRCA_tumor, BRCA_sites)
-
-### New set of informative CpG sites -- 27k, hg38
-
- auc_scores <- compute_AUC(tumor_matrix, control_matrix)
- tumor_sites <- select_informative_sites(tumor_table=tumor_matrix, auc=auc_scores, platform=illumina27k_hg38[3:4])
- tumor_purity <- compute_purity(tumor_matrix, cpg_sites, platform=illumina27k_hg38[3:4])
-
-### New set of informative CpG islands
-
- bs_toy_reduced <- reduce_to_regions(bs_toy_matrix, bs_toy_sites, cpg_islands)
- bs_tumor_toy_matrix <- bs_toy_reduced[, 1:10]
- bs_control_toy_matrix <- bs_toy_reduced[, 11:20]
- auc <- compute_AUC(bs_tumor_toy_matrix, bs_control_toy_matrix)
- bs_toy_regions <- select_informative_regions(bs_tumor_toy_matrix, auc)
- bs_toy_purity <- compute_purity(bs_tumor_toy_matrix, bs_toy_regions, ref_table=cpg_islands)