diff --git a/DESCRIPTION b/DESCRIPTION index 8115c3b..2ac94d4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -6,11 +6,11 @@ Authors@R: person(given = "Loïc", family = "Guille", email = "loic.guille@uclouvain.be", comment = c(ORCID = "0000-0002-8387-1092"), role = c("aut")), person(given = "Laurent", family = "Gatto", email = "laurent.gatto@uclouvain.be", comment = c(ORCID = "0000-0002-1520-2268"), role = c("ctb")), person("e-OMIX", role = c("fnd"))) -Description: QFeaturesGUI is a suite of shiny apps that serve as graphical interfaces for the QFeatures package. The package currently has two apps, importQFeatures and processQFeatures. +Description: QFeaturesGUI is a suite of shiny apps that serve as graphical interfaces for the QFeatures package. The package provides three apps: import, process, and visualise. biocViews: Software, ShinyApps, GUI, Proteomics, SingleCell, DataImport, Preprocessing URL: https://rformassspectrometry.github.io/QFeaturesGUI/, https://github.com/rformassspectrometry/QFeaturesGUI BugReports: https://github.com/rformassspectrometry/QFeaturesGUI/issues -License: MIT + file LICENSE +License: GPL (>= 3) Encoding: UTF-8 LazyData: false Imports: diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 9042449..0000000 --- a/LICENSE +++ /dev/null @@ -1,2 +0,0 @@ -YEAR: 2024 -COPYRIGHT HOLDER: QFeaturesGUI authors diff --git a/LICENSE.md b/LICENSE.md index 3d26cb9..175443c 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,21 +1,595 @@ -# MIT License - -Copyright (c) 2024 QFeaturesGUI authors - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. +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 b8d256c..4398ba8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,7 +1,11 @@ # Generated by roxygen2: do not edit by hand +export(import) export(importQFeatures) +export(process) export(processQFeatures) +export(visualise) +export(visualizeQFeatures) importFrom(DT, dataTableOutput, datatable, @@ -14,7 +18,8 @@ importFrom(MsCoreUtils, importFrom(MultiAssayExperiment, ExperimentList, MultiAssayExperiment, - getWithColData + getWithColData, + longForm ) importFrom(QFeatures, QFeatures, @@ -48,12 +53,19 @@ importFrom(dplyr,mutate) importFrom(ggplot2, aes, annotate, + element_text, + facet_grid, geom_boxplot, geom_histogram, + geom_line, + geom_point, geom_violin, geom_vline, ggplot, - scale_x_continuous + scale_x_continuous, + scale_x_discrete, + theme, + theme_minimal ) importFrom(htmltools, HTML, @@ -178,7 +190,8 @@ importFrom(shinyjs, ) importFrom(stats, as.formula, - na.exclude + na.exclude, + setNames ) importFrom(tibble,rownames_to_column) importFrom(tidyr,pivot_longer) diff --git a/NEWS.md b/NEWS.md index 34c6908..3f56bba 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,11 @@ ## QFeaturesGUI 0.99.3 +- Rename the app launchers to `import()`, `process()`, and `visualise()`. + The old names `importQFeatures()`, `processQFeatures()`, and + `visualizeQFeatures()` remain available as deprecated wrappers and warn + with the replacement function name. + - Use default for argument `row.names` when using `read.table`. ## QFeaturesGUI 0.99.2 diff --git a/R/build_import_server.R b/R/build_import_server.R index b7c0f42..b110998 100644 --- a/R/build_import_server.R +++ b/R/build_import_server.R @@ -5,7 +5,7 @@ #' @param input_table a dataframe that contains #' the input table given by the user #' -#' @return return the server function for the importQFeatures app. +#' @return return the server function for the import app. #' @rdname INTERNAL_build_import_server #' @keywords internal #' diff --git a/R/build_import_ui.R b/R/build_import_ui.R index fb45615..d9f0e27 100644 --- a/R/build_import_ui.R +++ b/R/build_import_ui.R @@ -1,6 +1,6 @@ #' UI builder for import app #' -#' @return A shiny dashboard UI for importQFeatures app +#' @return A shiny dashboard UI for import app #' @rdname INTERNAL_build_import_ui #' @keywords internal #' @@ -14,7 +14,7 @@ build_import_ui <- function() { ui <- dashboardPage( skin = "blue", - header = header("importQFeatures"), + header = header("import"), dashboardSidebar(disable = TRUE, minified = FALSE, width = 0), dashboardBody( useShinyjs(), diff --git a/R/build_process_server.R b/R/build_process_server.R index dc86bd2..dfa21a7 100644 --- a/R/build_process_server.R +++ b/R/build_process_server.R @@ -1,4 +1,4 @@ -#' Server Builder for the processQFeatures app +#' Server Builder for the process app #' #' @param qfeatures a `QFeatures` object given by the user #' @param initial_sets index of the base sets of the QFeatures @@ -6,12 +6,12 @@ #' @param has_qfeatures `logical(1)` indicating whether the app was launched #' with an initial QFeatures object #' -#' @return return the server function for the processQFeatures app. +#' @return return the server function for the process app. #' @rdname INTERNAL_build_process_server #' @keywords internal #' #' @importFrom QFeatures QFeatures -#' @importFrom shiny observeEvent +#' @importFrom shiny observeEvent observe reactiveVal downloadHandler #' @importFrom shinydashboard updateTabItems #' @importFrom shinyalert shinyalert #' @@ -39,257 +39,116 @@ build_process_server <- function(qfeatures, initial_sets, initial_steps, has_qfe server_sidebar(input, output, session) server_module_workflow_config("workflow_config") server_dynamic_workflow(input, output, session) - server_module_summary_tab("summary_tab") - - uploaded_qfeatures <- shiny::reactiveVal(NULL) - upload_message <- shiny::reactiveVal(NULL) - startup_reading <- shiny::reactiveVal(FALSE) - - output$startup_initial_sets_label <- shiny::renderText({ - uploaded <- uploaded_qfeatures() - if (is.null(uploaded)) { - return("Initial sets") - } - - selected_sets <- input$startup_initial_sets - if (is.null(selected_sets)) { - selected_sets <- names(uploaded) - } - - paste0("Initial sets (", length(selected_sets), " selected)") + # Adapt the process app's non-reactive store and workflow notifications + # to the reactive QFeatures input expected by the summary module. + summary_qfeatures <- reactiveVal(.qf$qfeatures) + observe({ + lapply(global_rv$step_rvs, function(rv) rv()) + summary_qfeatures(.qf$qfeatures) }) + server_module_summary( + "summary_tab", + qfeatures = summary_qfeatures, + assay_labels = remove_QFeaturesGUI + ) - output$startup_initial_sets_ui <- shiny::renderUI({ - uploaded <- uploaded_qfeatures() - if (startup_reading()) { - return(NULL) - } - if (is.null(uploaded)) { - return(shiny::p( - "Upload an .rds file containing a QFeatures object to", - "choose the initial sets." - )) - } - - shiny::tagList( - shiny::tags$label( - `for` = "startup_initial_sets", - class = "control-label", - shiny::textOutput("startup_initial_sets_label", inline = TRUE) - ), - shiny::selectizeInput( - "startup_initial_sets", - NULL, - choices = names(uploaded), - selected = names(uploaded), - multiple = TRUE, - width = "100%", - options = list( - plugins = list("remove_button"), - placeholder = "Choose one or more initial sets" - ) - ) - ) - }) - - output$startup_upload_message <- shiny::renderUI({ - msg <- upload_message() - if (is.null(msg)) { - return(NULL) - } - shiny::tags$div(class = "text-danger", msg) - }) - - output$startup_read_status <- shiny::renderUI({ - if (!startup_reading()) { - return(NULL) - } - - shiny::tags$div( - class = "qfeatures-startup-read-status", - shiny::tags$div( - class = "progress", - shiny::tags$div( - class = "progress-bar progress-bar-striped active", - role = "progressbar", - style = "width: 100%;" - ) - ), - shiny::tags$p( - shiny::tags$em( - "Reading QFeatures object. This can take some time for large files." - ) - ) - ) - }) - - show_startup_upload_modal <- function() { - shiny::showModal(shiny::modalDialog( - title = "Load a QFeatures object", - shiny::p( - "processQFeatures was started without a QFeatures object.", - "Upload an .rds file and choose initial sets, or start", - "with the bundled demo." - ), - shiny::fileInput( - "startup_qfeatures_rds", - "QFeatures RDS file", - accept = c(".rds", ".Rds", ".RDS") - ), - shiny::uiOutput("startup_initial_sets_ui"), - shiny::uiOutput("startup_read_status"), - shiny::uiOutput("startup_upload_message"), - easyClose = FALSE, - size = "l", - footer = shiny::tagList( - shiny::modalButton("Cancel"), - shiny::actionButton( - "startup_use_demo_qfeatures", - "Use demo QFeatures", - class = "btn-default" - ), - shiny::actionButton( - "startup_load_qfeatures", - "Load QFeatures", - class = "btn-primary" - ) - ) - )) - } - - load_startup_qfeatures <- function(uploaded, selected_sets, workflow_steps) { - initial_idx <- tryCatch( - normalise_initial_sets(uploaded, selected_sets), - error = function(e) e - ) - if (inherits(initial_idx, "error")) { - upload_message(conditionMessage(initial_idx)) - return(invisible(NULL)) - } - - if (is.null(workflow_steps)) { - workflow_steps <- initial_steps - } - - .qf$qfeatures <- format_qfeatures(uploaded, initial_idx) - global_rv$workflow_config <- workflow_steps - global_rv$code_lines <- list() - shiny::removeModal() - - n_sets <- length(initial_idx) - n_steps <- length(workflow_steps) - shinyalert( - title = "QFeatures loaded", - text = paste0( - "Loaded QFeatures with ", n_sets, - " initial set", if (n_sets != 1) "s" else "", ".", - if (n_steps > 0) { - paste0( - "\nWorkflow pre-configured with ", n_steps, - " step", if (n_steps != 1) "s" else "", "." + output[["summary_tab-download_qfeatures"]] <- downloadHandler( + filename = function() { + "processQFeatures_files.zip" + }, + content = function(file) { + with_task_loader( + caption = "Preparing download, can be quite time consuming", + expr = { + tmpdir <- tempdir() + final_qfeatures <- .qf$qfeatures + names(final_qfeatures) <- remove_QFeaturesGUI(names(final_qfeatures)) + rds_file <- file.path(tmpdir, "processQFeatures_QFeatures_object.rds") + saveRDS(final_qfeatures, rds_file) + rmd_file <- file.path(tmpdir, "sessionInfo.Rmd") + SI_file <- file.path(tmpdir, "processQFeatures_sessionInfo.html") + r_file <- file.path(tmpdir, "processQFeatures_script.R") + writeLines( + c( + "---", + "title : \"SessionInfo\"", + "output: html_document", + "---", + "", + "```{r}", + "sessionInfo()", + "```" + ), + rmd_file + ) + rmarkdown::render( + rmd_file, + output_file = SI_file, + quiet = TRUE + ) + writeLines( + c( + "# Reproducible R script", + paste0("# Generated on: ", Sys.time()), + "", + "####################################\n######### Package loading ##########\n####################################\nlibrary(QFeatures)\nlibrary(MsCoreUtils)\n", + "####################################\n########## Load dataset ############\n####################################\n## Replace 'myDataset' with the path towards your initial Qfeatures .rds file.\n## Or directly assign your initial QFeatures object to qf.\nqf <- readRDS('myDataset') \n", + unlist(global_rv$code_lines) + ), + r_file + ) + utils::zip( + zipfile = file, + files = c(rds_file, SI_file, r_file), + flags = "-j" ) - } else { - "" - } - ), - closeOnClickOutside = TRUE, - type = "success", - confirmButtonCol = "#3c8dbc" - ) - - invisible(NULL) - } - - shiny::observeEvent(input$startup_qfeatures_rds, - { - uploaded_qfeatures(NULL) - upload_message(NULL) - startup_reading(TRUE) - datapath <- input$startup_qfeatures_rds$datapath - - session$onFlushed(function() { - uploaded <- tryCatch( - check_qfeatures(datapath), - error = function(e) e - ) - startup_reading(FALSE) - if (inherits(uploaded, "error")) { - upload_message(paste( - "Could not load QFeatures object:", - conditionMessage(uploaded) - )) - return(invisible(NULL)) } - - uploaded_qfeatures(uploaded) - }, once = TRUE) - }, - ignoreInit = TRUE - ) - - shiny::observeEvent(input$startup_load_qfeatures, - { - uploaded <- uploaded_qfeatures() - if (is.null(uploaded)) { - upload_message( - "Upload a valid .rds file containing a QFeatures object." - ) - return(invisible(NULL)) - } - - workflow_steps <- input[["workflow_config-workflow_list"]] - load_startup_qfeatures( - uploaded, - input$startup_initial_sets, - workflow_steps ) - }, - ignoreInit = TRUE + } ) - shiny::observeEvent(input$startup_use_demo_qfeatures, - { - uploaded_qfeatures(NULL) - upload_message(NULL) - startup_reading(TRUE) + server_qfeatures_startup( + input, output, session, + app_name = "process", + has_qfeatures = has_qfeatures, + select_initial_sets = TRUE, + on_load = function(uploaded, initial_idx) { workflow_steps <- input[["workflow_config-workflow_list"]] + if (is.null(workflow_steps)) { + workflow_steps <- initial_steps + } - session$onFlushed(function() { - demo_qfeatures <- tryCatch( - demo_process_qfeatures(), - error = function(e) e - ) - startup_reading(FALSE) - if (inherits(demo_qfeatures, "error")) { - upload_message(paste( - "Could not create demo QFeatures object:", - conditionMessage(demo_qfeatures) - )) - return(invisible(NULL)) - } - - uploaded_qfeatures(demo_qfeatures) - load_startup_qfeatures( - demo_qfeatures, - names(demo_qfeatures), - workflow_steps - ) - }, once = TRUE) - }, - ignoreInit = TRUE - ) + .qf$qfeatures <- format_qfeatures(uploaded, initial_idx) + summary_qfeatures(.qf$qfeatures) + global_rv$workflow_config <- workflow_steps + global_rv$code_lines <- list() + + n_sets <- length(initial_idx) + n_steps <- length(workflow_steps) + shinyalert( + title = "QFeatures loaded", + text = paste0( + "Loaded QFeatures with ", n_sets, + " initial set", if (n_sets != 1) "s" else "", ".", + if (n_steps > 0) { + paste0( + "\nWorkflow pre-configured with ", n_steps, + " step", if (n_steps != 1) "s" else "", "." + ) + } else { + "" + } + ), + closeOnClickOutside = TRUE, + type = "success", + confirmButtonCol = "#3c8dbc" + ) - shiny::observeEvent(input$startup_show_upload, - { - show_startup_upload_modal() - }, - ignoreInit = TRUE + invisible(NULL) + } ) if (!has_qfeatures) { - session$onFlushed(function() { - show_startup_upload_modal() - }, once = TRUE) return(invisible(NULL)) } diff --git a/R/build_process_ui.R b/R/build_process_ui.R index 3703de9..63b5330 100644 --- a/R/build_process_ui.R +++ b/R/build_process_ui.R @@ -1,4 +1,4 @@ -#' UI builder for the processQFeatures app +#' UI builder for the process app #' #' @param initial_steps prefilled workflow steps #' @return A shiny dashboard UI @@ -11,13 +11,13 @@ #' @importFrom htmltools includeCSS #' @importFrom shinyFeedback useShinyFeedback #' @importFrom shinyalert useShinyalert -#' @importFrom shiny icon +#' @importFrom shiny icon downloadButton #' @importFrom waiter useWaiter #' @importFrom shinyjs useShinyjs build_process_ui <- function(initial_steps) { ui <- dashboardPage( skin = "blue", - header = header("processQFeatures"), + header = header("process"), sidebar = dashboardSidebar( sidebarMenu( menuItem("Workflow Config", @@ -49,7 +49,15 @@ build_process_ui <- function(initial_steps) { ), tabItem( tabName = "summary_tab", - interface_module_summary_tab("summary_tab") + interface_module_summary( + "summary_tab", + downloadButton( + outputId = "summary_tab-download_qfeatures", + "Download QFeatures", + class = "load-button", + style = "width: 100%;" + ) + ) ), # Preconstructed workflow step tabs tabItem(tabName = "step_1", uiOutput("dynamic_step_ui_1")), @@ -74,7 +82,7 @@ build_process_ui <- function(initial_steps) { tabItem(tabName = "step_20", uiOutput("dynamic_step_ui_20")) ) ), - title = "processQFeatures", + title = "process", scrollToTop = TRUE ) diff --git a/R/build_visualise_server.R b/R/build_visualise_server.R new file mode 100644 index 0000000..3f206bc --- /dev/null +++ b/R/build_visualise_server.R @@ -0,0 +1,43 @@ +build_visualise_server <- function(qfeatures, has_qfeatures) { + server <- function(input, output, session) { + global_rv$exception_data <- data.frame( + id = character(), + title = character(), + type = character(), + func_call = character(), + message = character(), + full_message = character(), + time = as.POSIXct(character()), + stringsAsFactors = FALSE + ) + server_exception_menu(input, output, session) + current_qfeatures <- shiny::reactiveVal( + if (has_qfeatures) qfeatures else NULL + ) + server_module_summary( + id = "visualize", + qfeatures = current_qfeatures + ) + + output$startup_upload_ui <- shiny::renderUI({ + if (is.null(current_qfeatures())) { + shiny::actionButton( + "startup_show_upload", + "Load QFeatures", + class = "btn-primary" + ) + } + }) + + server_qfeatures_startup( + input, output, session, + app_name = "visualise", + has_qfeatures = has_qfeatures, + on_load = function(uploaded, initial_idx) { + current_qfeatures(uploaded) + } + ) + } + + server +} diff --git a/R/build_visualise_ui.R b/R/build_visualise_ui.R new file mode 100644 index 0000000..889b38a --- /dev/null +++ b/R/build_visualise_ui.R @@ -0,0 +1,26 @@ +#' UI builder for visualise +#' +#' @return A shiny dashboard UI for the visualise app +#' @rdname INTERNAL_build_visualise_ui +#' @keywords internal +#' +#' @importFrom shinydashboard dashboardBody +#' @importFrom shinydashboardPlus dashboardSidebar +#' @importFrom shinyjs useShinyjs +#' @importFrom waiter useWaiter +build_visualise_ui <- function() { + ui <- dashboardPage( + skin = "blue", + header = header("visualise"), + sidebar = dashboardSidebar(disable = TRUE, minified = FALSE, width = 0), + body = dashboardBody( + useShinyjs(), + waiter::useWaiter(), + includeCSS(system.file(package = "QFeaturesGUI", "www", "style.css")), + shiny::uiOutput("startup_upload_ui"), + interface_module_summary(id = "visualize") + ), + scrollToTop = TRUE + ) + ui +} diff --git a/R/code_generator_importQFeatures.R b/R/code_generator_importQFeatures.R index 2a9af9b..1077e17 100644 --- a/R/code_generator_importQFeatures.R +++ b/R/code_generator_importQFeatures.R @@ -76,10 +76,10 @@ code_generator_read_table <- function(id, arg_as_param, file = NULL, sep = NULL, ) } else { if (id == "input") { - codeLines <- + codeLines <- "# Replace dataFrame1 with the value passed as assayData arg\n\ninput_table <- dataFrame1\n" } else { - codeLines <- + codeLines <- "# Replace dataFrame2 with the value passed as colData arg\n\nsample_table <- dataFrame2\n" } } diff --git a/R/code_generator_processQFeatures.R b/R/code_generator_processQFeatures.R index 21d5e40..fc95d86 100644 --- a/R/code_generator_processQFeatures.R +++ b/R/code_generator_processQFeatures.R @@ -61,7 +61,7 @@ check_for_missing_set <- function(qf, step_number) { currentStep_setNames <- vec[grep(pattern = paste0("QFeaturesGUI#", step_number), vec, fixed = TRUE)] current <- gsub("_\\(QFeaturesGUI#[0-9]+\\)_*[a-z]*_*[a-z]*_*[0-9]*", "", currentStep_setNames) if (length(initial) != length(current)) { - initial_setNames <- initial_setNames[initial!=setdiff(initial, current)] + initial_setNames <- initial_setNames[initial != setdiff(initial, current)] initial_setNames <- remove_QFeaturesGUI(initial_setNames) codeLines <- sprintf( "##After filtering steps one or more set has been deleted.\nstep%s_setNames <- c(%s)\n", @@ -293,7 +293,8 @@ codeGeneratorImpute <- function(method, step_number) { stop("Unknown imputation method: ", method, ". Use one of the available methods: ", names(specs), - call. = FALSE) + call. = FALSE + ) } default_args <- specs[[method]]$call_args diff --git a/R/deprecated.R b/R/deprecated.R new file mode 100644 index 0000000..f32ab47 --- /dev/null +++ b/R/deprecated.R @@ -0,0 +1,48 @@ +#' Deprecated functions in QFeaturesGUI +#' +#' @description +#' These functions are retained for compatibility with older versions of +#' QFeaturesGUI. They issue a deprecation warning and forward all arguments +#' to the replacement function. +#' +#' @details +#' The following functions are deprecated: +#' \itemize{ +#' \item \code{importQFeatures()}: use \code{\link{import}()}. +#' \item \code{processQFeatures()}: use \code{\link{process}()}. +#' \item \code{visualizeQFeatures()}: use \code{\link{visualise}()}. +#' } +#' They are at the deprecated stage of the Bioconductor deprecation cycle +#' and may be made defunct in a future release cycle. +#' +#' @param ... Arguments passed to the corresponding replacement function. +#' @return A Shiny application object returned by the replacement function. +#' @name QFeaturesGUI-deprecated +#' @keywords internal +#' @examples +#' # Use import(), process(), and visualise() in new code. +#' import_app <- suppressWarnings(importQFeatures()) +#' process_app <- suppressWarnings(processQFeatures()) +#' visualise_app <- suppressWarnings(visualizeQFeatures()) +NULL + +#' @rdname QFeaturesGUI-deprecated +#' @export +importQFeatures <- function(...) { + .Deprecated("import", package = "QFeaturesGUI") + import(...) +} + +#' @rdname QFeaturesGUI-deprecated +#' @export +processQFeatures <- function(...) { + .Deprecated("process", package = "QFeaturesGUI") + process(...) +} + +#' @rdname QFeaturesGUI-deprecated +#' @export +visualizeQFeatures <- function(...) { + .Deprecated("visualise", package = "QFeaturesGUI") + visualise(...) +} diff --git a/R/importQFeatures.R b/R/import.R similarity index 74% rename from R/importQFeatures.R rename to R/import.R index 0078e4e..d4f3c6d 100644 --- a/R/importQFeatures.R +++ b/R/import.R @@ -1,6 +1,6 @@ #' @title A shiny app to import QFeatures objects. #' -#' @description importQFeatures is a simple graphical interface to import bulk and single-cell proteomics data. +#' @description import is a simple graphical interface to import bulk and single-cell proteomics data. #' The app uses the \code{\link[QFeatures]{readQFeatures}} function from the QFeatures package to convert simple tables (single or multiple, CSV or TSV) to a QFeatures object. #' The app allows users to convert tables to a QFeatures object. #' @@ -8,7 +8,7 @@ #' @param assayData A data frame that contains the input table. #' @param maxSize An integer that changes the shiny.maxRequestSize value, in MB. #' -#' @return The "importQFeatures" Shiny app object. +#' @return The "import" Shiny app object. #' @export #' @importFrom shiny shinyApp runApp onStop #' @@ -17,13 +17,13 @@ #' #' data("sampleTable") #' data("inputTable") -#' app <- importQFeatures(colData = sampleTable, assayData = inputTable, maxSize = 100) +#' app <- import(colData = sampleTable, assayData = inputTable, maxSize = 100) #' #' if (interactive()) { #' shiny::runApp(app) #' } #' -importQFeatures <- function(colData = NULL, assayData = NULL, maxSize = 1000) { +import <- function(colData = NULL, assayData = NULL, maxSize = 1000) { oldOptions <- options(shiny.maxRequestSize = maxSize * 1024^2) onStop(function() options(oldOptions)) ui <- build_import_ui() diff --git a/R/interface_module_filtering_tab.R b/R/interface_module_filtering_tab.R index f4eeac1..58c2f28 100644 --- a/R/interface_module_filtering_tab.R +++ b/R/interface_module_filtering_tab.R @@ -90,7 +90,8 @@ interface_module_filtering_tab <- function(id, type = c("samples", "features")) width = "100%", class = "load-button" ), - tooltipText = paste("Write the processed sets to the QFeatures object.", + tooltipText = paste( + "Write the processed sets to the QFeatures object.", "This is needed to proceed to the next steps." ), placement = "top" diff --git a/R/interface_module_modality_plot.R b/R/interface_module_modality_plot.R new file mode 100644 index 0000000..3898910 --- /dev/null +++ b/R/interface_module_modality_plot.R @@ -0,0 +1,49 @@ +#' Modalities plot interface module +#' +#' @param id module id +#' @return A fluid row containing settings and the plot +#' @rdname INTERNAL_interface_module_modality_plot +#' @keywords internal +interface_module_modality_plot <- function(id) { + fluidRow( + box( + title = "Settings", + status = "primary", + width = 4, + solidHeader = FALSE, + collapsible = FALSE, + selectInput(NS(id, "selected_assay"), + label = "Select sets", + choices = NULL, + multiple = TRUE + ), + selectInput(NS(id, "reference_modality"), + label = "Select reference modality", + choices = NULL, + multiple = FALSE + ), + selectizeInput(NS(id, "featnames"), + "Select feature to inspect", + choices = NULL), + selectizeInput(NS(id, "annotation"), + "Select sample annotation", + choices = NULL), + actionButton(NS(id, "render"), "Render plot", + width = "100%", + class = "load-button" + ) + ), + box( + title = "Intensity across modality", + status = "primary", + width = 8, + solidHeader = FALSE, + collapsible = FALSE, + with_output_waiter(plotlyOutput(outputId = NS(id, "modality_plot")), + html = waiter::spin_6(), + color = "transparent" + ) + ) + ) +} + diff --git a/R/interface_module_pca_box.R b/R/interface_module_pca_box.R new file mode 100644 index 0000000..2fa9d6c --- /dev/null +++ b/R/interface_module_pca_box.R @@ -0,0 +1,89 @@ +#' PCA settings and plot interface module +#' +#' @param id module id +#' @return A fluid row containing PCA settings and the plot +#' @rdname INTERNAL_interface_module_pca_box +#' @keywords internal +#' +#' @importFrom shiny fluidRow column selectInput checkboxInput numericInput NS +#' @importFrom shinydashboardPlus box +#' @importFrom plotly plotlyOutput +#' +interface_module_pca_box <- function(id) { + fluidRow( + box( + title = "Settings", + status = "primary", + width = 4, + solidHeader = FALSE, + collapsible = FALSE, + selectInput( + inputId = NS(id, "pca_type"), + choices = c("samples", "features"), + label = "Select dimension reduction type", + selected = "samples" + ), + selectInput( + inputId = NS(id, "selected_assay"), + choices = NULL, + label = "Select the set for dimension reduction" + ), + column( + width = 6, + selectInput( + inputId = NS(id, "x_axis"), + label = "Component on X axis", + choices = c("PC1", "PC2", "PC3", "PC4", "PC5", "PC6"), + selected = "PC1" + ), + ), + column( + width = 6, + selectInput( + inputId = NS(id, "y_axis"), + label = "Component on Y axis", + choices = c("PC1", "PC2", "PC3", "PC4", "PC5", "PC6"), + selected = "PC2" + ), + ), + selectInput( + inputId = NS(id, "pca_color"), + label = "Color by", + choices = "NULL" + ), + checkboxInput( + inputId = NS(id, "scale"), + label = "Scale data", + value = TRUE + ), + checkboxInput( + inputId = NS(id, "center"), + label = "Center data", + value = TRUE + ), + checkboxInput( + inputId = NS(id, "show_legend"), + label = "Show Legend", + value = FALSE + ), + numericInput( + inputId = NS(id, "color_width"), + label = "Color value max length (chr)", + value = 10, + min = 5, + max = 30 + ) + ), + box( + title = "Dimension Reduction (Nipals)", + status = "primary", + width = 8, + solidHeader = FALSE, + collapsible = FALSE, + with_output_waiter(plotlyOutput(outputId = NS(id, "pca")), + html = waiter::spin_6(), + color = "transparent" + ) + ) + ) +} diff --git a/R/interface_module_qc_metrics.R b/R/interface_module_qc_metrics.R index c38acea..1675ccd 100644 --- a/R/interface_module_qc_metrics.R +++ b/R/interface_module_qc_metrics.R @@ -6,86 +6,12 @@ #' @rdname INTERNAL_interface_module_qc_metrics #' @keywords internal #' -#' @importFrom shiny fluidRow tagList selectInput NS column -#' @importFrom shinydashboardPlus box boxSidebar -#' @importFrom plotly plotlyOutput +#' @importFrom shiny fluidRow tagList NS +#' @importFrom shinydashboardPlus box #' interface_module_qc_metrics <- function(id, type) { tagList( - fluidRow( - box( - title = "Settings", - status = "primary", - width = 4, - solidHeader = FALSE, - collapsible = FALSE, - selectInput( - inputId = NS(id, "assay_type"), - choices = c("samples", "features"), - label = "Select dimension reduction type", - selected = "samples" - ), - selectInput( - inputId = NS(id, "selected_assay"), - choices = NULL, - label = "Select the set for dimension reduction" - ), - column(width = 6, - selectInput( - inputId = NS(id,"x_axis"), - label = "Component on X axis", - choices = c("PC1", "PC2", "PC3", "PC4", "PC5", "PC6"), - selected = "PC1" - ), - ), - column(width = 6, - selectInput( - inputId = NS(id,"y_axis"), - label = "Component on Y axis", - choices = c("PC1", "PC2", "PC3", "PC4", "PC5", "PC6"), - selected = "PC2" - ), - ), - - selectInput( - inputId = NS(id, "pca_color"), - label = "Color by", - choices = NULL - ), - checkboxInput( - inputId = NS(id, "scale"), - label = "Scale data", - value = TRUE - ), - checkboxInput( - inputId = NS(id, "center"), - label = "Center data", - value = TRUE - ), - checkboxInput( - inputId = NS(id, "show_legend"), - label = "Show Legend", - value = FALSE - ), - numericInput( - inputId = NS(id, "color_width"), - label = "Color value max length (chr)", - value = 10, - min = 5, - max = 30 - ) - ), - box( - title = "Dimension Reduction (Nipals)", - status = "primary", - width = 8, - solidHeader = FALSE, - collapsible = FALSE, - interface_module_pca( - NS(id, "features") - ) - ) - ), + interface_module_pca_box(NS(id, "features")), fluidRow( box( title = "Single Feature Visualisation", @@ -99,20 +25,3 @@ interface_module_qc_metrics <- function(id, type) { ) ) } - -#' PCA plot interface module -#' -#' @param id module id -#' @return a plotly for PCA -#' @rdname INTERNAL_interface_module_pca_box -#' @keywords internal -#' -#' @importFrom shiny selectInput checkboxInput numericInput NS -#' @importFrom plotly plotlyOutput -#' -interface_module_pca <- function(id) { - with_output_waiter(plotlyOutput(outputId = NS(id, "pca")), - html = waiter::spin_6(), - color = "transparent" - ) -} diff --git a/R/interface_module_summary_tab.R b/R/interface_module_summary.R similarity index 54% rename from R/interface_module_summary_tab.R rename to R/interface_module_summary.R index de23362..0d774d4 100644 --- a/R/interface_module_summary_tab.R +++ b/R/interface_module_summary.R @@ -1,15 +1,16 @@ -#' Summary tab for the interface module +#' QFeatures summary interface module #' #' @param id the id of the module -#' @return a box with the summary tab +#' @param ... Additional UI elements to append to the summary box. +#' @return a box with the QFeatures summary #' -#' @rdname INTERNAL_interface_module_summary_tab +#' @rdname INTERNAL_interface_module_summary #' @keywords internal #' @importFrom shinydashboardPlus box #' @importFrom DT dataTableOutput #' @importFrom shiny NS #' @importFrom plotly plotlyOutput -interface_module_summary_tab <- function(id) { +interface_module_summary <- function(id, ...) { box( title = "QFeatures Summary", status = "primary", @@ -35,11 +36,24 @@ interface_module_summary_tab <- function(id) { color = "transparent" ) ), - downloadButton( - outputId = NS(id, "download_qfeatures"), - "Download QFeatures", - class = "load-button", - style = "width: 100%;" - ) + box( + title = "Dimension reduction", + status = "primary", + width = 12, + solidHeader = TRUE, + collapsible = TRUE, + collapsed = TRUE, + interface_module_pca_box(NS(id, "summary_pca")) + ), + box( + title = "Across modality intensities", + status = "primary", + width = 12, + solidHeader = TRUE, + collapsible = TRUE, + collapsed = TRUE, + interface_module_modality_plot(NS(id, "modality_plot")) + ), + ... ) } diff --git a/R/processQFeatures.R b/R/process.R similarity index 74% rename from R/processQFeatures.R rename to R/process.R index bc056c7..d622556 100644 --- a/R/processQFeatures.R +++ b/R/process.R @@ -1,14 +1,15 @@ #' Launch a Shiny application to process QFeatures objects #' #' @description -#' \code{processQFeatures()} launches an interactive Shiny application +#' \code{process()} launches an interactive Shiny application #' that allows users to visually configure and apply pre-processing #' workflows to a \linkS4class{QFeatures} object. #' #' The input \code{qfeatures} can be provided as an in-memory #' \linkS4class{QFeatures} object, as a path to an \code{.rds} file #' containing one, or omitted. If omitted, the application prompts the user -#' to upload a \linkS4class{QFeatures} object from an \code{.rds} file. +#' to upload a \linkS4class{QFeatures} object from an \code{.rds} file +#' or use the bundled demo dataset. #' #' @param qfeatures Optional \linkS4class{QFeatures} object to be processed, #' or a character string specifying the path to a \code{.rds} file @@ -22,16 +23,25 @@ #' the initial sets after uploading the \code{.rds} file. #' #' @param prefilledSteps A character vector specifying the initial workflow -#' steps to display when the application launches. Steps must be provided -#' using their internal identifiers (e.g. \code{"sampleFiltering"}, -#' \code{"featureFiltering"}, \code{"normalisation"}). -#' +#' steps to display when the application launches. Available steps are: +#' \itemize{ +#' \item \code{"sampleFiltering"} +#' \item \code{"featureFiltering"} +#' \item \code{"normalisation"} +#' \item \code{"zeroToNA"} +#' \item \code{"logTransform"} +#' \item \code{"imputation"} +#' \item \code{"missingValuesFeatures"} +#' \item \code{"missingValuesSamples"} +#' \item \code{"aggregation"} +#' \item \code{"join"} +#' } #' @param maxSize An integer that changes the \code{shiny.maxRequestSize} #' value, in MB. This controls the maximum upload size for the startup #' \code{.rds} file upload modal. #' #' @return -#' The processQFeatures Shiny application. +#' The process Shiny application. #' #' @details #' The application provides a drag-and-drop workflow builder that allows @@ -48,25 +58,25 @@ #' library(QFeaturesGUI) #' #' -#' app <- processQFeatures() +#' app <- process() #' #' if (interactive()) { #' shiny::runApp(app) #' } -processQFeatures <- function( - qfeatures = NULL, - initialSets = NULL, - prefilledSteps = c( - "sampleFiltering", - "featureFiltering", - "missingValuesFeatures", - "missingValuesSamples", - "normalisation", - "aggregation", - "join", - "aggregation" - ), - maxSize = 100 +process <- function( + qfeatures = NULL, + initialSets = NULL, + prefilledSteps = c( + "sampleFiltering", + "featureFiltering", + "missingValuesFeatures", + "missingValuesSamples", + "normalisation", + "aggregation", + "join", + "aggregation" + ), + maxSize = 100 ) { qfeatures_missing <- missing(qfeatures) || is.null(qfeatures) initial_steps <- check_prefilled_steps(prefilledSteps) diff --git a/R/server_import_tab.R b/R/server_import_tab.R index d8ab6c7..ab37c12 100644 --- a/R/server_import_tab.R +++ b/R/server_import_tab.R @@ -14,11 +14,11 @@ #' @keywords internal #' server_import_tab <- function( - input, - output, - session, - sample_table, - input_table + input, + output, + session, + sample_table, + input_table ) { imported_input <- box_read_table_server( id = "input", diff --git a/R/server_module_box_readQFeatures.R b/R/server_module_box_readQFeatures.R index 47ad94c..8b767ba 100644 --- a/R/server_module_box_readQFeatures.R +++ b/R/server_module_box_readQFeatures.R @@ -108,7 +108,8 @@ box_readqfeatures_server <- function(id, input_table, sample_table) { error_handler( qfeatures_to_df, component_name = "qfeatures_to_df", - page_assays_subset(qfeatures(), "_(QFeaturesGUI#0)") + page_assays_subset(qfeatures(), "_(QFeaturesGUI#0)"), + assay_labels = remove_QFeaturesGUI ) }) diff --git a/R/server_module_filtering_box.R b/R/server_module_filtering_box.R index d44b7d9..f16a2cc 100644 --- a/R/server_module_filtering_box.R +++ b/R/server_module_filtering_box.R @@ -8,7 +8,7 @@ #' @rdname INTERNAL_server_module_filtering_box #' @keywords internal #' -#' @importFrom shiny moduleServer updateSelectInput reactive observe is.reactive req updateTextInput updateSelectInput selectizeInput numericInput updateSelectizeInput +#' @importFrom shiny moduleServer updateSelectInput reactive observe observeEvent is.reactive req updateTextInput updateSelectInput selectizeInput numericInput updateSelectizeInput #' @importFrom SummarizedExperiment colData rowData #' @importFrom shinyFeedback feedbackDanger #' @importFrom QFeatures filterFeatures @@ -131,7 +131,7 @@ server_module_filtering_box <- function(id, assays_to_process, type, state) { observe({ req(operator_choices()) - selected_operator <- input$filter_operator + selected_operator <- shiny::isolate(input$filter_operator) if (!(selected_operator %in% unname(operator_choices()))) { selected_operator <- unname(operator_choices())[[1]] } @@ -256,13 +256,18 @@ server_module_filtering_box <- function(id, assays_to_process, type, state) { ) }) - observe({ + # Input events arrive after the browser has bound the value widget. + observeEvent(input[[paste0("filter_ui_", type)]], { + req(input$filter_operator) + if (is_missingness_filter_operator(input$filter_operator)) { + return() + } feedbackDanger( inputId = paste0("filter_ui_", type), show = is_empty_categorical_multiselect(), text = "Select at least one value for this condition." ) - }) + }, ignoreNULL = TRUE) server_module_annotation_plot( "annotation_plot", @@ -370,12 +375,12 @@ server_module_filtering_box <- function(id, assays_to_process, type, state) { #' @importFrom plotly plot_ly renderPlotly #' server_module_annotation_plot <- function( - id, - assays_to_process, - type, - filter_value, - selected_annotation, - filter_operator + id, + assays_to_process, + type, + filter_value, + selected_annotation, + filter_operator ) { moduleServer(id, function(input, output, session) { rowname_selector_key <- ".qfeaturesgui_rowname" @@ -513,10 +518,10 @@ missingness_filter_plot_values <- function(values, operator) { } missingness_annotation_plot_wrapper <- function( - annotation, - filtered_annotation, - assay_name, - annotation_name + annotation, + filtered_annotation, + assay_name, + annotation_name ) { categories <- levels(annotation) annotation <- factor(annotation, levels = categories) @@ -570,10 +575,10 @@ missingness_annotation_plot_wrapper <- function( #' @importFrom plotly plot_ly config %>% add_histogram layout add_annotations #' annotation_plot_wrapper <- function( - annotation, - filtered_annotation, - assay_name, - annotation_name + annotation, + filtered_annotation, + assay_name, + annotation_name ) { if (all(is.na(annotation))) { plot <- plot_ly( diff --git a/R/server_module_filtering_tab.R b/R/server_module_filtering_tab.R index 1783e2b..0adb47f 100644 --- a/R/server_module_filtering_tab.R +++ b/R/server_module_filtering_tab.R @@ -13,11 +13,11 @@ #' @importFrom htmltools tags #' @importFrom shinydashboard renderInfoBox infoBox server_module_filtering_tab <- function( - id, - step_number, - step_rv, - parent_rv, - type = c("samples", "features") + id, + step_number, + step_rv, + parent_rv, + type = c("samples", "features") ) { type <- match.arg(type) diff --git a/R/server_module_modality_plot.R b/R/server_module_modality_plot.R new file mode 100644 index 0000000..641dfbe --- /dev/null +++ b/R/server_module_modality_plot.R @@ -0,0 +1,159 @@ +#' modality plot server module +#' +#' @param id module id +#' @param assays_to_process A reactive containing a QFeatures object with the +#' assays available for this module. +#' @param assay_labels A function taking a character vector of assay names and +#' returning a character vector of display labels of the same length. +#' Defaults to [identity()]. Original names are retained as selection values. +#' +#' @return A Shiny module server function managing modality plot settings and +#' rendering +#' @rdname INTERNAL_server_module_modality_plot_box +#' @keywords internal +#' +#' @importFrom shiny moduleServer observe req reactive +#' @importFrom ggplot2 geom_line geom_point geom_boxplot facet_grid theme_minimal theme element_text scale_x_discrete +#' @importFrom SummarizedExperiment colData +#' @importFrom MultiAssayExperiment longForm +#' @importFrom plotly plot_ly renderPlotly layout +#' +server_module_modality_plot <- function(id, assays_to_process, assay_labels = identity) { + stopifnot(is.reactive(assays_to_process), is.function(assay_labels)) + moduleServer(id, function(input, output, session) { + assay_choices <- reactive({ + assay_names <- names(assays_to_process()) + if (length(assay_names) == 0L) { + return(character()) + } + labels <- assay_labels(assay_names) + stopifnot(is.character(labels), length(labels) == length(assay_names)) + setNames(assay_names, labels) + }) + + observe({ + choices <- assay_choices() + selected <- intersect(isolate(input$selected_assay), unname(choices)) + if (length(selected) == 0) { + selected <- if (length(choices) > 0L) unname(choices[1]) else character() + } + updateSelectInput(session, + "selected_assay", + choices = choices, + selected = selected + ) + }) + + observe({ + req(assays_to_process()) + choices <- c("Sample names", colnames(colData(assays_to_process()))) + selected <- isolate(input$annotation) + if (length(selected) != 1L || !(selected %in% choices)) { + selected <- "Sample names" + } + updateSelectInput(session, + "annotation", + choices = choices, + selected = selected + ) + }) + + sub_qfeat <- reactive({ + qfeatures <- assays_to_process() + req(input$selected_assay, input$selected_assay %in% names(qfeatures)) + selected <- suppressWarnings(suppressMessages(assays_to_process()[, , which(names(qfeatures) %in% input$selected_assay)])) + stopifnot(is(selected, "QFeatures")) + selected + }) + + observe({ + req(input$selected_assay) + updateSelectInput(session, + "reference_modality", + choices = input$selected_assay + ) + }) + + observe({ + req(sub_qfeat()) + req(input$reference_modality) + featNames <- rownames(sub_qfeat())[[input$reference_modality]] + selectedFeat <- intersect(isolate(input$featnames), featNames) + if (length(featNames) == 0) { + selectedFeat <- NULL + } else if (length(selectedFeat) == 0) { + selectedFeat <- featNames[[1]] + } + updateSelectizeInput( + session, + "featnames", + choices = featNames, + selected = selectedFeat, + server = TRUE + ) + }) + modality_data <- reactive({ + req(sub_qfeat()) + req(input$featnames, input$annotation) + feat <- suppressWarnings(suppressMessages(assays_to_process()[input$featnames, , ])) + feat <- suppressWarnings(suppressMessages(feat[, , names(sub_qfeat())])) + modality_df <- suppressMessages(data.frame(longForm(feat))) + if (input$annotation != "Sample names") { + sample_metadata <- colData(feat) + req(input$annotation %in% colnames(sample_metadata)) + sample_index <- match(modality_df$primary, rownames(sample_metadata)) + modality_df$sample_group <- factor( + sample_metadata[[input$annotation]][sample_index], + exclude = NULL + ) + } + modality_df$assay <- factor(modality_df$assay, + levels = names(sub_qfeat()) + ) + modality_df + }) + + modality_plot <- eventReactive(input$render, { + plot_data <- modality_data() + req(nrow(plot_data) > 0L) + if (input$annotation == "Sample names") { + plot <- ggplot(plot_data, aes(x = colname, y = value, group = rowname)) + + geom_line(aes(color = rowname)) + + geom_point(aes(color = rowname)) + + scale_x_discrete(labels = function(x) { + ifelse( + nchar(x) > 10, + paste0(substr(x, 1, 7), "..."), + x + ) + }) + + facet_grid(~assay) + + theme_minimal() + + theme(axis.text.x = element_text(angle = -90, hjust = 0)) + } else { + plot_data$rowname <- factor(plot_data$rowname, + levels = unique(plot_data$rowname) + ) + plot <- ggplot(plot_data, aes(x = rowname, y = value, fill = sample_group)) + + geom_boxplot(na.rm = TRUE) + + ggplot2::labs(x = "Feature", y = "Intensity", fill = input$annotation) + + scale_x_discrete(labels = function(x) { + ifelse( + nchar(x) > 10, + paste0(substr(x, 1, 7), "..."), + x + ) + }) + + facet_grid(~assay, scales = "free_x") + + theme_minimal() + + theme(axis.text.x = element_text(angle = -90, hjust = 0)) + } + plot + }) + + output$modality_plot <- renderPlotly({ + ggplotly(modality_plot()) %>% + layout(boxmode = "group") + }) + }) +} diff --git a/R/server_module_pca_box.R b/R/server_module_pca_box.R new file mode 100644 index 0000000..51393ca --- /dev/null +++ b/R/server_module_pca_box.R @@ -0,0 +1,185 @@ +#' PCA settings and plot server module +#' +#' @param id module id +#' @param assays_to_process A reactive containing a QFeatures object with the +#' assays available for PCA. +#' @param assay_labels A function taking a character vector of assay names and +#' returning a character vector of display labels of the same length. +#' Defaults to [identity()]. Original names are retained as selection values. +#' +#' @return A Shiny module server function managing PCA settings and rendering +#' @rdname INTERNAL_server_module_pca_box +#' @keywords internal +#' +#' @importFrom shiny moduleServer observe req reactive updateSelectInput is.reactive isolate +#' @importFrom MultiAssayExperiment getWithColData +#' @importFrom plotly plot_ly renderPlotly layout +#' @importFrom SummarizedExperiment colData rowData +#' @importFrom methods is +#' @importFrom stats setNames +#' +server_module_pca_box <- function(id, assays_to_process, assay_labels = identity) { + stopifnot(is.reactive(assays_to_process), is.function(assay_labels)) + moduleServer(id, function(input, output, session) { + assay_choices <- reactive({ + assay_names <- names(assays_to_process()) + if (length(assay_names) == 0L) { + return(character()) + } + labels <- assay_labels(assay_names) + stopifnot(is.character(labels), length(labels) == length(assay_names)) + setNames(assay_names, labels) + }) + + observe({ + choices <- assay_choices() + selected <- isolate(input$selected_assay) + if (length(selected) != 1L || !(selected %in% choices)) { + selected <- if (length(choices) > 0L) unname(choices[1]) else character() + } + updateSelectInput(session, + "selected_assay", + choices = choices, + selected = selected + ) + }) + + single_assay <- reactive({ + qfeatures <- assays_to_process() + req(input$selected_assay, input$selected_assay %in% names(qfeatures)) + selected <- suppressWarnings(getWithColData(qfeatures, input$selected_assay)) + stopifnot(is(selected, "SummarizedExperiment")) + selected + }) + + annotation_names <- reactive({ + req(single_assay()) + req(input$pca_type %in% c("samples", "features")) + if (input$pca_type == "features") { + c("NULL", colnames(rowData(single_assay()))) + } else { + c("NULL", colnames(colData(single_assay()))) + } + }) + + observe({ + updateSelectInput(session, + "pca_color", + choices = annotation_names(), + selected = "NULL" + ) + }) + + color_data <- reactive({ + req(single_assay()) + req(input$pca_color, input$pca_color %in% annotation_names()) + if (input$pca_color != "NULL") { + req(input$color_width) + if (input$pca_type == "features") { + df <- rowData(single_assay())[, input$pca_color, drop = FALSE] + } else { + df <- colData(single_assay())[, input$pca_color, drop = FALSE] + } + if (is.character(df[, 1])) { + df[, 1] <- ifelse(nchar(df[, 1]) > input$color_width, + paste0(substr(df[, 1], 1, input$color_width), "..."), df[, 1] + ) + } + if (all(is.na(df))) { + df[, 1] <- "NA" + } + colnames(df) <- input$pca_color + return(df) + } + }) + + pca_result <- reactive({ + req(input$pca_type %in% c("samples", "features")) + req(!is.null(input$scale), !is.null(input$center)) + req(single_assay()) + req(!is_empty_set(single_assay())) + req(ncol(single_assay()) > 0L) + error_handler( + nipalsWrapper, + "QC Nipals", + sce = single_assay(), + transpose = input$pca_type == "samples", + scale = input$scale, + center = input$center + ) + }) + dataframe <- reactive({ + req(input$pca_color, input$pca_color %in% annotation_names()) + req(single_assay()) + req(!is_empty_set(single_assay())) + req(ncol(single_assay()) > 0L) + req(pca_result()) + if (input$pca_color == "NULL") { + as.data.frame( + data.frame(pca_result()$scores) + ) + } else { + req(color_data()) + scores_df <- as.data.frame(data.frame(pca_result()$scores)) + scores_df$.qfeaturesgui_row_id <- rownames(scores_df) + color_df <- as.data.frame(color_data()) + color_df$.qfeaturesgui_row_id <- rownames(color_df) + as.data.frame(merge( + scores_df, + color_df, + by = ".qfeaturesgui_row_id", + sort = FALSE + )) + } + }) + + output$pca <- renderPlotly({ + req(single_assay()) + if (is_empty_set(single_assay()) || ncol(single_assay()) == 0L) { + message_text <- paste0( + "PCA cannot be computed for this set (", + nrow(single_assay()), " row", if (nrow(single_assay()) != 1L) "s" else "", + ", ", + ncol(single_assay()), " column", if (ncol(single_assay()) != 1L) "s" else "", + ")." + ) + empty_plot <- plot_ly( + x = numeric(0), + y = numeric(0), + type = "scatter", + mode = "markers" + ) + empty_plot <- plotly::add_annotations( + empty_plot, + text = message_text, + xref = "paper", + yref = "paper", + x = 0.5, + y = 0.5, + showarrow = FALSE + ) + empty_plot <- layout( + empty_plot, + showlegend = FALSE, + xaxis = list(showticklabels = FALSE, zeroline = FALSE, showgrid = FALSE), + yaxis = list(showticklabels = FALSE, zeroline = FALSE, showgrid = FALSE) + ) + return(empty_plot) + } + req(input$x_axis, input$y_axis, !is.null(input$show_legend)) + req(dataframe()) + req(pca_result()) + # TODO: Add a table with the selected points. + error_handler( + pca_plotly, + component_name = "PCA quality control plot", + df = dataframe(), + pca_result = pca_result(), + color_name = input$pca_color, + show_legend = input$show_legend, + x_component = input$x_axis, + y_component = input$y_axis + ) + }) + }) +} diff --git a/R/server_module_qc_metrics.R b/R/server_module_qc_metrics.R index 5748246..41f652a 100644 --- a/R/server_module_qc_metrics.R +++ b/R/server_module_qc_metrics.R @@ -6,214 +6,16 @@ #' @rdname INTERNAL_server_module_qc_metrics #' @keywords internal #' -#' @importFrom shiny moduleServer updateSelectInput observeEvent eventReactive is.reactive -#' @importFrom MultiAssayExperiment getWithColData +#' @importFrom shiny moduleServer is.reactive #' server_module_qc_metrics <- function(id, assays_to_process) { stopifnot(is.reactive(assays_to_process)) moduleServer(id, function(input, output, session) { - assays_choices_vector <- reactive({ - original_names <- names(assays_to_process()) - modified_names <- remove_QFeaturesGUI(original_names) - choices_vector <- setNames(original_names, modified_names) - return(choices_vector) - }) - observe({ - choices <- assays_choices_vector() - req(choices) - updateSelectInput(session, - "selected_assay", - choices = names(choices) - ) - }) - - single_assay <- reactive({ - req(input$selected_assay) - req(assays_to_process()) - # Warning appears here - # Warning message: 'experiments' dropped; see 'drops()' - # see with Chris - suppressWarnings(getWithColData( - assays_to_process(), - assays_choices_vector()[input$selected_assay] - )) - }) - annotation_names <- reactive({ - req(single_assay()) - if (input$assay_type == "features") { - c("NULL", colnames(rowData(single_assay()))) - } else { - c("NULL", colnames(colData(single_assay()))) - } - }) - - observe({ - req(single_assay()) - req(annotation_names()) - stopifnot(is(single_assay(), "SummarizedExperiment")) - updateSelectInput(session, - "pca_color", - choices = annotation_names(), - selected = "NULL" - ) - }) - server_module_pca_box( id = "features", - single_assay = single_assay, - pca_type = reactive(input$assay_type), - scale = reactive(input$scale), - center = reactive(input$center), - color = reactive(input$pca_color), - show_legend = reactive(input$show_legend), - color_width = reactive(input$color_width), - x_component = reactive(input$x_axis), - y_component = reactive(input$y_axis) + assays_to_process = assays_to_process, + assay_labels = remove_QFeaturesGUI ) - server_module_viz_box("viz_box", assays_to_process) }) } - -#' PCA Box server module -#' -#' @param id module id -#' @param single_assay a reactiveVal that contains the selected assay -#' @param pca_type sample or features -#' @param scale a boolean that specifies if the data should be scaled -#' @param center a boolen that specifies if the data should be centered -#' @param show_legend a boolean that specifies if the legend should be shown -#' @param color which metadata use for color -#' @param color_width how many letter display in the legend -#' @param x_component the principal component to display on x axis -#' @param y_component the principal component to display on y axis -#' -#' @return A shiny module server function that contains the PCA logic -#' @rdname INTERNAL_server_module_pca_box -#' @keywords internal -#' -#' @importFrom shiny moduleServer observe req reactive updateSelectInput -#' @importFrom plotly plot_ly renderPlotly layout %>% -#' @importFrom SummarizedExperiment colData rowData -#' @importFrom methods is -#' -server_module_pca_box <- function(id, single_assay, pca_type, scale, center, show_legend, color, color_width, x_component, y_component) { - moduleServer(id, function(input, output, session) { - stopifnot(is.reactive(pca_type)) - stopifnot(is.reactive(scale)) - stopifnot(is.reactive(center)) - stopifnot(is.reactive(show_legend)) - stopifnot(is.reactive(color)) - stopifnot(is.reactive(color_width)) - stopifnot(is.reactive(x_component)) - stopifnot(is.reactive(y_component)) - - color_data <- reactive({ - req(single_assay()) - req(color()) - if (color() != "NULL") { - if (pca_type() == "features") { - df <- rowData(single_assay())[, color(), drop = FALSE] - } else { - df <- colData(single_assay())[, color(), drop = FALSE] - } - if (is.character(df[, 1])) { - df[, 1] <- ifelse(nchar(df[, 1]) > color_width(), - paste0(substr(df[, 1], 1, color_width()), "..."), df[, 1] - ) - } - if (all(is.na(df))) { - df[, 1] <- "NA" - } - colnames(df) <- color() - return(df) - } - }) - - - pca_result <- reactive({ - req(single_assay()) - req(!is_empty_set(single_assay())) - req(ncol(single_assay()) > 0L) - error_handler( - nipalsWrapper, - "QC Nipals", - sce = single_assay(), - transpose = pca_type() == "samples", - scale = scale(), - center = center() - ) - }) - dataframe <- reactive({ - req(single_assay()) - req(!is_empty_set(single_assay())) - req(ncol(single_assay()) > 0L) - req(pca_result()) - if (color() == "NULL") { - as.data.frame( - data.frame(pca_result()$scores) - ) - } else { - req(color_data()) - scores_df <- as.data.frame(data.frame(pca_result()$scores)) - scores_df$.qfeaturesgui_row_id <- rownames(scores_df) - color_df <- as.data.frame(color_data()) - color_df$.qfeaturesgui_row_id <- rownames(color_df) - as.data.frame(merge( - scores_df, - color_df, - by = ".qfeaturesgui_row_id", - sort = FALSE - )) - } - }) - - output$pca <- renderPlotly({ - req(single_assay()) - if (is_empty_set(single_assay()) || ncol(single_assay()) == 0L) { - message_text <- paste0( - "PCA cannot be computed for this set (", - nrow(single_assay()), " row", if (nrow(single_assay()) != 1L) "s" else "", - ", ", - ncol(single_assay()), " column", if (ncol(single_assay()) != 1L) "s" else "", - ")." - ) - empty_plot <- plot_ly( - x = numeric(0), - y = numeric(0), - type = "scatter", - mode = "markers" - ) - empty_plot <- plotly::add_annotations( - empty_plot, - text = message_text, - xref = "paper", - yref = "paper", - x = 0.5, - y = 0.5, - showarrow = FALSE - ) - empty_plot <- layout( - empty_plot, - showlegend = FALSE, - xaxis = list(showticklabels = FALSE, zeroline = FALSE, showgrid = FALSE), - yaxis = list(showticklabels = FALSE, zeroline = FALSE, showgrid = FALSE) - ) - return(empty_plot) - } - req(dataframe()) - req(pca_result()) - # TODO: Add a table with the selected points. - error_handler( - pca_plotly, - component_name = "PCA quality control plot", - df = dataframe(), - pca_result = pca_result(), - color_name = color(), - show_legend = show_legend(), - x_component = x_component(), - y_component = y_component() - ) - }) - }) -} diff --git a/R/server_module_summary.R b/R/server_module_summary.R new file mode 100644 index 0000000..389cd8b --- /dev/null +++ b/R/server_module_summary.R @@ -0,0 +1,78 @@ +#' QFeatures summary module server +#' +#' @param id the id of the module +#' @param qfeatures A reactive containing the QFeatures object to summarize, +#' or NULL while no object is available. +#' @param assay_labels A function taking assay names and returning display +#' labels of the same length. Defaults to [identity()]. +#' @return a server module for the QFeatures summary +#' +#' @rdname INTERNAL_server_module_summary +#' @keywords internal +#' +#' @importFrom DT renderDataTable datatable +#' @importFrom SummarizedExperiment assay +#' @importFrom shiny moduleServer reactive is.reactive +#' @importFrom plotly renderPlotly + +server_module_summary <- function(id, qfeatures, assay_labels = identity) { + stopifnot(is.reactive(qfeatures), is.function(assay_labels)) + moduleServer(id, function(input, output, session) { + qfeatures_df <- reactive({ + qfeatures_to_df(qfeatures(), assay_labels = assay_labels) + }) + + output$qfeatures_dt <- DT::renderDataTable({ + DT::datatable(qfeatures_df(), + extensions = "FixedColumns", + selection = "single", + options = list( + searching = FALSE, + scrollX = TRUE, + fixedColumns = TRUE, + pageLength = 5, + lengthMenu = c(5, 10, 15) + ) + ) + }) + + output$assay_table <- DT::renderDataTable({ + current_qfeatures <- qfeatures() + row <- input$qfeatures_dt_rows_selected + if (length(row) == 1L && row %in% seq_along(current_qfeatures)) { + DT::datatable( + data.frame(assay(current_qfeatures[[row]])), + extensions = "FixedColumns", + options = list( + searching = FALSE, + scrollX = TRUE, + fixedColumns = TRUE, + pageLength = 5, + lengthMenu = c(5, 10, 15, 20) + ) + ) + } + }) + + output$qfeatures_plot <- renderPlotly({ + current_qfeatures <- qfeatures() + if (length(current_qfeatures) > 0L) { + empty_qfeatures <- current_qfeatures[1, ] + names(empty_qfeatures) <- assay_labels(names(empty_qfeatures)) + plot(empty_qfeatures, + interactive = TRUE + ) + } + }) + server_module_pca_box( + id = "summary_pca", + assays_to_process = qfeatures, + assay_labels = assay_labels + ) + server_module_modality_plot( + id = "modality_plot", + assays_to_process = qfeatures, + assay_labels = assay_labels + ) + }) +} diff --git a/R/server_module_summary_tab.R b/R/server_module_summary_tab.R deleted file mode 100644 index b21f828..0000000 --- a/R/server_module_summary_tab.R +++ /dev/null @@ -1,129 +0,0 @@ -#' Summary tab module server -#' -#' @param id the id of the module -#' @return a server module for the summary tab -#' -#' @rdname INTERNAL_server_module_summary_tab -#' @keywords internal -#' -#' @importFrom DT renderDataTable datatable -#' @importFrom SummarizedExperiment assay -#' @importFrom shiny moduleServer observe reactive -#' @importFrom plotly renderPlotly plot_ly - -server_module_summary_tab <- function(id) { - moduleServer(id, function(input, output, session) { - # Reactive that subscribes to every step's reactiveVal. - # Re-fires whenever any step is saved, invalidating all outputs below. - any_step_saved <- reactive({ - lapply(global_rv$step_rvs, function(rv) rv()) - }) - - qfeatures_df <- reactive({ - any_step_saved() - error_handler( - qfeatures_to_df, - component_name = "qfeatures_to_df", - .qf$qfeatures - ) - }) - - output$qfeatures_dt <- DT::renderDataTable({ - DT::datatable(qfeatures_df(), - extensions = "FixedColumns", - selection = "single", - options = list( - searching = FALSE, - scrollX = TRUE, - fixedColumns = TRUE, - pageLength = 5, - lengthMenu = c(5, 10, 15) - ) - ) - }) - - output$assay_table <- DT::renderDataTable({ - any_step_saved() - if (!is.null(input$qfeatures_dt_rows_selected)) { - row <- input$qfeatures_dt_rows_selected - DT::datatable( - data.frame(assay(.qf$qfeatures[[row]])), - extensions = "FixedColumns", - options = list( - searching = FALSE, - scrollX = TRUE, - fixedColumns = TRUE, - pageLength = 5, - lengthMenu = c(5, 10, 15, 20) - ) - ) - } - }) - - output$qfeatures_plot <- renderPlotly({ - any_step_saved() - if (length(.qf$qfeatures) > 0) { - empty_qfeatures <- .qf$qfeatures[1, ] - names(empty_qfeatures) <- remove_QFeaturesGUI(names(empty_qfeatures)) - plot(empty_qfeatures, - interactive = TRUE - ) - } - }) - - output$download_qfeatures <- downloadHandler( - filename = function() { - "processQFeatures_files.zip" - }, - content = function(file) { - with_task_loader( - caption = "Preparing download, can be quite time consuming", - expr = { - tmpdir <- tempdir() - final_qfeatures <- .qf$qfeatures - names(final_qfeatures) <- remove_QFeaturesGUI(names(final_qfeatures)) - rds_file <- file.path(tmpdir, "processQFeatures_QFeatures_object.rds") - saveRDS(final_qfeatures, rds_file) - rmd_file <- file.path(tmpdir, "sessionInfo.Rmd") - SI_file <- file.path(tmpdir, "processQFeatures_sessionInfo.html") - r_file <- file.path(tmpdir, "processQFeatures_script.R") - writeLines( - c( - "---", - "title : \"SessionInfo\"", - "output: html_document", - "---", - "", - "```{r}", - "sessionInfo()", - "```" - ), - rmd_file - ) - rmarkdown::render( - rmd_file, - output_file = SI_file, - quiet = TRUE - ) - writeLines( - c( - "# Reproducible R script", - paste0("# Generated on: ", Sys.time()), - "", - "####################################\n######### Package loading ##########\n####################################\nlibrary(QFeatures)\nlibrary(MsCoreUtils)\n", - "####################################\n########## Load dataset ############\n####################################\n## Replace 'myDataset' with the path towards your initial Qfeatures .rds file.\n## Or directly assign your initial QFeatures object to qf.\nqf <- readRDS('myDataset') \n", - unlist(global_rv$code_lines) - ), - r_file - ) - utils::zip( - zipfile = file, - files = c(rds_file, SI_file, r_file), - flags = "-j" - ) - } - ) - } - ) - }) -} diff --git a/R/server_qfeatures_startup.R b/R/server_qfeatures_startup.R new file mode 100644 index 0000000..6f5bb1a --- /dev/null +++ b/R/server_qfeatures_startup.R @@ -0,0 +1,224 @@ +#' Shared startup loader for QFeatures applications +#' +#' @param input,output,session The parent Shiny server objects. +#' @param app_name Application name displayed in the startup modal. +#' @param has_qfeatures Whether an initial QFeatures object was supplied. +#' @param on_load Callback receiving the loaded QFeatures object and integer +#' assay indices. Called in an isolated reactive context. +#' @param select_initial_sets Whether to let users select initial assays. +#' +#' @return No return value; registers startup outputs and observers. +#' @keywords internal +#' @noRd +server_qfeatures_startup <- function( + input, output, session, app_name, has_qfeatures, on_load, + select_initial_sets = FALSE +) { + uploaded_qfeatures <- shiny::reactiveVal(NULL) + upload_message <- shiny::reactiveVal(NULL) + startup_reading <- shiny::reactiveVal(FALSE) + + if (select_initial_sets) { + output$startup_initial_sets_label <- shiny::renderText({ + uploaded <- uploaded_qfeatures() + if (is.null(uploaded)) { + return("Initial sets") + } + + selected_sets <- input$startup_initial_sets + if (is.null(selected_sets)) { + selected_sets <- names(uploaded) + } + paste0("Initial sets (", length(selected_sets), " selected)") + }) + + output$startup_initial_sets_ui <- shiny::renderUI({ + uploaded <- uploaded_qfeatures() + if (startup_reading()) { + return(NULL) + } + if (is.null(uploaded)) { + return(shiny::p( + "Upload an .rds file containing a QFeatures object to", + "choose the initial sets." + )) + } + + shiny::tagList( + shiny::tags$label( + "for" = "startup_initial_sets", + class = "control-label", + shiny::textOutput("startup_initial_sets_label", inline = TRUE) + ), + shiny::selectizeInput( + "startup_initial_sets", + NULL, + choices = names(uploaded), + selected = names(uploaded), + multiple = TRUE, + width = "100%", + options = list( + plugins = list("remove_button"), + placeholder = "Choose one or more initial sets" + ) + ) + ) + }) + } + + output$startup_upload_message <- shiny::renderUI({ + msg <- upload_message() + if (is.null(msg)) { + return(NULL) + } + shiny::tags$div(class = "text-danger", msg) + }) + + output$startup_read_status <- shiny::renderUI({ + if (!startup_reading()) { + return(NULL) + } + + shiny::tags$div( + class = "qfeatures-startup-read-status", + shiny::tags$div( + class = "progress", + shiny::tags$div( + class = "progress-bar progress-bar-striped active", + role = "progressbar", + style = "width: 100%;" + ) + ), + shiny::tags$p(shiny::tags$em( + "Reading QFeatures object. This can take some time for large files." + )) + ) + }) + + show_startup_upload_modal <- function() { + shiny::showModal(shiny::modalDialog( + title = "Load a QFeatures object", + shiny::p( + paste0(app_name, " was started without a QFeatures object."), + if (select_initial_sets) { + "Upload an .rds file and choose initial sets, or start with the bundled demo." + } else { + "Upload an .rds file, or start with the bundled demo." + } + ), + shiny::fileInput( + "startup_qfeatures_rds", + "QFeatures RDS file", + accept = c(".rds", ".Rds", ".RDS") + ), + if (select_initial_sets) { + shiny::uiOutput("startup_initial_sets_ui") + }, + shiny::uiOutput("startup_read_status"), + shiny::uiOutput("startup_upload_message"), + easyClose = FALSE, + size = "l", + footer = shiny::tagList( + shiny::modalButton("Cancel"), + shiny::actionButton( + "startup_use_demo_qfeatures", + "Use demo QFeatures", + class = "btn-default" + ), + shiny::actionButton( + "startup_load_qfeatures", + "Load QFeatures", + class = "btn-primary" + ) + ) + ), session = session) + } + + load_startup_qfeatures <- function(uploaded, selected_sets = names(uploaded)) { + result <- tryCatch({ + initial_idx <- if (select_initial_sets) { + normalise_initial_sets(uploaded, selected_sets) + } else { + seq_along(uploaded) + } + shiny::isolate(on_load(uploaded, initial_idx)) + NULL + }, error = function(e) e) + + if (inherits(result, "error")) { + upload_message(conditionMessage(result)) + return(invisible(NULL)) + } + upload_message(NULL) + shiny::removeModal(session = session) + invisible(NULL) + } + + read_startup_qfeatures <- function(reader, use_demo = FALSE, processed = FALSE) { + uploaded_qfeatures(NULL) + upload_message(NULL) + startup_reading(TRUE) + + session$onFlushed(function() { + uploaded <- tryCatch(reader(processed), error = function(e) e) + startup_reading(FALSE) + if (inherits(uploaded, "error")) { + upload_message(paste( + if (use_demo) { + "Could not create demo QFeatures object:" + } else { + "Could not load QFeatures object:" + }, + conditionMessage(uploaded) + )) + return(invisible(NULL)) + } + + uploaded_qfeatures(uploaded) + if (use_demo) { + load_startup_qfeatures(uploaded) + } + }, once = TRUE) + } + + shiny::observeEvent(input$startup_qfeatures_rds, { + datapath <- input$startup_qfeatures_rds$datapath + read_startup_qfeatures(function(processed = FALSE) check_qfeatures(datapath)) + }, ignoreInit = TRUE) + + shiny::observeEvent(input$startup_load_qfeatures, { + if (startup_reading()) { + return(invisible(NULL)) + } + uploaded <- uploaded_qfeatures() + if (is.null(uploaded)) { + upload_message( + "Upload a valid .rds file containing a QFeatures object." + ) + return(invisible(NULL)) + } + + selected_sets <- if (select_initial_sets) { + input$startup_initial_sets + } else { + names(uploaded) + } + load_startup_qfeatures(uploaded, selected_sets) + }, ignoreInit = TRUE) + + shiny::observeEvent(input$startup_use_demo_qfeatures, { + read_startup_qfeatures(demo_qfeatures, use_demo = TRUE, processed = app_name == "visualise") + }, ignoreInit = TRUE) + + shiny::observeEvent(input$startup_show_upload, { + show_startup_upload_modal() + }, ignoreInit = TRUE) + + if (!has_qfeatures) { + session$onFlushed(function() { + show_startup_upload_modal() + }, once = TRUE) + } + + invisible(NULL) +} diff --git a/R/utils_global.R b/R/utils_global.R index 0c4d97d..f027c1a 100644 --- a/R/utils_global.R +++ b/R/utils_global.R @@ -78,10 +78,12 @@ error_handler <- function(func, component_name, ...) { #' @importFrom htmltools HTML div #' #' @rdname INTERNAL_show_exception_notification -show_exception_notification <- function(component_name, - type = c("error", "warning"), - time, - duration = 30) { +show_exception_notification <- function( + component_name, + type = c("error", "warning"), + time, + duration = 30 +) { type <- match.arg(type) title <- paste0( @@ -203,10 +205,12 @@ loading <- function(msg) { #' @return A UI element wrapped with waiter behavior. #' @rdname INTERNAL_with_output_waiter #' @keywords internal -with_output_waiter <- function(element, - html = waiter::spin_fading_circles(), - color = "rgba(0, 0, 0, 0.25)", - image = "") { +with_output_waiter <- function( + element, + html = waiter::spin_fading_circles(), + color = "rgba(0, 0, 0, 0.25)", + image = "" +) { output_id <- element$attribs$id if (is.null(output_id) && is.list(element) && length(element) > 0L) { first_child <- element[[1]] @@ -385,12 +389,16 @@ with_task_loader <- function(caption = NULL, expr) { #' Will convert a qfeatures object to a summary data.frame object #' #' @param qfeatures a qfeatures object +#' @param assay_labels A function taking assay names and returning display +#' labels of the same length. Defaults to [identity()]. #' #' @return a data.frame object #' @rdname INTERNAL_qfeatures_to_df #' @keywords internal #' -qfeatures_to_df <- function(qfeatures) { +qfeatures_to_df <- function(qfeatures, assay_labels = identity) { + assay_names <- assay_labels(names(qfeatures)) + stopifnot(length(assay_names) == length(qfeatures)) df <- data.frame( "Name" = rep.int(0, length(qfeatures)), "Class" = rep.int(0, length(qfeatures)), @@ -400,7 +408,7 @@ qfeatures_to_df <- function(qfeatures) { "nSamplesMetadata" = rep.int(0, length(qfeatures)) ) for (i in seq_along(qfeatures)) { - df[i, "Name"] <- remove_QFeaturesGUI(names(qfeatures)[[i]]) + df[i, "Name"] <- assay_names[[i]] df[i, "Class"] <- class(qfeatures[[i]])[[1]] df[i, "nFeatures"] <- nrow(qfeatures[[i]])[[1]] df[i, "nSamples"] <- ncol(qfeatures[[i]])[[1]] @@ -465,30 +473,15 @@ page_assays_subset <- function(qfeatures, pattern) { #' #' @importFrom shiny tags tagAppendAttributes #' -#' @examples -#' ## Plain text trigger with info icon -#' bs3Tooltip( -#' trigger = "assayData", -#' tooltipText = paste0( -#' "A data.frame or any object that can be coerced into a data.frame, ", -#' "holding the quantitative assay." -#' ) -#' ) -#' -#' ## Button trigger -#' bs3Tooltip( -#' trigger = shiny::actionButton("btn", "Import"), -#' tooltipText = "Click to import the data", -#' placement = "top" -#' ) -#' #' @rdname INTERNAL_bs3Tooltip #' @keywords internal #' -bs3Tooltip <- function(trigger, - tooltipText, - placement = c("right", "left", "top", "bottom"), - icon = "fa-info-circle") { +bs3Tooltip <- function( + trigger, + tooltipText, + placement = c("right", "left", "top", "bottom"), + icon = "fa-info-circle" +) { stopifnot( is.character(tooltipText), length(tooltipText) == 1L, is.character(icon), length(icon) == 1L diff --git a/R/utils_processQFeatures.R b/R/utils_processQFeatures.R index fb9fbbe..8581bed 100644 --- a/R/utils_processQFeatures.R +++ b/R/utils_processQFeatures.R @@ -180,89 +180,6 @@ normalise_initial_sets <- function(qfeatures, initialSets) { unique(idx) } -#' Validate and load a QFeatures object -#' -#' Internal helper to validate the \code{qfeatures} argument. If a character -#' path is provided, the function attempts to read an RDS file and validates -#' that it contains a \linkS4class{QFeatures} object. -#' -#' @param qfeatures A \linkS4class{QFeatures} object or a character path to -#' an RDS file containing one. -#' -#' @return A validated \linkS4class{QFeatures} object. -#' -#' @keywords internal -#' @noRd -check_qfeatures <- function(qfeatures) { - if (missing(qfeatures)) { - stop("`qfeatures` argument is missing") - } - - from_rds_file <- FALSE - if (is.character(qfeatures)) { - from_rds_file <- TRUE - if (length(qfeatures) != 1L) { - stop("`qfeatures` must be a single path to an RDS file.") - } - if (!file.exists(qfeatures)) { - stop("The file '", qfeatures, "' does not exist.") - } - - qfeatures <- tryCatch( - readRDS(qfeatures), - error = function(e) { - stop("Failed to read RDS file: ", e$message) - } - ) - } - - if (!inherits(qfeatures, "QFeatures")) { - if (from_rds_file) { - stop("The RDS file does not contain a QFeatures object.") - } - stop( - "`qfeatures` must be a QFeatures object or a valid path to an RDS file containing one." - ) - } - - qfeatures -} - -#' Build the bundled demo QFeatures object -#' -#' @return A \linkS4class{QFeatures} object built from the package -#' \code{inputTable} and \code{sampleTable} example datasets. -#' -#' @keywords internal -#' @noRd -demo_process_qfeatures <- function() { - data_env <- new.env(parent = emptyenv()) - utils::data( - list = c("inputTable", "sampleTable"), - package = "QFeaturesGUI", - envir = data_env - ) - - if (!exists("inputTable", envir = data_env, inherits = FALSE) || - !exists("sampleTable", envir = data_env, inherits = FALSE)) { - stop("Bundled demo data could not be loaded.") - } - - qfeatures <- QFeatures::readQFeatures( - assayData = data_env$inputTable, - colData = data_env$sampleTable, - runCol = "Raw.file", - quantCols = NULL, - removeEmptyCols = TRUE, - verbose = FALSE - ) - if (length(qfeatures) > 0) { - qfeatures <- QFeatures::zeroIsNA(qfeatures, i = seq_along(qfeatures)) - } - - qfeatures -} - #' Validate and map prefilled workflow steps #' #' Internal helper to validate workflow step identifiers and convert them @@ -449,7 +366,7 @@ nipalsWrapper <- function(sce, center, scale, transpose = FALSE) { mat <- assay(sce) dimMat <- dim(mat) mat <- mat[rowSums(is.finite(mat)) > 2, colSums(is.finite(mat)) > 2] - if (!identical(dim(mat), dimMat)){ + if (!identical(dim(mat), dimMat)) { warning("Some variable(s) with less than 3 observations were removed") } @@ -531,12 +448,12 @@ pca_plotly <- function(df, pca_result, color_name, show_legend, x_component, y_c layout( xaxis = list(title = paste( x_component, - round(pca_result$R2[as.integer(strsplit(x_component,"PC")[[1]][2])] * 100, 2), + round(pca_result$R2[as.integer(strsplit(x_component, "PC")[[1]][2])] * 100, 2), "% of the variance" )), yaxis = list(title = paste( y_component, - round(pca_result$R2[as.integer(strsplit(y_component,"PC")[[1]][2])] * 100, 2), + round(pca_result$R2[as.integer(strsplit(y_component, "PC")[[1]][2])] * 100, 2), "% of the variance" )), showlegend = show_legend, @@ -770,10 +687,11 @@ available_imputation_methods <- function() { assert_imputation_method_available <- function(method) { specs <- imputation_method_specs() if (!(method %in% names(specs))) { - stop("Unknown imputation method: ", method, + stop("Unknown imputation method: ", method, ". Use one of the available methods: ", names(specs), - call. = FALSE) + call. = FALSE + ) } required_package <- specs[[method]]$package @@ -1357,8 +1275,10 @@ annotation_cols <- function(x, what) { #' @importFrom MsCoreUtils robustSummary medianPolish #' @importFrom waiter Waiter spin_fading_circles #' -aggregation_qfeatures <- function(qfeatures, method, - fcol) { +aggregation_qfeatures <- function( + qfeatures, method, + fcol +) { n <- length(qfeatures) caption <- if (n > 0L) { paste0("Aggregation of 1/", n, " sets") diff --git a/R/utils_qfeatures.R b/R/utils_qfeatures.R new file mode 100644 index 0000000..37a421a --- /dev/null +++ b/R/utils_qfeatures.R @@ -0,0 +1,92 @@ +#' Validate and load a QFeatures object +#' +#' Internal helper to validate the \code{qfeatures} argument. If a character +#' path is provided, the function attempts to read an RDS file and validates +#' that it contains a \linkS4class{QFeatures} object. +#' +#' @param qfeatures A \linkS4class{QFeatures} object or a character path to +#' an RDS file containing one. +#' +#' @return A validated \linkS4class{QFeatures} object. +#' +#' @keywords internal +#' @noRd +check_qfeatures <- function(qfeatures) { + if (missing(qfeatures)) { + stop("`qfeatures` argument is missing") + } + + from_rds_file <- FALSE + if (is.character(qfeatures)) { + from_rds_file <- TRUE + if (length(qfeatures) != 1L) { + stop("`qfeatures` must be a single path to an RDS file.") + } + if (!file.exists(qfeatures)) { + stop("The file '", qfeatures, "' does not exist.") + } + + qfeatures <- tryCatch( + readRDS(qfeatures), + error = function(e) { + stop("Failed to read RDS file: ", e$message) + } + ) + } + + if (!inherits(qfeatures, "QFeatures")) { + if (from_rds_file) { + stop("The RDS file does not contain a QFeatures object.") + } + stop( + "`qfeatures` must be a QFeatures object or a valid path to an RDS file containing one." + ) + } + + qfeatures +} + +#' Build the bundled demo QFeatures object +#' +#' @param fullProcessing `logical(1)` indicating if the demo qfeatures +#' should already be processed +#' @return A \linkS4class{QFeatures} object built from the package +#' \code{inputTable} and \code{sampleTable} example datasets. +#' +#' @keywords internal +#' @noRd +demo_qfeatures <- function(fullProcessing = FALSE) { + data_env <- new.env(parent = emptyenv()) + utils::data( + list = c("inputTable", "sampleTable"), + package = "QFeaturesGUI", + envir = data_env + ) + + if (!exists("inputTable", envir = data_env, inherits = FALSE) || + !exists("sampleTable", envir = data_env, inherits = FALSE)) { + stop("Bundled demo data could not be loaded.") + } + + qfeatures <- QFeatures::readQFeatures( + assayData = data_env$inputTable, + colData = data_env$sampleTable, + runCol = "Raw.file", + quantCols = NULL, + removeEmptyCols = TRUE, + verbose = FALSE + ) + qfeatures <- QFeatures::zeroIsNA(qfeatures, i = seq_along(qfeatures)) + if (fullProcessing) { + qfeatures <- qfeatures[, colData(qfeatures)$SampleType %in% c("Monocyte", "Macrophage"), ] + qfeatures <- filterFeatures(qfeatures, ~ Potential.contaminant != "+" & Reverse != "+" ) + logNames <- paste0(names(qfeatures), "_log") + qfeatures <- QFeatures::logTransform(qfeatures, i = names(qfeatures), name = logNames) + qfeatures <- QFeatures::joinAssays(qfeatures, i = logNames, name = "joinedPSM") + qfeatures <- QFeatures::aggregateFeatures(qfeatures, i = "joinedPSM", name = "peptides", fun = colMedians, fcol = "Modified.sequence", na.rm = TRUE) + qfeatures <- QFeatures::aggregateFeatures(qfeatures, i = "peptides", name = "proteins", fun = colMedians, fcol = "protein", na.rm = TRUE) + qfeatures <- QFeatures::normalize(qfeatures, i = "proteins", name = "protNorm", method = "center.median") + } + + qfeatures +} diff --git a/R/visualise.R b/R/visualise.R new file mode 100644 index 0000000..a257b08 --- /dev/null +++ b/R/visualise.R @@ -0,0 +1,63 @@ +#' Launch a Shiny application to visualise QFeatures objects +#' +#' @description +#' \code{visualise()} launches an interactive Shiny application +#' that allows users to visualise a \linkS4class{QFeatures} object. +#' +#' The input \code{qfeatures} can be provided as an in-memory +#' \linkS4class{QFeatures} object, as a path to an \code{.rds} file +#' containing one, or omitted. If omitted, the application prompts the user +#' to upload a \linkS4class{QFeatures} object from an \code{.rds} file +#' or use the bundled demo dataset. +#' +#' @param qfeatures Optional \linkS4class{QFeatures} object to visualise, +#' or a character string specifying the path to an \code{.rds} file +#' containing one. If omitted or \code{NULL}, the app displays a startup +#' modal for uploading a file or loading the bundled demo. +#' +#' @param maxSize An integer that changes the \code{shiny.maxRequestSize} +#' value, in MB. This controls the maximum upload size for the startup +#' \code{.rds} file upload modal. +#' +#' @return +#' The visualise Shiny application. +#' +#' @export +#' +#' @importFrom shiny shinyApp runApp onStop +#' +#' @examples +#' +#' library(QFeaturesGUI) +#' +#' +#' app <- visualise() +#' +#' if (interactive()) { +#' shiny::runApp(app) +#' } +visualise <- function( + qfeatures = NULL, + maxSize = 100 +) { + qfeatures_missing <- missing(qfeatures) || is.null(qfeatures) + + if (!qfeatures_missing) { + qfeatures <- check_qfeatures(qfeatures) + } + + oldOptions <- options(shiny.maxRequestSize = maxSize * 1024^2) + onStop(function() options(oldOptions)) + addResourcePath( + "app-assets", + system.file("www", package = "QFeaturesGUI") + ) + + ui <- build_visualise_ui() + server <- build_visualise_server( + qfeatures, + has_qfeatures = !qfeatures_missing + ) + + shinyApp(ui = ui, server = server) +} diff --git a/README.md b/README.md index 7e33aed..608549a 100644 --- a/README.md +++ b/README.md @@ -34,12 +34,15 @@ analysis workflow. Currently available applications include: -- **Data import** (`importQFeatures`) +- **Data import** (`import`)\ Import quantitative proteomics data into `QFeatures` objects -- **Data processing** (`processQFeatures`) +- **Data processing** (`process`)\ Perform common data processing steps on `QFeatures` and `scp` objects +- **Data visualisation** (`visualise`)\ + Explore and visualise `QFeatures` objects + Additional applications will be added in future releases. diff --git a/_pkgdown.yml b/_pkgdown.yml index 2869ebc..ac7ede5 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -37,8 +37,13 @@ articles: reference: - title: Application launchers contents: - - importQFeatures - - processQFeatures + - import + - process + - visualise + + - title: Deprecated functions + contents: + - QFeaturesGUI-deprecated - title: Data contents: diff --git a/man/QFeaturesGUI-deprecated.Rd b/man/QFeaturesGUI-deprecated.Rd new file mode 100644 index 0000000..ef9ffe4 --- /dev/null +++ b/man/QFeaturesGUI-deprecated.Rd @@ -0,0 +1,43 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/deprecated.R +\name{QFeaturesGUI-deprecated} +\alias{QFeaturesGUI-deprecated} +\alias{importQFeatures} +\alias{processQFeatures} +\alias{visualizeQFeatures} +\title{Deprecated functions in QFeaturesGUI} +\usage{ +importQFeatures(...) + +processQFeatures(...) + +visualizeQFeatures(...) +} +\arguments{ +\item{...}{Arguments passed to the corresponding replacement function.} +} +\value{ +A Shiny application object returned by the replacement function. +} +\description{ +These functions are retained for compatibility with older versions of +QFeaturesGUI. They issue a deprecation warning and forward all arguments +to the replacement function. +} +\details{ +The following functions are deprecated: +\itemize{ +\item \code{importQFeatures()}: use \code{\link{import}()}. +\item \code{processQFeatures()}: use \code{\link{process}()}. +\item \code{visualizeQFeatures()}: use \code{\link{visualise}()}. +} +They are at the deprecated stage of the Bioconductor deprecation cycle +and may be made defunct in a future release cycle. +} +\examples{ +# Use import(), process(), and visualise() in new code. +import_app <- suppressWarnings(importQFeatures()) +process_app <- suppressWarnings(processQFeatures()) +visualise_app <- suppressWarnings(visualizeQFeatures()) +} +\keyword{internal} diff --git a/man/importQFeatures.Rd b/man/import.Rd similarity index 64% rename from man/importQFeatures.Rd rename to man/import.Rd index 8f7aafb..7b9e137 100644 --- a/man/importQFeatures.Rd +++ b/man/import.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/importQFeatures.R -\name{importQFeatures} -\alias{importQFeatures} +% Please edit documentation in R/import.R +\name{import} +\alias{import} \title{A shiny app to import QFeatures objects.} \usage{ -importQFeatures(colData = NULL, assayData = NULL, maxSize = 1000) +import(colData = NULL, assayData = NULL, maxSize = 1000) } \arguments{ \item{colData}{A data frame that contains the sample table.} @@ -14,10 +14,10 @@ importQFeatures(colData = NULL, assayData = NULL, maxSize = 1000) \item{maxSize}{An integer that changes the shiny.maxRequestSize value, in MB.} } \value{ -The "importQFeatures" Shiny app object. +The "import" Shiny app object. } \description{ -importQFeatures is a simple graphical interface to import bulk and single-cell proteomics data. +import is a simple graphical interface to import bulk and single-cell proteomics data. The app uses the \code{\link[QFeatures]{readQFeatures}} function from the QFeatures package to convert simple tables (single or multiple, CSV or TSV) to a QFeatures object. The app allows users to convert tables to a QFeatures object. } @@ -26,7 +26,7 @@ library(QFeaturesGUI) data("sampleTable") data("inputTable") -app <- importQFeatures(colData = sampleTable, assayData = inputTable, maxSize = 100) +app <- import(colData = sampleTable, assayData = inputTable, maxSize = 100) if (interactive()) { shiny::runApp(app) diff --git a/man/processQFeatures.Rd b/man/process.Rd similarity index 76% rename from man/processQFeatures.Rd rename to man/process.Rd index f173847..dfb26c9 100644 --- a/man/processQFeatures.Rd +++ b/man/process.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/processQFeatures.R -\name{processQFeatures} -\alias{processQFeatures} +% Please edit documentation in R/process.R +\name{process} +\alias{process} \title{Launch a Shiny application to process QFeatures objects} \usage{ -processQFeatures( +process( qfeatures = NULL, initialSets = NULL, prefilledSteps = c("sampleFiltering", "featureFiltering", "missingValuesFeatures", @@ -25,26 +25,37 @@ processing. If \code{NULL} and \code{qfeatures} is provided, all assays in the initial sets after uploading the \code{.rds} file.} \item{prefilledSteps}{A character vector specifying the initial workflow -steps to display when the application launches. Steps must be provided -using their internal identifiers (e.g. \code{"sampleFiltering"}, -\code{"featureFiltering"}, \code{"normalisation"}).} +steps to display when the application launches. Available steps are: +\itemize{ +\item \code{"sampleFiltering"} +\item \code{"featureFiltering"} +\item \code{"normalisation"} +\item \code{"zeroToNA"} +\item \code{"logTransform"} +\item \code{"imputation"} +\item \code{"missingValuesFeatures"} +\item \code{"missingValuesSamples"} +\item \code{"aggregation"} +\item \code{"join"} +}} \item{maxSize}{An integer that changes the \code{shiny.maxRequestSize} value, in MB. This controls the maximum upload size for the startup \code{.rds} file upload modal.} } \value{ -The processQFeatures Shiny application. +The process Shiny application. } \description{ -\code{processQFeatures()} launches an interactive Shiny application +\code{process()} launches an interactive Shiny application that allows users to visually configure and apply pre-processing workflows to a \linkS4class{QFeatures} object. The input \code{qfeatures} can be provided as an in-memory \linkS4class{QFeatures} object, as a path to an \code{.rds} file containing one, or omitted. If omitted, the application prompts the user -to upload a \linkS4class{QFeatures} object from an \code{.rds} file. +to upload a \linkS4class{QFeatures} object from an \code{.rds} file +or use the bundled demo dataset. } \details{ The application provides a drag-and-drop workflow builder that allows @@ -57,7 +68,7 @@ applied to the selected assays. library(QFeaturesGUI) -app <- processQFeatures() +app <- process() if (interactive()) { shiny::runApp(app) diff --git a/man/visualise.Rd b/man/visualise.Rd new file mode 100644 index 0000000..77fdf6c --- /dev/null +++ b/man/visualise.Rd @@ -0,0 +1,42 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/visualise.R +\name{visualise} +\alias{visualise} +\title{Launch a Shiny application to visualise QFeatures objects} +\usage{ +visualise(qfeatures = NULL, maxSize = 100) +} +\arguments{ +\item{qfeatures}{Optional \linkS4class{QFeatures} object to visualise, +or a character string specifying the path to an \code{.rds} file +containing one. If omitted or \code{NULL}, the app displays a startup +modal for uploading a file or loading the bundled demo.} + +\item{maxSize}{An integer that changes the \code{shiny.maxRequestSize} +value, in MB. This controls the maximum upload size for the startup +\code{.rds} file upload modal.} +} +\value{ +The visualise Shiny application. +} +\description{ +\code{visualise()} launches an interactive Shiny application +that allows users to visualise a \linkS4class{QFeatures} object. + +The input \code{qfeatures} can be provided as an in-memory +\linkS4class{QFeatures} object, as a path to an \code{.rds} file +containing one, or omitted. If omitted, the application prompts the user +to upload a \linkS4class{QFeatures} object from an \code{.rds} file +or use the bundled demo dataset. +} +\examples{ + +library(QFeaturesGUI) + + +app <- visualise() + +if (interactive()) { + shiny::runApp(app) +} +} diff --git a/tests/testthat/test-process.R b/tests/testthat/test-process.R new file mode 100644 index 0000000..3a34a8a --- /dev/null +++ b/tests/testthat/test-process.R @@ -0,0 +1,29 @@ +test_that("process can be constructed without a QFeatures object", { + app <- process() + + expect_s3_class(app, "shiny.appobj") +}) + +test_that("process startup initializes the selected assays and workflow", { + qf <- make_test_qfeatures() + path <- tempfile(fileext = ".rds") + saveRDS(qf, path) + + shiny::testServer( + build_process_server(NULL, integer(), character(), has_qfeatures = FALSE), + { + session$flushReact() + expect_null(.qf$qfeatures) + session$setInputs(startup_qfeatures_rds = data.frame(datapath = path)) + session$flushReact() + session$setInputs( + startup_initial_sets = "set2", + startup_load_qfeatures = 1 + ) + expect_identical(names(.qf$qfeatures), c("set1", "set2_(QFeaturesGUI#0)")) + expect_qfeatures_equal(summary_qfeatures(), .qf$qfeatures) + expect_identical(global_rv$workflow_config, character()) + } + ) +}) + diff --git a/tests/testthat/test-processQFeatures.R b/tests/testthat/test-processQFeatures.R deleted file mode 100644 index fa3c4b1..0000000 --- a/tests/testthat/test-processQFeatures.R +++ /dev/null @@ -1,5 +0,0 @@ -test_that("processQFeatures can be constructed without a QFeatures object", { - app <- processQFeatures() - - expect_s3_class(app, "shiny.appobj") -}) diff --git a/tests/testthat/test-shinytest2-importQFeatures.R b/tests/testthat/test-shinytest2-import.R similarity index 98% rename from tests/testthat/test-shinytest2-importQFeatures.R rename to tests/testthat/test-shinytest2-import.R index 451c55d..454f952 100644 --- a/tests/testthat/test-shinytest2-importQFeatures.R +++ b/tests/testthat/test-shinytest2-import.R @@ -6,7 +6,7 @@ test_that("{shinytest2}: twoTable_importQFeatures", { data("inputTable", package = "QFeaturesGUI") data("sampleTable", package = "QFeaturesGUI") - appObject <- importQFeatures( + appObject <- import( colData = sampleTable, assayData = inputTable ) @@ -90,7 +90,7 @@ test_that("{shinytest2}: oneTable_importQFeatures", { data("inputTable", package = "QFeaturesGUI") - appObject <- importQFeatures( + appObject <- import( assayData = inputTable ) diff --git a/tests/testthat/test-shinytest2-processQFeatures.R b/tests/testthat/test-shinytest2-process.R similarity index 96% rename from tests/testthat/test-shinytest2-processQFeatures.R rename to tests/testthat/test-shinytest2-process.R index 4ce3089..c23fd31 100644 --- a/tests/testthat/test-shinytest2-processQFeatures.R +++ b/tests/testthat/test-shinytest2-process.R @@ -96,10 +96,8 @@ make_process_test_qfeatures <- function() { )) } -add_expected_process_assays <- function( - qfeatures, processed_qfeatures, - step_number, type -) { +add_expected_process_assays <- function(qfeatures, processed_qfeatures, + step_number, type) { expected <- qfeatures for (assay_name in names(processed_qfeatures)) { expected[[paste0(assay_name, "_", type, "_", step_number)]] <- @@ -161,10 +159,10 @@ run_filtering_module_export <- function(qfeatures, type, condition_specs) { exported } -test_that("{shinytest2}: processQFeatures demo startup loads bundled QFeatures", { +test_that("{shinytest2}: process demo startup loads bundled QFeatures", { testthat::skip_on_cran() - appObject <- QFeaturesGUI::processQFeatures(prefilledSteps = character()) + appObject <- QFeaturesGUI::process(prefilledSteps = character()) app <- AppDriver$new( appObject, name = "processQFeatures_demo_startup", @@ -184,7 +182,7 @@ test_that("{shinytest2}: processQFeatures demo startup loads bundled QFeatures", ))) }) -test_that("{shinytest2} recording: processQFeatures", { +test_that("{shinytest2} recording: process", { testthat::skip_on_cran() data("inputTable", package = "QFeaturesGUI") @@ -197,12 +195,12 @@ test_that("{shinytest2} recording: processQFeatures", { removeEmptyCols = TRUE, verbose = FALSE ) - appObject <- QFeaturesGUI::processQFeatures(qf, prefilledSteps = c( + appObject <- QFeaturesGUI::process(qf, prefilledSteps = c( "zeroToNA", "logTransform", "sampleFiltering", "featureFiltering", "missingValuesFeatures", "missingValuesSamples", "normalisation", "aggregation", "join", "aggregation" )) app <- AppDriver$new(appObject, - name = "processQFeatures", height = 1619, width = 1080 + name = "process", height = 1619, width = 1080 ) on.exit(app$stop(), add = TRUE) @@ -312,7 +310,7 @@ test_that("{shinytest2}: zeroToNA exports the expected QFeatures object", { qf <- make_process_test_qfeatures() app <- AppDriver$new( - QFeaturesGUI::processQFeatures(qf, prefilledSteps = "zeroToNA"), + QFeaturesGUI::process(qf, prefilledSteps = "zeroToNA"), name = "processQFeatures_zeroToNA", height = 900, width = 1200 @@ -335,7 +333,7 @@ test_that("{shinytest2}: logTransform exports the expected QFeatures object", { qf <- make_process_test_qfeatures() app <- AppDriver$new( - QFeaturesGUI::processQFeatures(qf, prefilledSteps = "logTransform"), + QFeaturesGUI::process(qf, prefilledSteps = "logTransform"), name = "processQFeatures_logTransform", height = 900, width = 1200 @@ -425,7 +423,7 @@ test_that("{shinytest2}: normalisation exports the expected QFeatures object", { qf <- make_process_test_qfeatures() app <- AppDriver$new( - QFeaturesGUI::processQFeatures(qf, prefilledSteps = "normalisation"), + QFeaturesGUI::process(qf, prefilledSteps = "normalisation"), name = "processQFeatures_normalisation", height = 900, width = 1200 @@ -456,7 +454,7 @@ test_that("{shinytest2}: aggregation exports the expected QFeatures object", { qf <- make_process_test_qfeatures() app <- AppDriver$new( - QFeaturesGUI::processQFeatures(qf, prefilledSteps = "aggregation"), + QFeaturesGUI::process(qf, prefilledSteps = "aggregation"), name = "processQFeatures_aggregation", height = 900, width = 1200 diff --git a/tests/testthat/test-utils-global.R b/tests/testthat/test-utils-global.R index d9e29d0..a8aa43e 100644 --- a/tests/testthat/test-utils-global.R +++ b/tests/testthat/test-utils-global.R @@ -24,7 +24,7 @@ test_that("qfeatures_to_df summarises dimensions and strips GUI suffixes", { qf <- make_test_qfeatures() names(qf) <- c("set1_(QFeaturesGUI#0)", "set2_(QFeaturesGUI#0)") - summary <- qfeatures_to_df(qf) + summary <- qfeatures_to_df(qf, assay_labels = remove_QFeaturesGUI) expect_equal(summary$Name, c("set1", "set2")) expect_equal(summary$nFeatures, c(4, 2)) diff --git a/tests/testthat/test-utils-processQFeatures.R b/tests/testthat/test-utils-processQFeatures.R index 9d0b1cc..139b978 100644 --- a/tests/testthat/test-utils-processQFeatures.R +++ b/tests/testthat/test-utils-processQFeatures.R @@ -42,56 +42,6 @@ test_that("normalise_initial_sets rejects invalid selectors", { ) }) -test_that("check_qfeatures validates objects and RDS paths", { - qf <- make_test_qfeatures() - - expect_s4_class(check_qfeatures(qf), "QFeatures") - - path <- tempfile(fileext = ".rds") - saveRDS(qf, path) - expect_s4_class(check_qfeatures(path), "QFeatures") - - expect_error(check_qfeatures(), "argument is missing") - expect_error( - check_qfeatures(tempfile(fileext = ".rds")), - "does not exist" - ) - expect_error( - check_qfeatures(c("first.rds", "second.rds")), - "single path" - ) - expect_error( - check_qfeatures(data.frame(x = 1)), - "must be a QFeatures object" - ) - - bad_path <- tempfile(fileext = ".rds") - saveRDS(data.frame(x = 1), bad_path) - expect_error( - check_qfeatures(bad_path), - "RDS file does not contain a QFeatures object" - ) -}) - -test_that("demo_process_qfeatures builds the bundled zero-to-NA demo object", { - data("inputTable", package = "QFeaturesGUI") - data("sampleTable", package = "QFeaturesGUI") - - expected <- QFeatures::readQFeatures( - assayData = inputTable, - colData = sampleTable, - runCol = "Raw.file", - quantCols = NULL, - removeEmptyCols = TRUE, - verbose = FALSE - ) - expected <- QFeatures::zeroIsNA(expected, i = seq_along(expected)) - - object <- demo_process_qfeatures() - - expect_qfeatures_equal(object, expected) -}) - test_that("check_prefilled_steps maps valid workflow identifiers", { expect_equal( check_prefilled_steps(c("sampleFiltering", "normalisation", "join")), diff --git a/tests/testthat/test-utils-qfeatures.R b/tests/testthat/test-utils-qfeatures.R new file mode 100644 index 0000000..f0ffd5f --- /dev/null +++ b/tests/testthat/test-utils-qfeatures.R @@ -0,0 +1,49 @@ +test_that("check_qfeatures validates objects and RDS paths", { + qf <- make_test_qfeatures() + + expect_s4_class(check_qfeatures(qf), "QFeatures") + + path <- tempfile(fileext = ".rds") + saveRDS(qf, path) + expect_s4_class(check_qfeatures(path), "QFeatures") + + expect_error(check_qfeatures(), "argument is missing") + expect_error( + check_qfeatures(tempfile(fileext = ".rds")), + "does not exist" + ) + expect_error( + check_qfeatures(c("first.rds", "second.rds")), + "single path" + ) + expect_error( + check_qfeatures(data.frame(x = 1)), + "must be a QFeatures object" + ) + + bad_path <- tempfile(fileext = ".rds") + saveRDS(data.frame(x = 1), bad_path) + expect_error( + check_qfeatures(bad_path), + "RDS file does not contain a QFeatures object" + ) +}) + +test_that("demo_qfeatures builds the bundled zero-to-NA demo object", { + data("inputTable", package = "QFeaturesGUI") + data("sampleTable", package = "QFeaturesGUI") + + expected <- QFeatures::readQFeatures( + assayData = inputTable, + colData = sampleTable, + runCol = "Raw.file", + quantCols = NULL, + removeEmptyCols = TRUE, + verbose = FALSE + ) + expected <- QFeatures::zeroIsNA(expected, i = seq_along(expected)) + + object <- demo_qfeatures() + + expect_qfeatures_equal(object, expected) +}) diff --git a/tests/testthat/test-visualise.R b/tests/testthat/test-visualise.R new file mode 100644 index 0000000..51efcf9 --- /dev/null +++ b/tests/testthat/test-visualise.R @@ -0,0 +1,51 @@ +test_that("visualise accepts omitted, object, and RDS inputs", { + qf <- make_test_qfeatures() + path <- tempfile(fileext = ".rds") + saveRDS(qf, path) + + expect_s3_class(visualise(), "shiny.appobj") + expect_s3_class(visualise(NULL), "shiny.appobj") + expect_s3_class(visualise(qf), "shiny.appobj") + expect_s3_class(visualise(path), "shiny.appobj") + expect_error(visualise(data.frame(x = 1)), "must be a QFeatures object") + expect_error(visualise(tempfile()), "does not exist") +}) + +test_that("visualization updates after an upload and hides the startup button", { + qf <- make_test_qfeatures() + path <- tempfile(fileext = ".rds") + saveRDS(qf, path) + + shiny::testServer(build_visualise_server(NULL, has_qfeatures = FALSE), { + session$flushReact() + expect_null(current_qfeatures()) + expect_match(output$startup_upload_ui$html, "startup_show_upload") + + session$setInputs(startup_qfeatures_rds = data.frame(datapath = path)) + session$flushReact() + expect_null(current_qfeatures()) + session$setInputs(startup_load_qfeatures = 1) + expect_qfeatures_equal(current_qfeatures(), qf) + expect_null(output$startup_upload_ui) + expect_match(output[["visualize-qfeatures_plot"]], "set1") + expect_match(output[["visualize-qfeatures_plot"]], "set2") + }) +}) + +test_that("visualization loads the bundled demo and retains existing assay names", { + demo <- demo_qfeatures(fullProcessing = TRUE) + + shiny::testServer(build_visualise_server(NULL, has_qfeatures = FALSE), { + session$flushReact() + session$setInputs(startup_use_demo_qfeatures = 1) + session$flushReact() + expect_qfeatures_equal(current_qfeatures(), demo) + expect_null(output$startup_upload_ui) + }) + + shiny::testServer(build_visualise_server(demo, has_qfeatures = TRUE), { + session$flushReact() + expect_qfeatures_equal(current_qfeatures(), demo) + expect_null(output$startup_upload_ui) + }) +}) diff --git a/vignettes/QFeaturesGUI.Rmd b/vignettes/QFeaturesGUI.Rmd index 322494c..31c09a3 100644 --- a/vignettes/QFeaturesGUI.Rmd +++ b/vignettes/QFeaturesGUI.Rmd @@ -138,7 +138,7 @@ For example, the application dedicated to importing data into a `QFeatures` object can be launched as follows: ```{r, eval = FALSE} -app <- importQFeatures() +app <- import() if (interactive()) { shiny::runApp(app) @@ -148,7 +148,7 @@ if (interactive()) { Similarly, the application dedicated to data processing can be launched using: ```{r launch, eval = FALSE} -app <- processQFeatures(qfeaturesObject) +app <- process(qfeaturesObject) if (interactive()) { shiny::runApp(app) @@ -164,11 +164,11 @@ interface. The use of each application is described in a corresponding vignette: -- **Data import**: `importQFeatures` - See the [importQFeatures vignette](importQFeatures.html) +- **Data import**: `import`\ + See the [import vignette](importQFeatures.html) -- **Data processing**: `processQFeatures` - See the [processQFeatures vignette](processQFeatures.html) +- **Data processing**: `process`\ + See the [process vignette](processQFeatures.html) Additional applications will be introduced in future releases and documented in their own vignettes. diff --git a/vignettes/importQFeatures.Rmd b/vignettes/importQFeatures.Rmd index 87fedfd..b47606a 100644 --- a/vignettes/importQFeatures.Rmd +++ b/vignettes/importQFeatures.Rmd @@ -1,5 +1,5 @@ --- -title: "importQFeatures App" +title: "import App" author: - name: Léopold Guyot - name: Loïc Guille @@ -14,7 +14,7 @@ bibliography: QFeaturesGUI.bib date: "`r BiocStyle::doc_date()`" package: "`r BiocStyle::pkg_ver('QFeaturesGUI')`" vignette: > - %\VignetteIndexEntry{importQFeatures App} + %\VignetteIndexEntry{import App} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- @@ -118,7 +118,7 @@ on a row (corresponding to an assay), the selected assay will appear below, once again check if everything looks as expected. Once everything looks fine, you can download the QFeatures object to use it with R or -continue the analysis using the `processQFeatures()` function. +continue the analysis using the `process()` function. To download, click on the `Download` button (`E`); this will download a `.zip` file containing *initial_QFeatures.rds*, the QFeatures object on your computer, diff --git a/vignettes/processQFeatures.Rmd b/vignettes/processQFeatures.Rmd index ce04bab..ae92e57 100644 --- a/vignettes/processQFeatures.Rmd +++ b/vignettes/processQFeatures.Rmd @@ -1,5 +1,5 @@ --- -title: "processQFeatures App" +title: "process App" author: - name: Léopold Guyot - name: Loïc Guille @@ -14,7 +14,7 @@ bibliography: QFeaturesGUI.bib date: "`r BiocStyle::doc_date()`" package: "`r BiocStyle::pkg_ver('QFeaturesGUI')`" vignette: > - %\VignetteIndexEntry{processQFeatures App} + %\VignetteIndexEntry{process App} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- @@ -31,10 +31,10 @@ knitr::opts_chunk$set( library(QFeaturesGUI) ``` -This app can be used once the data from `importQFeatures()` have been downloaded. In order to +This app can be used once the data from `import()` have been downloaded. In order to do that, unzip the folder downloaded, and load the RDS that contain the QFeatures object in your R -environment or pass directly the path as an argument when using `processQFeatures()`. -You can also directly start the application `processQFeatures()` and load the RDS into +environment or pass directly the path as an argument when using `process()`. +You can also directly start the application `process()` and load the RDS into the application. # Start the app