bio-basespace-sdk 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of bio-basespace-sdk might be problematic. Click here for more details.
- data/.document +5 -0
- data/.rspec +1 -0
- data/.travis.yml +11 -0
- data/Gemfile +16 -0
- data/License.txt +275 -0
- data/README.md +671 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/examples/0_app_triggering.rb +135 -0
- data/examples/1_authentication.rb +156 -0
- data/examples/2_browsing.rb +84 -0
- data/examples/3_accessing_files.rb +129 -0
- data/examples/4_app_result_upload.rb +102 -0
- data/examples/5_purchasing.rb +119 -0
- data/lib/basespace.rb +126 -0
- data/lib/basespace/api/api_client.rb +313 -0
- data/lib/basespace/api/base_api.rb +242 -0
- data/lib/basespace/api/basespace_api.rb +789 -0
- data/lib/basespace/api/basespace_error.rb +80 -0
- data/lib/basespace/api/billing_api.rb +115 -0
- data/lib/basespace/model.rb +78 -0
- data/lib/basespace/model/app_result.rb +158 -0
- data/lib/basespace/model/app_result_response.rb +40 -0
- data/lib/basespace/model/app_session.rb +99 -0
- data/lib/basespace/model/app_session_compact.rb +43 -0
- data/lib/basespace/model/app_session_launch_object.rb +58 -0
- data/lib/basespace/model/app_session_response.rb +41 -0
- data/lib/basespace/model/application.rb +47 -0
- data/lib/basespace/model/application_compact.rb +44 -0
- data/lib/basespace/model/basespace_model.rb +60 -0
- data/lib/basespace/model/coverage.rb +48 -0
- data/lib/basespace/model/coverage_meta_response.rb +40 -0
- data/lib/basespace/model/coverage_metadata.rb +43 -0
- data/lib/basespace/model/coverage_response.rb +40 -0
- data/lib/basespace/model/file.rb +172 -0
- data/lib/basespace/model/file_response.rb +40 -0
- data/lib/basespace/model/genome_response.rb +40 -0
- data/lib/basespace/model/genome_v1.rb +56 -0
- data/lib/basespace/model/list_response.rb +53 -0
- data/lib/basespace/model/multipart_upload.rb +288 -0
- data/lib/basespace/model/product.rb +50 -0
- data/lib/basespace/model/project.rb +103 -0
- data/lib/basespace/model/project_response.rb +40 -0
- data/lib/basespace/model/purchase.rb +89 -0
- data/lib/basespace/model/purchase_response.rb +39 -0
- data/lib/basespace/model/purchased_product.rb +56 -0
- data/lib/basespace/model/query_parameters.rb +86 -0
- data/lib/basespace/model/query_parameters_purchased_product.rb +67 -0
- data/lib/basespace/model/refund_purchase_response.rb +40 -0
- data/lib/basespace/model/resource_list.rb +48 -0
- data/lib/basespace/model/response_status.rb +42 -0
- data/lib/basespace/model/run_compact.rb +55 -0
- data/lib/basespace/model/sample.rb +127 -0
- data/lib/basespace/model/sample_response.rb +40 -0
- data/lib/basespace/model/user.rb +80 -0
- data/lib/basespace/model/user_compact.rb +45 -0
- data/lib/basespace/model/user_response.rb +40 -0
- data/lib/basespace/model/variant.rb +57 -0
- data/lib/basespace/model/variant_header.rb +44 -0
- data/lib/basespace/model/variant_info.rb +48 -0
- data/lib/basespace/model/variants_header_response.rb +40 -0
- data/spec/basespaceapi_spec.rb +26 -0
- data/spec/basespaceerror_spec.rb +87 -0
- data/spec/basespacemodel_spec.rb +57 -0
- metadata +239 -0
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "bio-basespace-sdk"
|
18
|
+
gem.homepage = "https://github.com/joejimbo/basespace-ruby-sdk"
|
19
|
+
gem.license = "Apache, Version 2.0"
|
20
|
+
gem.summary = %Q{Bio::BaseSpace is a Ruby based SDK to be used in the development of Apps and scripts for working with Illumina's BaseSpace cloud-computing solution for next-gen sequencing data analysis.}
|
21
|
+
gem.description = %Q{Bio::BaseSpace is a Ruby based SDK ported from the Python based BaseSpacePy SDK to be used in the development of Apps and scripts for working with Illumina's BaseSpace cloud-computing solution for next-gen sequencing data analysis.
|
22
|
+
|
23
|
+
The primary purpose of the SDK is to provide an easy-to-use Ruby environment enabling developers to authenticate a user, retrieve data, and upload data/results from their own analysis to BaseSpace.
|
24
|
+
|
25
|
+
If you haven't already done so, you may wish to familiarize yourself with the general BaseSpace developers documentation (https://developer.basespace.illumina.com/) and create a new BaseSpace App to be used when working through the examples provided in 'examples' folder.}
|
26
|
+
gem.email = "joachim.baran@gmail.com"
|
27
|
+
gem.authors = ["Joachim Baran", "Raoul Bonnal", "Eri Kibukawa", "Francesco Strozzi", "Toshiaki Katayama"]
|
28
|
+
# gem.executable = 'basespace-ruby'
|
29
|
+
# dependencies defined in Gemfile
|
30
|
+
end
|
31
|
+
Jeweler::RubygemsDotOrgTasks.new
|
32
|
+
|
33
|
+
require 'rspec/core'
|
34
|
+
require 'rspec/core/rake_task'
|
35
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
36
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
37
|
+
end
|
38
|
+
|
39
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
40
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
41
|
+
spec.rcov = true
|
42
|
+
end
|
43
|
+
|
44
|
+
task :default => :spec
|
45
|
+
|
46
|
+
require 'rdoc/task'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "BaseSpace Ruby SDK #{version}"
|
52
|
+
# rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.2
|
@@ -0,0 +1,135 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright 2013 Toshiaki Katayama, Joachim Baran
|
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
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
# Application triggering
|
17
|
+
# https://developer.basespace.illumina.com/docs/content/documentation/sdk-samples/python-sdk-overview#Application_triggering
|
18
|
+
|
19
|
+
require 'basespace'
|
20
|
+
|
21
|
+
include Bio::BaseSpace
|
22
|
+
|
23
|
+
# This script demonstrates how to retrieve the AppSession object produced
|
24
|
+
# when a user initiates an app. Further it's demonstrated how to automatically
|
25
|
+
# generate the scope strings to request access to the data object (a project or a sample)
|
26
|
+
# that the app was triggered to analyze.
|
27
|
+
#
|
28
|
+
# NOTE: You will need to fill in client values for your app below
|
29
|
+
|
30
|
+
# Initialize an authentication object using the key and secret from your app.
|
31
|
+
opts = {
|
32
|
+
# FILL IN WITH YOUR APP VALUES HERE!
|
33
|
+
'client_id' => '<your client key>',
|
34
|
+
'client_secret' => '<your client secret>',
|
35
|
+
'access_token' => '<your access token>',
|
36
|
+
'app_session_id' => '<app session id>',
|
37
|
+
'basespace_url' => 'https://api.basespace.illumina.com/',
|
38
|
+
'api_version' => 'v1pre3',
|
39
|
+
}
|
40
|
+
|
41
|
+
# Test if client variables have been set.
|
42
|
+
unless opts.select{|k,v| v[/^<.*>$/]}.empty?
|
43
|
+
opts = Bio::BaseSpace.load_credentials
|
44
|
+
exit 1 unless opts
|
45
|
+
end
|
46
|
+
|
47
|
+
# First we will initialize a BaseSpace API object using our app information and the appSessionId.
|
48
|
+
bs_api = BaseSpaceAPI.new(opts['client_id'], opts['client_secret'], opts['basespace_url'], opts['api_version'], opts['app_session_id'])
|
49
|
+
|
50
|
+
# Using the bmy_app_session.spaceApi we can request the appSession object corresponding to the AppSession id supplied.
|
51
|
+
my_app_session = bs_api.get_app_session
|
52
|
+
puts my_app_session
|
53
|
+
|
54
|
+
# An app session contains a referal to one or more appLaunchObjects which reference the data module
|
55
|
+
# the user launched the app on. This can be a list of projects, samples, or a mixture of objects.
|
56
|
+
puts "Type of data the app was triggered on can be seen in 'references'"
|
57
|
+
puts my_app_session.references.inspect # same as my_app_session.get_attr('References') inspect is used to put surrounding []
|
58
|
+
puts
|
59
|
+
|
60
|
+
# We can also get a handle to the user who started the AppSession.
|
61
|
+
puts "We can get a handle for the user who triggered the app"
|
62
|
+
puts my_app_session.user_created_by # same as my_app_session.get_attr('UserCreatedBy')
|
63
|
+
puts
|
64
|
+
|
65
|
+
# Let's have a closer look at the appSessionLaunchObject.
|
66
|
+
my_reference = my_app_session.references.first
|
67
|
+
|
68
|
+
puts "We can get out information such as the href to the launch object:"
|
69
|
+
puts my_reference.href_content # same as my_reference.get_attr('HrefContent')
|
70
|
+
puts
|
71
|
+
puts "and the specific type of that object:"
|
72
|
+
puts my_reference.type # same as my_reference.get_attr('Type')
|
73
|
+
puts
|
74
|
+
|
75
|
+
# Now we will want to ask for more permission for the specific reference object.
|
76
|
+
my_reference_content = my_reference.content
|
77
|
+
|
78
|
+
puts "We can get out the specific project objects by using 'content':"
|
79
|
+
puts my_reference_content
|
80
|
+
puts
|
81
|
+
|
82
|
+
puts "The scope string for requesting write access to the reference object is:"
|
83
|
+
puts my_reference_content.get_access_str('write')
|
84
|
+
puts
|
85
|
+
|
86
|
+
# We can easily request write access to the reference object, so that our App can start contributing analysis.
|
87
|
+
# By default, we ask for write permission and authentication for a device.
|
88
|
+
access_map = bs_api.get_access(my_reference_content, 'write')
|
89
|
+
# We may limit our request to read access only if that's all that is needed
|
90
|
+
read_access_map = bs_api.get_access(my_reference_content, 'read')
|
91
|
+
|
92
|
+
puts "We get the following access map for the write request"
|
93
|
+
puts access_map
|
94
|
+
puts
|
95
|
+
|
96
|
+
# NOTE You'll need to use a writable project for the following code.
|
97
|
+
# It will fail if the session is read only (e.g., demo projects).
|
98
|
+
|
99
|
+
## PAUSE HERE
|
100
|
+
# Have the user visit the verification uri to grant us access.
|
101
|
+
puts "Please visit the following URL within 15 seconds and grant access"
|
102
|
+
puts access_map['verification_with_code_uri']
|
103
|
+
|
104
|
+
link = access_map['verification_with_code_uri']
|
105
|
+
host = RbConfig::CONFIG['host_os']
|
106
|
+
case host
|
107
|
+
when /mswin|mingw|cygwin/
|
108
|
+
system("start #{link}")
|
109
|
+
when /darwin/
|
110
|
+
system("open #{link}")
|
111
|
+
when /linux/
|
112
|
+
system("xdg-open #{link}")
|
113
|
+
end
|
114
|
+
# BaseSpace exception: authorization_pending - User has not yet approved the access request (RuntimeError).
|
115
|
+
sleep(15)
|
116
|
+
## PAUSE HERE
|
117
|
+
|
118
|
+
# Once the user has granted us the access to the object we requested we can get
|
119
|
+
# the basespace access token and start browsing simply by calling updatePriviliges
|
120
|
+
# on the BaseSpaceAPI instance.
|
121
|
+
code = access_map['device_code']
|
122
|
+
bs_api.update_privileges(code)
|
123
|
+
puts "The BaseSpaceAPI instance was update with write privileges"
|
124
|
+
puts bs_api
|
125
|
+
puts
|
126
|
+
|
127
|
+
# for more details on access-requests and authentication and an example of the web-based case
|
128
|
+
# see example 1_authentication.rb
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
@@ -0,0 +1,156 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright 2013 Toshiaki Katayama, Joachim Baran
|
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
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
# Requesting an access-token for data browsing
|
17
|
+
# https://developer.basespace.illumina.com/docs/content/documentation/sdk-samples/python-sdk-overview#Requesting_an_access-token_for_data_browsing
|
18
|
+
|
19
|
+
require 'basespace'
|
20
|
+
|
21
|
+
include Bio::BaseSpace
|
22
|
+
|
23
|
+
# Demonstrates the basic BaseSpace authentication process The work-flow is as follows:
|
24
|
+
# scope-request -> user grants access -> browsing data. The scenario is demonstrated both for device and web-based apps.
|
25
|
+
#
|
26
|
+
# Further we demonstrate how a BaseSpaceAPI instance may be preserved across multiple
|
27
|
+
# http-request for the same app session using Python's pickle module.
|
28
|
+
#
|
29
|
+
# NOTE You will need to fill client values for your app below!
|
30
|
+
|
31
|
+
opts = {
|
32
|
+
# FILL IN WITH YOUR APP VALUES HERE!
|
33
|
+
'client_id' => '<your client key>',
|
34
|
+
'client_secret' => '<your client secret>',
|
35
|
+
'access_token' => '<your access token>',
|
36
|
+
'app_session_id' => '<app session id>',
|
37
|
+
'basespace_url' => 'https://api.basespace.illumina.com/',
|
38
|
+
'api_version' => 'v1pre3',
|
39
|
+
}
|
40
|
+
|
41
|
+
# Test if client variables have been set.
|
42
|
+
unless opts.select{|k,v| v[/^<.*>$/]}.empty?
|
43
|
+
opts = Bio::BaseSpace.load_credentials
|
44
|
+
exit 1 unless opts
|
45
|
+
end
|
46
|
+
|
47
|
+
bs_api = BaseSpaceAPI.new(opts['client_id'], opts['client_secret'], opts['basespace_url'], opts['api_version'], opts['app_session_id'])
|
48
|
+
|
49
|
+
# First, get the verification code and uri for scope 'browse global'.
|
50
|
+
device_info = bs_api.get_verification_code('browse global')
|
51
|
+
|
52
|
+
## PAUSE HERE
|
53
|
+
# Have the user visit the verification uri to grant us access.
|
54
|
+
puts "Please visit the following URL within 15 seconds and grant access"
|
55
|
+
puts device_info['verification_with_code_uri']
|
56
|
+
|
57
|
+
link = device_info['verification_with_code_uri']
|
58
|
+
host = RbConfig::CONFIG['host_os']
|
59
|
+
case host
|
60
|
+
when /mswin|mingw|cygwin/
|
61
|
+
system("start #{link}")
|
62
|
+
when /darwin/
|
63
|
+
system("open #{link}")
|
64
|
+
when /linux/
|
65
|
+
system("xdg-open #{link}")
|
66
|
+
end
|
67
|
+
sleep(15)
|
68
|
+
## PAUSE HERE
|
69
|
+
|
70
|
+
# Once the user has granted us access to objects we requested, we can get
|
71
|
+
# the basespace access token and start browsing simply by calling updatePriviliges
|
72
|
+
# on the baseSpaceApi instance.
|
73
|
+
code = device_info['device_code']
|
74
|
+
bs_api.update_privileges(code)
|
75
|
+
|
76
|
+
# As a reference the provided access-token can be obtained from the BaseSpaceAPI object.
|
77
|
+
puts "My Access-token: #{bs_api.get_access_token}"
|
78
|
+
puts
|
79
|
+
|
80
|
+
# Let's try and grab all available genomes with our new api!
|
81
|
+
all_genomes = bs_api.get_available_genomes
|
82
|
+
puts "Genomes: #{all_genomes}"
|
83
|
+
puts
|
84
|
+
|
85
|
+
# If at a later stage we wish to initialize a BaseSpaceAPI object when we already have
|
86
|
+
# an access-token from a previous sessions, this may simply be done by initializing the BaseSpaceAPI
|
87
|
+
# object using the key-word AccessToken.
|
88
|
+
my_token = bs_api.get_access_token
|
89
|
+
bs_api = BaseSpaceAPI.new(opts['client_id'], opts['client_secret'], opts['basespace_url'], opts['api_version'], opts['app_session_id'], my_token)
|
90
|
+
puts "A BaseSpaceAPI instance initialized with an access-token:"
|
91
|
+
puts bs_api
|
92
|
+
puts
|
93
|
+
|
94
|
+
#################### Web-based verification #################################
|
95
|
+
# The scenario where the authentication is done through a web-browser.
|
96
|
+
|
97
|
+
bs_api_web = BaseSpaceAPI.new(opts['client_id'], opts['client_secret'], opts['basespace_url'], opts['api_version'], opts['app_session_id'])
|
98
|
+
user_url= bs_api_web.get_web_verification_code('browse global', 'http://localhost', 'myState')
|
99
|
+
|
100
|
+
puts "Have the user visit:"
|
101
|
+
puts user_url
|
102
|
+
puts
|
103
|
+
|
104
|
+
link = user_url
|
105
|
+
host = RbConfig::CONFIG['host_os']
|
106
|
+
case host
|
107
|
+
when /mswin|mingw|cygwin/
|
108
|
+
system("start #{link}")
|
109
|
+
when /darwin/
|
110
|
+
system("open #{link}")
|
111
|
+
when /linux/
|
112
|
+
system("xdg-open #{link}")
|
113
|
+
end
|
114
|
+
|
115
|
+
# Once the grant has been given you will be redirected to a url looking something like this
|
116
|
+
# http://localhost/?code=<MY DEVICE CODE FROM REDICRECT>&state=myState&action=oauthv2authorization
|
117
|
+
# By getting the code parameter from the above http request we can now get our access-token.
|
118
|
+
|
119
|
+
my_code = '<MY DEVICE CODE FROM REDICRECT>'
|
120
|
+
#bs_api_web.update_privileges(my_code)
|
121
|
+
|
122
|
+
user = bs_api.get_user_by_id('current')
|
123
|
+
puts "Get current user"
|
124
|
+
puts user
|
125
|
+
puts bs_api
|
126
|
+
puts
|
127
|
+
|
128
|
+
#### Carry on with the work...
|
129
|
+
|
130
|
+
# Now we wish to store the API object for the next time we get a request in this session
|
131
|
+
# make a file to store the BaseSpaceAPI instance in. For easy identification we will name
|
132
|
+
# this by any id that may be used for identifying the session again.
|
133
|
+
my_session_id = bs_api.app_session_id + '.marshal'
|
134
|
+
File.open(my_session_id, 'w') do |f|
|
135
|
+
Marshal.dump(bs_api, f)
|
136
|
+
end
|
137
|
+
|
138
|
+
# Imagine the current request is done, we will simulate this by deleting the api instance.
|
139
|
+
bs_api = nil
|
140
|
+
puts "Try printing the removed API, we get: '#{bs_api}' (<-- should be empty)"
|
141
|
+
puts
|
142
|
+
|
143
|
+
# Next request in the session with id = id123 comes in.
|
144
|
+
# We will check if there is already a BaseSpaceAPI stored for the session.
|
145
|
+
if File.exists?(my_session_id)
|
146
|
+
File.open(my_session_id) do |f|
|
147
|
+
bs_api = Marshal.load(f)
|
148
|
+
end
|
149
|
+
puts
|
150
|
+
puts "We got the API back!"
|
151
|
+
puts bs_api
|
152
|
+
else
|
153
|
+
puts "Looks like we haven't stored anything for this session yet"
|
154
|
+
# create a BaseSpaceAPI for the first time
|
155
|
+
end
|
156
|
+
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright 2013 Toshiaki Katayama, Joachim Baran
|
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
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
# Browsing data with global browse access
|
17
|
+
# https://developer.basespace.illumina.com/docs/content/documentation/sdk-samples/python-sdk-overview#Browsing_data_with_global_browse_access
|
18
|
+
|
19
|
+
require 'basespace'
|
20
|
+
|
21
|
+
include Bio::BaseSpace
|
22
|
+
|
23
|
+
# This script demonstrates basic browsing of BaseSpace objects once an access-token
|
24
|
+
# for global browsing has been obtained.
|
25
|
+
|
26
|
+
opts = {
|
27
|
+
# FILL IN WITH YOUR APP VALUES HERE!
|
28
|
+
'client_id' => '<your client key>',
|
29
|
+
'client_secret' => '<your client secret>',
|
30
|
+
'access_token' => '<your access token>',
|
31
|
+
'app_session_id' => '<app session id>',
|
32
|
+
'basespace_url' => 'https://api.basespace.illumina.com/',
|
33
|
+
'api_version' => 'v1pre3',
|
34
|
+
}
|
35
|
+
|
36
|
+
# Test if client variables have been set.
|
37
|
+
unless opts.select{|k,v| v[/^<.*>$/]}.empty?
|
38
|
+
opts = Bio::BaseSpace.load_credentials
|
39
|
+
exit 1 unless opts
|
40
|
+
end
|
41
|
+
|
42
|
+
# First, create a client for making calls for this user session.
|
43
|
+
my_api = BaseSpaceAPI.new(opts['client_id'], opts['client_secret'], opts['basespace_url'], opts['api_version'], opts['app_session_id'], opts['access_token'])
|
44
|
+
|
45
|
+
# Now let's grab the genome with id=4.
|
46
|
+
my_genome = my_api.get_genome_by_id('4')
|
47
|
+
puts "The Genome is #{my_genome}"
|
48
|
+
puts "We can get more information from the genome object"
|
49
|
+
puts "Id: #{my_genome.id}"
|
50
|
+
puts "Href: #{my_genome.href}"
|
51
|
+
puts "DisplayName: #{my_genome.display_name}"
|
52
|
+
puts
|
53
|
+
|
54
|
+
# Get a list of all genomes.
|
55
|
+
all_genomes = my_api.get_available_genomes
|
56
|
+
puts "Genomes: #{all_genomes}"
|
57
|
+
puts
|
58
|
+
|
59
|
+
# Let's have a look at the current user.
|
60
|
+
user = my_api.get_user_by_id('current')
|
61
|
+
puts "The current user is #{user}"
|
62
|
+
puts
|
63
|
+
|
64
|
+
# Now list the projects for this user.
|
65
|
+
my_projects = my_api.get_project_by_user('current')
|
66
|
+
puts "The projects for this user are #{my_projects}"
|
67
|
+
puts
|
68
|
+
|
69
|
+
# We can also achieve this by making a call using the 'user instance'.
|
70
|
+
my_projects2 = user.get_projects(my_api)
|
71
|
+
puts "Projects retrieved from the user instance #{my_projects2}"
|
72
|
+
puts
|
73
|
+
|
74
|
+
# List the runs available for the current user.
|
75
|
+
runs = user.get_runs(my_api)
|
76
|
+
puts "The runs for this user are #{runs}"
|
77
|
+
puts
|
78
|
+
|
79
|
+
=begin [NOTE] commented out as this example is same as the above (bug in Python version?)
|
80
|
+
# In the same manner we can get a list of accessible user runs
|
81
|
+
runs = user.get_runs(my_api)
|
82
|
+
print "Runs retrieved from user instance #{runs}"
|
83
|
+
puts
|
84
|
+
=end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright 2013 Toshiaki Katayama, Joachim Baran
|
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
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
# Accessing file-trees and querying BAM or VCF files
|
17
|
+
# https://developer.basespace.illumina.com/docs/content/documentation/sdk-samples/python-sdk-overview#Accessing_file-trees_and_querying_BAM_or_VCF_files
|
18
|
+
|
19
|
+
require 'basespace'
|
20
|
+
|
21
|
+
include Bio::BaseSpace
|
22
|
+
|
23
|
+
# This script demonstrates how to access Samples and AppResults from a projects and
|
24
|
+
# how to work with the available file data for such instances.
|
25
|
+
|
26
|
+
opts = {
|
27
|
+
# FILL IN WITH YOUR APP VALUES HERE!
|
28
|
+
'client_id' => '<your client key>',
|
29
|
+
'client_secret' => '<your client secret>',
|
30
|
+
'access_token' => '<your access token>',
|
31
|
+
'app_session_id' => '<app session id>',
|
32
|
+
'basespace_url' => 'https://api.basespace.illumina.com/',
|
33
|
+
'api_version' => 'v1pre3',
|
34
|
+
}
|
35
|
+
|
36
|
+
# Test if client variables have been set.
|
37
|
+
unless opts.select{|k,v| v[/^<.*>$/]}.empty?
|
38
|
+
opts = Bio::BaseSpace.load_credentials
|
39
|
+
exit 1 unless opts
|
40
|
+
end
|
41
|
+
|
42
|
+
# First, create a client for making calls for this user session.
|
43
|
+
my_api = BaseSpaceAPI.new(opts['client_id'], opts['client_secret'], opts['basespace_url'], opts['api_version'], opts['app_session_id'], opts['access_token'])
|
44
|
+
user = my_api.get_user_by_id('current')
|
45
|
+
my_projects = my_api.get_project_by_user('current')
|
46
|
+
|
47
|
+
app_results = nil
|
48
|
+
samples = nil
|
49
|
+
|
50
|
+
# Let's list all the AppResults and samples for these projects.
|
51
|
+
my_projects.each do |single_project|
|
52
|
+
puts "# Project: #{single_project}"
|
53
|
+
|
54
|
+
app_results = single_project.get_app_results(my_api)
|
55
|
+
puts " The App results for project #{single_project} are"
|
56
|
+
puts " #{app_results}"
|
57
|
+
|
58
|
+
# app_results.each do |app_res|
|
59
|
+
# puts " # AppResult: #{app_res.id}"
|
60
|
+
# files = app_res.get_files(my_api)
|
61
|
+
# puts files
|
62
|
+
# end
|
63
|
+
|
64
|
+
samples = single_project.get_samples(my_api)
|
65
|
+
puts " The samples for project #{single_project} are"
|
66
|
+
puts " #{samples}"
|
67
|
+
|
68
|
+
# samples.each do |sample|
|
69
|
+
# puts " # Sample: #{sample}"
|
70
|
+
# files = sample.get_files(my_api)
|
71
|
+
# puts files
|
72
|
+
# end
|
73
|
+
end
|
74
|
+
|
75
|
+
# We will take a further look at the files belonging to the sample and
|
76
|
+
# analysis from the last project in the loop above.
|
77
|
+
app_results.each do |app_res|
|
78
|
+
puts "# AppResult: #{app_res.id}"
|
79
|
+
files = app_res.get_files(my_api)
|
80
|
+
puts files
|
81
|
+
end
|
82
|
+
samples.each do |sample|
|
83
|
+
puts "# Sample: #{sample}"
|
84
|
+
files = sample.get_files(my_api)
|
85
|
+
puts files
|
86
|
+
end
|
87
|
+
|
88
|
+
# [TODO] We need to identify file IDs for BAM and VCF which can be accessed by everyone (for testing)
|
89
|
+
# The BAM file 2150156 and the VCF file 2150158 are not available for public
|
90
|
+
# => Forbidden: Sorry but this requires READ access to this resource.
|
91
|
+
#
|
92
|
+
# https://basespace.illumina.com/datacentral
|
93
|
+
#
|
94
|
+
# Project: Cancer Sequencing Demo - id=4
|
95
|
+
# AppResult: 31193
|
96
|
+
# L2I_S1.bam - id: '5595005', size: '673519149'
|
97
|
+
#
|
98
|
+
# Project: ResequencingPhixRun - id=12
|
99
|
+
# AppResult: 6522
|
100
|
+
# Indels.1.vcf - id: '3360125', size: '747'
|
101
|
+
# Project: BaseSpaceDemo - id=2
|
102
|
+
# AppResult: 1031
|
103
|
+
# Indels.1.vcf - id: '535594', size: '5214'
|
104
|
+
#
|
105
|
+
|
106
|
+
#
|
107
|
+
# Working with files.
|
108
|
+
#
|
109
|
+
|
110
|
+
# We grab a BAM by id and get the coverage for an interval + accompanying meta-data.
|
111
|
+
my_bam = my_api.get_file_by_id('5595005') # [TODO] What file ID to use?
|
112
|
+
puts "# BAM: #{my_bam}"
|
113
|
+
cov_meta = my_bam.get_coverage_meta(my_api, 'chr2')
|
114
|
+
puts cov_meta
|
115
|
+
cov = my_bam.get_interval_coverage(my_api, 'chr2', '1', '20000') # [TODO] What seqname and position to use?
|
116
|
+
puts cov
|
117
|
+
|
118
|
+
# and a vcf file
|
119
|
+
#my_vcf = my_api.get_file_by_id('3360125') # [TODO] What file ID to use?
|
120
|
+
my_vcf = my_api.get_file_by_id('44153695') # Public data >> Resequencing >> HiSeq 2500 2x150 Human Genome Demo
|
121
|
+
puts "# VCF: #{my_vcf}"
|
122
|
+
# Let's get the variant meta info
|
123
|
+
var_meta = my_vcf.get_variant_meta(my_api)
|
124
|
+
puts var_meta
|
125
|
+
#var = my_vcf.filter_variant(my_api, 'phix', '1', '5386') # [TODO] What seqname and position to use?
|
126
|
+
var = my_vcf.filter_variant(my_api, '2', '1', '11000')
|
127
|
+
puts var
|
128
|
+
|
129
|
+
|