├── .Rbuildignore ├── .gitignore ├── .travis.yml ├── CONTRIBUTING.rst ├── DESCRIPTION ├── GRPC.rst ├── GoogleGenomics.Rproj ├── LICENSE ├── NAMESPACE ├── NEWS ├── R ├── GoogleGenomics.R ├── authenticate.R ├── client.R ├── grpc.R ├── reads.R ├── variants.R └── zzz.R ├── README.rst ├── cleanup ├── configure ├── configure.ac ├── configure.win ├── man ├── GoogleGenomics.Rd ├── authenticate.Rd ├── callGRPCMethod.Rd ├── defaultGcloudCredsPath.Rd ├── getRProtoBufDefaultObject.Rd ├── getReads.Rd ├── getReadsPage.Rd ├── getSearchPage.Rd ├── getVariantCalls.Rd ├── getVariants.Rd ├── getVariantsPage.Rd ├── isGRPCAvailable.Rd ├── readsToGAlignments.Rd ├── variantsToGRanges.Rd └── variantsToVRanges.Rd ├── shiny └── .gitignore ├── src ├── Makevars.in ├── Makevars.win ├── README.rst ├── client-annotations.cc ├── client-common.cc ├── client-common.h ├── client-datasets.cc ├── client-reads.cc ├── client-references.cc ├── client-variants.cc ├── google │ ├── api │ │ ├── annotations.proto │ │ └── http.proto │ ├── genomics │ │ └── v1 │ │ │ ├── annotations.proto │ │ │ ├── cigar.proto │ │ │ ├── datasets.proto │ │ │ ├── operations.proto │ │ │ ├── position.proto │ │ │ ├── range.proto │ │ │ ├── readalignment.proto │ │ │ ├── readgroup.proto │ │ │ ├── readgroupset.proto │ │ │ ├── reads.proto │ │ │ ├── references.proto │ │ │ └── variants.proto │ ├── iam │ │ └── v1 │ │ │ ├── iam_policy.proto │ │ │ └── policy.proto │ ├── longrunning │ │ └── operations.proto │ └── rpc │ │ ├── code.proto │ │ └── status.proto ├── init.cc ├── rprotobuf.cc └── rprotobuf.h ├── tests ├── runTests.R └── testthat │ ├── test-getReads.R │ ├── test-getVariantCalls.R │ └── test-getVariants.R └── vignettes ├── AnnotatingVariants.Rmd ├── PlottingAlignments.Rmd └── VariantAnnotation-comparison-test.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^\.httr-oauth$ 4 | ^\.travis\.yml$ 5 | ^inst\/doc\/.*\.md$ 6 | ^shiny$ 7 | ^README\.rst$ 8 | ^CONTRIBUTING\.rst$ 9 | \.pb\.cc$ 10 | \.pb\.h$ 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *~ 3 | .Rapp.history 4 | .Rhistory 5 | .RData 6 | .httr-oauth 7 | .Rproj.user 8 | *.Rproj 9 | *.html 10 | *.tex 11 | .DS_Store 12 | config.status 13 | config.log 14 | *.o 15 | *.so 16 | *.pb.cc 17 | *.pb.h 18 | src/Makevars 19 | src/config.h 20 | src/symbols.rds 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: r 2 | sudo: false 3 | cache: packages 4 | 5 | # For RProtoBuf dependency in Suggests. 6 | addons: 7 | apt: 8 | packages: 9 | - libprotobuf-dev 10 | - libprotoc-dev 11 | 12 | # Package caching only makes sense for the release versions. 13 | r: bioc-release 14 | 15 | warnings_are_errors: false 16 | r_build_args: 17 | # Secure auth credentials can not be made available for pull requests. 18 | r_check_args: "$(if [[ $TRAVIS_PULL_REQUEST != 'false' ]]; then echo '--no-examples'; fi)" 19 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | How to contribute 2 | ================= 3 | 4 | First of all, thank you for contributing! 5 | 6 | The mailing list 7 | ---------------- 8 | 9 | For general questions or if you are having trouble getting started, try the 10 | `Google Genomics Discuss mailing list `_. 11 | It's a good way to sync up with other people who use googlegenomics including the core developers. You can subscribe 12 | by sending an email to ``google-genomics-discuss+subscribe@googlegroups.com`` or just post using 13 | the `web forum page `_. 14 | 15 | 16 | Submitting issues 17 | ----------------- 18 | 19 | If you are encountering a bug in the code or have a feature request in mind - file away! 20 | 21 | 22 | Submitting a pull request 23 | ------------------------- 24 | 25 | If you are ready to contribute code, Github provides a nice `overview on how to create a pull request 26 | `_. 27 | 28 | Some general rules to follow: 29 | 30 | * Do your work in `a fork `_ of this repo. 31 | * Create a branch for each update that you're working on. 32 | These branches are often called "feature" or "topic" branches. Any changes 33 | that you push to your feature branch will automatically be shown in the pull request. 34 | * Keep your pull requests as small as possible. Large pull requests are hard to review. 35 | Try to break up your changes into self-contained and incremental pull requests. 36 | * The first line of commit messages should be a short (<80 character) summary, 37 | followed by an empty line and then any details that you want to share about the commit. 38 | * Please try to follow the existing syntax style. 39 | 40 | When testing your changes, setup the environment variable GOOGLE_API_KEY to contain the public API 41 | key from your Google Developer Console with the Genomics API enabled. This will enable the tests 42 | and the vignettes to be run, which are otherwise short-circuited in the absence of auth credentials. 43 | With the environment variable set, build the package and run checks as follows: 44 | 45 | .. code:: sh 46 | 47 | export GOOGLE_API_KEY= 48 | R CMD build GoogleGenomics 49 | R CMD check GoogleGenomics_.tar.gz 50 | 51 | Optionally, you can also enable Travis for your fork and set up the environment variable in your 52 | `Travis settings `_ so that 53 | these tests are run automatically whenever you push to your feature branch. 54 | 55 | When you submit or change your pull request, the Travis build system will automatically build the 56 | package and run standard tests. A pull request does not acquire secure environment variables and 57 | will skip running unit tests and vignettes. If you set up Travis for your fork, a link to your 58 | Travis build in the pull request will speed up the review process. If your pull request fails to 59 | pass tests, review the test log, make changes and then push them to your feature branch to be tested 60 | again. 61 | 62 | 63 | C++ Code 64 | -------- 65 | 66 | If you want to change the C++ code, follow the `README `_ inside the 67 | src directory. 68 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: GoogleGenomics 2 | Version: 2.5.0 3 | Title: R Client for Google Genomics API 4 | Author: Cassie Doll, Nicole Deflaux 5 | Maintainer: Siddhartha Bagaria 6 | Authors@R: c(person("Cassie", "Doll", role = c("aut")), 7 | person("Nicole", "Deflaux", role = c("aut")), 8 | person("Siddhartha", "Bagaria", role = c("aut", "cre"), 9 | email="bagaria.siddhartha@gmail.com")) 10 | Depends: 11 | R (>= 3.1.0), 12 | GenomicAlignments (>= 1.0.1), 13 | VariantAnnotation 14 | Imports: 15 | Biostrings, 16 | GenomeInfoDb, 17 | GenomicRanges, 18 | IRanges, 19 | httr, 20 | rjson, 21 | Rsamtools, 22 | S4Vectors (>= 0.9.25), 23 | Biobase, 24 | methods, 25 | utils 26 | Suggests: 27 | BiocStyle, 28 | RProtoBuf, 29 | httpuv, 30 | knitr, 31 | rmarkdown, 32 | testthat, 33 | ggbio, 34 | ggplot2, 35 | BSgenome.Hsapiens.UCSC.hg19, 36 | org.Hs.eg.db, 37 | TxDb.Hsapiens.UCSC.hg19.knownGene 38 | Description: Provides an R package to interact with the Google Genomics API. 39 | SystemRequirements: GNU make 40 | VignetteBuilder: knitr 41 | License: Apache License (== 2.0) | file LICENSE 42 | URL: https://cloud.google.com/genomics/ 43 | BugReports: https://github.com/Bioconductor/GoogleGenomics/issues 44 | biocViews: DataImport, ThirdPartyClient, Genetics 45 | RoxygenNote: 6.0.1 46 | PackageStatus: Deprecated 47 | -------------------------------------------------------------------------------- /GRPC.rst: -------------------------------------------------------------------------------- 1 | GoogleGenomics with gRPC 2 | ======================== 3 | 4 | .. role:: r(code) 5 | :language: r 6 | 7 | .. role:: sh(code) 8 | :language: sh 9 | 10 | `gRPC`_ is an RPC framework designed to be performant for large streams of data 11 | exchanges with remote services. The framework also allows for easy service 12 | definition in the form of protocol buffers. 13 | 14 | Google Genomics API offers gRPC endpoints and recommends using streaming method 15 | equivalents for large streams of reads and variants. With streaming gRPC, there 16 | is no need for paginated responses, and the entire data range is received as 17 | part of one response. 18 | 19 | .. _gRPC: https://grpc.io/ 20 | .. _Homebrew: https://brew.sh/ 21 | 22 | Installing 23 | ---------- 24 | 25 | Windows 26 | This R package currently does not have support for gRPC in Windows. 27 | 28 | MacOS 29 | Our recommendation is to use the `Homebrew`_ package manager to install gRPC 30 | and all dependencies. Once Homebrew is set up, you can install gRPC by 31 | 32 | :sh:`brew install grpc` 33 | 34 | Linux 35 | Install from source (see below). 36 | 37 | Source 38 | You may need these prerequisites to install from source: 39 | 40 | .. code:: sh 41 | 42 | [sudo] apt-get install build-essential autoconf libtool 43 | 44 | Download the current release version of gRPC and install with the included 45 | SSL libraries. Using the system SSL libraries may not work for you if your 46 | particular version has not been tested with gRPC. 47 | 48 | .. code:: sh 49 | 50 | git clone -b $(curl -L https://grpc.io/release) https://github.com/grpc/grpc 51 | cd grpc 52 | git submodule update --init 53 | [sudo] make HAS_SYSTEM_OPENSSL_NPN=false HAS_SYSTEM_OPENSSL_ALPN=false install 54 | [sudo] make -C third_party/protobuf install 55 | 56 | 57 | R Package setup 58 | --------------- 59 | 60 | The R package will look for gRPC libraries during the package configuration 61 | step. Be sure to select :r:`type="source"` when running :r:`biocLite` or 62 | :r:`install.packages`. 63 | 64 | The package will search in standard locations, and use the :sh:`pkg-config` 65 | tool, if available on your machine, to get the parameters. If unable to find, 66 | you will need to specify the path manually. For example, if your install 67 | location is :sh:`/opt/local/`: 68 | 69 | .. code:: r 70 | 71 | biocLite("GoogleGenomics", type="source", 72 | configure.args=paste("--with-grpc-include='/opt/local/include'", 73 | "--with-grpc-libs='/opt/local/lib'", 74 | "--with-grpc-bin='/opt/local/bin'")) 75 | 76 | Or from github: 77 | 78 | .. code:: r 79 | 80 | devtools::install_github("Bioconductor/GoogleGenomics", force=TRUE, 81 | args=paste0("--configure-args='", 82 | "--with-grpc-include=/opt/local/include ", 83 | "--with-grpc-libs=/opt/local/lib ", 84 | "--with-grpc-bin=/opt/local/bin'")) 85 | 86 | You can also use the environment variables :sh:`GRPC_INCLUDE_PATH`, 87 | :sh:`GRPC_LIBS_PATH` and :sh:`GRPC_BIN_PATH` to specify the same parameters 88 | as above. 89 | 90 | Usage 91 | ----- 92 | 93 | You can use the :r:`callGRPCMethod` method to call any Google Genomics v1 API 94 | method. The request parameters can be supplied as a json string, in which case 95 | the response will also be returned as a json string. The other option is to 96 | use an :r:`RProtoBuf` message suitably modified to contain the request 97 | parameters; use the :r:`getRProtoBufDefaultObject` method to get a default 98 | instance that you can modify. The response will be an :r:`RProtoBuf` object. 99 | 100 | The :r:`getReads` and :r:`getVariants` methods will default to using gRPC 101 | streaming methods if the package could find gRPC libraries when installing 102 | itself. The default behavior can be controlled by the option 103 | :r:`google_genomics_use_grpc`. 104 | 105 | 106 | Limitations 107 | ----------- 108 | 109 | - For Google Genomics API, the set of fields returned might be different with 110 | gRPC but all essential fields should be present in both methods, and will 111 | have the same names. 112 | 113 | - API key mode of authentication does not work with gRPC. 114 | 115 | -------------------------------------------------------------------------------- /GoogleGenomics.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageInstallArgs: --no-multiarch --with-keep.source 20 | PackageCheckArgs: --as-cran 21 | PackageRoxygenize: rd 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | useDynLib(GoogleGenomics, .registration = TRUE, .fixes = "C_") 2 | 3 | ## API related imports ## 4 | import(httr) 5 | import(methods) 6 | importFrom(rjson, fromJSON, toJSON) 7 | 8 | ## Bioc utility functions and S4 constructors ## 9 | import(S4Vectors) 10 | importFrom(Biobase, "sampleNames<-") 11 | importFrom(Biostrings, DNAStringSet, DNAStringSetList) 12 | importFrom(GenomeInfoDb, "seqlevelsStyle<-") 13 | importFrom(GenomicAlignments, GAlignments) 14 | importFrom(GenomicRanges, GRanges) 15 | importFrom(IRanges, IRanges) 16 | importFrom(Rsamtools, bamFlagAsBitMatrix) 17 | importFrom(VariantAnnotation, strand, VRanges) 18 | 19 | ## Utility imports ## 20 | importFrom(utils, installed.packages) 21 | 22 | #### Exports #### 23 | 24 | ## Authentication ## 25 | export(authenticate) 26 | export(defaultGcloudCredsPath) 27 | 28 | ## Generic Search ## 29 | export(getSearchPage) 30 | 31 | ## gRPC ## 32 | export(callGRPCMethod) 33 | export(getRProtoBufDefaultObject) 34 | export(isGRPCAvailable) 35 | 36 | ## Reads ## 37 | export(getReadsPage) 38 | export(getReads) 39 | export(readsToGAlignments) 40 | 41 | ## Variants ## 42 | export(getVariantsPage) 43 | export(getVariantCalls) 44 | export(getVariants) 45 | export(variantsToGRanges) 46 | export(variantsToVRanges) 47 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | CHANGES IN VERSION 2.0.0 2 | ------------------------ 3 | gRPC support and more authentication options. 4 | 5 | o Can use gRPC to access the entire method set in v1 API. 6 | 7 | o Support for application default credentials. 8 | 9 | o Support for GCE service account credentials. 10 | 11 | CHANGES IN VERSION 1.1.3 12 | ------------------------ 13 | Refactoring of material in variant annotation vignettes. 14 | 15 | CHANGES IN VERSION 1.1.2 16 | ------------------------ 17 | Added additional introductory material to the vignettes. 18 | 19 | CHANGES IN VERSION 1.1.1 20 | ------------------------ 21 | use rowRanges() instead of defunct rowData() 22 | 23 | CHANGES IN VERSION 1.0.0 24 | ------------------------ 25 | 26 | NEW FEATURES 27 | 28 | o Authentication support for native apps, service accounts, and API keys. 29 | 30 | o Support for retreiving Reads and Variants. 31 | 32 | o Simple converters to GAlignments for Reads, and GRanges and VRanges for 33 | Variants. 34 | -------------------------------------------------------------------------------- /R/GoogleGenomics.R: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Google Inc. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the 'License'); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an 'AS IS' BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | #' A basic R package for Google Genomics API. 16 | #' 17 | #' For more details, read the package README. 18 | #' 19 | #' @docType package 20 | #' @name GoogleGenomics 21 | NULL 22 | -------------------------------------------------------------------------------- /R/client.R: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Google Inc. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the 'License'); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an 'AS IS' BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | #' Get one page of search results for a particular entity type from Google 16 | #' Genomics. 17 | #' 18 | #' In general, use higher level methods such as getReads and getVariants 19 | #' instead. 20 | #' 21 | #' @param entityType Entities with a search API such as reads, variants, 22 | #' variantSets, etc... 23 | #' @param body The body of the message to POST to the search endpoint. 24 | #' @param fields The fields to be returned in the search response. 25 | #' @param pageToken The page token. This can be NULL for the first page. 26 | #' 27 | #' @return The raw response converted from JSON to an R object. 28 | #' @family page fetch functions 29 | #' @examples 30 | #' # Authenticated on package load from the env variable GOOGLE_API_KEY. 31 | #' body <- list(readGroupSetIds=list("CMvnhpKTFhDnk4_9zcKO3_YB"), 32 | #' referenceName="22", 33 | #' start=16051400, end=16051500, pageToken=NULL) 34 | #' reads <- getSearchPage("reads", body, NULL, NULL) 35 | #' summary(reads) 36 | getSearchPage <- function(entityType, body, fields, pageToken) { 37 | 38 | if (missing(entityType)) { 39 | stop("Missing required parameter entityType") 40 | } 41 | if (missing(body)) { 42 | stop("Missing required parameter body") 43 | } 44 | if (missing(fields)) { 45 | stop("Missing required parameter fields") 46 | } 47 | if (missing(pageToken)) { 48 | stop("Missing required parameter pageToken") 49 | } 50 | 51 | if (!authenticated()) { 52 | stop("You are not authenticated; see ?GoogleGenomics::authenticate.") 53 | } 54 | 55 | queryParams <- list() 56 | queryConfig <- config() 57 | 58 | if (!is.null(fields)) { 59 | if (!grepl("nextPageToken", fields)) { 60 | fields <- paste(fields, "nextPageToken", sep=",") 61 | } 62 | queryParams <- list(fields=fields) 63 | } 64 | 65 | if (.authStore$use_api_key) { 66 | queryParams <- c(queryParams, key=.authStore$api_key) 67 | } else { 68 | queryConfig <- config(token=.authStore$google_token) 69 | } 70 | 71 | message(paste("Fetching", entityType, "page.")) 72 | response <- POST(paste(getOption("google_genomics_endpoint"), 73 | tolower(entityType), 74 | "search", 75 | sep="/"), 76 | query=queryParams, 77 | body=toJSON(body), 78 | queryConfig, 79 | add_headers("Content-Type"="application/json")) 80 | 81 | checkResponse(response) 82 | 83 | content(response) 84 | } 85 | 86 | checkResponse <- function(response) { 87 | messages <- list() 88 | 89 | # Check for error messages in response body. 90 | # TODO: other API responses can succeed but still include warnings. 91 | # Emit those here as well. 92 | if ("error" %in% names(content(response))) { 93 | messages <- c(messages, paste("ERROR:", content(response)$error[[3]])) 94 | } 95 | 96 | # Check for specific status codes for which we would like to return specific 97 | # messages. 98 | if (403 == status_code(response)) { 99 | if (.authStore$use_api_key) { 100 | messages <- c(messages, paste("Authentication error; please check the", 101 | "public API key you provided. See", 102 | "?GoogleGenomics::authenticate for", 103 | "details.")) 104 | } else { 105 | messages <- c(messages, paste("Authentication error; please try to run", 106 | "GoogleGenomics::authenticate again. If", 107 | "the problem persists, please contact", 108 | "Google Genomics support.")) 109 | } 110 | } else if (400 == status_code(response)) { 111 | if (.authStore$use_api_key) { 112 | messages <- c(messages, paste("This could be from an incorrect public", 113 | "API key. See", 114 | "?GoogleGenomics::authenticate for", 115 | "details.")) 116 | } 117 | } 118 | 119 | if (0 != length(messages)) { 120 | warning(paste(messages, collapse="\n"), immediate.=TRUE) 121 | } 122 | 123 | # Lastly, emit a general message and stop for status code >= 300. 124 | stop_for_status(response) 125 | } 126 | -------------------------------------------------------------------------------- /R/grpc.R: -------------------------------------------------------------------------------- 1 | # Copyright 2017 GoogleGenomics R package authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the 'License'); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an 'AS IS' BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | #' Returns if this package was built with gRPC support. 16 | #' 17 | #' @return TRUE iff the package was built with gRPC support. 18 | isGRPCAvailable <- function() { 19 | # Value will be substituted when running the configure script. 20 | isTRUE(.Call(C_builtWithGRPC)) 21 | } 22 | 23 | #' Returns a protocol buffer Message object from 24 | #' \code{\link[RProtoBuf]{RProtoBuf}}. 25 | #' 26 | #' Needs gRPC support at package build time and the RProtoBuf package. 27 | #' See package README for instructions on installing gRPC. 28 | #' 29 | #' @param fullyQualifiedName Type of the message object to return. 30 | #' 31 | #' @return Default instance of the Message. 32 | #' @examples 33 | #' if (isGRPCAvailable()) { 34 | #' getRProtoBufDefaultObject("google.genomics.v1.SearchReadsRequest") 35 | #' } 36 | getRProtoBufDefaultObject <- function(fullyQualifiedName) { 37 | stopifnot(isGRPCAvailable()) 38 | stopifnot(requireNamespace("RProtoBuf")) 39 | 40 | # We lookup the object dynamically because it is available only with gRPC. 41 | .Call(get0("C_GetRProtoBufMessage"), fullyQualifiedName) 42 | } 43 | 44 | #' Issues a gRPC call to the Google Genomics service and returns the 45 | #' response. 46 | #' 47 | #' Needs gRPC support at package build time and the RProtoBuf package. 48 | #' See package README for instructions on installing gRPC. 49 | #' 50 | #' In general, use higher level methods such as getReads and getVariants 51 | #' instead. 52 | #' 53 | #' @param methodName The RPC method name. 54 | #' @param request The request object for the RPC, either as a JSON object 55 | #' generated from \code{\link[rjson]{rjson}}, or as a 56 | #' \code{\link[RProtoBuf]{RProtoBuf}} object modified from the 57 | #' default instance obtained from 58 | #' \code{\link{getRProtoBufDefaultObject}}. 59 | #' 60 | #' @return The raw response converted from JSON to an R object, or the 61 | #' RProtoBuf object if the request was an RProtoBuf object. 62 | #' @family page fetch functions 63 | #' @examples 64 | #' # Authenticated on package load from the env variable GOOGLE_API_KEY. 65 | #' if (isGRPCAvailable()) { 66 | #' request <- list(readGroupSetIds=list("CMvnhpKTFhDnk4_9zcKO3_YB"), 67 | #' referenceName="22", 68 | #' start=16051400, end=16051500, pageToken=NULL) 69 | #' reads <- callGRPCMethod("SearchReads", request) 70 | #' summary(reads) 71 | #' } else { 72 | #' message("gRPC support is disabled; package was not compiled with GRPC") 73 | #' } 74 | callGRPCMethod <- function(methodName, request) { 75 | stopifnot(isGRPCAvailable()) 76 | 77 | if (!is.character(request) && !is(request, "Message")) { 78 | warning("Invalid request type") 79 | return(NULL) 80 | } 81 | 82 | method <- get0(paste0("C_", methodName)) 83 | if (is.null(method)) { 84 | warning("Invalid method name for Google Genomics API: ", methodName) 85 | return(NULL) 86 | } 87 | 88 | .Call(method, request, getGRPCCreds()) 89 | } 90 | -------------------------------------------------------------------------------- /R/reads.R: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Google Inc. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the 'License'); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an 'AS IS' BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | #' Get one page of reads from Google Genomics. 16 | #' 17 | #' In general, use the getReads method instead. It calls this method, 18 | #' returning reads from all of the pages that comprise the requested 19 | #' genomic range. 20 | #' 21 | #' By default, this function gets reads for a small genomic region for one 22 | #' sample in 1,000 Genomes. 23 | #' 24 | #' Note that the Global Alliance for Genomics and Health API uses a 0-based 25 | #' coordinate system. For more detail, please see GA4GH discussions such 26 | #' as the following: 27 | #' \itemize{ 28 | #' \item\url{https://github.com/ga4gh/schemas/issues/168} 29 | #' \item\url{https://github.com/ga4gh/schemas/issues/121} 30 | #'} 31 | #' 32 | #' @param readGroupSetId The read group set ID. 33 | #' @param chromosome The chromosome. 34 | #' @param start Start position on the chromosome in 0-based coordinates. 35 | #' @param end End position on the chromosome in 0-based coordinates. 36 | #' @param fields A subset of fields to retrieve. The default (NULL) will 37 | #' return all fields. 38 | #' @param pageToken The page token. This can be NULL (default) for the first 39 | #' page. 40 | #' @return A two-element list is returned by the function. 41 | #' 42 | #' reads: A list of R objects corresponding to the JSON objects returned 43 | #' by the Google Genomics Reads API. 44 | #' 45 | #' nextPageToken: The token to be used to retrieve the next page of 46 | #' results, if applicable. 47 | #' @family page fetch functions 48 | #' @examples 49 | #' # Authenticated on package load from the env variable GOOGLE_API_KEY. 50 | #' readsPage <- getReadsPage() 51 | #' summary(readsPage) 52 | #' summary(readsPage$reads[[1]]) 53 | getReadsPage <- function(readGroupSetId="CMvnhpKTFhDnk4_9zcKO3_YB", 54 | chromosome="22", 55 | start=16051400, 56 | end=16051500, 57 | fields=NULL, 58 | pageToken=NULL) { 59 | 60 | body <- list(readGroupSetIds=list(readGroupSetId), referenceName=chromosome, 61 | start=start, end=end, pageToken=pageToken) 62 | 63 | results <- getSearchPage("reads", body, fields, pageToken) 64 | 65 | list(reads=results$alignments, nextPageToken=results$nextPageToken) 66 | } 67 | 68 | streamReads <- function(readGroupSetId, chromosome, start, end) { 69 | if (missing(readGroupSetId) || missing(chromosome) || 70 | missing(start) || missing(end)) { 71 | stop("All arguments need to be provided to streamReads.") 72 | } 73 | 74 | body <- list(readGroupSetId = readGroupSetId, referenceName = chromosome, 75 | start = start, end = end) 76 | 77 | callGRPCMethod("StreamReads", toJSON(body)) 78 | } 79 | 80 | #' Get reads from Google Genomics. 81 | #' 82 | #' This function will return all of the reads that comprise the requested 83 | #' genomic range, iterating over paginated results as necessary. 84 | #' 85 | #' By default, this function gets reads for a small genomic region for one 86 | #' sample in 1,000 Genomes. 87 | #' 88 | #' Optionally pass a converter as appropriate for your use case. By passing it 89 | #' to this method, only the converted objects will be accumulated in memory. 90 | #' The converter function should return an empty container of the desired type 91 | #' if called without any arguments. 92 | #' 93 | #' @param readGroupSetId The read group set ID. 94 | #' @param chromosome The chromosome. 95 | #' @param start Start position on the chromosome in 0-based coordinates. 96 | #' @param end End position on the chromosome in 0-based coordinates. 97 | #' @param fields A subset of fields to retrieve. The default (NULL) will 98 | #' return all fields. 99 | #' @param converter A function that takes a list of read R objects and returns 100 | #' them converted to the desired type. 101 | #' @param useGRPC Whether to use GRPC mechanism to query. 102 | #' @return By default, the return value is a list of R objects 103 | #' corresponding to the JSON objects returned by the Google Genomics 104 | #' Reads API. If a converter is passed, object(s) of the type 105 | #' returned by the converter will be returned by this function. 106 | #' @seealso \code{\link{getVariants}} 107 | #' @examples 108 | #' # Authenticated on package load from the env variable GOOGLE_API_KEY. 109 | #' reads <- getReads() 110 | #' summary(reads) 111 | #' summary(reads[[1]]) 112 | getReads <- function(readGroupSetId="CMvnhpKTFhDnk4_9zcKO3_YB", 113 | chromosome="22", 114 | start=16051400, 115 | end=16051500, 116 | fields=NULL, 117 | converter=c, 118 | useGRPC = getOption("google_genomics_use_grpc")) { 119 | if (isTRUE(useGRPC)) { 120 | stopifnot(isGRPCAvailable()) 121 | result <- streamReads(readGroupSetId, chromosome, start, end) 122 | if (is.null(result)) { 123 | stop("Something went wrong. Check printed messages above.") 124 | } 125 | return(converter(fromJSON(result)$alignments)) 126 | } 127 | 128 | pageToken <- NULL 129 | reads <- converter() 130 | repeat { 131 | result <- getReadsPage(readGroupSetId=readGroupSetId, 132 | chromosome=chromosome, 133 | start=start, 134 | end=end, 135 | fields=fields, 136 | pageToken=pageToken) 137 | pageToken <- result$nextPageToken 138 | # TODO improve performance, 139 | # see https://github.com/Bioconductor/GoogleGenomics/issues/17 140 | reads <- c(reads, converter(result$reads)) 141 | if (is.null(pageToken) || pageToken == "") { 142 | break 143 | } 144 | message(paste("Continuing read query with the nextPageToken:", pageToken)) 145 | } 146 | 147 | message("Reads are now available.") 148 | reads 149 | } 150 | 151 | # Transformation helpers 152 | cigar_enum_map <- list( 153 | ALIGNMENT_MATCH="M", 154 | CLIP_HARD="H", 155 | CLIP_SOFT="S", 156 | DELETE="D", 157 | INSERT="I", 158 | PAD="P", 159 | SEQUENCE_MATCH="=", 160 | SEQUENCE_MISMATCH="X", 161 | SKIP="N") 162 | 163 | getCigar <- function(read) { 164 | paste( 165 | sapply( 166 | read$alignment$cigar, 167 | function(cigarPiece) { 168 | paste0(cigarPiece$operationLength, 169 | cigar_enum_map[cigarPiece$operation]) 170 | }), 171 | collapse="") 172 | } 173 | 174 | getPosition <- function(read) { 175 | as.integer(read$alignment$position$position) 176 | } 177 | 178 | getReferenceName <- function(read) { 179 | read$alignment$position$referenceName 180 | } 181 | 182 | getFlags <- function(read) { 183 | flags <- 0 184 | 185 | if (isTRUE(read$numberReads == 2)) { 186 | flags <- flags + 1 # read_paired 187 | } 188 | if (isTRUE(read$properPlacement)) { 189 | flags <- flags + 2 # read_proper_pair 190 | } 191 | if (is.null(getPosition(read))) { 192 | flags <- flags + 4 # read_unmapped 193 | } 194 | if (is.null(read$nextMatePosition$position)) { 195 | flags <- flags + 8 # mate_unmapped 196 | } 197 | if (isTRUE(read$alignment$position$reverseStrand)) { 198 | flags <- flags + 16 # read_reverse_strand 199 | } 200 | if (isTRUE(read$nextMatePosition$reverseStrand)) { 201 | flags <- flags + 32 # mate_reverse_strand 202 | } 203 | if (isTRUE(read$readNumber == 0)) { 204 | flags <- flags + 64 # first_in_pair 205 | } 206 | if (isTRUE(read$readNumber == 1)) { 207 | flags <- flags + 128 # second_in_pair 208 | } 209 | if (isTRUE(read$secondaryAlignment)) { 210 | flags <- flags + 256 # secondary_alignment 211 | } 212 | if (isTRUE(read$failedVendorQualityChecks)) { 213 | flags <- flags + 512 # failed_quality_check 214 | } 215 | if (isTRUE(read$duplicateFragment)) { 216 | flags <- flags + 1024 # duplicate_read 217 | } 218 | if (isTRUE(read$supplementaryAlignment)) { 219 | flags <- flags + 2048 # supplementary_alignment 220 | } 221 | flags 222 | } 223 | 224 | #' Convert reads to GAlignments. 225 | #' 226 | #' Note that the Global Alliance for Genomics and Health API uses a 0-based 227 | #' coordinate system. For more detail, please see GA4GH discussions such 228 | #' as the following: 229 | #' \itemize{ 230 | #' \item\url{https://github.com/ga4gh/schemas/issues/168} 231 | #' \item\url{https://github.com/ga4gh/schemas/issues/121} 232 | #' } 233 | #' 234 | #' @param reads A list of R objects corresponding to the JSON objects 235 | #' returned by the Google Genomics Reads API. 236 | #' @param oneBasedCoord Convert genomic positions to 1-based coordinates. 237 | #' @param slStyle The style for seqnames (chrN or N or...). Default is UCSC. 238 | #' @return \link[GenomicAlignments]{GAlignments} 239 | #' @family reads converter functions 240 | #' @examples 241 | #' # Authenticated on package load from the env variable GOOGLE_API_KEY. 242 | #' alignments1 <- getReads(converter=readsToGAlignments) 243 | #' summary(alignments1) 244 | #' alignments2 <- readsToGAlignments(getReads()) 245 | #' print(identical(alignments1, alignments2)) 246 | readsToGAlignments <- function(reads, oneBasedCoord=TRUE, slStyle="UCSC") { 247 | 248 | if (missing(reads)) { 249 | return(GAlignments()) 250 | } 251 | 252 | # Transform the Genomics API data into a GAlignments object 253 | names <- sapply(reads, "[[", "fragmentName") 254 | cigars <- sapply(reads, getCigar) 255 | positions <- sapply(reads, getPosition) 256 | if (oneBasedCoord) { 257 | positions <- as.integer(positions + 1) 258 | } 259 | flags <- sapply(reads, getFlags) 260 | chromosomes <- sapply(reads, getReferenceName) 261 | 262 | isMinusStrand <- bamFlagAsBitMatrix(as.integer(flags), 263 | bitnames="isMinusStrand") 264 | alignments <- GAlignments( 265 | seqnames=Rle(chromosomes), 266 | strand=strand(as.vector(ifelse(isMinusStrand, "-", "+"))), 267 | pos=positions, cigar=cigars, names=names, flag=flags) 268 | 269 | seqlevelsStyle(alignments) <- slStyle 270 | alignments 271 | } 272 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | # Copyright 2014 Google Inc. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the 'License'); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an 'AS IS' BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | .onLoad <- function(libname, pkgname) { 16 | currentOptions <- options() 17 | defaultOptions <- list( 18 | google_genomics_endpoint="https://genomics.googleapis.com/v1", 19 | google_auth_cache_httr=file.path("~", ".r-google-auth-httr"), 20 | google_genomics_use_grpc=isGRPCAvailable()) 21 | toset <- !(names(defaultOptions) %in% names(currentOptions)) 22 | if (any(toset)) options(defaultOptions[toset]) 23 | 24 | authenticate() 25 | 26 | invisible() 27 | } 28 | 29 | .onAttach <- function(libname, pkgname) { 30 | msg <- sprintf( 31 | "Package '%s' is deprecated and will be removed from Bioconductor 32 | version %s", pkgname, "3.9") 33 | .Deprecated(msg=paste(strwrap(msg, exdent=2), collapse="\n")) 34 | } 35 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | GoogleGenomics |Build Status|_ 2 | =============================== 3 | 4 | .. |Build Status| image:: http://img.shields.io/travis/Bioconductor/GoogleGenomics.svg?style=flat 5 | .. _Build Status: https://travis-ci.org/Bioconductor/GoogleGenomics 6 | 7 | .. role:: r(code) 8 | :language: r 9 | 10 | .. role:: sh(code) 11 | :language: sh 12 | 13 | This R client fetches reads and variants data from the `Google Genomics API`_ 14 | and provides converters to obtain `Bioconductor`_ S4 classes like GAlignments, 15 | and GRanges and VRanges. 16 | 17 | .. _Google Genomics API: https://cloud.google.com/genomics 18 | .. _Bioconductor: http://www.bioconductor.org/ 19 | .. _gRPC: https://grpc.io/ 20 | 21 | Installing 22 | ---------- 23 | 24 | Use the Bioconductor repositories to install this package. 25 | 26 | If you have `gRPC`_ installed, you will be able to access the entire v1 27 | Google Genomics API through the :r:`callGRPCMethod` function provided in 28 | the package and use more performant reads and variant search methods. 29 | Without gRPC support, you will still be able to query reads and variants; 30 | see the vignettes for sample usage. 31 | 32 | * [Optional] Installing gRPC 33 | 34 | See `our guide on gRPC `_. 35 | 36 | * Installing R package 37 | 38 | .. code:: r 39 | 40 | source("http://bioconductor.org/biocLite.R") 41 | useDevel(TRUE) # Skip this step if you do not want the devel version. 42 | 43 | biocLite("GoogleGenomics") # If gRPC is not installed. 44 | biocLite("GoogleGenomics", type="source") # If gRPC is installed. 45 | library(GoogleGenomics) 46 | 47 | Authentication 48 | -------------- 49 | 50 | Call :r:`authenticate` to set up credentials. Check the function 51 | documentation for details on various available options. The function will 52 | return :r:`TRUE` on successful authentication. 53 | 54 | Examples 55 | -------- 56 | 57 | See the following examples for more detail: 58 | 59 | * `Working with Reads `_ 60 | 61 | * `Working with Variants `_ 62 | 63 | * `Variant Annotation Comparison Test `_ 64 | 65 | * and also the `integration tests <./tests/testthat>`_ 66 | 67 | Project status 68 | -------------- 69 | 70 | The package is integrated with gRPC when available on the system where the 71 | package was built. With gRPC support, the entire v1 API is accessible. 72 | Without gRPC support, this package can be used to search for reads and 73 | variants, and convert them to various Bioconductor formats. 74 | -------------------------------------------------------------------------------- /cleanup: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Copyright 2017 GoogleGenomics R package authors. All rights reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the 'License'); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an 'AS IS' BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | rm -f config.* src/Makevars src/config.h 18 | rm -f src/*.so src/*.o 19 | find src -iname '*.pb.*' | xargs rm -f 20 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # Copyright 2017 GoogleGenomics R package authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the 'License'); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an 'AS IS' BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | AC_PREREQ(2.69) 16 | 17 | AC_INIT([GoogleGenomics],[2.0.0]) dnl package name, version 18 | 19 | dnl Find the compiler and compiler flags to use 20 | : ${R_HOME=`R RHOME`} 21 | if test -z "${R_HOME}"; then 22 | AC_MSG_ERROR("could not determine R_HOME") 23 | fi 24 | CC=`"${R_HOME}/bin/R" CMD config CC` 25 | CPP=`"${R_HOME}/bin/R" CMD config CPP` 26 | CFLAGS=`"${R_HOME}/bin/R" CMD config CFLAGS` 27 | CPPFLAGS=`"${R_HOME}/bin/R" CMD config CPPFLAGS` 28 | CXX=`"${R_HOME}/bin/R" CMD config CXX` 29 | CXXFLAGS=`"${R_HOME}/bin/R" CMD config CXXFLAGS` 30 | LIBS=`"${R_HOME}/bin/R" CMD CONFIG LDFLAGS` 31 | 32 | CPPFLAGS="${CPPFLAGS} -I." 33 | 34 | 35 | dnl Check for user supplied include paths, from a configure option or 36 | dnl from an environment variable 37 | AC_ARG_WITH([grpc-include], 38 | AC_HELP_STRING([--with-grpc-include=INCLUDE_PATH], 39 | [the location of GRPC header files]), 40 | [grpc_include_path=$withval]) 41 | if test -n "${grpc_include_path}"; then 42 | CPPFLAGS="${CPPFLAGS} -I${grpc_include_path}" 43 | else 44 | if test -n "${GRPC_INCLUDE_PATH}"; then 45 | CPPFLAGS="${CPPFLAGS} -I${GRPC_INCLUDE_PATH}" 46 | fi 47 | fi 48 | 49 | dnl Same for library search paths 50 | AC_ARG_WITH([grpc-libs], 51 | AC_HELP_STRING([--with-grpc-libs=LIB_PATH], 52 | [the location of GRPC libraries]), 53 | [grpc_libs_path=$withval]) 54 | if test -n "${grpc_libs_path}"; then 55 | LIBS="${LIBS} -L${grpc_libs_path}" 56 | else 57 | if test -n "${GRPC_LIBS_PATH}"; then 58 | LIBS="${LIBS} -L${GRPC_LIBS_PATH}" 59 | fi 60 | fi 61 | 62 | dnl Same for binary search paths 63 | AC_ARG_WITH([grpc-bin], 64 | AC_HELP_STRING([--with-grpc-bin=BIN_PATH], 65 | [the location of GRPC binaries]), 66 | [grpc_bin_path=$withval]) 67 | if test -n "${grpc_bin_path}"; then 68 | PATH="${grpc_bin_path}:${PATH}" 69 | else 70 | if test -n "${GRPC_BIN_PATH}"; then 71 | PATH="${GRPC_BIN_PATH}:${PATH}" 72 | fi 73 | fi 74 | 75 | DEFAULT_LIBS="${LIBS}" 76 | AC_LANG(C++) 77 | AC_REQUIRE_CPP 78 | 79 | dnl use pkg-config for ProtoBuf settings if available 80 | AC_ARG_VAR(PKGCONFIG, "Whether pkg-config exists or not") 81 | PKGCONFIG=0 82 | AC_CHECK_PROG(PKGCONFIG, pkg-config, 1) 83 | if test "${PKGCONFIG}" -eq 1 && pkg-config --exists protobuf; then 84 | CPPFLAGS="${CPPFLAGS} "`pkg-config --cflags protobuf` 85 | LIBS="${LIBS} "`pkg-config --libs protobuf` 86 | else 87 | LIBS="${LIBS} -lprotobuf" 88 | fi 89 | 90 | AC_MSG_CHECKING([if ProtoBuf version >= 3.0.0]) 91 | AC_RUN_IFELSE([AC_LANG_PROGRAM( 92 | [#include 93 | #include ], 94 | [exit(GOOGLE_PROTOBUF_VERSION < 3000000)])], 95 | [AC_MSG_RESULT("yes"); HAVE_PROTOBUF=1], 96 | [AC_MSG_RESULT("no"); HAVE_PROTOBUF=0]) 97 | 98 | HAVE_GRPC=0 99 | if test "${HAVE_PROTOBUF}" -eq 1; then 100 | AC_ARG_VAR(PROTOC_BINARY, "Absolute path of the protoc binary") 101 | AC_PATH_PROG(PROTOC_BINARY, protoc, 102 | AC_MSG_ERROR("protoc binary not found in $PATH")) 103 | 104 | dnl Use pkg-config for gRPC settings 105 | if test "${PKGCONFIG}" -eq 1 && pkg-config --exists grpc grpc; then 106 | CPPFLAGS="${CPPFLAGS} "`pkg-config --cflags grpc grpc++` 107 | LIBS="${LIBS} "`pkg-config --libs grpc grpc++` 108 | else 109 | LIBS="${LIBS} -lgrpc -lgrpc++" 110 | fi 111 | 112 | AC_MSG_CHECKING([gRPC]) 113 | AC_RUN_IFELSE([AC_LANG_PROGRAM( 114 | [#include ], 115 | [::grpc::ClientContext context])], 116 | [AC_MSG_RESULT("yes"); HAVE_GRPC=1], 117 | [AC_MSG_RESULT("no")]) 118 | fi 119 | 120 | AC_ARG_VAR(GRPC_PLUGIN, "Absolute path of the grpc plugin binary") 121 | 122 | dnl Some final checks 123 | if test "${HAVE_GRPC}" -eq 1; then 124 | AC_PATH_PROG(GRPC_PLUGIN, grpc_cpp_plugin, 125 | AC_MSG_ERROR("grpc_cpp_plugin binary not found in $PATH")) 126 | fi 127 | 128 | if test "${HAVE_GRPC}" -eq 0; then 129 | LIBS=${DEFAULT_LIBS} 130 | AC_MSG_WARN("[ 131 | gRPC installation could not be found, 132 | or protocol buffer library is not >= 3.0.0. 133 | If your installation is in a non-standard location, 134 | please see installation instructions at 135 | https://github.com/Bioconductor/GoogleGenomics/blob/master/README.rst 136 | "]) 137 | fi 138 | 139 | AC_SUBST(HAVE_GRPC) 140 | AC_CONFIG_FILES([src/Makevars]) 141 | AC_OUTPUT 142 | -------------------------------------------------------------------------------- /configure.win: -------------------------------------------------------------------------------- 1 | # Copyright 2017 GoogleGenomics R package authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the 'License'); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an 'AS IS' BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /man/GoogleGenomics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/GoogleGenomics.R 3 | \docType{package} 4 | \name{GoogleGenomics} 5 | \alias{GoogleGenomics} 6 | \alias{GoogleGenomics-package} 7 | \title{A basic R package for Google Genomics API.} 8 | \description{ 9 | For more details, read the package README. 10 | } 11 | -------------------------------------------------------------------------------- /man/authenticate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/authenticate.R 3 | \name{authenticate} 4 | \alias{authenticate} 5 | \title{Configure how to authenticate for Google Genomics API.} 6 | \usage{ 7 | authenticate(file, clientId, clientSecret, invokeBrowser, 8 | apiKey = Sys.getenv("GOOGLE_API_KEY"), 9 | gcloudCredsPath = defaultGcloudCredsPath(), tryGCEServiceAccount = TRUE) 10 | } 11 | \arguments{ 12 | \item{file}{Client secrets file obtained from Google Developer Console. This 13 | file could be for a native application or a service account. If this file 14 | is not present, clientId and clientSecret must be provided for native 15 | application credentials.} 16 | 17 | \item{clientId}{Client ID from Google Developer Console, overridden if file 18 | is provided.} 19 | 20 | \item{clientSecret}{Client Secret from Google Developer Console, overridden 21 | if file is provided.} 22 | 23 | \item{invokeBrowser}{If TRUE or not provided, the default browser is invoked 24 | with the auth URL iff the \code{\link[httpuv]{httpuv}} package is 25 | installed (suggested). If FALSE, a URL is output which needs to be copy 26 | pasted in a browser, and the resulting token needs to be pasted back into 27 | the R session. With both the options, you will still need to login to your 28 | Google account if not logged in already.} 29 | 30 | \item{apiKey}{Public API key that can be used to call the Genomics API for 31 | public datasets. This method of authentication does not need you to login 32 | to your Google account. Providing this key overrides all other arguments.} 33 | 34 | \item{gcloudCredsPath}{Path to the generated json file with application 35 | default credentials.} 36 | 37 | \item{tryGCEServiceAccount}{If TRUE, will try checking if this is a GCE VM 38 | instance with a valid service account. If valid credentials are found, 39 | will use them over all other options.} 40 | } 41 | \value{ 42 | TRUE if successful, FALSE if not. 43 | } 44 | \description{ 45 | Follow the sign up instructions at 46 | \url{https://cloud.google.com/genomics/install-genomics-tools}. 47 | } 48 | \details{ 49 | There are four primary ways, in order of preference, of authenticating: 50 | 51 | 1. When running on Google Compute Engine, configure your VM to be 52 | authenticated at the time of initial setup. See 53 | \url{https://cloud.google.com/compute/docs/access/create-enable-service-accounts-for-instances#using}. 54 | 55 | 2. Use the gcloud tool to generate application default credentials. If the 56 | generated file is not in its standard location, you can set the environment 57 | variable GOOGLE_APPLICATION_CREDENTIALS with its path, or provide the 58 | gcloudCredsPath argument. 59 | 60 | 3. For public data, use a public API key from the project that you want to 61 | access. You can either set the GOOGLE_API_KEY environment variable, or 62 | provide the apiKey argument. Does not work with gRPC. 63 | 64 | 4. Download secrets file (native application or service account) or 65 | provide the clientId and clientSecret pair. See 66 | \url{https://cloud.google.com/genomics/downloading-credentials-for-api-access}. 67 | Native application credentials should only be used when accessing data for 68 | which your own account is not authorized. 69 | 70 | This method is called with default arguments at package load time. 71 | } 72 | \examples{ 73 | apiKey <- Sys.getenv("GOOGLE_API_KEY") 74 | if (!is.na(apiKey) && nchar(apiKey)>0) { 75 | authenticate(apiKey=apiKey) 76 | } 77 | \dontrun{ 78 | authenticate() 79 | authenticate(file="clientSecrets.json") 80 | authenticate(file="clientSecrets.json", invokeBrowser=FALSE) 81 | authenticate(clientId="abc", clientSecret="xyz", invokeBrowser=FALSE) 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /man/callGRPCMethod.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/grpc.R 3 | \name{callGRPCMethod} 4 | \alias{callGRPCMethod} 5 | \title{Issues a gRPC call to the Google Genomics service and returns the 6 | response.} 7 | \usage{ 8 | callGRPCMethod(methodName, request) 9 | } 10 | \arguments{ 11 | \item{methodName}{The RPC method name.} 12 | 13 | \item{request}{The request object for the RPC, either as a JSON object 14 | generated from \code{\link[rjson]{rjson}}, or as a 15 | \code{\link[RProtoBuf]{RProtoBuf}} object modified from the 16 | default instance obtained from 17 | \code{\link{getRProtoBufDefaultObject}}.} 18 | } 19 | \value{ 20 | The raw response converted from JSON to an R object, or the 21 | RProtoBuf object if the request was an RProtoBuf object. 22 | } 23 | \description{ 24 | Needs gRPC support at package build time and the RProtoBuf package. 25 | See package README for instructions on installing gRPC. 26 | } 27 | \details{ 28 | In general, use higher level methods such as getReads and getVariants 29 | instead. 30 | } 31 | \examples{ 32 | # Authenticated on package load from the env variable GOOGLE_API_KEY. 33 | if (isGRPCAvailable()) { 34 | request <- list(readGroupSetIds=list("CMvnhpKTFhDnk4_9zcKO3_YB"), 35 | referenceName="22", 36 | start=16051400, end=16051500, pageToken=NULL) 37 | reads <- callGRPCMethod("SearchReads", request) 38 | summary(reads) 39 | } else { 40 | message("gRPC support is disabled; package was not compiled with GRPC") 41 | } 42 | } 43 | \seealso{ 44 | Other page fetch functions: \code{\link{getReadsPage}}, 45 | \code{\link{getSearchPage}}, 46 | \code{\link{getVariantsPage}} 47 | } 48 | -------------------------------------------------------------------------------- /man/defaultGcloudCredsPath.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/authenticate.R 3 | \name{defaultGcloudCredsPath} 4 | \alias{defaultGcloudCredsPath} 5 | \title{Returns the standard location for application default credentials as 6 | generated by the gcloud CLI tool.} 7 | \usage{ 8 | defaultGcloudCredsPath() 9 | } 10 | \value{ 11 | File path for credentials json. 12 | } 13 | \description{ 14 | Returns the standard location for application default credentials as 15 | generated by the gcloud CLI tool. 16 | } 17 | \examples{ 18 | defaultGcloudCredsPath() 19 | } 20 | -------------------------------------------------------------------------------- /man/getRProtoBufDefaultObject.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/grpc.R 3 | \name{getRProtoBufDefaultObject} 4 | \alias{getRProtoBufDefaultObject} 5 | \title{Returns a protocol buffer Message object from 6 | \code{\link[RProtoBuf]{RProtoBuf}}.} 7 | \usage{ 8 | getRProtoBufDefaultObject(fullyQualifiedName) 9 | } 10 | \arguments{ 11 | \item{fullyQualifiedName}{Type of the message object to return.} 12 | } 13 | \value{ 14 | Default instance of the Message. 15 | } 16 | \description{ 17 | Needs gRPC support at package build time and the RProtoBuf package. 18 | See package README for instructions on installing gRPC. 19 | } 20 | \examples{ 21 | if (isGRPCAvailable()) { 22 | getRProtoBufDefaultObject("google.genomics.v1.SearchReadsRequest") 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /man/getReads.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reads.R 3 | \name{getReads} 4 | \alias{getReads} 5 | \title{Get reads from Google Genomics.} 6 | \usage{ 7 | getReads(readGroupSetId = "CMvnhpKTFhDnk4_9zcKO3_YB", chromosome = "22", 8 | start = 16051400, end = 16051500, fields = NULL, converter = c, 9 | useGRPC = getOption("google_genomics_use_grpc")) 10 | } 11 | \arguments{ 12 | \item{readGroupSetId}{The read group set ID.} 13 | 14 | \item{chromosome}{The chromosome.} 15 | 16 | \item{start}{Start position on the chromosome in 0-based coordinates.} 17 | 18 | \item{end}{End position on the chromosome in 0-based coordinates.} 19 | 20 | \item{fields}{A subset of fields to retrieve. The default (NULL) will 21 | return all fields.} 22 | 23 | \item{converter}{A function that takes a list of read R objects and returns 24 | them converted to the desired type.} 25 | 26 | \item{useGRPC}{Whether to use GRPC mechanism to query.} 27 | } 28 | \value{ 29 | By default, the return value is a list of R objects 30 | corresponding to the JSON objects returned by the Google Genomics 31 | Reads API. If a converter is passed, object(s) of the type 32 | returned by the converter will be returned by this function. 33 | } 34 | \description{ 35 | This function will return all of the reads that comprise the requested 36 | genomic range, iterating over paginated results as necessary. 37 | } 38 | \details{ 39 | By default, this function gets reads for a small genomic region for one 40 | sample in 1,000 Genomes. 41 | 42 | Optionally pass a converter as appropriate for your use case. By passing it 43 | to this method, only the converted objects will be accumulated in memory. 44 | The converter function should return an empty container of the desired type 45 | if called without any arguments. 46 | } 47 | \examples{ 48 | # Authenticated on package load from the env variable GOOGLE_API_KEY. 49 | reads <- getReads() 50 | summary(reads) 51 | summary(reads[[1]]) 52 | } 53 | \seealso{ 54 | \code{\link{getVariants}} 55 | } 56 | -------------------------------------------------------------------------------- /man/getReadsPage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reads.R 3 | \name{getReadsPage} 4 | \alias{getReadsPage} 5 | \title{Get one page of reads from Google Genomics.} 6 | \usage{ 7 | getReadsPage(readGroupSetId = "CMvnhpKTFhDnk4_9zcKO3_YB", chromosome = "22", 8 | start = 16051400, end = 16051500, fields = NULL, pageToken = NULL) 9 | } 10 | \arguments{ 11 | \item{readGroupSetId}{The read group set ID.} 12 | 13 | \item{chromosome}{The chromosome.} 14 | 15 | \item{start}{Start position on the chromosome in 0-based coordinates.} 16 | 17 | \item{end}{End position on the chromosome in 0-based coordinates.} 18 | 19 | \item{fields}{A subset of fields to retrieve. The default (NULL) will 20 | return all fields.} 21 | 22 | \item{pageToken}{The page token. This can be NULL (default) for the first 23 | page.} 24 | } 25 | \value{ 26 | A two-element list is returned by the function. 27 | 28 | reads: A list of R objects corresponding to the JSON objects returned 29 | by the Google Genomics Reads API. 30 | 31 | nextPageToken: The token to be used to retrieve the next page of 32 | results, if applicable. 33 | } 34 | \description{ 35 | In general, use the getReads method instead. It calls this method, 36 | returning reads from all of the pages that comprise the requested 37 | genomic range. 38 | } 39 | \details{ 40 | By default, this function gets reads for a small genomic region for one 41 | sample in 1,000 Genomes. 42 | 43 | Note that the Global Alliance for Genomics and Health API uses a 0-based 44 | coordinate system. For more detail, please see GA4GH discussions such 45 | as the following: 46 | \itemize{ 47 | \item\url{https://github.com/ga4gh/schemas/issues/168} 48 | \item\url{https://github.com/ga4gh/schemas/issues/121} 49 | } 50 | } 51 | \examples{ 52 | # Authenticated on package load from the env variable GOOGLE_API_KEY. 53 | readsPage <- getReadsPage() 54 | summary(readsPage) 55 | summary(readsPage$reads[[1]]) 56 | } 57 | \seealso{ 58 | Other page fetch functions: \code{\link{callGRPCMethod}}, 59 | \code{\link{getSearchPage}}, 60 | \code{\link{getVariantsPage}} 61 | } 62 | -------------------------------------------------------------------------------- /man/getSearchPage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/client.R 3 | \name{getSearchPage} 4 | \alias{getSearchPage} 5 | \title{Get one page of search results for a particular entity type from Google 6 | Genomics.} 7 | \usage{ 8 | getSearchPage(entityType, body, fields, pageToken) 9 | } 10 | \arguments{ 11 | \item{entityType}{Entities with a search API such as reads, variants, 12 | variantSets, etc...} 13 | 14 | \item{body}{The body of the message to POST to the search endpoint.} 15 | 16 | \item{fields}{The fields to be returned in the search response.} 17 | 18 | \item{pageToken}{The page token. This can be NULL for the first page.} 19 | } 20 | \value{ 21 | The raw response converted from JSON to an R object. 22 | } 23 | \description{ 24 | In general, use higher level methods such as getReads and getVariants 25 | instead. 26 | } 27 | \examples{ 28 | # Authenticated on package load from the env variable GOOGLE_API_KEY. 29 | body <- list(readGroupSetIds=list("CMvnhpKTFhDnk4_9zcKO3_YB"), 30 | referenceName="22", 31 | start=16051400, end=16051500, pageToken=NULL) 32 | reads <- getSearchPage("reads", body, NULL, NULL) 33 | summary(reads) 34 | } 35 | \seealso{ 36 | Other page fetch functions: \code{\link{callGRPCMethod}}, 37 | \code{\link{getReadsPage}}, \code{\link{getVariantsPage}} 38 | } 39 | -------------------------------------------------------------------------------- /man/getVariantCalls.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/variants.R 3 | \name{getVariantCalls} 4 | \alias{getVariantCalls} 5 | \title{Elaborate the result of getVariants as a VRanges with all 6 | calls for all samples} 7 | \usage{ 8 | getVariantCalls(variantSetId = "10473108253681171589", chromosome = "22", 9 | start = 16051400, end = 16051500, fields = NULL, converter = c, 10 | oneBasedCoord = TRUE, nullAction = "stop") 11 | } 12 | \arguments{ 13 | \item{variantSetId}{The dataset ID.} 14 | 15 | \item{chromosome}{The chromosome.} 16 | 17 | \item{start}{Start position on the chromosome in 0-based coordinates.} 18 | 19 | \item{end}{End position on the chromosome in 0-based coordinates.} 20 | 21 | \item{fields}{A subset of fields to retrieve. The default (NULL) will 22 | return all fields.} 23 | 24 | \item{converter}{A function that takes a list of variant R objects and 25 | returns them converted to the desired type.} 26 | 27 | \item{oneBasedCoord}{Convert returned addresses to 1-based address system} 28 | 29 | \item{nullAction}{either \code{"stop"} or \code{"warn"} telling how to deal 30 | with event in which request yields no variants; for 31 | \code{"warn"} we return NULL} 32 | } 33 | \value{ 34 | By default, the return value is a VRanges object. 35 | If a converter is passed, object(s) of the type returned by the 36 | converter will be returned by this function. 37 | } 38 | \description{ 39 | Elaborate the result of getVariants as a VRanges with all 40 | calls for all samples 41 | } 42 | \examples{ 43 | \dontrun{ 44 | getVariantCalls() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /man/getVariants.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/variants.R 3 | \name{getVariants} 4 | \alias{getVariants} 5 | \title{Get variants from Google Genomics.} 6 | \usage{ 7 | getVariants(variantSetId = "10473108253681171589", chromosome = "22", 8 | start = 16051400, end = 16051500, fields = NULL, converter = c, 9 | useGRPC = getOption("google_genomics_use_grpc")) 10 | } 11 | \arguments{ 12 | \item{variantSetId}{The dataset ID.} 13 | 14 | \item{chromosome}{The chromosome.} 15 | 16 | \item{start}{Start position on the chromosome in 0-based coordinates.} 17 | 18 | \item{end}{End position on the chromosome in 0-based coordinates.} 19 | 20 | \item{fields}{A subset of fields to retrieve. The default (NULL) will 21 | return all fields.} 22 | 23 | \item{converter}{A function that takes a list of variant R objects and 24 | returns them converted to the desired type.} 25 | 26 | \item{useGRPC}{Whether to use GRPC mechanism to query.} 27 | } 28 | \value{ 29 | By default, the return value is a list of R objects 30 | corresponding to the JSON objects returned by the Google Genomics 31 | Variants API. If a converter is passed, object(s) of the type 32 | returned by the converter will be returned by this function. 33 | } 34 | \description{ 35 | This function will return all of the variants that comprise the requested 36 | genomic range, iterating over paginated results as necessary. 37 | } 38 | \details{ 39 | By default, this function gets variants from a small section of 1000 40 | Genomes phase 1 variants. 41 | 42 | Optionally pass a converter as appropriate for your use case. By passing it 43 | to this method, only the converted objects will be accumulated in memory. 44 | The converter function should return an empty container of the desired type 45 | if called without any arguments. 46 | } 47 | \examples{ 48 | # Authenticated on package load from the env variable GOOGLE_API_KEY. 49 | variants <- getVariants() 50 | summary(variants) 51 | summary(variants[[1]]) 52 | } 53 | \seealso{ 54 | \code{\link{getReads}} for equivalent function for reads, and 55 | \code{\link{variantsToVRanges}} for a converter function. 56 | } 57 | -------------------------------------------------------------------------------- /man/getVariantsPage.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/variants.R 3 | \name{getVariantsPage} 4 | \alias{getVariantsPage} 5 | \title{Get one page of variants from Google Genomics.} 6 | \usage{ 7 | getVariantsPage(variantSetId = "10473108253681171589", chromosome = "22", 8 | start = 16051400, end = 16051500, fields = NULL, pageToken = NULL) 9 | } 10 | \arguments{ 11 | \item{variantSetId}{The dataset ID.} 12 | 13 | \item{chromosome}{The chromosome.} 14 | 15 | \item{start}{Start position on the chromosome in 0-based coordinates.} 16 | 17 | \item{end}{End position on the chromosome in 0-based coordinates.} 18 | 19 | \item{fields}{A subset of fields to retrieve. The default (NULL) will 20 | return all fields.} 21 | 22 | \item{pageToken}{The page token. This can be NULL (default) for the first 23 | page.} 24 | } 25 | \value{ 26 | A two-element list is returned by the function. 27 | 28 | variants: A list of R objects corresponding to the JSON objects returned 29 | by the Google Genomics Variants API. 30 | 31 | nextPageToken: The token to be used to retrieve the next page of 32 | results, if applicable. 33 | } 34 | \description{ 35 | In general, use the getVariants method instead. It calls this method, 36 | returning variants from all of the pages that comprise the requested 37 | genomic range. 38 | } 39 | \details{ 40 | By default, this function gets variants from a small section of 1000 41 | Genomes phase 1 variants. 42 | } 43 | \examples{ 44 | # Authenticated on package load from the env variable GOOGLE_API_KEY. 45 | variantsPage <- getVariantsPage() 46 | summary(variantsPage) 47 | summary(variantsPage$variants[[1]]) 48 | } 49 | \seealso{ 50 | Other page fetch functions: \code{\link{callGRPCMethod}}, 51 | \code{\link{getReadsPage}}, \code{\link{getSearchPage}} 52 | } 53 | -------------------------------------------------------------------------------- /man/isGRPCAvailable.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/grpc.R 3 | \name{isGRPCAvailable} 4 | \alias{isGRPCAvailable} 5 | \title{Returns if this package was built with gRPC support.} 6 | \usage{ 7 | isGRPCAvailable() 8 | } 9 | \value{ 10 | TRUE iff the package was built with gRPC support. 11 | } 12 | \description{ 13 | Returns if this package was built with gRPC support. 14 | } 15 | -------------------------------------------------------------------------------- /man/readsToGAlignments.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/reads.R 3 | \name{readsToGAlignments} 4 | \alias{readsToGAlignments} 5 | \title{Convert reads to GAlignments.} 6 | \usage{ 7 | readsToGAlignments(reads, oneBasedCoord = TRUE, slStyle = "UCSC") 8 | } 9 | \arguments{ 10 | \item{reads}{A list of R objects corresponding to the JSON objects 11 | returned by the Google Genomics Reads API.} 12 | 13 | \item{oneBasedCoord}{Convert genomic positions to 1-based coordinates.} 14 | 15 | \item{slStyle}{The style for seqnames (chrN or N or...). Default is UCSC.} 16 | } 17 | \value{ 18 | \link[GenomicAlignments]{GAlignments} 19 | } 20 | \description{ 21 | Note that the Global Alliance for Genomics and Health API uses a 0-based 22 | coordinate system. For more detail, please see GA4GH discussions such 23 | as the following: 24 | \itemize{ 25 | \item\url{https://github.com/ga4gh/schemas/issues/168} 26 | \item\url{https://github.com/ga4gh/schemas/issues/121} 27 | } 28 | } 29 | \examples{ 30 | # Authenticated on package load from the env variable GOOGLE_API_KEY. 31 | alignments1 <- getReads(converter=readsToGAlignments) 32 | summary(alignments1) 33 | alignments2 <- readsToGAlignments(getReads()) 34 | print(identical(alignments1, alignments2)) 35 | } 36 | -------------------------------------------------------------------------------- /man/variantsToGRanges.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/variants.R 3 | \name{variantsToGRanges} 4 | \alias{variantsToGRanges} 5 | \title{Convert variants to GRanges.} 6 | \usage{ 7 | variantsToGRanges(variants, oneBasedCoord = TRUE, slStyle = "UCSC") 8 | } 9 | \arguments{ 10 | \item{variants}{A list of R objects corresponding to the JSON objects 11 | returned by the Google Genomics Variants API.} 12 | 13 | \item{oneBasedCoord}{Convert genomic positions to 1-based coordinates.} 14 | 15 | \item{slStyle}{The style for seqnames (chrN or N or...). Default is UCSC.} 16 | } 17 | \value{ 18 | \link[GenomicRanges]{GRanges} 19 | } 20 | \description{ 21 | Note that the Global Alliance for Genomics and Health API uses a 0-based 22 | coordinate system. For more detail, please see GA4GH discussions such 23 | as the following: 24 | \itemize{ 25 | \item\url{https://github.com/ga4gh/schemas/issues/168} 26 | \item\url{https://github.com/ga4gh/schemas/issues/121} 27 | } 28 | } 29 | \examples{ 30 | # Authenticated on package load from the env variable GOOGLE_API_KEY. 31 | variants1 <- getVariants(converter=variantsToGRanges) 32 | summary(variants1) 33 | variants2 <- variantsToGRanges(getVariants()) 34 | print(identical(variants1, variants2)) 35 | } 36 | \seealso{ 37 | Other variants converter functions: \code{\link{variantsToVRanges}} 38 | } 39 | -------------------------------------------------------------------------------- /man/variantsToVRanges.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/variants.R 3 | \name{variantsToVRanges} 4 | \alias{variantsToVRanges} 5 | \title{Convert variants to VRanges.} 6 | \usage{ 7 | variantsToVRanges(variants, oneBasedCoord = TRUE, slStyle = "UCSC") 8 | } 9 | \arguments{ 10 | \item{variants}{A list of R objects corresponding to the JSON objects 11 | returned by the Google Genomics Variants API.} 12 | 13 | \item{oneBasedCoord}{Convert genomic positions to 1-based coordinates.} 14 | 15 | \item{slStyle}{The style for seqnames (chrN or N or...). Default is UCSC.} 16 | } 17 | \value{ 18 | \link[VariantAnnotation]{VRanges} 19 | } 20 | \description{ 21 | Note that the Global Alliance for Genomics and Health API uses a 0-based 22 | coordinate system. For more detail, please see GA4GH discussions such 23 | as the following: 24 | \itemize{ 25 | \item\url{https://github.com/ga4gh/schemas/issues/168} 26 | \item\url{https://github.com/ga4gh/schemas/issues/121} 27 | } 28 | } 29 | \examples{ 30 | # Authenticated on package load from the env variable GOOGLE_API_KEY. 31 | variants1 <- getVariants(converter=variantsToVRanges) 32 | summary(variants1) 33 | variants2 <- variantsToVRanges(getVariants()) 34 | print(identical(variants1, variants2)) 35 | } 36 | \seealso{ 37 | Other variants converter functions: \code{\link{variantsToGRanges}} 38 | } 39 | -------------------------------------------------------------------------------- /shiny/.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bioconductor/GoogleGenomics/243494d461270d7ef60998519861d89c66f986be/shiny/.gitignore -------------------------------------------------------------------------------- /src/Makevars.in: -------------------------------------------------------------------------------- 1 | # Copyright 2017 GoogleGenomics R package authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the 'License'); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an 'AS IS' BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | CXX_STD = CXX11 16 | 17 | PKG_LIBS = @LIBS@ 18 | 19 | # Do not compile gRPC related code. 20 | ifeq "@HAVE_GRPC@" "0" 21 | 22 | PKG_CPPFLAGS = @CPPFLAGS@ 23 | OBJECTS = init.o 24 | 25 | # Compile and link the generated protocol buffer code included with this package. 26 | else 27 | 28 | PKG_CPPFLAGS = @CPPFLAGS@ -DHAVE_GRPC 29 | 30 | PROTO_SOURCES = $(wildcard google/*/*.proto google/*/*/*.proto) 31 | PROTO_CC = $(patsubst %.proto, %.pb.cc, $(PROTO_SOURCES)) 32 | PROTO_OBJECTS = $(patsubst %.proto, %.pb.o, $(PROTO_SOURCES)) 33 | 34 | SERVICE_CC = $(patsubst %.proto, %.grpc.pb.cc, $(PROTO_SOURCES)) 35 | # SERVICE_OBJECTS = $(patsubst %.proto, %.grpc.pb.o, $(PROTO_SOURCES)) 36 | SERVICES = $(addprefix google/genomics/v1/, annotations datasets reads references variants) 37 | SERVICE_OBJECTS = $(addsuffix .grpc.pb.o, $(SERVICES)) 38 | 39 | PACKAGE_OBJECTS = $(patsubst %.cc, %.o, $(wildcard *.cc)) 40 | 41 | OBJECTS = $(PROTO_OBJECTS) $(SERVICE_OBJECTS) $(PACKAGE_OBJECTS) 42 | 43 | .PHONY: all clean protolib 44 | 45 | $(SHLIB): $(OBJECTS) 46 | 47 | $(PROTO_CC) $(SERVICE_CC): protolib 48 | 49 | protolib: $(PROTO_SOURCES) 50 | @PROTOC_BINARY@ $(filter -I%, $(CPPFLAGS)) -I. --cpp_out=. --grpc_out=. \ 51 | --plugin=protoc-gen-grpc=@GRPC_PLUGIN@ $? 52 | 53 | clean: 54 | rm $(PROTO_CC) $(PROTO_CC:.cc=.h) $(SERVICE_CC) $(SERVICE_CC:.cc=.h) $(OBJECTS) 55 | 56 | endif 57 | -------------------------------------------------------------------------------- /src/Makevars.win: -------------------------------------------------------------------------------- 1 | # Copyright 2017 GoogleGenomics R package authors. All rights reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the 'License'); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an 'AS IS' BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | OBJECTS = init.o 16 | -------------------------------------------------------------------------------- /src/README.rst: -------------------------------------------------------------------------------- 1 | C++ library for Google Genomics 2 | =============================== 3 | 4 | This directory contains the C++ code for this R package. Almost all the code here is to bind into 5 | the gRPC C++ stubs for Google Genomics API. 6 | 7 | Code Organization 8 | ----------------- 9 | 10 | google/ 11 | This directory contains the protocol buffer files for Google Genomics and dependencies. They were 12 | copied as-is from the `googleapis repo `_ with the same 13 | directory structure. If you are updating the protocol buffer files, please only copy the files 14 | needed by the genomics API as otherwise it increases the package compilation time. If there are 15 | new methods, then the corresponding client-\*.cc file will need to add that method, and the method 16 | will need to be registered in init.cc. 17 | 18 | client-common.* 19 | These files contain utility functions, templated functions, and macros to interface any given 20 | C++ stub method with an R object that is either a JSON string or an RProtoBuf object. It also 21 | handles passing authentication to gRPC from the R package. 22 | 23 | client-\*.cc 24 | These are Genomics API services that have a macro each for each service method. The macros will 25 | check if this is a paginated RPC or not, and handle accordingly. 26 | 27 | init.* 28 | Package initialization and visible method registration. Any new C++ method to be made visible to R 29 | code (including new service methods) will need to be registered here. 30 | 31 | rprotobuf.* 32 | Methods to wrap and unwrap RProtoBuf objects, and create a new RProtoBuf object using the 33 | descriptor pool of this shared library. RProtoBuf shared library that is loaded when the RProtoBuf 34 | package is loaded will not be able to search genomics protocol buffer names as each shared 35 | library has its own internal descriptor pool. 36 | -------------------------------------------------------------------------------- /src/client-annotations.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017 GoogleGenomics R package authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the 'License'); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an 'AS IS' BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | using ::std::placeholders::_1; 29 | using ::std::placeholders::_2; 30 | using ::std::placeholders::_3; 31 | 32 | using ::grpc::ClientContext; 33 | using ::grpc::ClientReader; 34 | using ::grpc::Status; 35 | 36 | using namespace ::google::genomics::v1; 37 | using namespace ::googlegenomics; 38 | 39 | extern "C" { 40 | METHOD(AnnotationServiceV1, CreateAnnotationSet, CreateAnnotationSetRequest, 41 | AnnotationSet) 42 | 43 | METHOD(AnnotationServiceV1, GetAnnotationSet, GetAnnotationSetRequest, 44 | AnnotationSet) 45 | 46 | METHOD(AnnotationServiceV1, UpdateAnnotationSet, UpdateAnnotationSetRequest, 47 | AnnotationSet) 48 | 49 | METHOD(AnnotationServiceV1, DeleteAnnotationSet, DeleteAnnotationSetRequest, 50 | google::protobuf::Empty) 51 | 52 | METHOD(AnnotationServiceV1, SearchAnnotationSets, SearchAnnotationSetsRequest, 53 | SearchAnnotationSetsResponse) 54 | 55 | METHOD(AnnotationServiceV1, CreateAnnotation, CreateAnnotationRequest, 56 | Annotation) 57 | 58 | METHOD(AnnotationServiceV1, BatchCreateAnnotations, 59 | BatchCreateAnnotationsRequest, BatchCreateAnnotationsResponse) 60 | 61 | METHOD(AnnotationServiceV1, GetAnnotation, GetAnnotationRequest, Annotation) 62 | 63 | METHOD(AnnotationServiceV1, UpdateAnnotation, UpdateAnnotationRequest, 64 | Annotation) 65 | 66 | METHOD(AnnotationServiceV1, DeleteAnnotation, DeleteAnnotationRequest, 67 | google::protobuf::Empty) 68 | 69 | METHOD(AnnotationServiceV1, SearchAnnotations, SearchAnnotationsRequest, 70 | SearchAnnotationsResponse) 71 | } // extern C 72 | -------------------------------------------------------------------------------- /src/client-common.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017 GoogleGenomics R package authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the 'License'); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an 'AS IS' BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | namespace googlegenomics { 29 | std::shared_ptr getChannel() { 30 | // Authentication is handled outside of gRPC to support the non-GRPC methods. 31 | // static 32 | std::shared_ptr channel = 33 | grpc::CreateChannel("genomics.googleapis.com:443", 34 | grpc::SslCredentials(grpc::SslCredentialsOptions())); 35 | 36 | return channel; 37 | } 38 | 39 | Status ApiKeyCredentialsPlugin::GetMetadata( 40 | grpc::string_ref, grpc::string_ref, const grpc::AuthContext&, 41 | std::multimap* metadata) { 42 | metadata->insert(std::make_pair("x-api-key", api_key_.c_str())); 43 | return Status::OK; 44 | } 45 | 46 | void InitContext(SEXP credentialsList, ClientContext* context) { 47 | std::string api_key; 48 | std::string json_refresh_token; 49 | std::string access_token; 50 | 51 | SEXP names = Rf_getAttrib(credentialsList, R_NamesSymbol); 52 | for (int i = 0; i < Rf_length(credentialsList); ++i) { 53 | SEXP element = VECTOR_ELT(credentialsList, i); 54 | if (element == R_NilValue) { 55 | continue; 56 | } 57 | 58 | const char* name = CHAR(STRING_ELT(names, i)); 59 | std::string value = std::string(CHAR(STRING_ELT(element, 0))); 60 | if (strcmp(name, "api_key") == 0) { 61 | api_key = value; 62 | } else if (strcmp(name, "json_refresh_token") == 0) { 63 | json_refresh_token = value; 64 | } else if (strcmp(name, "access_token") == 0) { 65 | access_token = value; 66 | } 67 | } 68 | 69 | if (!api_key.empty()) { 70 | context->set_credentials(grpc::MetadataCredentialsFromPlugin( 71 | std::unique_ptr(new ApiKeyCredentialsPlugin(api_key)))); 72 | } 73 | 74 | if (!access_token.empty()) { 75 | context->set_credentials(grpc::AccessTokenCredentials(access_token)); 76 | } else if (!json_refresh_token.empty()) { 77 | context->set_credentials( 78 | grpc::GoogleRefreshTokenCredentials(json_refresh_token)); 79 | } 80 | 81 | context->set_wait_for_ready(true); 82 | } 83 | 84 | void ExplainError(const Status& status) { 85 | switch (status.error_code()) { 86 | case StatusCode::UNAUTHENTICATED: 87 | case StatusCode::PERMISSION_DENIED: 88 | REprintf( 89 | "Authentication error: %s\nPlease try authenticating again, or use " 90 | "a different method.\n", 91 | status.error_message().data()); 92 | break; 93 | default: 94 | REprintf("RPC Failed: %s\n", status.error_message().data()); 95 | } 96 | } 97 | 98 | // Checks the R request type and returns a protocol buffer request. 99 | // Cleans up any allocated memory for the call. 100 | SEXP FinalizeCall(SEXP request, ::google::protobuf::Message* request_message, 101 | ::google::protobuf::Message* response_message) { 102 | if (!(TYPEOF(request) == STRSXP || TYPEOF(request) == CHARSXP)) { 103 | return MakeRProtoBufObject( 104 | dynamic_cast<::google::protobuf::Message*>(response_message)); 105 | } 106 | 107 | std::string response_json; 108 | ::google::protobuf::util::Status status = 109 | ::google::protobuf::util::MessageToJsonString(*response_message, 110 | &response_json); 111 | if (!status.ok()) { 112 | REprintf("Error in final response conversion to json: %s\n", 113 | status.ToString().c_str()); 114 | return R_NilValue; 115 | } 116 | 117 | delete request_message; 118 | delete response_message; 119 | 120 | // R will make a copy of the string. 121 | SEXP response = PROTECT(Rf_mkString(response_json.c_str())); 122 | UNPROTECT(1); 123 | return response; 124 | } 125 | 126 | } // namespace googlegenomics 127 | -------------------------------------------------------------------------------- /src/client-common.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 GoogleGenomics R package authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the 'License'); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an 'AS IS' BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef GOOGLE_GENOMICS_CLIENT_COMMON_H 16 | #define GOOGLE_GENOMICS_CLIENT_COMMON_H 17 | 18 | #include 19 | #include 20 | 21 | #define R_NO_REMAP 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include 34 | 35 | namespace googlegenomics { 36 | using ::grpc::Channel; 37 | using ::grpc::ClientContext; 38 | using ::grpc::Status; 39 | using ::grpc::StatusCode; 40 | 41 | std::shared_ptr getChannel(); 42 | 43 | class ApiKeyCredentialsPlugin : public grpc::MetadataCredentialsPlugin { 44 | public: 45 | ApiKeyCredentialsPlugin(std::string api_key) : api_key_(api_key) {} 46 | 47 | Status GetMetadata( 48 | grpc::string_ref, grpc::string_ref, const grpc::AuthContext&, 49 | std::multimap* metadata) override; 50 | 51 | private: 52 | std::string api_key_; 53 | }; 54 | 55 | void InitContext(SEXP credentialsList, ClientContext* context); 56 | 57 | void ExplainError(const Status& status); 58 | 59 | // Checker for the presence of a page token field. 60 | template 61 | struct has_page_token : std::false_type {}; 62 | template 63 | struct has_page_token< 64 | Request, 65 | typename std::enable_if().clear_page_token()), void>::value>::type> 67 | : std::true_type {}; 68 | 69 | // Checks the R request type and returns a protocol buffer request. 70 | template 71 | Request* GetMessageObjectFromRequest(SEXP request) { 72 | if (!(TYPEOF(request) == STRSXP || TYPEOF(request) == CHARSXP)) { 73 | return static_cast(GetMessageFromRProtoBufObject(request)); 74 | } 75 | 76 | std::string request_json; 77 | switch (TYPEOF(request)) { 78 | case CHARSXP: 79 | request_json = std::string(CHAR(request)); 80 | break; 81 | case STRSXP: 82 | request_json = std::string(CHAR(STRING_ELT(request, 0))); 83 | } 84 | 85 | Request* request_message = new Request; 86 | ::google::protobuf::util::Status status = 87 | ::google::protobuf::util::JsonStringToMessage(request_json, 88 | request_message); 89 | if (!status.ok()) { 90 | REprintf("Error in initial request conversion from json: %s\n", 91 | status.ToString().c_str()); 92 | return nullptr; 93 | } 94 | 95 | return request_message; 96 | } 97 | 98 | // Cleans up any allocated memory for the call. 99 | SEXP FinalizeCall(SEXP request, ::google::protobuf::Message* request_message, 100 | ::google::protobuf::Message* response_message); 101 | 102 | // For non-paginated RPCs. 103 | template ::value, int>::type = 0> 105 | SEXP RPC( 106 | std::function stubMethod, 107 | SEXP request, SEXP credentialsList) { 108 | Request* request_message = GetMessageObjectFromRequest(request); 109 | if (request_message == nullptr) { 110 | return R_NilValue; 111 | } 112 | 113 | Response* response_message = new Response; 114 | ClientContext context; 115 | InitContext(credentialsList, &context); 116 | Status status = stubMethod(&context, *request_message, response_message); 117 | if (!status.ok()) { 118 | ExplainError(status); 119 | return R_NilValue; 120 | } 121 | 122 | return FinalizeCall(request, request_message, response_message); 123 | } 124 | 125 | // For paginated RPCs. 126 | template ::value, int>::type = 0> 128 | SEXP RPC( 129 | std::function stubMethod, 130 | SEXP request, SEXP credentialsList) { 131 | Request* request_message = GetMessageObjectFromRequest(request); 132 | if (request_message == nullptr) { 133 | return R_NilValue; 134 | } 135 | 136 | Response* response_message = new Response; 137 | do { 138 | Response response_chunk; 139 | ClientContext context; 140 | InitContext(credentialsList, &context); 141 | Status status = stubMethod(&context, *request_message, &response_chunk); 142 | if (!status.ok()) { 143 | ExplainError(status); 144 | return R_NilValue; 145 | } 146 | request_message->set_page_token(response_chunk.next_page_token()); 147 | response_message->MergeFrom(response_chunk); 148 | R_CheckUserInterrupt(); 149 | } while (!request_message->page_token().empty()); 150 | response_message->clear_next_page_token(); 151 | 152 | return FinalizeCall(request, request_message, response_message); 153 | } 154 | 155 | // For streamed RPCs. 156 | template 157 | SEXP StreamedRPC(std::function>( 158 | ClientContext*, const Request&)> 159 | stubMethod, 160 | SEXP request, SEXP credentialsList) { 161 | Request* request_message = GetMessageObjectFromRequest(request); 162 | if (request_message == nullptr) { 163 | return R_NilValue; 164 | } 165 | 166 | ClientContext context; 167 | InitContext(credentialsList, &context); 168 | Response* response_message = new Response; 169 | Response response_chunk; 170 | std::unique_ptr> reader = 171 | stubMethod(&context, *request_message); 172 | while (reader->Read(&response_chunk)) { 173 | response_message->MergeFrom(response_chunk); 174 | R_CheckUserInterrupt(); 175 | } 176 | 177 | Status status = reader->Finish(); 178 | if (!status.ok()) { 179 | ExplainError(status); 180 | return R_NilValue; 181 | } 182 | 183 | return FinalizeCall(request, request_message, response_message); 184 | } 185 | 186 | // Convenience macros to avoid boiler plate. 187 | #define METHOD(Service, MethodName, RequestType, ResponseType) \ 188 | SEXP MethodName(SEXP request, SEXP credentialsList) { \ 189 | std::unique_ptr stub = Service::NewStub(getChannel()); \ 190 | return RPC( \ 191 | std::bind(&Service::Stub::MethodName, stub.get(), _1, _2, _3), \ 192 | request, credentialsList); \ 193 | } 194 | 195 | #define STREAMED_METHOD(Service, MethodName, RequestType, ResponseType) \ 196 | SEXP MethodName(SEXP request, SEXP credentialsList) { \ 197 | std::unique_ptr stub = Service::NewStub(getChannel()); \ 198 | return StreamedRPC( \ 199 | std::bind(&Service::Stub::MethodName, stub.get(), _1, _2), request, \ 200 | credentialsList); \ 201 | } 202 | 203 | } // namespace googlegenomics 204 | 205 | #endif /* GOOGLE_GENOMICS_CLIENT_COMMON_H */ 206 | -------------------------------------------------------------------------------- /src/client-datasets.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017 GoogleGenomics R package authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the 'License'); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an 'AS IS' BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | using ::std::placeholders::_1; 29 | using ::std::placeholders::_2; 30 | using ::std::placeholders::_3; 31 | 32 | using ::grpc::ClientContext; 33 | using ::grpc::ClientReader; 34 | using ::grpc::Status; 35 | 36 | using namespace ::google::genomics::v1; 37 | using namespace ::googlegenomics; 38 | 39 | extern "C" { 40 | METHOD(DatasetServiceV1, ListDatasets, ListDatasetsRequest, 41 | ListDatasetsResponse) 42 | 43 | METHOD(DatasetServiceV1, CreateDataset, CreateDatasetRequest, Dataset) 44 | 45 | METHOD(DatasetServiceV1, GetDataset, GetDatasetRequest, Dataset) 46 | 47 | METHOD(DatasetServiceV1, UpdateDataset, UpdateDatasetRequest, Dataset) 48 | 49 | METHOD(DatasetServiceV1, DeleteDataset, DeleteDatasetRequest, 50 | google::protobuf::Empty) 51 | 52 | METHOD(DatasetServiceV1, UndeleteDataset, UndeleteDatasetRequest, Dataset) 53 | 54 | METHOD(DatasetServiceV1, SetIamPolicy, google::iam::v1::SetIamPolicyRequest, 55 | google::iam::v1::Policy) 56 | 57 | METHOD(DatasetServiceV1, GetIamPolicy, google::iam::v1::GetIamPolicyRequest, 58 | google::iam::v1::Policy) 59 | 60 | METHOD(DatasetServiceV1, TestIamPermissions, 61 | google::iam::v1::TestIamPermissionsRequest, 62 | google::iam::v1::TestIamPermissionsResponse) 63 | } // extern C 64 | -------------------------------------------------------------------------------- /src/client-reads.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017 GoogleGenomics R package authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the 'License'); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an 'AS IS' BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | using ::std::placeholders::_1; 29 | using ::std::placeholders::_2; 30 | using ::std::placeholders::_3; 31 | 32 | using ::grpc::ClientContext; 33 | using ::grpc::ClientReader; 34 | using ::grpc::Status; 35 | 36 | using namespace ::google::genomics::v1; 37 | using namespace ::googlegenomics; 38 | 39 | extern "C" { 40 | STREAMED_METHOD(StreamingReadService, StreamReads, StreamReadsRequest, 41 | StreamReadsResponse) 42 | 43 | METHOD(ReadServiceV1, ImportReadGroupSets, ImportReadGroupSetsRequest, 44 | google::longrunning::Operation) 45 | 46 | METHOD(ReadServiceV1, ExportReadGroupSet, ExportReadGroupSetRequest, 47 | google::longrunning::Operation) 48 | 49 | METHOD(ReadServiceV1, SearchReadGroupSets, SearchReadGroupSetsRequest, 50 | SearchReadGroupSetsResponse) 51 | 52 | METHOD(ReadServiceV1, UpdateReadGroupSet, UpdateReadGroupSetRequest, 53 | ReadGroupSet) 54 | 55 | METHOD(ReadServiceV1, DeleteReadGroupSet, DeleteReadGroupSetRequest, 56 | google::protobuf::Empty) 57 | 58 | METHOD(ReadServiceV1, GetReadGroupSet, GetReadGroupSetRequest, ReadGroupSet) 59 | 60 | METHOD(ReadServiceV1, ListCoverageBuckets, ListCoverageBucketsRequest, 61 | ListCoverageBucketsResponse) 62 | 63 | METHOD(ReadServiceV1, SearchReads, SearchReadsRequest, SearchReadsResponse) 64 | } // extern C 65 | -------------------------------------------------------------------------------- /src/client-references.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017 GoogleGenomics R package authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the 'License'); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an 'AS IS' BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | using ::std::placeholders::_1; 29 | using ::std::placeholders::_2; 30 | using ::std::placeholders::_3; 31 | 32 | using ::grpc::ClientContext; 33 | using ::grpc::ClientReader; 34 | using ::grpc::Status; 35 | 36 | using namespace ::google::genomics::v1; 37 | using namespace ::googlegenomics; 38 | 39 | extern "C" { 40 | METHOD(ReferenceServiceV1, SearchReferenceSets, SearchReferenceSetsRequest, 41 | SearchReferenceSetsResponse) 42 | 43 | METHOD(ReferenceServiceV1, GetReferenceSet, GetReferenceSetRequest, 44 | ReferenceSet) 45 | 46 | METHOD(ReferenceServiceV1, SearchReferences, SearchReferencesRequest, 47 | SearchReferencesResponse) 48 | 49 | METHOD(ReferenceServiceV1, GetReference, GetReferenceRequest, Reference) 50 | 51 | METHOD(ReferenceServiceV1, ListBases, ListBasesRequest, ListBasesResponse) 52 | } // extern C 53 | -------------------------------------------------------------------------------- /src/client-variants.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017 GoogleGenomics R package authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the 'License'); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an 'AS IS' BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | using ::std::placeholders::_1; 29 | using ::std::placeholders::_2; 30 | using ::std::placeholders::_3; 31 | 32 | using ::grpc::ClientContext; 33 | using ::grpc::ClientReader; 34 | using ::grpc::Status; 35 | 36 | using namespace ::google::genomics::v1; 37 | using namespace ::googlegenomics; 38 | 39 | extern "C" { 40 | STREAMED_METHOD(StreamingVariantService, StreamVariants, StreamVariantsRequest, 41 | StreamVariantsResponse) 42 | 43 | METHOD(VariantServiceV1, ImportVariants, ImportVariantsRequest, 44 | google::longrunning::Operation) 45 | 46 | METHOD(VariantServiceV1, CreateVariantSet, CreateVariantSetRequest, VariantSet) 47 | 48 | METHOD(VariantServiceV1, ExportVariantSet, ExportVariantSetRequest, 49 | google::longrunning::Operation) 50 | 51 | METHOD(VariantServiceV1, GetVariantSet, GetVariantSetRequest, VariantSet) 52 | 53 | METHOD(VariantServiceV1, SearchVariantSets, SearchVariantSetsRequest, 54 | SearchVariantSetsResponse) 55 | 56 | METHOD(VariantServiceV1, DeleteVariantSet, DeleteVariantSetRequest, 57 | google::protobuf::Empty) 58 | 59 | METHOD(VariantServiceV1, UpdateVariantSet, UpdateVariantSetRequest, VariantSet) 60 | 61 | METHOD(VariantServiceV1, SearchVariants, SearchVariantsRequest, 62 | SearchVariantsResponse) 63 | 64 | METHOD(VariantServiceV1, CreateVariant, CreateVariantRequest, Variant) 65 | 66 | METHOD(VariantServiceV1, UpdateVariant, UpdateVariantRequest, Variant) 67 | 68 | METHOD(VariantServiceV1, DeleteVariant, DeleteVariantRequest, 69 | google::protobuf::Empty) 70 | 71 | METHOD(VariantServiceV1, GetVariant, GetVariantRequest, Variant) 72 | 73 | METHOD(VariantServiceV1, MergeVariants, MergeVariantsRequest, 74 | google::protobuf::Empty) 75 | 76 | METHOD(VariantServiceV1, SearchCallSets, SearchCallSetsRequest, 77 | SearchCallSetsResponse) 78 | 79 | METHOD(VariantServiceV1, CreateCallSet, CreateCallSetRequest, CallSet) 80 | 81 | METHOD(VariantServiceV1, UpdateCallSet, UpdateCallSetRequest, CallSet) 82 | 83 | METHOD(VariantServiceV1, DeleteCallSet, DeleteCallSetRequest, 84 | google::protobuf::Empty) 85 | 86 | METHOD(VariantServiceV1, GetCallSet, GetCallSetRequest, CallSet) 87 | } // extern C 88 | -------------------------------------------------------------------------------- /src/google/api/annotations.proto: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015, Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.api; 18 | 19 | import "google/api/http.proto"; 20 | import "google/protobuf/descriptor.proto"; 21 | 22 | option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; 23 | option java_multiple_files = true; 24 | option java_outer_classname = "AnnotationsProto"; 25 | option java_package = "com.google.api"; 26 | option objc_class_prefix = "GAPI"; 27 | 28 | extend google.protobuf.MethodOptions { 29 | // See `HttpRule`. 30 | HttpRule http = 72295728; 31 | } 32 | -------------------------------------------------------------------------------- /src/google/api/http.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.api; 18 | 19 | option cc_enable_arenas = true; 20 | option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; 21 | option java_multiple_files = true; 22 | option java_outer_classname = "HttpProto"; 23 | option java_package = "com.google.api"; 24 | option objc_class_prefix = "GAPI"; 25 | 26 | 27 | // Defines the HTTP configuration for a service. It contains a list of 28 | // [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method 29 | // to one or more HTTP REST API methods. 30 | message Http { 31 | // A list of HTTP configuration rules that apply to individual API methods. 32 | // 33 | // **NOTE:** All service configuration rules follow "last one wins" order. 34 | repeated HttpRule rules = 1; 35 | } 36 | 37 | // `HttpRule` defines the mapping of an RPC method to one or more HTTP 38 | // REST APIs. The mapping determines what portions of the request 39 | // message are populated from the path, query parameters, or body of 40 | // the HTTP request. The mapping is typically specified as an 41 | // `google.api.http` annotation, see "google/api/annotations.proto" 42 | // for details. 43 | // 44 | // The mapping consists of a field specifying the path template and 45 | // method kind. The path template can refer to fields in the request 46 | // message, as in the example below which describes a REST GET 47 | // operation on a resource collection of messages: 48 | // 49 | // 50 | // service Messaging { 51 | // rpc GetMessage(GetMessageRequest) returns (Message) { 52 | // option (google.api.http).get = "/v1/messages/{message_id}/{sub.subfield}"; 53 | // } 54 | // } 55 | // message GetMessageRequest { 56 | // message SubMessage { 57 | // string subfield = 1; 58 | // } 59 | // string message_id = 1; // mapped to the URL 60 | // SubMessage sub = 2; // `sub.subfield` is url-mapped 61 | // } 62 | // message Message { 63 | // string text = 1; // content of the resource 64 | // } 65 | // 66 | // The same http annotation can alternatively be expressed inside the 67 | // `GRPC API Configuration` YAML file. 68 | // 69 | // http: 70 | // rules: 71 | // - selector: .Messaging.GetMessage 72 | // get: /v1/messages/{message_id}/{sub.subfield} 73 | // 74 | // This definition enables an automatic, bidrectional mapping of HTTP 75 | // JSON to RPC. Example: 76 | // 77 | // HTTP | RPC 78 | // -----|----- 79 | // `GET /v1/messages/123456/foo` | `GetMessage(message_id: "123456" sub: SubMessage(subfield: "foo"))` 80 | // 81 | // In general, not only fields but also field paths can be referenced 82 | // from a path pattern. Fields mapped to the path pattern cannot be 83 | // repeated and must have a primitive (non-message) type. 84 | // 85 | // Any fields in the request message which are not bound by the path 86 | // pattern automatically become (optional) HTTP query 87 | // parameters. Assume the following definition of the request message: 88 | // 89 | // 90 | // message GetMessageRequest { 91 | // message SubMessage { 92 | // string subfield = 1; 93 | // } 94 | // string message_id = 1; // mapped to the URL 95 | // int64 revision = 2; // becomes a parameter 96 | // SubMessage sub = 3; // `sub.subfield` becomes a parameter 97 | // } 98 | // 99 | // 100 | // This enables a HTTP JSON to RPC mapping as below: 101 | // 102 | // HTTP | RPC 103 | // -----|----- 104 | // `GET /v1/messages/123456?revision=2&sub.subfield=foo` | `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: "foo"))` 105 | // 106 | // Note that fields which are mapped to HTTP parameters must have a 107 | // primitive type or a repeated primitive type. Message types are not 108 | // allowed. In the case of a repeated type, the parameter can be 109 | // repeated in the URL, as in `...?param=A¶m=B`. 110 | // 111 | // For HTTP method kinds which allow a request body, the `body` field 112 | // specifies the mapping. Consider a REST update method on the 113 | // message resource collection: 114 | // 115 | // 116 | // service Messaging { 117 | // rpc UpdateMessage(UpdateMessageRequest) returns (Message) { 118 | // option (google.api.http) = { 119 | // put: "/v1/messages/{message_id}" 120 | // body: "message" 121 | // }; 122 | // } 123 | // } 124 | // message UpdateMessageRequest { 125 | // string message_id = 1; // mapped to the URL 126 | // Message message = 2; // mapped to the body 127 | // } 128 | // 129 | // 130 | // The following HTTP JSON to RPC mapping is enabled, where the 131 | // representation of the JSON in the request body is determined by 132 | // protos JSON encoding: 133 | // 134 | // HTTP | RPC 135 | // -----|----- 136 | // `PUT /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: "123456" message { text: "Hi!" })` 137 | // 138 | // The special name `*` can be used in the body mapping to define that 139 | // every field not bound by the path template should be mapped to the 140 | // request body. This enables the following alternative definition of 141 | // the update method: 142 | // 143 | // service Messaging { 144 | // rpc UpdateMessage(Message) returns (Message) { 145 | // option (google.api.http) = { 146 | // put: "/v1/messages/{message_id}" 147 | // body: "*" 148 | // }; 149 | // } 150 | // } 151 | // message Message { 152 | // string message_id = 1; 153 | // string text = 2; 154 | // } 155 | // 156 | // 157 | // The following HTTP JSON to RPC mapping is enabled: 158 | // 159 | // HTTP | RPC 160 | // -----|----- 161 | // `PUT /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: "123456" text: "Hi!")` 162 | // 163 | // Note that when using `*` in the body mapping, it is not possible to 164 | // have HTTP parameters, as all fields not bound by the path end in 165 | // the body. This makes this option more rarely used in practice of 166 | // defining REST APIs. The common usage of `*` is in custom methods 167 | // which don't use the URL at all for transferring data. 168 | // 169 | // It is possible to define multiple HTTP methods for one RPC by using 170 | // the `additional_bindings` option. Example: 171 | // 172 | // service Messaging { 173 | // rpc GetMessage(GetMessageRequest) returns (Message) { 174 | // option (google.api.http) = { 175 | // get: "/v1/messages/{message_id}" 176 | // additional_bindings { 177 | // get: "/v1/users/{user_id}/messages/{message_id}" 178 | // } 179 | // }; 180 | // } 181 | // } 182 | // message GetMessageRequest { 183 | // string message_id = 1; 184 | // string user_id = 2; 185 | // } 186 | // 187 | // 188 | // This enables the following two alternative HTTP JSON to RPC 189 | // mappings: 190 | // 191 | // HTTP | RPC 192 | // -----|----- 193 | // `GET /v1/messages/123456` | `GetMessage(message_id: "123456")` 194 | // `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: "123456")` 195 | // 196 | // # Rules for HTTP mapping 197 | // 198 | // The rules for mapping HTTP path, query parameters, and body fields 199 | // to the request message are as follows: 200 | // 201 | // 1. The `body` field specifies either `*` or a field path, or is 202 | // omitted. If omitted, it assumes there is no HTTP body. 203 | // 2. Leaf fields (recursive expansion of nested messages in the 204 | // request) can be classified into three types: 205 | // (a) Matched in the URL template. 206 | // (b) Covered by body (if body is `*`, everything except (a) fields; 207 | // else everything under the body field) 208 | // (c) All other fields. 209 | // 3. URL query parameters found in the HTTP request are mapped to (c) fields. 210 | // 4. Any body sent with an HTTP request can contain only (b) fields. 211 | // 212 | // The syntax of the path template is as follows: 213 | // 214 | // Template = "/" Segments [ Verb ] ; 215 | // Segments = Segment { "/" Segment } ; 216 | // Segment = "*" | "**" | LITERAL | Variable ; 217 | // Variable = "{" FieldPath [ "=" Segments ] "}" ; 218 | // FieldPath = IDENT { "." IDENT } ; 219 | // Verb = ":" LITERAL ; 220 | // 221 | // The syntax `*` matches a single path segment. It follows the semantics of 222 | // [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.2 Simple String 223 | // Expansion. 224 | // 225 | // The syntax `**` matches zero or more path segments. It follows the semantics 226 | // of [RFC 6570](https://tools.ietf.org/html/rfc6570) Section 3.2.3 Reserved 227 | // Expansion. NOTE: it must be the last segment in the path except the Verb. 228 | // 229 | // The syntax `LITERAL` matches literal text in the URL path. 230 | // 231 | // The syntax `Variable` matches the entire path as specified by its template; 232 | // this nested template must not contain further variables. If a variable 233 | // matches a single path segment, its template may be omitted, e.g. `{var}` 234 | // is equivalent to `{var=*}`. 235 | // 236 | // NOTE: the field paths in variables and in the `body` must not refer to 237 | // repeated fields or map fields. 238 | // 239 | // Use CustomHttpPattern to specify any HTTP method that is not included in the 240 | // `pattern` field, such as HEAD, or "*" to leave the HTTP method unspecified for 241 | // a given URL path rule. The wild-card rule is useful for services that provide 242 | // content to Web (HTML) clients. 243 | message HttpRule { 244 | // Selects methods to which this rule applies. 245 | // 246 | // Refer to [selector][google.api.DocumentationRule.selector] for syntax details. 247 | string selector = 1; 248 | 249 | // Determines the URL pattern is matched by this rules. This pattern can be 250 | // used with any of the {get|put|post|delete|patch} methods. A custom method 251 | // can be defined using the 'custom' field. 252 | oneof pattern { 253 | // Used for listing and getting information about resources. 254 | string get = 2; 255 | 256 | // Used for updating a resource. 257 | string put = 3; 258 | 259 | // Used for creating a resource. 260 | string post = 4; 261 | 262 | // Used for deleting a resource. 263 | string delete = 5; 264 | 265 | // Used for updating a resource. 266 | string patch = 6; 267 | 268 | // Custom pattern is used for defining custom verbs. 269 | CustomHttpPattern custom = 8; 270 | } 271 | 272 | // The name of the request field whose value is mapped to the HTTP body, or 273 | // `*` for mapping all fields not captured by the path pattern to the HTTP 274 | // body. NOTE: the referred field must not be a repeated field and must be 275 | // present at the top-level of request message type. 276 | string body = 7; 277 | 278 | // Additional HTTP bindings for the selector. Nested bindings must 279 | // not contain an `additional_bindings` field themselves (that is, 280 | // the nesting may only be one level deep). 281 | repeated HttpRule additional_bindings = 11; 282 | } 283 | 284 | // A custom pattern is used for defining custom HTTP verb. 285 | message CustomHttpPattern { 286 | // The name of this custom HTTP verb. 287 | string kind = 1; 288 | 289 | // The path matched by this custom verb. 290 | string path = 2; 291 | } 292 | -------------------------------------------------------------------------------- /src/google/genomics/v1/cigar.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.genomics.v1; 18 | 19 | import "google/api/annotations.proto"; 20 | 21 | option cc_enable_arenas = true; 22 | option go_package = "google.golang.org/genproto/googleapis/genomics/v1;genomics"; 23 | option java_multiple_files = true; 24 | option java_outer_classname = "CigarProto"; 25 | option java_package = "com.google.genomics.v1"; 26 | 27 | 28 | // A single CIGAR operation. 29 | message CigarUnit { 30 | // Describes the different types of CIGAR alignment operations that exist. 31 | // Used wherever CIGAR alignments are used. 32 | enum Operation { 33 | OPERATION_UNSPECIFIED = 0; 34 | 35 | // An alignment match indicates that a sequence can be aligned to the 36 | // reference without evidence of an INDEL. Unlike the 37 | // `SEQUENCE_MATCH` and `SEQUENCE_MISMATCH` operators, 38 | // the `ALIGNMENT_MATCH` operator does not indicate whether the 39 | // reference and read sequences are an exact match. This operator is 40 | // equivalent to SAM's `M`. 41 | ALIGNMENT_MATCH = 1; 42 | 43 | // The insert operator indicates that the read contains evidence of bases 44 | // being inserted into the reference. This operator is equivalent to SAM's 45 | // `I`. 46 | INSERT = 2; 47 | 48 | // The delete operator indicates that the read contains evidence of bases 49 | // being deleted from the reference. This operator is equivalent to SAM's 50 | // `D`. 51 | DELETE = 3; 52 | 53 | // The skip operator indicates that this read skips a long segment of the 54 | // reference, but the bases have not been deleted. This operator is commonly 55 | // used when working with RNA-seq data, where reads may skip long segments 56 | // of the reference between exons. This operator is equivalent to SAM's 57 | // `N`. 58 | SKIP = 4; 59 | 60 | // The soft clip operator indicates that bases at the start/end of a read 61 | // have not been considered during alignment. This may occur if the majority 62 | // of a read maps, except for low quality bases at the start/end of a read. 63 | // This operator is equivalent to SAM's `S`. Bases that are soft 64 | // clipped will still be stored in the read. 65 | CLIP_SOFT = 5; 66 | 67 | // The hard clip operator indicates that bases at the start/end of a read 68 | // have been omitted from this alignment. This may occur if this linear 69 | // alignment is part of a chimeric alignment, or if the read has been 70 | // trimmed (for example, during error correction or to trim poly-A tails for 71 | // RNA-seq). This operator is equivalent to SAM's `H`. 72 | CLIP_HARD = 6; 73 | 74 | // The pad operator indicates that there is padding in an alignment. This 75 | // operator is equivalent to SAM's `P`. 76 | PAD = 7; 77 | 78 | // This operator indicates that this portion of the aligned sequence exactly 79 | // matches the reference. This operator is equivalent to SAM's `=`. 80 | SEQUENCE_MATCH = 8; 81 | 82 | // This operator indicates that this portion of the aligned sequence is an 83 | // alignment match to the reference, but a sequence mismatch. This can 84 | // indicate a SNP or a read error. This operator is equivalent to SAM's 85 | // `X`. 86 | SEQUENCE_MISMATCH = 9; 87 | } 88 | 89 | Operation operation = 1; 90 | 91 | // The number of genomic bases that the operation runs for. Required. 92 | int64 operation_length = 2; 93 | 94 | // `referenceSequence` is only used at mismatches 95 | // (`SEQUENCE_MISMATCH`) and deletions (`DELETE`). 96 | // Filling this field replaces SAM's MD tag. If the relevant information is 97 | // not available, this field is unset. 98 | string reference_sequence = 3; 99 | } 100 | -------------------------------------------------------------------------------- /src/google/genomics/v1/datasets.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.genomics.v1; 18 | 19 | import "google/api/annotations.proto"; 20 | import "google/iam/v1/iam_policy.proto"; 21 | import "google/iam/v1/policy.proto"; 22 | import "google/protobuf/empty.proto"; 23 | import "google/protobuf/field_mask.proto"; 24 | import "google/protobuf/timestamp.proto"; 25 | 26 | option cc_enable_arenas = true; 27 | option go_package = "google.golang.org/genproto/googleapis/genomics/v1;genomics"; 28 | option java_multiple_files = true; 29 | option java_outer_classname = "DatasetsProto"; 30 | option java_package = "com.google.genomics.v1"; 31 | 32 | 33 | // This service manages datasets, which are collections of genomic data. 34 | service DatasetServiceV1 { 35 | // Lists datasets within a project. 36 | // 37 | // For the definitions of datasets and other genomics resources, see 38 | // [Fundamentals of Google 39 | // Genomics](https://cloud.google.com/genomics/fundamentals-of-google-genomics) 40 | rpc ListDatasets(ListDatasetsRequest) returns (ListDatasetsResponse) { 41 | option (google.api.http) = { get: "/v1/datasets" }; 42 | } 43 | 44 | // Creates a new dataset. 45 | // 46 | // For the definitions of datasets and other genomics resources, see 47 | // [Fundamentals of Google 48 | // Genomics](https://cloud.google.com/genomics/fundamentals-of-google-genomics) 49 | rpc CreateDataset(CreateDatasetRequest) returns (Dataset) { 50 | option (google.api.http) = { post: "/v1/datasets" body: "dataset" }; 51 | } 52 | 53 | // Gets a dataset by ID. 54 | // 55 | // For the definitions of datasets and other genomics resources, see 56 | // [Fundamentals of Google 57 | // Genomics](https://cloud.google.com/genomics/fundamentals-of-google-genomics) 58 | rpc GetDataset(GetDatasetRequest) returns (Dataset) { 59 | option (google.api.http) = { get: "/v1/datasets/{dataset_id}" }; 60 | } 61 | 62 | // Updates a dataset. 63 | // 64 | // For the definitions of datasets and other genomics resources, see 65 | // [Fundamentals of Google 66 | // Genomics](https://cloud.google.com/genomics/fundamentals-of-google-genomics) 67 | // 68 | // This method supports patch semantics. 69 | rpc UpdateDataset(UpdateDatasetRequest) returns (Dataset) { 70 | option (google.api.http) = { patch: "/v1/datasets/{dataset_id}" body: "dataset" }; 71 | } 72 | 73 | // Deletes a dataset and all of its contents (all read group sets, 74 | // reference sets, variant sets, call sets, annotation sets, etc.) 75 | // This is reversible (up to one week after the deletion) via 76 | // the 77 | // [datasets.undelete][google.genomics.v1.DatasetServiceV1.UndeleteDataset] 78 | // operation. 79 | // 80 | // For the definitions of datasets and other genomics resources, see 81 | // [Fundamentals of Google 82 | // Genomics](https://cloud.google.com/genomics/fundamentals-of-google-genomics) 83 | rpc DeleteDataset(DeleteDatasetRequest) returns (google.protobuf.Empty) { 84 | option (google.api.http) = { delete: "/v1/datasets/{dataset_id}" }; 85 | } 86 | 87 | // Undeletes a dataset by restoring a dataset which was deleted via this API. 88 | // 89 | // For the definitions of datasets and other genomics resources, see 90 | // [Fundamentals of Google 91 | // Genomics](https://cloud.google.com/genomics/fundamentals-of-google-genomics) 92 | // 93 | // This operation is only possible for a week after the deletion occurred. 94 | rpc UndeleteDataset(UndeleteDatasetRequest) returns (Dataset) { 95 | option (google.api.http) = { post: "/v1/datasets/{dataset_id}:undelete" body: "*" }; 96 | } 97 | 98 | // Sets the access control policy on the specified dataset. Replaces any 99 | // existing policy. 100 | // 101 | // For the definitions of datasets and other genomics resources, see 102 | // [Fundamentals of Google 103 | // Genomics](https://cloud.google.com/genomics/fundamentals-of-google-genomics) 104 | // 105 | // See Setting a 106 | // Policy for more information. 107 | rpc SetIamPolicy(google.iam.v1.SetIamPolicyRequest) returns (google.iam.v1.Policy) { 108 | option (google.api.http) = { post: "/v1/{resource=datasets/*}:setIamPolicy" body: "*" }; 109 | } 110 | 111 | // Gets the access control policy for the dataset. This is empty if the 112 | // policy or resource does not exist. 113 | // 114 | // See Getting a 115 | // Policy for more information. 116 | // 117 | // For the definitions of datasets and other genomics resources, see 118 | // [Fundamentals of Google 119 | // Genomics](https://cloud.google.com/genomics/fundamentals-of-google-genomics) 120 | rpc GetIamPolicy(google.iam.v1.GetIamPolicyRequest) returns (google.iam.v1.Policy) { 121 | option (google.api.http) = { post: "/v1/{resource=datasets/*}:getIamPolicy" body: "*" }; 122 | } 123 | 124 | // Returns permissions that a caller has on the specified resource. 125 | // See Testing 126 | // Permissions for more information. 127 | // 128 | // For the definitions of datasets and other genomics resources, see 129 | // [Fundamentals of Google 130 | // Genomics](https://cloud.google.com/genomics/fundamentals-of-google-genomics) 131 | rpc TestIamPermissions(google.iam.v1.TestIamPermissionsRequest) returns (google.iam.v1.TestIamPermissionsResponse) { 132 | option (google.api.http) = { post: "/v1/{resource=datasets/*}:testIamPermissions" body: "*" }; 133 | } 134 | } 135 | 136 | // A Dataset is a collection of genomic data. 137 | // 138 | // For more genomics resource definitions, see [Fundamentals of Google 139 | // Genomics](https://cloud.google.com/genomics/fundamentals-of-google-genomics) 140 | message Dataset { 141 | // The server-generated dataset ID, unique across all datasets. 142 | string id = 1; 143 | 144 | // The Google Cloud project ID that this dataset belongs to. 145 | string project_id = 2; 146 | 147 | // The dataset name. 148 | string name = 3; 149 | 150 | // The time this dataset was created, in seconds from the epoch. 151 | google.protobuf.Timestamp create_time = 4; 152 | } 153 | 154 | // The dataset list request. 155 | message ListDatasetsRequest { 156 | // Required. The Google Cloud project ID to list datasets for. 157 | string project_id = 1; 158 | 159 | // The maximum number of results to return in a single page. If unspecified, 160 | // defaults to 50. The maximum value is 1024. 161 | int32 page_size = 2; 162 | 163 | // The continuation token, which is used to page through large result sets. 164 | // To get the next page of results, set this parameter to the value of 165 | // `nextPageToken` from the previous response. 166 | string page_token = 3; 167 | } 168 | 169 | // The dataset list response. 170 | message ListDatasetsResponse { 171 | // The list of matching Datasets. 172 | repeated Dataset datasets = 1; 173 | 174 | // The continuation token, which is used to page through large result sets. 175 | // Provide this value in a subsequent request to return the next page of 176 | // results. This field will be empty if there aren't any additional results. 177 | string next_page_token = 2; 178 | } 179 | 180 | message CreateDatasetRequest { 181 | // The dataset to be created. Must contain projectId and name. 182 | Dataset dataset = 1; 183 | } 184 | 185 | message UpdateDatasetRequest { 186 | // The ID of the dataset to be updated. 187 | string dataset_id = 1; 188 | 189 | // The new dataset data. 190 | Dataset dataset = 2; 191 | 192 | // An optional mask specifying which fields to update. At this time, the only 193 | // mutable field is [name][google.genomics.v1.Dataset.name]. The only 194 | // acceptable value is "name". If unspecified, all mutable fields will be 195 | // updated. 196 | google.protobuf.FieldMask update_mask = 3; 197 | } 198 | 199 | message DeleteDatasetRequest { 200 | // The ID of the dataset to be deleted. 201 | string dataset_id = 1; 202 | } 203 | 204 | message UndeleteDatasetRequest { 205 | // The ID of the dataset to be undeleted. 206 | string dataset_id = 1; 207 | } 208 | 209 | message GetDatasetRequest { 210 | // The ID of the dataset. 211 | string dataset_id = 1; 212 | } 213 | -------------------------------------------------------------------------------- /src/google/genomics/v1/operations.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.genomics.v1; 18 | 19 | import "google/api/annotations.proto"; 20 | import "google/protobuf/any.proto"; 21 | import "google/protobuf/timestamp.proto"; 22 | 23 | option cc_enable_arenas = true; 24 | option go_package = "google.golang.org/genproto/googleapis/genomics/v1;genomics"; 25 | option java_multiple_files = true; 26 | option java_outer_classname = "OperationsProto"; 27 | option java_package = "com.google.genomics.v1"; 28 | 29 | 30 | // Metadata describing an [Operation][google.longrunning.Operation]. 31 | message OperationMetadata { 32 | // The Google Cloud Project in which the job is scoped. 33 | string project_id = 1; 34 | 35 | // The time at which the job was submitted to the Genomics service. 36 | google.protobuf.Timestamp create_time = 2; 37 | 38 | // The time at which the job began to run. 39 | google.protobuf.Timestamp start_time = 3; 40 | 41 | // The time at which the job stopped running. 42 | google.protobuf.Timestamp end_time = 4; 43 | 44 | // The original request that started the operation. Note that this will be in 45 | // current version of the API. If the operation was started with v1beta2 API 46 | // and a GetOperation is performed on v1 API, a v1 request will be returned. 47 | google.protobuf.Any request = 5; 48 | 49 | // Optional event messages that were generated during the job's execution. 50 | // This also contains any warnings that were generated during import 51 | // or export. 52 | repeated OperationEvent events = 6; 53 | 54 | // This field is deprecated. Use `labels` instead. Optionally provided by the 55 | // caller when submitting the request that creates the operation. 56 | string client_id = 7; 57 | 58 | // Runtime metadata on this Operation. 59 | google.protobuf.Any runtime_metadata = 8; 60 | 61 | // Optionally provided by the caller when submitting the request that creates 62 | // the operation. 63 | map labels = 9; 64 | } 65 | 66 | // An event that occurred during an [Operation][google.longrunning.Operation]. 67 | message OperationEvent { 68 | // Optional time of when event started. 69 | google.protobuf.Timestamp start_time = 1; 70 | 71 | // Optional time of when event finished. An event can have a start time and no 72 | // finish time. If an event has a finish time, there must be a start time. 73 | google.protobuf.Timestamp end_time = 2; 74 | 75 | // Required description of event. 76 | string description = 3; 77 | } 78 | -------------------------------------------------------------------------------- /src/google/genomics/v1/position.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.genomics.v1; 18 | 19 | import "google/api/annotations.proto"; 20 | 21 | option cc_enable_arenas = true; 22 | option go_package = "google.golang.org/genproto/googleapis/genomics/v1;genomics"; 23 | option java_multiple_files = true; 24 | option java_outer_classname = "PositionProto"; 25 | option java_package = "com.google.genomics.v1"; 26 | 27 | 28 | // An abstraction for referring to a genomic position, in relation to some 29 | // already known reference. For now, represents a genomic position as a 30 | // reference name, a base number on that reference (0-based), and a 31 | // determination of forward or reverse strand. 32 | message Position { 33 | // The name of the reference in whatever reference set is being used. 34 | string reference_name = 1; 35 | 36 | // The 0-based offset from the start of the forward strand for that reference. 37 | int64 position = 2; 38 | 39 | // Whether this position is on the reverse strand, as opposed to the forward 40 | // strand. 41 | bool reverse_strand = 3; 42 | } 43 | -------------------------------------------------------------------------------- /src/google/genomics/v1/range.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.genomics.v1; 18 | 19 | import "google/api/annotations.proto"; 20 | 21 | option cc_enable_arenas = true; 22 | option go_package = "google.golang.org/genproto/googleapis/genomics/v1;genomics"; 23 | option java_multiple_files = true; 24 | option java_outer_classname = "RangeProto"; 25 | option java_package = "com.google.genomics.v1"; 26 | 27 | 28 | // A 0-based half-open genomic coordinate range for search requests. 29 | message Range { 30 | // The reference sequence name, for example `chr1`, 31 | // `1`, or `chrX`. 32 | string reference_name = 1; 33 | 34 | // The start position of the range on the reference, 0-based inclusive. 35 | int64 start = 2; 36 | 37 | // The end position of the range on the reference, 0-based exclusive. 38 | int64 end = 3; 39 | } 40 | -------------------------------------------------------------------------------- /src/google/genomics/v1/readalignment.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.genomics.v1; 18 | 19 | import "google/api/annotations.proto"; 20 | import "google/genomics/v1/cigar.proto"; 21 | import "google/genomics/v1/position.proto"; 22 | import "google/protobuf/struct.proto"; 23 | 24 | option cc_enable_arenas = true; 25 | option go_package = "google.golang.org/genproto/googleapis/genomics/v1;genomics"; 26 | option java_multiple_files = true; 27 | option java_outer_classname = "ReadAlignmentProto"; 28 | option java_package = "com.google.genomics.v1"; 29 | 30 | 31 | // A linear alignment can be represented by one CIGAR string. Describes the 32 | // mapped position and local alignment of the read to the reference. 33 | message LinearAlignment { 34 | // The position of this alignment. 35 | Position position = 1; 36 | 37 | // The mapping quality of this alignment. Represents how likely 38 | // the read maps to this position as opposed to other locations. 39 | // 40 | // Specifically, this is -10 log10 Pr(mapping position is wrong), rounded to 41 | // the nearest integer. 42 | int32 mapping_quality = 2; 43 | 44 | // Represents the local alignment of this sequence (alignment matches, indels, 45 | // etc) against the reference. 46 | repeated CigarUnit cigar = 3; 47 | } 48 | 49 | // A read alignment describes a linear alignment of a string of DNA to a 50 | // [reference sequence][google.genomics.v1.Reference], in addition to metadata 51 | // about the fragment (the molecule of DNA sequenced) and the read (the bases 52 | // which were read by the sequencer). A read is equivalent to a line in a SAM 53 | // file. A read belongs to exactly one read group and exactly one 54 | // [read group set][google.genomics.v1.ReadGroupSet]. 55 | // 56 | // For more genomics resource definitions, see [Fundamentals of Google 57 | // Genomics](https://cloud.google.com/genomics/fundamentals-of-google-genomics) 58 | // 59 | // ### Reverse-stranded reads 60 | // 61 | // Mapped reads (reads having a non-null `alignment`) can be aligned to either 62 | // the forward or the reverse strand of their associated reference. Strandedness 63 | // of a mapped read is encoded by `alignment.position.reverseStrand`. 64 | // 65 | // If we consider the reference to be a forward-stranded coordinate space of 66 | // `[0, reference.length)` with `0` as the left-most position and 67 | // `reference.length` as the right-most position, reads are always aligned left 68 | // to right. That is, `alignment.position.position` always refers to the 69 | // left-most reference coordinate and `alignment.cigar` describes the alignment 70 | // of this read to the reference from left to right. All per-base fields such as 71 | // `alignedSequence` and `alignedQuality` share this same left-to-right 72 | // orientation; this is true of reads which are aligned to either strand. For 73 | // reverse-stranded reads, this means that `alignedSequence` is the reverse 74 | // complement of the bases that were originally reported by the sequencing 75 | // machine. 76 | // 77 | // ### Generating a reference-aligned sequence string 78 | // 79 | // When interacting with mapped reads, it's often useful to produce a string 80 | // representing the local alignment of the read to reference. The following 81 | // pseudocode demonstrates one way of doing this: 82 | // 83 | // out = "" 84 | // offset = 0 85 | // for c in read.alignment.cigar { 86 | // switch c.operation { 87 | // case "ALIGNMENT_MATCH", "SEQUENCE_MATCH", "SEQUENCE_MISMATCH": 88 | // out += read.alignedSequence[offset:offset+c.operationLength] 89 | // offset += c.operationLength 90 | // break 91 | // case "CLIP_SOFT", "INSERT": 92 | // offset += c.operationLength 93 | // break 94 | // case "PAD": 95 | // out += repeat("*", c.operationLength) 96 | // break 97 | // case "DELETE": 98 | // out += repeat("-", c.operationLength) 99 | // break 100 | // case "SKIP": 101 | // out += repeat(" ", c.operationLength) 102 | // break 103 | // case "CLIP_HARD": 104 | // break 105 | // } 106 | // } 107 | // return out 108 | // 109 | // ### Converting to SAM's CIGAR string 110 | // 111 | // The following pseudocode generates a SAM CIGAR string from the 112 | // `cigar` field. Note that this is a lossy conversion 113 | // (`cigar.referenceSequence` is lost). 114 | // 115 | // cigarMap = { 116 | // "ALIGNMENT_MATCH": "M", 117 | // "INSERT": "I", 118 | // "DELETE": "D", 119 | // "SKIP": "N", 120 | // "CLIP_SOFT": "S", 121 | // "CLIP_HARD": "H", 122 | // "PAD": "P", 123 | // "SEQUENCE_MATCH": "=", 124 | // "SEQUENCE_MISMATCH": "X", 125 | // } 126 | // cigarStr = "" 127 | // for c in read.alignment.cigar { 128 | // cigarStr += c.operationLength + cigarMap[c.operation] 129 | // } 130 | // return cigarStr 131 | message Read { 132 | // The server-generated read ID, unique across all reads. This is different 133 | // from the `fragmentName`. 134 | string id = 1; 135 | 136 | // The ID of the read group this read belongs to. A read belongs to exactly 137 | // one read group. This is a server-generated ID which is distinct from SAM's 138 | // RG tag (for that value, see 139 | // [ReadGroup.name][google.genomics.v1.ReadGroup.name]). 140 | string read_group_id = 2; 141 | 142 | // The ID of the read group set this read belongs to. A read belongs to 143 | // exactly one read group set. 144 | string read_group_set_id = 3; 145 | 146 | // The fragment name. Equivalent to QNAME (query template name) in SAM. 147 | string fragment_name = 4; 148 | 149 | // The orientation and the distance between reads from the fragment are 150 | // consistent with the sequencing protocol (SAM flag 0x2). 151 | bool proper_placement = 5; 152 | 153 | // The fragment is a PCR or optical duplicate (SAM flag 0x400). 154 | bool duplicate_fragment = 6; 155 | 156 | // The observed length of the fragment, equivalent to TLEN in SAM. 157 | int32 fragment_length = 7; 158 | 159 | // The read number in sequencing. 0-based and less than numberReads. This 160 | // field replaces SAM flag 0x40 and 0x80. 161 | int32 read_number = 8; 162 | 163 | // The number of reads in the fragment (extension to SAM flag 0x1). 164 | int32 number_reads = 9; 165 | 166 | // Whether this read did not pass filters, such as platform or vendor quality 167 | // controls (SAM flag 0x200). 168 | bool failed_vendor_quality_checks = 10; 169 | 170 | // The linear alignment for this alignment record. This field is null for 171 | // unmapped reads. 172 | LinearAlignment alignment = 11; 173 | 174 | // Whether this alignment is secondary. Equivalent to SAM flag 0x100. 175 | // A secondary alignment represents an alternative to the primary alignment 176 | // for this read. Aligners may return secondary alignments if a read can map 177 | // ambiguously to multiple coordinates in the genome. By convention, each read 178 | // has one and only one alignment where both `secondaryAlignment` 179 | // and `supplementaryAlignment` are false. 180 | bool secondary_alignment = 12; 181 | 182 | // Whether this alignment is supplementary. Equivalent to SAM flag 0x800. 183 | // Supplementary alignments are used in the representation of a chimeric 184 | // alignment. In a chimeric alignment, a read is split into multiple 185 | // linear alignments that map to different reference contigs. The first 186 | // linear alignment in the read will be designated as the representative 187 | // alignment; the remaining linear alignments will be designated as 188 | // supplementary alignments. These alignments may have different mapping 189 | // quality scores. In each linear alignment in a chimeric alignment, the read 190 | // will be hard clipped. The `alignedSequence` and 191 | // `alignedQuality` fields in the alignment record will only 192 | // represent the bases for its respective linear alignment. 193 | bool supplementary_alignment = 13; 194 | 195 | // The bases of the read sequence contained in this alignment record, 196 | // **without CIGAR operations applied** (equivalent to SEQ in SAM). 197 | // `alignedSequence` and `alignedQuality` may be 198 | // shorter than the full read sequence and quality. This will occur if the 199 | // alignment is part of a chimeric alignment, or if the read was trimmed. When 200 | // this occurs, the CIGAR for this read will begin/end with a hard clip 201 | // operator that will indicate the length of the excised sequence. 202 | string aligned_sequence = 14; 203 | 204 | // The quality of the read sequence contained in this alignment record 205 | // (equivalent to QUAL in SAM). 206 | // `alignedSequence` and `alignedQuality` may be shorter than the full read 207 | // sequence and quality. This will occur if the alignment is part of a 208 | // chimeric alignment, or if the read was trimmed. When this occurs, the CIGAR 209 | // for this read will begin/end with a hard clip operator that will indicate 210 | // the length of the excised sequence. 211 | repeated int32 aligned_quality = 15; 212 | 213 | // The mapping of the primary alignment of the 214 | // `(readNumber+1)%numberReads` read in the fragment. It replaces 215 | // mate position and mate strand in SAM. 216 | Position next_mate_position = 16; 217 | 218 | // A map of additional read alignment information. This must be of the form 219 | // map (string key mapping to a list of string values). 220 | map info = 17; 221 | } 222 | -------------------------------------------------------------------------------- /src/google/genomics/v1/readgroup.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.genomics.v1; 18 | 19 | import "google/api/annotations.proto"; 20 | import "google/protobuf/struct.proto"; 21 | 22 | option cc_enable_arenas = true; 23 | option go_package = "google.golang.org/genproto/googleapis/genomics/v1;genomics"; 24 | option java_multiple_files = true; 25 | option java_outer_classname = "ReadGroupProto"; 26 | option java_package = "com.google.genomics.v1"; 27 | 28 | 29 | // A read group is all the data that's processed the same way by the sequencer. 30 | message ReadGroup { 31 | message Experiment { 32 | // A client-supplied library identifier; a library is a collection of DNA 33 | // fragments which have been prepared for sequencing from a sample. This 34 | // field is important for quality control as error or bias can be introduced 35 | // during sample preparation. 36 | string library_id = 1; 37 | 38 | // The platform unit used as part of this experiment, for example 39 | // flowcell-barcode.lane for Illumina or slide for SOLiD. Corresponds to the 40 | // @RG PU field in the SAM spec. 41 | string platform_unit = 2; 42 | 43 | // The sequencing center used as part of this experiment. 44 | string sequencing_center = 3; 45 | 46 | // The instrument model used as part of this experiment. This maps to 47 | // sequencing technology in the SAM spec. 48 | string instrument_model = 4; 49 | } 50 | 51 | message Program { 52 | // The command line used to run this program. 53 | string command_line = 1; 54 | 55 | // The user specified locally unique ID of the program. Used along with 56 | // `prevProgramId` to define an ordering between programs. 57 | string id = 2; 58 | 59 | // The display name of the program. This is typically the colloquial name of 60 | // the tool used, for example 'bwa' or 'picard'. 61 | string name = 3; 62 | 63 | // The ID of the program run before this one. 64 | string prev_program_id = 4; 65 | 66 | // The version of the program run. 67 | string version = 5; 68 | } 69 | 70 | // The server-generated read group ID, unique for all read groups. 71 | // Note: This is different than the @RG ID field in the SAM spec. For that 72 | // value, see [name][google.genomics.v1.ReadGroup.name]. 73 | string id = 1; 74 | 75 | // The dataset to which this read group belongs. 76 | string dataset_id = 2; 77 | 78 | // The read group name. This corresponds to the @RG ID field in the SAM spec. 79 | string name = 3; 80 | 81 | // A free-form text description of this read group. 82 | string description = 4; 83 | 84 | // A client-supplied sample identifier for the reads in this read group. 85 | string sample_id = 5; 86 | 87 | // The experiment used to generate this read group. 88 | Experiment experiment = 6; 89 | 90 | // The predicted insert size of this read group. The insert size is the length 91 | // the sequenced DNA fragment from end-to-end, not including the adapters. 92 | int32 predicted_insert_size = 7; 93 | 94 | // The programs used to generate this read group. Programs are always 95 | // identical for all read groups within a read group set. For this reason, 96 | // only the first read group in a returned set will have this field 97 | // populated. 98 | repeated Program programs = 10; 99 | 100 | // The reference set the reads in this read group are aligned to. 101 | string reference_set_id = 11; 102 | 103 | // A map of additional read group information. This must be of the form 104 | // map (string key mapping to a list of string values). 105 | map info = 12; 106 | } 107 | -------------------------------------------------------------------------------- /src/google/genomics/v1/readgroupset.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.genomics.v1; 18 | 19 | import "google/api/annotations.proto"; 20 | import "google/genomics/v1/readgroup.proto"; 21 | import "google/protobuf/struct.proto"; 22 | 23 | option cc_enable_arenas = true; 24 | option go_package = "google.golang.org/genproto/googleapis/genomics/v1;genomics"; 25 | option java_multiple_files = true; 26 | option java_outer_classname = "ReadGroupSetProto"; 27 | option java_package = "com.google.genomics.v1"; 28 | 29 | 30 | // A read group set is a logical collection of read groups, which are 31 | // collections of reads produced by a sequencer. A read group set typically 32 | // models reads corresponding to one sample, sequenced one way, and aligned one 33 | // way. 34 | // 35 | // * A read group set belongs to one dataset. 36 | // * A read group belongs to one read group set. 37 | // * A read belongs to one read group. 38 | // 39 | // For more genomics resource definitions, see [Fundamentals of Google 40 | // Genomics](https://cloud.google.com/genomics/fundamentals-of-google-genomics) 41 | message ReadGroupSet { 42 | // The server-generated read group set ID, unique for all read group sets. 43 | string id = 1; 44 | 45 | // The dataset to which this read group set belongs. 46 | string dataset_id = 2; 47 | 48 | // The reference set to which the reads in this read group set are aligned. 49 | string reference_set_id = 3; 50 | 51 | // The read group set name. By default this will be initialized to the sample 52 | // name of the sequenced data contained in this set. 53 | string name = 4; 54 | 55 | // The filename of the original source file for this read group set, if any. 56 | string filename = 5; 57 | 58 | // The read groups in this set. There are typically 1-10 read groups in a read 59 | // group set. 60 | repeated ReadGroup read_groups = 6; 61 | 62 | // A map of additional read group set information. 63 | map info = 7; 64 | } 65 | -------------------------------------------------------------------------------- /src/google/iam/v1/iam_policy.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.iam.v1; 18 | 19 | import "google/api/annotations.proto"; 20 | import "google/iam/v1/policy.proto"; 21 | 22 | option cc_enable_arenas = true; 23 | option csharp_namespace = "Google.Cloud.Iam.V1"; 24 | option go_package = "google.golang.org/genproto/googleapis/iam/v1;iam"; 25 | option java_multiple_files = true; 26 | option java_outer_classname = "IamPolicyProto"; 27 | option java_package = "com.google.iam.v1"; 28 | 29 | 30 | // ## API Overview 31 | // 32 | // Manages Identity and Access Management (IAM) policies. 33 | // 34 | // Any implementation of an API that offers access control features 35 | // implements the google.iam.v1.IAMPolicy interface. 36 | // 37 | // ## Data model 38 | // 39 | // Access control is applied when a principal (user or service account), takes 40 | // some action on a resource exposed by a service. Resources, identified by 41 | // URI-like names, are the unit of access control specification. Service 42 | // implementations can choose the granularity of access control and the 43 | // supported permissions for their resources. 44 | // For example one database service may allow access control to be 45 | // specified only at the Table level, whereas another might allow access control 46 | // to also be specified at the Column level. 47 | // 48 | // ## Policy Structure 49 | // 50 | // See google.iam.v1.Policy 51 | // 52 | // This is intentionally not a CRUD style API because access control policies 53 | // are created and deleted implicitly with the resources to which they are 54 | // attached. 55 | service IAMPolicy { 56 | // Sets the access control policy on the specified resource. Replaces any 57 | // existing policy. 58 | rpc SetIamPolicy(SetIamPolicyRequest) returns (Policy) { 59 | option (google.api.http) = { post: "/v1/{resource=**}:setIamPolicy" body: "*" }; 60 | } 61 | 62 | // Gets the access control policy for a resource. 63 | // Returns an empty policy if the resource exists and does not have a policy 64 | // set. 65 | rpc GetIamPolicy(GetIamPolicyRequest) returns (Policy) { 66 | option (google.api.http) = { post: "/v1/{resource=**}:getIamPolicy" body: "*" }; 67 | } 68 | 69 | // Returns permissions that a caller has on the specified resource. 70 | // If the resource does not exist, this will return an empty set of 71 | // permissions, not a NOT_FOUND error. 72 | rpc TestIamPermissions(TestIamPermissionsRequest) returns (TestIamPermissionsResponse) { 73 | option (google.api.http) = { post: "/v1/{resource=**}:testIamPermissions" body: "*" }; 74 | } 75 | } 76 | 77 | // Request message for `SetIamPolicy` method. 78 | message SetIamPolicyRequest { 79 | // REQUIRED: The resource for which the policy is being specified. 80 | // `resource` is usually specified as a path. For example, a Project 81 | // resource is specified as `projects/{project}`. 82 | string resource = 1; 83 | 84 | // REQUIRED: The complete policy to be applied to the `resource`. The size of 85 | // the policy is limited to a few 10s of KB. An empty policy is a 86 | // valid policy but certain Cloud Platform services (such as Projects) 87 | // might reject them. 88 | Policy policy = 2; 89 | } 90 | 91 | // Request message for `GetIamPolicy` method. 92 | message GetIamPolicyRequest { 93 | // REQUIRED: The resource for which the policy is being requested. 94 | // `resource` is usually specified as a path. For example, a Project 95 | // resource is specified as `projects/{project}`. 96 | string resource = 1; 97 | } 98 | 99 | // Request message for `TestIamPermissions` method. 100 | message TestIamPermissionsRequest { 101 | // REQUIRED: The resource for which the policy detail is being requested. 102 | // `resource` is usually specified as a path. For example, a Project 103 | // resource is specified as `projects/{project}`. 104 | string resource = 1; 105 | 106 | // The set of permissions to check for the `resource`. Permissions with 107 | // wildcards (such as '*' or 'storage.*') are not allowed. For more 108 | // information see 109 | // [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions). 110 | repeated string permissions = 2; 111 | } 112 | 113 | // Response message for `TestIamPermissions` method. 114 | message TestIamPermissionsResponse { 115 | // A subset of `TestPermissionsRequest.permissions` that the caller is 116 | // allowed. 117 | repeated string permissions = 1; 118 | } 119 | -------------------------------------------------------------------------------- /src/google/iam/v1/policy.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.iam.v1; 18 | 19 | import "google/api/annotations.proto"; 20 | 21 | option cc_enable_arenas = true; 22 | option csharp_namespace = "Google.Cloud.Iam.V1"; 23 | option go_package = "google.golang.org/genproto/googleapis/iam/v1;iam"; 24 | option java_multiple_files = true; 25 | option java_outer_classname = "PolicyProto"; 26 | option java_package = "com.google.iam.v1"; 27 | 28 | 29 | // Defines an Identity and Access Management (IAM) policy. It is used to 30 | // specify access control policies for Cloud Platform resources. 31 | // 32 | // 33 | // A `Policy` consists of a list of `bindings`. A `Binding` binds a list of 34 | // `members` to a `role`, where the members can be user accounts, Google groups, 35 | // Google domains, and service accounts. A `role` is a named list of permissions 36 | // defined by IAM. 37 | // 38 | // **Example** 39 | // 40 | // { 41 | // "bindings": [ 42 | // { 43 | // "role": "roles/owner", 44 | // "members": [ 45 | // "user:mike@example.com", 46 | // "group:admins@example.com", 47 | // "domain:google.com", 48 | // "serviceAccount:my-other-app@appspot.gserviceaccount.com", 49 | // ] 50 | // }, 51 | // { 52 | // "role": "roles/viewer", 53 | // "members": ["user:sean@example.com"] 54 | // } 55 | // ] 56 | // } 57 | // 58 | // For a description of IAM and its features, see the 59 | // [IAM developer's guide](https://cloud.google.com/iam). 60 | message Policy { 61 | // Version of the `Policy`. The default version is 0. 62 | int32 version = 1; 63 | 64 | // Associates a list of `members` to a `role`. 65 | // Multiple `bindings` must not be specified for the same `role`. 66 | // `bindings` with no members will result in an error. 67 | repeated Binding bindings = 4; 68 | 69 | // `etag` is used for optimistic concurrency control as a way to help 70 | // prevent simultaneous updates of a policy from overwriting each other. 71 | // It is strongly suggested that systems make use of the `etag` in the 72 | // read-modify-write cycle to perform policy updates in order to avoid race 73 | // conditions: An `etag` is returned in the response to `getIamPolicy`, and 74 | // systems are expected to put that etag in the request to `setIamPolicy` to 75 | // ensure that their change will be applied to the same version of the policy. 76 | // 77 | // If no `etag` is provided in the call to `setIamPolicy`, then the existing 78 | // policy is overwritten blindly. 79 | bytes etag = 3; 80 | } 81 | 82 | // Associates `members` with a `role`. 83 | message Binding { 84 | // Role that is assigned to `members`. 85 | // For example, `roles/viewer`, `roles/editor`, or `roles/owner`. 86 | // Required 87 | string role = 1; 88 | 89 | // Specifies the identities requesting access for a Cloud Platform resource. 90 | // `members` can have the following values: 91 | // 92 | // * `allUsers`: A special identifier that represents anyone who is 93 | // on the internet; with or without a Google account. 94 | // 95 | // * `allAuthenticatedUsers`: A special identifier that represents anyone 96 | // who is authenticated with a Google account or a service account. 97 | // 98 | // * `user:{emailid}`: An email address that represents a specific Google 99 | // account. For example, `alice@gmail.com` or `joe@example.com`. 100 | // 101 | // 102 | // * `serviceAccount:{emailid}`: An email address that represents a service 103 | // account. For example, `my-other-app@appspot.gserviceaccount.com`. 104 | // 105 | // * `group:{emailid}`: An email address that represents a Google group. 106 | // For example, `admins@example.com`. 107 | // 108 | // * `domain:{domain}`: A Google Apps domain name that represents all the 109 | // users of that domain. For example, `google.com` or `example.com`. 110 | // 111 | // 112 | repeated string members = 2; 113 | } 114 | 115 | // The difference delta between two policies. 116 | message PolicyDelta { 117 | // The delta for Bindings between two policies. 118 | repeated BindingDelta binding_deltas = 1; 119 | } 120 | 121 | // One delta entry for Binding. Each individual change (only one member in each 122 | // entry) to a binding will be a separate entry. 123 | message BindingDelta { 124 | // The type of action performed on a Binding in a policy. 125 | enum Action { 126 | // Unspecified. 127 | ACTION_UNSPECIFIED = 0; 128 | 129 | // Addition of a Binding. 130 | ADD = 1; 131 | 132 | // Removal of a Binding. 133 | REMOVE = 2; 134 | } 135 | 136 | // The action that was performed on a Binding. 137 | // Required 138 | Action action = 1; 139 | 140 | // Role that is assigned to `members`. 141 | // For example, `roles/viewer`, `roles/editor`, or `roles/owner`. 142 | // Required 143 | string role = 2; 144 | 145 | // A single identity requesting access for a Cloud Platform resource. 146 | // Follows the same format of Binding.members. 147 | // Required 148 | string member = 3; 149 | } 150 | -------------------------------------------------------------------------------- /src/google/longrunning/operations.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.longrunning; 18 | 19 | import "google/api/annotations.proto"; 20 | import "google/protobuf/any.proto"; 21 | import "google/protobuf/empty.proto"; 22 | import "google/rpc/status.proto"; 23 | 24 | option csharp_namespace = "Google.LongRunning"; 25 | option go_package = "google.golang.org/genproto/googleapis/longrunning;longrunning"; 26 | option java_multiple_files = true; 27 | option java_outer_classname = "OperationsProto"; 28 | option java_package = "com.google.longrunning"; 29 | 30 | 31 | // Manages long-running operations with an API service. 32 | // 33 | // When an API method normally takes long time to complete, it can be designed 34 | // to return [Operation][google.longrunning.Operation] to the client, and the client can use this 35 | // interface to receive the real response asynchronously by polling the 36 | // operation resource, or pass the operation resource to another API (such as 37 | // Google Cloud Pub/Sub API) to receive the response. Any API service that 38 | // returns long-running operations should implement the `Operations` interface 39 | // so developers can have a consistent client experience. 40 | service Operations { 41 | // Lists operations that match the specified filter in the request. If the 42 | // server doesn't support this method, it returns `UNIMPLEMENTED`. 43 | // 44 | // NOTE: the `name` binding below allows API services to override the binding 45 | // to use different resource name schemes, such as `users/*/operations`. 46 | rpc ListOperations(ListOperationsRequest) returns (ListOperationsResponse) { 47 | option (google.api.http) = { get: "/v1/{name=operations}" }; 48 | } 49 | 50 | // Gets the latest state of a long-running operation. Clients can use this 51 | // method to poll the operation result at intervals as recommended by the API 52 | // service. 53 | rpc GetOperation(GetOperationRequest) returns (Operation) { 54 | option (google.api.http) = { get: "/v1/{name=operations/**}" }; 55 | } 56 | 57 | // Deletes a long-running operation. This method indicates that the client is 58 | // no longer interested in the operation result. It does not cancel the 59 | // operation. If the server doesn't support this method, it returns 60 | // `google.rpc.Code.UNIMPLEMENTED`. 61 | rpc DeleteOperation(DeleteOperationRequest) returns (google.protobuf.Empty) { 62 | option (google.api.http) = { delete: "/v1/{name=operations/**}" }; 63 | } 64 | 65 | // Starts asynchronous cancellation on a long-running operation. The server 66 | // makes a best effort to cancel the operation, but success is not 67 | // guaranteed. If the server doesn't support this method, it returns 68 | // `google.rpc.Code.UNIMPLEMENTED`. Clients can use 69 | // [Operations.GetOperation][google.longrunning.Operations.GetOperation] or 70 | // other methods to check whether the cancellation succeeded or whether the 71 | // operation completed despite cancellation. On successful cancellation, 72 | // the operation is not deleted; instead, it becomes an operation with 73 | // an [Operation.error][google.longrunning.Operation.error] value with a [google.rpc.Status.code][google.rpc.Status.code] of 1, 74 | // corresponding to `Code.CANCELLED`. 75 | rpc CancelOperation(CancelOperationRequest) returns (google.protobuf.Empty) { 76 | option (google.api.http) = { post: "/v1/{name=operations/**}:cancel" body: "*" }; 77 | } 78 | } 79 | 80 | // This resource represents a long-running operation that is the result of a 81 | // network API call. 82 | message Operation { 83 | // The server-assigned name, which is only unique within the same service that 84 | // originally returns it. If you use the default HTTP mapping, the 85 | // `name` should have the format of `operations/some/unique/name`. 86 | string name = 1; 87 | 88 | // Service-specific metadata associated with the operation. It typically 89 | // contains progress information and common metadata such as create time. 90 | // Some services might not provide such metadata. Any method that returns a 91 | // long-running operation should document the metadata type, if any. 92 | google.protobuf.Any metadata = 2; 93 | 94 | // If the value is `false`, it means the operation is still in progress. 95 | // If true, the operation is completed, and either `error` or `response` is 96 | // available. 97 | bool done = 3; 98 | 99 | // The operation result, which can be either an `error` or a valid `response`. 100 | // If `done` == `false`, neither `error` nor `response` is set. 101 | // If `done` == `true`, exactly one of `error` or `response` is set. 102 | oneof result { 103 | // The error result of the operation in case of failure or cancellation. 104 | google.rpc.Status error = 4; 105 | 106 | // The normal response of the operation in case of success. If the original 107 | // method returns no data on success, such as `Delete`, the response is 108 | // `google.protobuf.Empty`. If the original method is standard 109 | // `Get`/`Create`/`Update`, the response should be the resource. For other 110 | // methods, the response should have the type `XxxResponse`, where `Xxx` 111 | // is the original method name. For example, if the original method name 112 | // is `TakeSnapshot()`, the inferred response type is 113 | // `TakeSnapshotResponse`. 114 | google.protobuf.Any response = 5; 115 | } 116 | } 117 | 118 | // The request message for [Operations.GetOperation][google.longrunning.Operations.GetOperation]. 119 | message GetOperationRequest { 120 | // The name of the operation resource. 121 | string name = 1; 122 | } 123 | 124 | // The request message for [Operations.ListOperations][google.longrunning.Operations.ListOperations]. 125 | message ListOperationsRequest { 126 | // The name of the operation collection. 127 | string name = 4; 128 | 129 | // The standard list filter. 130 | string filter = 1; 131 | 132 | // The standard list page size. 133 | int32 page_size = 2; 134 | 135 | // The standard list page token. 136 | string page_token = 3; 137 | } 138 | 139 | // The response message for [Operations.ListOperations][google.longrunning.Operations.ListOperations]. 140 | message ListOperationsResponse { 141 | // A list of operations that matches the specified filter in the request. 142 | repeated Operation operations = 1; 143 | 144 | // The standard List next-page token. 145 | string next_page_token = 2; 146 | } 147 | 148 | // The request message for [Operations.CancelOperation][google.longrunning.Operations.CancelOperation]. 149 | message CancelOperationRequest { 150 | // The name of the operation resource to be cancelled. 151 | string name = 1; 152 | } 153 | 154 | // The request message for [Operations.DeleteOperation][google.longrunning.Operations.DeleteOperation]. 155 | message DeleteOperationRequest { 156 | // The name of the operation resource to be deleted. 157 | string name = 1; 158 | } 159 | 160 | -------------------------------------------------------------------------------- /src/google/rpc/code.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.rpc; 18 | 19 | option go_package = "google.golang.org/genproto/googleapis/rpc/code;code"; 20 | option java_multiple_files = true; 21 | option java_outer_classname = "CodeProto"; 22 | option java_package = "com.google.rpc"; 23 | option objc_class_prefix = "RPC"; 24 | 25 | 26 | // The canonical error codes for Google APIs. 27 | // 28 | // 29 | // Sometimes multiple error codes may apply. Services should return 30 | // the most specific error code that applies. For example, prefer 31 | // `OUT_OF_RANGE` over `FAILED_PRECONDITION` if both codes apply. 32 | // Similarly prefer `NOT_FOUND` or `ALREADY_EXISTS` over `FAILED_PRECONDITION`. 33 | enum Code { 34 | // Not an error; returned on success 35 | // 36 | // HTTP Mapping: 200 OK 37 | OK = 0; 38 | 39 | // The operation was cancelled, typically by the caller. 40 | // 41 | // HTTP Mapping: 499 Client Closed Request 42 | CANCELLED = 1; 43 | 44 | // Unknown error. For example, this error may be returned when 45 | // a `Status` value received from another address space belongs to 46 | // an error space that is not known in this address space. Also 47 | // errors raised by APIs that do not return enough error information 48 | // may be converted to this error. 49 | // 50 | // HTTP Mapping: 500 Internal Server Error 51 | UNKNOWN = 2; 52 | 53 | // The client specified an invalid argument. Note that this differs 54 | // from `FAILED_PRECONDITION`. `INVALID_ARGUMENT` indicates arguments 55 | // that are problematic regardless of the state of the system 56 | // (e.g., a malformed file name). 57 | // 58 | // HTTP Mapping: 400 Bad Request 59 | INVALID_ARGUMENT = 3; 60 | 61 | // The deadline expired before the operation could complete. For operations 62 | // that change the state of the system, this error may be returned 63 | // even if the operation has completed successfully. For example, a 64 | // successful response from a server could have been delayed long 65 | // enough for the deadline to expire. 66 | // 67 | // HTTP Mapping: 504 Gateway Timeout 68 | DEADLINE_EXCEEDED = 4; 69 | 70 | // Some requested entity (e.g., file or directory) was not found. 71 | // For privacy reasons, this code *may* be returned when the client 72 | // does not have the access rights to the entity, though such usage is 73 | // discouraged. 74 | // 75 | // HTTP Mapping: 404 Not Found 76 | NOT_FOUND = 5; 77 | 78 | // The entity that a client attempted to create (e.g., file or directory) 79 | // already exists. 80 | // 81 | // HTTP Mapping: 409 Conflict 82 | ALREADY_EXISTS = 6; 83 | 84 | // The caller does not have permission to execute the specified 85 | // operation. `PERMISSION_DENIED` must not be used for rejections 86 | // caused by exhausting some resource (use `RESOURCE_EXHAUSTED` 87 | // instead for those errors). `PERMISSION_DENIED` must not be 88 | // used if the caller can not be identified (use `UNAUTHENTICATED` 89 | // instead for those errors). 90 | // 91 | // HTTP Mapping: 403 Forbidden 92 | PERMISSION_DENIED = 7; 93 | 94 | // The request does not have valid authentication credentials for the 95 | // operation. 96 | // 97 | // HTTP Mapping: 401 Unauthorized 98 | UNAUTHENTICATED = 16; 99 | 100 | // Some resource has been exhausted, perhaps a per-user quota, or 101 | // perhaps the entire file system is out of space. 102 | // 103 | // HTTP Mapping: 429 Too Many Requests 104 | RESOURCE_EXHAUSTED = 8; 105 | 106 | // The operation was rejected because the system is not in a state 107 | // required for the operation's execution. For example, the directory 108 | // to be deleted is non-empty, an rmdir operation is applied to 109 | // a non-directory, etc. 110 | // 111 | // Service implementors can use the following guidelines to decide 112 | // between `FAILED_PRECONDITION`, `ABORTED`, and `UNAVAILABLE`: 113 | // (a) Use `UNAVAILABLE` if the client can retry just the failing call. 114 | // (b) Use `ABORTED` if the client should retry at a higher level 115 | // (e.g., restarting a read-modify-write sequence). 116 | // (c) Use `FAILED_PRECONDITION` if the client should not retry until 117 | // the system state has been explicitly fixed. E.g., if an "rmdir" 118 | // fails because the directory is non-empty, `FAILED_PRECONDITION` 119 | // should be returned since the client should not retry unless 120 | // the files are deleted from the directory. 121 | // 122 | // HTTP Mapping: 400 Bad Request 123 | FAILED_PRECONDITION = 9; 124 | 125 | // The operation was aborted, typically due to a concurrency issue such as 126 | // a sequencer check failure or transaction abort. 127 | // 128 | // See the guidelines above for deciding between `FAILED_PRECONDITION`, 129 | // `ABORTED`, and `UNAVAILABLE`. 130 | // 131 | // HTTP Mapping: 409 Conflict 132 | ABORTED = 10; 133 | 134 | // The operation was attempted past the valid range. E.g., seeking or 135 | // reading past end-of-file. 136 | // 137 | // Unlike `INVALID_ARGUMENT`, this error indicates a problem that may 138 | // be fixed if the system state changes. For example, a 32-bit file 139 | // system will generate `INVALID_ARGUMENT` if asked to read at an 140 | // offset that is not in the range [0,2^32-1], but it will generate 141 | // `OUT_OF_RANGE` if asked to read from an offset past the current 142 | // file size. 143 | // 144 | // There is a fair bit of overlap between `FAILED_PRECONDITION` and 145 | // `OUT_OF_RANGE`. We recommend using `OUT_OF_RANGE` (the more specific 146 | // error) when it applies so that callers who are iterating through 147 | // a space can easily look for an `OUT_OF_RANGE` error to detect when 148 | // they are done. 149 | // 150 | // HTTP Mapping: 400 Bad Request 151 | OUT_OF_RANGE = 11; 152 | 153 | // The operation is not implemented or is not supported/enabled in this 154 | // service. 155 | // 156 | // HTTP Mapping: 501 Not Implemented 157 | UNIMPLEMENTED = 12; 158 | 159 | // Internal errors. This means that some invariants expected by the 160 | // underlying system have been broken. This error code is reserved 161 | // for serious errors. 162 | // 163 | // HTTP Mapping: 500 Internal Server Error 164 | INTERNAL = 13; 165 | 166 | // The service is currently unavailable. This is most likely a 167 | // transient condition, which can be corrected by retrying with 168 | // a backoff. 169 | // 170 | // See the guidelines above for deciding between `FAILED_PRECONDITION`, 171 | // `ABORTED`, and `UNAVAILABLE`. 172 | // 173 | // HTTP Mapping: 503 Service Unavailable 174 | UNAVAILABLE = 14; 175 | 176 | // Unrecoverable data loss or corruption. 177 | // 178 | // HTTP Mapping: 500 Internal Server Error 179 | DATA_LOSS = 15; 180 | } 181 | -------------------------------------------------------------------------------- /src/google/rpc/status.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Google Inc. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.rpc; 18 | 19 | import "google/protobuf/any.proto"; 20 | 21 | option go_package = "google.golang.org/genproto/googleapis/rpc/status;status"; 22 | option java_multiple_files = true; 23 | option java_outer_classname = "StatusProto"; 24 | option java_package = "com.google.rpc"; 25 | option objc_class_prefix = "RPC"; 26 | 27 | 28 | // The `Status` type defines a logical error model that is suitable for different 29 | // programming environments, including REST APIs and RPC APIs. It is used by 30 | // [gRPC](https://github.com/grpc). The error model is designed to be: 31 | // 32 | // - Simple to use and understand for most users 33 | // - Flexible enough to meet unexpected needs 34 | // 35 | // # Overview 36 | // 37 | // The `Status` message contains three pieces of data: error code, error message, 38 | // and error details. The error code should be an enum value of 39 | // [google.rpc.Code][google.rpc.Code], but it may accept additional error codes if needed. The 40 | // error message should be a developer-facing English message that helps 41 | // developers *understand* and *resolve* the error. If a localized user-facing 42 | // error message is needed, put the localized message in the error details or 43 | // localize it in the client. The optional error details may contain arbitrary 44 | // information about the error. There is a predefined set of error detail types 45 | // in the package `google.rpc` which can be used for common error conditions. 46 | // 47 | // # Language mapping 48 | // 49 | // The `Status` message is the logical representation of the error model, but it 50 | // is not necessarily the actual wire format. When the `Status` message is 51 | // exposed in different client libraries and different wire protocols, it can be 52 | // mapped differently. For example, it will likely be mapped to some exceptions 53 | // in Java, but more likely mapped to some error codes in C. 54 | // 55 | // # Other uses 56 | // 57 | // The error model and the `Status` message can be used in a variety of 58 | // environments, either with or without APIs, to provide a 59 | // consistent developer experience across different environments. 60 | // 61 | // Example uses of this error model include: 62 | // 63 | // - Partial errors. If a service needs to return partial errors to the client, 64 | // it may embed the `Status` in the normal response to indicate the partial 65 | // errors. 66 | // 67 | // - Workflow errors. A typical workflow has multiple steps. Each step may 68 | // have a `Status` message for error reporting purpose. 69 | // 70 | // - Batch operations. If a client uses batch request and batch response, the 71 | // `Status` message should be used directly inside batch response, one for 72 | // each error sub-response. 73 | // 74 | // - Asynchronous operations. If an API call embeds asynchronous operation 75 | // results in its response, the status of those operations should be 76 | // represented directly using the `Status` message. 77 | // 78 | // - Logging. If some API errors are stored in logs, the message `Status` could 79 | // be used directly after any stripping needed for security/privacy reasons. 80 | message Status { 81 | // The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code]. 82 | int32 code = 1; 83 | 84 | // A developer-facing error message, which should be in English. Any 85 | // user-facing error message should be localized and sent in the 86 | // [google.rpc.Status.details][google.rpc.Status.details] field, or localized by the client. 87 | string message = 2; 88 | 89 | // A list of messages that carry the error details. There will be a 90 | // common set of message types for APIs to use. 91 | repeated google.protobuf.Any details = 3; 92 | } 93 | -------------------------------------------------------------------------------- /src/init.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017 GoogleGenomics R package authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the 'License'); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an 'AS IS' BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | 18 | #ifdef HAVE_GRPC 19 | #include 20 | #include 21 | #endif /* HAVE_GRPC */ 22 | 23 | extern "C" { 24 | 25 | SEXP builtWithGRPC() { 26 | #ifdef HAVE_GRPC 27 | return Rf_ScalarLogical(true); 28 | #else 29 | return Rf_ScalarLogical(false); 30 | #endif 31 | } 32 | 33 | #ifdef HAVE_GRPC 34 | extern SEXP GetRProtoBufMessage(SEXP); 35 | extern SEXP CreateAnnotationSet(SEXP, SEXP); 36 | extern SEXP GetAnnotationSet(SEXP, SEXP); 37 | extern SEXP UpdateAnnotationSet(SEXP, SEXP); 38 | extern SEXP DeleteAnnotationSet(SEXP, SEXP); 39 | extern SEXP SearchAnnotationSets(SEXP, SEXP); 40 | extern SEXP CreateAnnotation(SEXP, SEXP); 41 | extern SEXP BatchCreateAnnotations(SEXP, SEXP); 42 | extern SEXP GetAnnotation(SEXP, SEXP); 43 | extern SEXP UpdateAnnotation(SEXP, SEXP); 44 | extern SEXP DeleteAnnotation(SEXP, SEXP); 45 | extern SEXP SearchAnnotations(SEXP, SEXP); 46 | extern SEXP ListDatasets(SEXP, SEXP); 47 | extern SEXP CreateDataset(SEXP, SEXP); 48 | extern SEXP GetDataset(SEXP, SEXP); 49 | extern SEXP UpdateDataset(SEXP, SEXP); 50 | extern SEXP DeleteDataset(SEXP, SEXP); 51 | extern SEXP UndeleteDataset(SEXP, SEXP); 52 | extern SEXP SetIamPolicy(SEXP, SEXP); 53 | extern SEXP GetIamPolicy(SEXP, SEXP); 54 | extern SEXP TestIamPermissions(SEXP, SEXP); 55 | extern SEXP StreamReads(SEXP, SEXP); 56 | extern SEXP ImportReadGroupSets(SEXP, SEXP); 57 | extern SEXP ExportReadGroupSet(SEXP, SEXP); 58 | extern SEXP SearchReadGroupSets(SEXP, SEXP); 59 | extern SEXP UpdateReadGroupSet(SEXP, SEXP); 60 | extern SEXP DeleteReadGroupSet(SEXP, SEXP); 61 | extern SEXP GetReadGroupSet(SEXP, SEXP); 62 | extern SEXP ListCoverageBuckets(SEXP, SEXP); 63 | extern SEXP SearchReads(SEXP, SEXP); 64 | extern SEXP SearchReferenceSets(SEXP, SEXP); 65 | extern SEXP GetReferenceSet(SEXP, SEXP); 66 | extern SEXP SearchReferences(SEXP, SEXP); 67 | extern SEXP GetReference(SEXP, SEXP); 68 | extern SEXP ListBases(SEXP, SEXP); 69 | extern SEXP StreamVariants(SEXP, SEXP); 70 | extern SEXP ImportVariants(SEXP, SEXP); 71 | extern SEXP CreateVariantSet(SEXP, SEXP); 72 | extern SEXP ExportVariantSet(SEXP, SEXP); 73 | extern SEXP GetVariantSet(SEXP, SEXP); 74 | extern SEXP SearchVariantSets(SEXP, SEXP); 75 | extern SEXP DeleteVariantSet(SEXP, SEXP); 76 | extern SEXP UpdateVariantSet(SEXP, SEXP); 77 | extern SEXP SearchVariants(SEXP, SEXP); 78 | extern SEXP CreateVariant(SEXP, SEXP); 79 | extern SEXP UpdateVariant(SEXP, SEXP); 80 | extern SEXP DeleteVariant(SEXP, SEXP); 81 | extern SEXP GetVariant(SEXP, SEXP); 82 | extern SEXP MergeVariants(SEXP, SEXP); 83 | extern SEXP SearchCallSets(SEXP, SEXP); 84 | extern SEXP CreateCallSet(SEXP, SEXP); 85 | extern SEXP UpdateCallSet(SEXP, SEXP); 86 | extern SEXP DeleteCallSet(SEXP, SEXP); 87 | extern SEXP GetCallSet(SEXP, SEXP); 88 | #endif /* HAVE_GRPC */ 89 | 90 | static const R_CallMethodDef callMethods[] = { 91 | {"builtWithGRPC", (DL_FUNC)&builtWithGRPC, 0}, 92 | #ifdef HAVE_GRPC 93 | {"GetRProtoBufMessage", (DL_FUNC)&GetRProtoBufMessage, 1}, 94 | {"CreateAnnotationSet", (DL_FUNC)&CreateAnnotationSet, 2}, 95 | {"GetAnnotationSet", (DL_FUNC)&GetAnnotationSet, 2}, 96 | {"UpdateAnnotationSet", (DL_FUNC)&UpdateAnnotationSet, 2}, 97 | {"DeleteAnnotationSet", (DL_FUNC)&DeleteAnnotationSet, 2}, 98 | {"SearchAnnotationSets", (DL_FUNC)&SearchAnnotationSets, 2}, 99 | {"CreateAnnotation", (DL_FUNC)&CreateAnnotation, 2}, 100 | {"BatchCreateAnnotations", (DL_FUNC)&BatchCreateAnnotations, 2}, 101 | {"GetAnnotation", (DL_FUNC)&GetAnnotation, 2}, 102 | {"UpdateAnnotation", (DL_FUNC)&UpdateAnnotation, 2}, 103 | {"DeleteAnnotation", (DL_FUNC)&DeleteAnnotation, 2}, 104 | {"SearchAnnotations", (DL_FUNC)&SearchAnnotations, 2}, 105 | {"ListDatasets", (DL_FUNC)&ListDatasets, 2}, 106 | {"CreateDataset", (DL_FUNC)&CreateDataset, 2}, 107 | {"GetDataset", (DL_FUNC)&GetDataset, 2}, 108 | {"UpdateDataset", (DL_FUNC)&UpdateDataset, 2}, 109 | {"DeleteDataset", (DL_FUNC)&DeleteDataset, 2}, 110 | {"UndeleteDataset", (DL_FUNC)&UndeleteDataset, 2}, 111 | {"SetIamPolicy", (DL_FUNC)&SetIamPolicy, 2}, 112 | {"GetIamPolicy", (DL_FUNC)&GetIamPolicy, 2}, 113 | {"TestIamPermissions", (DL_FUNC)&TestIamPermissions, 2}, 114 | {"StreamReads", (DL_FUNC)&StreamReads, 2}, 115 | {"ImportReadGroupSets", (DL_FUNC)&ImportReadGroupSets, 2}, 116 | {"ExportReadGroupSet", (DL_FUNC)&ExportReadGroupSet, 2}, 117 | {"SearchReadGroupSets", (DL_FUNC)&SearchReadGroupSets, 2}, 118 | {"UpdateReadGroupSet", (DL_FUNC)&UpdateReadGroupSet, 2}, 119 | {"DeleteReadGroupSet", (DL_FUNC)&DeleteReadGroupSet, 2}, 120 | {"GetReadGroupSet", (DL_FUNC)&GetReadGroupSet, 2}, 121 | {"ListCoverageBuckets", (DL_FUNC)&ListCoverageBuckets, 2}, 122 | {"SearchReads", (DL_FUNC)&SearchReads, 2}, 123 | {"SearchReferenceSets", (DL_FUNC)&SearchReferenceSets, 2}, 124 | {"GetReferenceSet", (DL_FUNC)&GetReferenceSet, 2}, 125 | {"SearchReferences", (DL_FUNC)&SearchReferences, 2}, 126 | {"GetReference", (DL_FUNC)&GetReference, 2}, 127 | {"ListBases", (DL_FUNC)&ListBases, 2}, 128 | {"StreamVariants", (DL_FUNC)&StreamVariants, 2}, 129 | {"ImportVariants", (DL_FUNC)&ImportVariants, 2}, 130 | {"CreateVariantSet", (DL_FUNC)&CreateVariantSet, 2}, 131 | {"ExportVariantSet", (DL_FUNC)&ExportVariantSet, 2}, 132 | {"GetVariantSet", (DL_FUNC)&GetVariantSet, 2}, 133 | {"SearchVariantSets", (DL_FUNC)&SearchVariantSets, 2}, 134 | {"DeleteVariantSet", (DL_FUNC)&DeleteVariantSet, 2}, 135 | {"UpdateVariantSet", (DL_FUNC)&UpdateVariantSet, 2}, 136 | {"SearchVariants", (DL_FUNC)&SearchVariants, 2}, 137 | {"CreateVariant", (DL_FUNC)&CreateVariant, 2}, 138 | {"UpdateVariant", (DL_FUNC)&UpdateVariant, 2}, 139 | {"DeleteVariant", (DL_FUNC)&DeleteVariant, 2}, 140 | {"GetVariant", (DL_FUNC)&GetVariant, 2}, 141 | {"MergeVariants", (DL_FUNC)&MergeVariants, 2}, 142 | {"SearchCallSets", (DL_FUNC)&SearchCallSets, 2}, 143 | {"CreateCallSet", (DL_FUNC)&CreateCallSet, 2}, 144 | {"UpdateCallSet", (DL_FUNC)&UpdateCallSet, 2}, 145 | {"DeleteCallSet", (DL_FUNC)&DeleteCallSet, 2}, 146 | {"GetCallSet", (DL_FUNC)&GetCallSet, 2}, 147 | #endif /* HAVE_GRPC */ 148 | {NULL, NULL, 0}}; 149 | 150 | /* 151 | * Initialize the shared library in the package. 152 | * The name of this function should always match the package name. 153 | */ 154 | void R_init_GoogleGenomics(DllInfo *dll) { 155 | R_registerRoutines(dll, NULL, callMethods, NULL, NULL); 156 | R_useDynamicSymbols(dll, FALSE); 157 | R_forceSymbols(dll, TRUE); 158 | 159 | #ifdef HAVE_GRPC 160 | GOOGLE_PROTOBUF_VERIFY_VERSION; 161 | grpc_init(); 162 | #endif 163 | } 164 | 165 | /* 166 | * Prepare to unload the shared library in the package. 167 | * The name of this function should always match the package name. 168 | */ 169 | void R_unload_GoogleGenomics(DllInfo *dll) { 170 | #ifdef HAVE_GRPC 171 | // Shutdown gRPC. 172 | grpc_shutdown(); 173 | #endif /* HAVE_GRPC */ 174 | } 175 | 176 | } // extern C 177 | -------------------------------------------------------------------------------- /src/rprotobuf.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017 GoogleGenomics R package authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the 'License'); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an 'AS IS' BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #include 18 | 19 | using ::google::protobuf::Message; 20 | 21 | extern "C" { 22 | 23 | void DeleteMessage(SEXP object) { 24 | Message* pointer = static_cast(R_ExternalPtrAddr(object)); 25 | delete pointer; 26 | R_ClearExternalPtr(object); 27 | } 28 | 29 | SEXP MakeRProtoBufObject(Message* message) { 30 | // Allocate the object. 31 | SEXP klass = PROTECT(R_do_MAKE_CLASS("Message")); 32 | SEXP result = PROTECT(R_do_new_object(klass)); 33 | 34 | // Set the pointer slot. 35 | SEXP pointer = PROTECT(R_MakeExternalPtr(message, R_NilValue, R_NilValue)); 36 | R_RegisterCFinalizer(pointer, &DeleteMessage); 37 | R_do_slot_assign(result, Rf_install("pointer"), pointer); 38 | 39 | // Set the type slot. 40 | const char* message_type = message->GetDescriptor()->full_name().c_str(); 41 | R_do_slot_assign(result, Rf_install("type"), 42 | PROTECT(Rf_mkString(message_type))); 43 | 44 | UNPROTECT(4); 45 | return result; 46 | } 47 | 48 | // Returns the protocol buffer contained in a RProtoBuf S4 Message object. 49 | Message* GetMessageFromRProtoBufObject(SEXP object) { 50 | const char* messageClasses[] = {"Message", ""}; 51 | if (R_check_class_etc(object, messageClasses) != 0) { 52 | REprintf("Object of unknown type provided as request."); 53 | return nullptr; 54 | }; 55 | SEXP pointer = R_do_slot(object, Rf_install("pointer")); 56 | return static_cast(R_ExternalPtrAddr(pointer)); 57 | } 58 | 59 | // 60 | SEXP GetRProtoBufMessage(SEXP type) { 61 | const char* type_name = CHAR(STRING_ELT(type, 0)); 62 | 63 | auto* desc = const_cast<::google::protobuf::Descriptor*>( 64 | ::google::protobuf::DescriptorPool::generated_pool() 65 | ->FindMessageTypeByName(type_name)); 66 | if (!desc) { 67 | REprintf("Message of type %s not found", type_name); 68 | return R_NilValue; 69 | } 70 | 71 | Message* msg = ::google::protobuf::MessageFactory::generated_factory() 72 | ->GetPrototype(desc) 73 | ->New(); 74 | return MakeRProtoBufObject(msg); 75 | } 76 | } // extern C 77 | -------------------------------------------------------------------------------- /src/rprotobuf.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 GoogleGenomics R package authors. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the 'License'); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an 'AS IS' BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | #define R_NO_REMAP 18 | #include 19 | #include 20 | 21 | extern "C" { 22 | 23 | void DeleteMessage(SEXP object); 24 | 25 | SEXP MakeRProtoBufObject(::google::protobuf::Message *message); 26 | 27 | ::google::protobuf::Message *GetMessageFromRProtoBufObject(SEXP object); 28 | 29 | SEXP GetRProtoBufMessage(SEXP type); 30 | 31 | } // extern C 32 | -------------------------------------------------------------------------------- /tests/runTests.R: -------------------------------------------------------------------------------- 1 | # The tests will only be run if there is an environment variable called 2 | # GOOGLE_API_KEY containing the public API key. 3 | 4 | # Get the API key from the environment variable. 5 | if (GoogleGenomics::authenticate()) { 6 | # Perform the tests 7 | library(testthat) 8 | test_check("GoogleGenomics") 9 | message("SUCCESS: All tests pass.") 10 | } else { 11 | # Skip the tests 12 | warning(paste( 13 | "Public key unavailable for authentication with Google Genomics.", 14 | "Skipping tests...")) 15 | } 16 | -------------------------------------------------------------------------------- /tests/testthat/test-getReads.R: -------------------------------------------------------------------------------- 1 | context("Reads") 2 | 3 | test_that("Raw reads are fetched correctly", { 4 | # Get raw reads from Reads API 5 | reads <- getReads(readGroupSetId="CMvnhpKTFhDnk4_9zcKO3_YB", 6 | chromosome="22", 7 | start=16051000, 8 | end=16055000) 9 | 10 | expect_equal(length(reads), 418) 11 | expect_equal(mode(reads), "list") 12 | expect_equal(class(reads), "list") 13 | expect_equal(0, length(setdiff(c("id", "fragmentName", "readGroupSetId"), 14 | names(reads[[1]])))) 15 | }) 16 | 17 | test_that("Reads are converted to GAlignments correctly", { 18 | # Get GAlignments from the Reads API 19 | galignments <- getReads(readGroupSetId="CMvnhpKTFhDnk4_9zcKO3_YB", 20 | chromosome="22", 21 | start=16051000, 22 | end=16055000, 23 | converter=readsToGAlignments) 24 | expect_equal(length(galignments), 418) 25 | expect_equal(mode(galignments), "S4") 26 | expect_equal(class(galignments)[1], "GAlignments") 27 | }) 28 | -------------------------------------------------------------------------------- /tests/testthat/test-getVariantCalls.R: -------------------------------------------------------------------------------- 1 | context("VariantCalls") 2 | 3 | fetchVariantCalls <- function(...) { 4 | getVariantCalls(variantSetId = "10473108253681171589", chromosome = "22", 5 | start = 50300077, end = 50301500, fields = NULL, converter = c, 6 | oneBasedCoord = TRUE) 7 | } 8 | 9 | test_that("Raw variant calls are fetched correctly", { 10 | # Get raw variant calls from Variants API 11 | variant_calls <- fetchVariantCalls() 12 | expect_equal(length(variant_calls), 29484) 13 | expect_equal(mode(variant_calls), "S4") 14 | expect_equal(class(variant_calls)[1], "VRanges") 15 | expect_equal(names(variant_calls[1]), "rs7410291") 16 | expect_equal(as.character(sampleNames(variant_calls[1])), "HG00261") 17 | expect_equal(variant_calls[1]$GT, "1/0") 18 | }) 19 | -------------------------------------------------------------------------------- /tests/testthat/test-getVariants.R: -------------------------------------------------------------------------------- 1 | context("Variants") 2 | 3 | fetchVariants <- function(...) { 4 | getVariants(variantSetId="10473108253681171589", chromosome="22", 5 | start=50300077, end=50301500, ...) 6 | } 7 | 8 | test_that("Raw variants are fetched correctly", { 9 | # Get raw variants from Variants API 10 | variants <- fetchVariants() 11 | expect_equal(length(variants), 27) 12 | expect_equal(mode(variants), "list") 13 | expect_equal(class(variants)[1], "list") 14 | expect_equal(0, length(setdiff(names(variants[[1]]), 15 | c("variantSetId", "id", "names", "created", 16 | "referenceName", "start", "end", 17 | "referenceBases", "alternateBases", 18 | "quality", "filter", "info", "calls")))) 19 | }) 20 | 21 | test_that("Variants are converted to GRanges correctly", { 22 | # Get GRanges from the Variants API 23 | granges <- fetchVariants(converter=variantsToGRanges) 24 | expect_equal(length(granges), 27) 25 | expect_equal(mode(granges), "S4") 26 | expect_equal(class(granges)[1], "GRanges") 27 | }) 28 | 29 | test_that("Variants are converted to VRanges correctly", { 30 | # Get VRanges from the Variants API 31 | vranges <- fetchVariants(converter=variantsToVRanges) 32 | expect_equal(length(vranges), 27) 33 | expect_equal(mode(vranges), "S4") 34 | expect_equal(class(vranges)[1], "VRanges") 35 | }) 36 | 37 | test_that("Variants data matches VariantAnnotation package", { 38 | # Get variants data from VariantAnnotation package 39 | fl <- system.file("extdata", "chr22.vcf.gz", package="VariantAnnotation") 40 | vcf <- readVcf(fl, "hg19") 41 | vranges <- fetchVariants(converter=variantsToVRanges) 42 | variantsReference <- as(vcf, "VRanges")[1:length(vranges)] 43 | 44 | # Check start positions. 45 | expect_equal(start(vranges), start(variantsReference)) 46 | 47 | # Check reference alleles. 48 | expect_equal(ref(vranges), ref(variantsReference)) 49 | 50 | # Check alternative allele after coercion from RLE. 51 | expect_equal(as.character(alt(vranges)), as.character(alt(variantsReference))) 52 | }) 53 | -------------------------------------------------------------------------------- /vignettes/AnnotatingVariants.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: Annotating Variants 3 | output: 4 | BiocStyle::html_document 5 | --- 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 25 | 26 | ```{r style, echo = FALSE, results = 'asis'} 27 | BiocStyle::markdown() 28 | ``` 29 | 30 | ```{r, echo=FALSE, results="hide"} 31 | # Ensure that any errors cause the Vignette build to fail. 32 | library(knitr) 33 | opts_chunk$set(error=FALSE) 34 | ``` 35 | 36 | ```{r, echo = FALSE} 37 | apiKey <- Sys.getenv("GOOGLE_API_KEY") 38 | if (nchar(apiKey) == 0) { 39 | warning(paste("To build this vignette, please setup the environment variable", 40 | "GOOGLE_API_KEY with the public API key from your Google", 41 | "Developer Console before loading the GoogleGenomics package,", 42 | "or run GoogleGenomics::authenticate.")) 43 | knitr::knit_exit() 44 | } 45 | ``` 46 | 47 | ## Working with Variants 48 | 49 | [Google Genomics](http://cloud.google.com/genomics) implements the [GA4GH](http://ga4gh.org/) variants API and this R package can retrieve data from that implementation. For more detail, see https://cloud.google.com/genomics/v1beta2/reference/variants 50 | 51 | 52 | ```{r message=FALSE} 53 | library(GoogleGenomics) 54 | # This vignette is authenticated on package load from the env variable GOOGLE_API_KEY. 55 | # When running interactively, call the authenticate method. 56 | # ?authenticate 57 | ``` 58 | 59 | By default, this function retrieves variants for a small genomic region from the [1,000 Genomes](http://googlegenomics.readthedocs.org/en/latest/use_cases/discover_public_data/1000_genomes.html) phase 1 variants. 60 | ```{r} 61 | variants <- getVariants() 62 | length(variants) 63 | ``` 64 | 65 | We can see that `r length(variants)` individual variants were returned and that the JSON response was deserialized into an R list object: 66 | ```{r} 67 | class(variants) 68 | mode(variants) 69 | ``` 70 | 71 | The top level field names are: 72 | ```{r} 73 | names(variants[[1]]) 74 | ``` 75 | 76 | The variant contains nested calls: 77 | ```{r} 78 | length(variants[[1]]$calls) 79 | ``` 80 | 81 | With top level call field names: 82 | ```{r} 83 | names(variants[[1]]$calls[[1]]) 84 | ``` 85 | 86 | And examining a call for a particular variant: 87 | ```{r} 88 | variants[[1]]$referenceName 89 | variants[[1]]$start 90 | variants[[1]]$alternateBases 91 | variants[[1]]$calls[[1]] 92 | ``` 93 | 94 | This is good, but this data becomes **much** more useful when it is converted to Bioconductor data types. For example, we can convert variants in this list representation to VRanges from `r Biocpkg("VariantAnnotation")`: 95 | ```{r} 96 | variantsToVRanges(variants) 97 | ``` 98 | 99 | ## Annotating Variants 100 | 101 | Next let's use package `r Biocpkg("VariantAnnotation")` to annotate some specific 1,000 Genomes Phase 1 variants. 102 | 103 | ```{r message=FALSE} 104 | library(VariantAnnotation) 105 | ``` 106 | 107 | Note that the parameters `start` and `end` are expressed in 0-based coordinates per the GA4GH specification but the Bioconductor data type converters in `r Biocpkg("GoogleGenomics")`, by default, transform the returned data to 1-based coordinates. 108 | ```{r} 109 | granges <- getVariants(variantSetId="10473108253681171589", 110 | chromosome="22", 111 | start=50300077, 112 | end=50303000, 113 | converter=variantsToGRanges) 114 | ``` 115 | 116 | Now locate the protein coding variants in each: 117 | ```{r message=FALSE} 118 | library(TxDb.Hsapiens.UCSC.hg19.knownGene) 119 | ``` 120 | 121 | ```{r} 122 | txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene 123 | granges_locations <- locateVariants(granges, txdb, CodingVariants()) 124 | granges_locations 125 | ``` 126 | 127 | And predict the effect of the protein coding variants: 128 | ```{r message=FALSE} 129 | library(BSgenome.Hsapiens.UCSC.hg19) 130 | ``` 131 | 132 | ```{r} 133 | granges_coding <- predictCoding(rep(granges, elementNROWS(granges$ALT)), 134 | txdb, 135 | seqSource=Hsapiens, 136 | varAllele=unlist(granges$ALT, use.names=FALSE)) 137 | 138 | granges_coding 139 | ``` 140 | 141 | Finally, add gene information: 142 | ```{r message=FALSE} 143 | library(org.Hs.eg.db) 144 | ``` 145 | 146 | ```{r} 147 | annots <- select(org.Hs.eg.db, 148 | keys=granges_coding$GENEID, 149 | keytype="ENTREZID", 150 | columns=c("SYMBOL", "GENENAME","ENSEMBL")) 151 | cbind(elementMetadata(granges_coding), annots) 152 | ``` 153 | 154 | ## Provenance 155 | ```{r} 156 | sessionInfo() 157 | ``` 158 | -------------------------------------------------------------------------------- /vignettes/PlottingAlignments.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: Plotting Alignments 3 | output: 4 | BiocStyle::html_document 5 | --- 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 25 | 26 | ```{r style, echo = FALSE, results = 'asis'} 27 | BiocStyle::markdown() 28 | ``` 29 | 30 | ```{r, echo=FALSE, results="hide"} 31 | # Ensure that any errors cause the Vignette build to fail. 32 | library(knitr) 33 | opts_chunk$set(error=FALSE) 34 | ``` 35 | 36 | ```{r, echo = FALSE} 37 | apiKey <- Sys.getenv("GOOGLE_API_KEY") 38 | if (nchar(apiKey) == 0) { 39 | warning(paste("To build this vignette, please setup the environment variable", 40 | "GOOGLE_API_KEY with the public API key from your Google", 41 | "Developer Console before loading the GoogleGenomics package,", 42 | "or run GoogleGenomics::authenticate.")) 43 | knitr::knit_exit() 44 | } 45 | ``` 46 | 47 | ## Working with Reads 48 | 49 | [Google Genomics](http://cloud.google.com/genomics) implements the [GA4GH](http://ga4gh.org/) reads API and this R package can retrieve data from that implementation. For more detail, see https://cloud.google.com/genomics/v1beta2/reference/reads 50 | ```{r message=FALSE} 51 | library(GoogleGenomics) 52 | # This vignette is authenticated on package load from the env variable GOOGLE_API_KEY. 53 | # When running interactively, call the authenticate method. 54 | # ?authenticate 55 | ``` 56 | 57 | By default, this function retrieves reads for a small genomic region for one sample in [1,000 Genomes](http://googlegenomics.readthedocs.org/en/latest/use_cases/discover_public_data/1000_genomes.html). 58 | ```{r} 59 | reads <- getReads() 60 | length(reads) 61 | ``` 62 | 63 | We can see that `r length(reads)` individual reads were returned and that the JSON response was deserialized into an R list object: 64 | ```{r} 65 | class(reads) 66 | mode(reads) 67 | ``` 68 | 69 | The top level field names are: 70 | ```{r} 71 | names(reads[[1]]) 72 | ``` 73 | 74 | And examining the alignment we see: 75 | ```{r} 76 | reads[[1]]$alignedSequence 77 | reads[[1]]$alignment$position$referenceName 78 | reads[[1]]$alignment$position$position 79 | ``` 80 | 81 | This is good, but this data becomes **much** more useful when it is converted to Bioconductor data types. For example, we can convert reads in this list representation to `r Biocpkg("GAlignments")`: 82 | ```{r} 83 | readsToGAlignments(reads) 84 | ``` 85 | 86 | ## Plotting Alignments 87 | 88 | Let's take a look at the reads that overlap [rs9536314](http://www.ncbi.nlm.nih.gov/SNP/snp_ref.cgi?rs=9536314) for sample NA12893 within the [Illumina Platinum Genomes](http://googlegenomics.readthedocs.org/en/latest/use_cases/discover_public_data/platinum_genomes.html) dataset. This SNP resides on chromosome 13 at position 33628137 in 0-based coordinates. 89 | ```{r} 90 | # Change the values of 'chromosome', 'start', or 'end' here if you wish to plot 91 | # alignments from a different portion of the genome. 92 | alignments <- getReads(readGroupSetId="CMvnhpKTFhD3he72j4KZuyc", 93 | chromosome="chr13", 94 | start=33628130, 95 | end=33628145, 96 | converter=readsToGAlignments) 97 | alignments 98 | ``` 99 | 100 | Notice that we passed the converter to the getReads method so that we're immediately working with GAlignments which means that we can start taking advantage of other Bioconductor functionality. Also keep in mind that the parameters `start` and `end` are expressed in 0-based coordinates per the GA4GH specification but the Bioconductor data type converters in `r Biocpkg("GoogleGenomics")`, by default, transform the returned data to 1-based coordinates. 101 | 102 | ```{r message=FALSE} 103 | library(ggbio) 104 | ``` 105 | 106 | We can display the basic alignments and coverage data: 107 | ```{r coverage} 108 | alignmentPlot <- autoplot(alignments, aes(color=strand, fill=strand)) 109 | coveragePlot <- ggplot(as(alignments, "GRanges")) + 110 | stat_coverage(color="gray40", fill="skyblue") 111 | tracks(alignmentPlot, coveragePlot, 112 | xlab="Reads overlapping rs9536314 for NA12893") 113 | ``` 114 | 115 | And also display the ideogram for the corresponding location on the chromosome: 116 | ```{r ideogram} 117 | ideogramPlot <- plotIdeogram(genome="hg19", subchr="chr13") 118 | ideogramPlot + xlim(as(alignments, "GRanges")) 119 | ``` 120 | 121 | ## Provenance 122 | ```{r} 123 | sessionInfo() 124 | ``` 125 | -------------------------------------------------------------------------------- /vignettes/VariantAnnotation-comparison-test.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: Reproducing Variant Annotation Results 3 | output: 4 | BiocStyle::html_document 5 | --- 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 25 | 26 | ```{r style, echo = FALSE, results = 'asis'} 27 | BiocStyle::markdown() 28 | ``` 29 | 30 | ```{r, echo=FALSE, results="hide"} 31 | # Ensure that any errors cause the Vignette build to fail. 32 | library(knitr) 33 | opts_chunk$set(error=FALSE) 34 | ``` 35 | 36 | ```{r, echo = FALSE} 37 | apiKey <- Sys.getenv("GOOGLE_API_KEY") 38 | if (nchar(apiKey) == 0) { 39 | warning(paste("To build this vignette, please setup the environment variable", 40 | "GOOGLE_API_KEY with the public API key from your Google", 41 | "Developer Console before loading the GoogleGenomics package,", 42 | "or run GoogleGenomics::authenticate.")) 43 | knitr::knit_exit() 44 | } 45 | ``` 46 | 47 | ## Load Data 48 | 49 | Below we compare the results of annotating variants via `r Biocpkg("VariantAnnotation")` specifically repeating a subset of the steps in vignette [Introduction to VariantAnnotation](http://bioconductor.org/packages/release/bioc/vignettes/VariantAnnotation/inst/doc/VariantAnnotation.pdf). We compare using data from 1,000 Genomes Phase 1 Variants: 50 | 51 | * as parsed from a VCF file 52 | * retrieved from the Google Genomics API 53 | 54 | ### VCF Data 55 | 56 | First we read in the data from the VCF file: 57 | ```{r message=FALSE} 58 | library(VariantAnnotation) 59 | ``` 60 | 61 | ```{r} 62 | fl <- system.file("extdata", "chr22.vcf.gz", package="VariantAnnotation") 63 | vcf <- readVcf(fl, "hg19") 64 | vcf <- renameSeqlevels(vcf, c("22"="chr22")) 65 | vcf 66 | ``` 67 | 68 | The file `chr22.vcf.gz` within package VariantAnnotation holds data for 5 of the 1,092 individuals in 1,000 Genomes, starting at position 50300078 and ending at position 50999964. 69 | 70 | `HG00096 HG00097 HG00099 HG00100 HG00101` 71 | 72 | ### Google Genomics Data 73 | 74 | Important data differences to note: 75 | 76 | * VCF data uses 1-based coordinates but data from the GA4GH APIs is 0-based. 77 | * There are two variants in the Google Genomics copy of 1,000 Genomes phase 1 variants that are not in `chr22.vcf.gz`. They are the only two variants within the genomic range with `ALT == `. 78 | 79 | 80 | ```{r message=FALSE} 81 | library(GoogleGenomics) 82 | # This vignette is authenticated on package load from the env variable GOOGLE_API_KEY. 83 | # When running interactively, call the authenticate method. 84 | # ?authenticate 85 | ``` 86 | 87 | ```{r} 88 | # We're just getting the first few variants so that this runs quickly. 89 | # If we wanted to get them all, we sould set end=50999964. 90 | granges <- getVariants(variantSetId="10473108253681171589", 91 | chromosome="22", 92 | start=50300077, 93 | end=50303000, 94 | converter=variantsToGRanges) 95 | ``` 96 | 97 | ### Compare the Loaded Data 98 | Ensure that the data retrieved by each matches: 99 | ```{r} 100 | vcf <- vcf[1:length(granges)] # Truncate the VCF data so that it is the same 101 | # set as what was retrieved from the API. 102 | ``` 103 | 104 | ```{r message=FALSE} 105 | library(testthat) 106 | ``` 107 | 108 | ```{r} 109 | expect_equal(start(granges), start(vcf)) 110 | expect_equal(end(granges), end(vcf)) 111 | expect_equal(as.character(granges$REF), as.character(ref(vcf))) 112 | expect_equal(as.character(unlist(granges$ALT)), as.character(unlist(alt(vcf)))) 113 | expect_equal(granges$QUAL, qual(vcf)) 114 | expect_equal(granges$FILTER, filt(vcf)) 115 | ``` 116 | 117 | ## Compare the Annotation Results 118 | 119 | Now locate the protein coding variants in each: 120 | ```{r message=FALSE} 121 | library(TxDb.Hsapiens.UCSC.hg19.knownGene) 122 | ``` 123 | 124 | ```{r} 125 | txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene 126 | 127 | rd <- rowRanges(vcf) 128 | vcf_locations <- locateVariants(rd, txdb, CodingVariants()) 129 | vcf_locations 130 | 131 | granges_locations <- locateVariants(granges, txdb, CodingVariants()) 132 | granges_locations 133 | 134 | expect_equal(granges_locations, vcf_locations) 135 | ``` 136 | 137 | And predict the effect of the protein coding variants: 138 | ```{r message=FALSE} 139 | library(BSgenome.Hsapiens.UCSC.hg19) 140 | ``` 141 | 142 | ```{r} 143 | vcf_coding <- predictCoding(vcf, txdb, seqSource=Hsapiens) 144 | vcf_coding 145 | 146 | granges_coding <- predictCoding(rep(granges, elementNROWS(granges$ALT)), 147 | txdb, 148 | seqSource=Hsapiens, 149 | varAllele=unlist(granges$ALT, use.names=FALSE)) 150 | 151 | granges_coding 152 | 153 | expect_equal(as.matrix(granges_coding$REFCODON), as.matrix(vcf_coding$REFCODON)) 154 | expect_equal(as.matrix(granges_coding$VARCODON), as.matrix(vcf_coding$VARCODON)) 155 | expect_equal(granges_coding$GENEID, vcf_coding$GENEID) 156 | expect_equal(granges_coding$CONSEQUENCE, vcf_coding$CONSEQUENCE) 157 | 158 | ``` 159 | 160 | ## Provenance 161 | ```{r} 162 | sessionInfo() 163 | ``` 164 | --------------------------------------------------------------------------------