bio-basespace-sdk 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of bio-basespace-sdk might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +479 -482
- data/Rakefile +3 -5
- data/VERSION +1 -1
- data/examples/0_app_triggering.rb +51 -62
- data/examples/1_authentication.rb +14 -99
- data/examples/2_browsing.rb +42 -44
- data/examples/3_accessing_files.rb +72 -77
- data/examples/4_app_result_upload.rb +97 -54
- data/examples/5_purchasing.rb +4 -10
- data/lib/basespace/api/api_client.rb +11 -5
- data/lib/basespace/api/base_api.rb +3 -3
- data/lib/basespace/api/basespace_api.rb +9 -9
- data/lib/basespace/model/project.rb +1 -1
- data/lib/basespace/model/sample.rb +6 -5
- metadata +6 -8
data/Rakefile
CHANGED
@@ -17,12 +17,10 @@ Jeweler::Tasks.new do |gem|
|
|
17
17
|
gem.name = "bio-basespace-sdk"
|
18
18
|
gem.homepage = "https://github.com/joejimbo/basespace-ruby-sdk"
|
19
19
|
gem.license = "Apache, Version 2.0"
|
20
|
-
gem.summary = %Q{
|
21
|
-
gem.description = %Q{
|
20
|
+
gem.summary = %Q{BaseSpace Ruby SDK is a Ruby based Software Development Kit 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{BaseSpace Ruby SDK is a Ruby based Software Development Kit 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
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.}
|
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.}
|
26
24
|
gem.email = "joachim.baran@gmail.com"
|
27
25
|
gem.authors = ["Joachim Baran", "Raoul Bonnal", "Eri Kibukawa", "Francesco Strozzi", "Toshiaki Katayama"]
|
28
26
|
# gem.executable = 'basespace-ruby'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
@@ -14,19 +14,12 @@
|
|
14
14
|
# limitations under the License.
|
15
15
|
|
16
16
|
# Application triggering
|
17
|
-
#
|
17
|
+
# https://github.com/joejimbo/basespace-ruby-sdk#application-triggering
|
18
18
|
|
19
19
|
require 'bio-basespace-sdk'
|
20
20
|
|
21
21
|
include Bio::BaseSpace
|
22
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
23
|
# Initialize an authentication object using the key and secret from your app.
|
31
24
|
opts = {
|
32
25
|
# FILL IN WITH YOUR APP VALUES HERE!
|
@@ -44,92 +37,88 @@ unless opts.select{|k,v| v[/^<.*>$/]}.empty?
|
|
44
37
|
exit 1 unless opts
|
45
38
|
end
|
46
39
|
|
47
|
-
#
|
40
|
+
# Initialize a BaseSpace API object:
|
48
41
|
bs_api = BaseSpaceAPI.new(opts['client_id'], opts['client_secret'], opts['basespace_url'], opts['api_version'], opts['app_session_id'])
|
49
42
|
|
50
|
-
# Using
|
43
|
+
# Using bs_api, we can request the AppSession object corresponding to the AppSession ID supplied
|
51
44
|
my_app_session = bs_api.get_app_session
|
52
45
|
puts my_app_session
|
53
46
|
|
54
|
-
# An app session contains a
|
55
|
-
# the user launched the
|
56
|
-
puts "Type of data the app was triggered on can be seen in 'references'"
|
57
|
-
puts my_app_session.references.inspect
|
58
|
-
|
47
|
+
# An app session contains a referral to one or more AppSessionLaunchObject instances, which reference the
|
48
|
+
# data module the user launched the App on. This can be a list of projects, samples, or a mixture of objects
|
49
|
+
puts "Type of data the app was triggered on can be seen in 'references':"
|
50
|
+
puts my_app_session.references.inspect # `inspect` shows the object contents
|
51
|
+
|
52
|
+
#
|
53
|
+
# We can get a handle to the user who started the `AppSession` and further information on the `AppSessionLaunchObject`:
|
54
|
+
#
|
59
55
|
|
60
|
-
|
61
|
-
puts
|
62
|
-
puts my_app_session.user_created_by # same as my_app_session.get_attr('UserCreatedBy')
|
56
|
+
puts "App session created by user:"
|
57
|
+
puts my_app_session.user_created_by
|
63
58
|
puts
|
64
59
|
|
65
|
-
# Let's have a closer look at the
|
60
|
+
# Let's have a closer look at the AppSessionLaunchObject class instance:
|
66
61
|
my_reference = my_app_session.references.first
|
67
62
|
|
68
|
-
puts "
|
69
|
-
puts my_reference.href_content
|
63
|
+
puts "href to the launch object:"
|
64
|
+
puts my_reference.href_content
|
70
65
|
puts
|
71
|
-
puts "
|
72
|
-
puts my_reference.type
|
66
|
+
puts "Type of that object:"
|
67
|
+
puts my_reference.type
|
73
68
|
puts
|
74
69
|
|
75
|
-
#
|
76
|
-
|
70
|
+
#
|
71
|
+
# This section shows how one can easily obtain the so-called "scope string" and make the access request.
|
72
|
+
#
|
73
|
+
# More background reading on scope strings can be found in the BaseSpace developer documentation under
|
74
|
+
#
|
75
|
+
# "BaseSpace Permissions"
|
76
|
+
# https://developer.basespace.illumina.com/docs/content/documentation/authentication/using-scope
|
77
|
+
#
|
77
78
|
|
78
|
-
puts "
|
79
|
+
puts "Project object:"
|
80
|
+
my_reference_content = my_reference.content
|
79
81
|
puts my_reference_content
|
80
82
|
puts
|
81
|
-
|
82
|
-
puts "The scope string for requesting write access to the reference object is:"
|
83
|
+
puts "Scope string for requesting write access to the reference object:"
|
83
84
|
puts my_reference_content.get_access_str('write')
|
84
|
-
puts
|
85
85
|
|
86
|
-
#
|
87
|
-
#
|
88
|
-
|
89
|
-
|
90
|
-
|
86
|
+
#
|
87
|
+
# The following call requests write permissions for a Web App:
|
88
|
+
#
|
89
|
+
|
90
|
+
verification_with_code_uri = bs_api.get_access(my_reference_content, 'write')
|
91
|
+
puts "Visit the URI within 15 seconds and grant access:"
|
92
|
+
puts verification_with_code_uri
|
91
93
|
|
92
|
-
|
94
|
+
#
|
95
|
+
# The following call requests write permissions for other Apps (Desktop, Mobile, Native):
|
96
|
+
#
|
97
|
+
|
98
|
+
access_map = bs_api.get_access(my_reference_content, 'write')
|
99
|
+
puts "Access map:"
|
93
100
|
puts access_map
|
94
|
-
puts
|
95
101
|
|
96
|
-
#
|
97
|
-
#
|
102
|
+
#
|
103
|
+
# Confirm 'write' privilege request:
|
104
|
+
#
|
98
105
|
|
99
|
-
|
100
|
-
|
101
|
-
puts
|
102
|
-
puts access_map['verification_with_code_uri']
|
106
|
+
puts "Visit the URI within 15 seconds and grant access:"
|
107
|
+
verification_with_code_uri = access_map['verification_with_code_uri']
|
108
|
+
puts verification_with_code_uri
|
103
109
|
|
104
110
|
link = access_map['verification_with_code_uri']
|
105
111
|
host = RbConfig::CONFIG['host_os']
|
106
112
|
case host
|
107
113
|
when /mswin|mingw|cygwin/
|
108
|
-
system("start #{
|
114
|
+
system("start #{verification_with_code_uri}")
|
109
115
|
when /darwin/
|
110
|
-
system("open #{
|
116
|
+
system("open #{verification_with_code_uri}")
|
111
117
|
when /linux/
|
112
|
-
system("xdg-open #{
|
118
|
+
system("xdg-open #{verification_with_code_uri}")
|
113
119
|
end
|
114
|
-
# BaseSpace exception: authorization_pending - User has not yet approved the access request (RuntimeError).
|
115
120
|
sleep(15)
|
116
|
-
## PAUSE HERE
|
117
121
|
|
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
122
|
code = access_map['device_code']
|
122
123
|
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
124
|
|
@@ -13,21 +13,13 @@
|
|
13
13
|
# See the License for the specific language governing permissions and
|
14
14
|
# limitations under the License.
|
15
15
|
|
16
|
-
#
|
17
|
-
#
|
16
|
+
# BaseSpace Authentication
|
17
|
+
# https://github.com/joejimbo/basespace-ruby-sdk#basespace-authentication
|
18
18
|
|
19
19
|
require 'bio-basespace-sdk'
|
20
20
|
|
21
21
|
include Bio::BaseSpace
|
22
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
23
|
opts = {
|
32
24
|
# FILL IN WITH YOUR APP VALUES HERE!
|
33
25
|
'client_id' => '<your client key>',
|
@@ -44,16 +36,22 @@ unless opts.select{|k,v| v[/^<.*>$/]}.empty?
|
|
44
36
|
exit 1 unless opts
|
45
37
|
end
|
46
38
|
|
39
|
+
# Initialize a BaseSpace API object:
|
47
40
|
bs_api = BaseSpaceAPI.new(opts['client_id'], opts['client_secret'], opts['basespace_url'], opts['api_version'], opts['app_session_id'])
|
48
41
|
|
49
|
-
#
|
50
|
-
|
42
|
+
#
|
43
|
+
# Get the verification code and uri for scope 'browse global':
|
44
|
+
#
|
51
45
|
|
52
|
-
|
53
|
-
|
54
|
-
puts "
|
46
|
+
device_info = bs_api.get_verification_code('browse global')
|
47
|
+
puts
|
48
|
+
puts "URI for user to visit and grant access:"
|
55
49
|
puts device_info['verification_with_code_uri']
|
56
50
|
|
51
|
+
#
|
52
|
+
# Grant access privileges:
|
53
|
+
#
|
54
|
+
|
57
55
|
link = device_info['verification_with_code_uri']
|
58
56
|
host = RbConfig::CONFIG['host_os']
|
59
57
|
case host
|
@@ -65,92 +63,9 @@ when /linux/
|
|
65
63
|
system("xdg-open #{link}")
|
66
64
|
end
|
67
65
|
sleep(15)
|
68
|
-
## PAUSE HERE
|
69
66
|
|
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
67
|
code = device_info['device_code']
|
74
68
|
bs_api.update_privileges(code)
|
75
69
|
|
76
|
-
|
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
|
70
|
+
puts "Access-token: #{bs_api.get_access_token}"
|
156
71
|
|
data/examples/2_browsing.rb
CHANGED
@@ -13,16 +13,13 @@
|
|
13
13
|
# See the License for the specific language governing permissions and
|
14
14
|
# limitations under the License.
|
15
15
|
|
16
|
-
# Browsing
|
17
|
-
#
|
16
|
+
# Browsing Data
|
17
|
+
# https://github.com/joejimbo/basespace-ruby-sdk#browsing-data
|
18
18
|
|
19
19
|
require 'bio-basespace-sdk'
|
20
20
|
|
21
21
|
include Bio::BaseSpace
|
22
22
|
|
23
|
-
# This script demonstrates basic browsing of BaseSpace objects once an access-token
|
24
|
-
# for global browsing has been obtained.
|
25
|
-
|
26
23
|
opts = {
|
27
24
|
# FILL IN WITH YOUR APP VALUES HERE!
|
28
25
|
'client_id' => '<your client key>',
|
@@ -39,46 +36,47 @@ unless opts.select{|k,v| v[/^<.*>$/]}.empty?
|
|
39
36
|
exit 1 unless opts
|
40
37
|
end
|
41
38
|
|
42
|
-
#
|
43
|
-
|
39
|
+
# Initialize a BaseSpace API object:
|
40
|
+
bs_api = BaseSpaceAPI.new(opts['client_id'], opts['client_secret'], opts['basespace_url'], opts['api_version'], opts['app_session_id'], opts['access_token'])
|
41
|
+
|
42
|
+
#
|
43
|
+
# Retrieve a genome object:
|
44
|
+
#
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
puts "The Genome is #{my_genome}"
|
48
|
-
puts "We can get more information from the genome object"
|
46
|
+
my_genome = bs_api.get_genome_by_id('4')
|
47
|
+
puts "Genome: #{my_genome}"
|
49
48
|
puts "Id: #{my_genome.id}"
|
50
49
|
puts "Href: #{my_genome.href}"
|
51
50
|
puts "DisplayName: #{my_genome.display_name}"
|
52
|
-
|
53
|
-
|
54
|
-
# Get a list of all genomes
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
runs = user.get_runs(
|
82
|
-
|
83
|
-
|
84
|
-
=end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Get a list of all available genomes:
|
54
|
+
#
|
55
|
+
|
56
|
+
all_genomes = bs_api.get_available_genomes
|
57
|
+
puts "Genomes: #{all_genomes.map { |g| g.to_s }.join(', ')}"
|
58
|
+
|
59
|
+
#
|
60
|
+
# Retrieve the `User` object for the current user and list all projects for this user:
|
61
|
+
#
|
62
|
+
|
63
|
+
user = bs_api.get_user_by_id('current')
|
64
|
+
puts "User -- #{user}"
|
65
|
+
|
66
|
+
my_projects = bs_api.get_project_by_user('current')
|
67
|
+
puts "Projects: #{my_projects.map { |p| p.to_s }.join(', ')}"
|
68
|
+
|
69
|
+
#
|
70
|
+
# We can also achieve this by making a call to the `User` instance:
|
71
|
+
#
|
72
|
+
|
73
|
+
my_projects = user.get_projects(bs_api)
|
74
|
+
puts "Projects: #{my_projects.map { |p| p.to_s }.join(', ')}"
|
75
|
+
|
76
|
+
#
|
77
|
+
# List all runs for a user:
|
78
|
+
#
|
79
|
+
|
80
|
+
runs = user.get_runs(bs_api)
|
81
|
+
puts "Runs: #{runs.map { |r| r.to_s }.join(', ')}"
|
82
|
+
|
@@ -13,16 +13,13 @@
|
|
13
13
|
# See the License for the specific language governing permissions and
|
14
14
|
# limitations under the License.
|
15
15
|
|
16
|
-
# Accessing
|
17
|
-
#
|
16
|
+
# Accessing and Querying Files
|
17
|
+
# https://github.com/joejimbo/basespace-ruby-sdk#accessing-and-querying-files
|
18
18
|
|
19
19
|
require 'bio-basespace-sdk'
|
20
20
|
|
21
21
|
include Bio::BaseSpace
|
22
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
23
|
opts = {
|
27
24
|
# FILL IN WITH YOUR APP VALUES HERE!
|
28
25
|
'client_id' => '<your client key>',
|
@@ -39,91 +36,89 @@ unless opts.select{|k,v| v[/^<.*>$/]}.empty?
|
|
39
36
|
exit 1 unless opts
|
40
37
|
end
|
41
38
|
|
42
|
-
#
|
43
|
-
|
44
|
-
|
45
|
-
|
39
|
+
# Initialize a BaseSpace API object:
|
40
|
+
bs_api = BaseSpaceAPI.new(opts['client_id'], opts['client_secret'], opts['basespace_url'], opts['api_version'], opts['app_session_id'], opts['access_token'])
|
41
|
+
|
42
|
+
### Accessing Files ###
|
43
|
+
|
44
|
+
#
|
45
|
+
# Get a project that we can work with:
|
46
|
+
#
|
46
47
|
|
47
|
-
|
48
|
-
|
48
|
+
user = bs_api.get_user_by_id('current')
|
49
|
+
my_projects = bs_api.get_project_by_user('current')
|
49
50
|
|
50
|
-
#
|
51
|
+
#
|
52
|
+
# List all the analyses and samples for these projects:
|
53
|
+
#
|
54
|
+
|
55
|
+
# Define 'samples' variable here, so that it can be reused further into the example again:
|
56
|
+
samples = nil
|
51
57
|
my_projects.each do |single_project|
|
52
|
-
puts "
|
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
|
58
|
+
puts "Project: #{single_project}"
|
74
59
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
puts files
|
60
|
+
app_results = single_project.get_app_results(bs_api)
|
61
|
+
puts " AppResult instances: #{app_results.map { |r| r.to_s }.join(', ')}"
|
62
|
+
|
63
|
+
samples = single_project.get_samples(bs_api)
|
64
|
+
puts " Sample instances: #{samples.map { |s| s.to_s }.join(', ')}"
|
81
65
|
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Look at the files belonging to the sample from the last project in the loop above:
|
69
|
+
#
|
70
|
+
|
82
71
|
samples.each do |sample|
|
83
|
-
puts "
|
84
|
-
files = sample.get_files(
|
85
|
-
puts files
|
72
|
+
puts "Sample: #{sample}"
|
73
|
+
files = sample.get_files(bs_api)
|
74
|
+
puts files.map { |f| " #{f}" }
|
86
75
|
end
|
87
76
|
|
88
|
-
|
89
|
-
|
90
|
-
# => Forbidden: Sorry but this requires READ access to this resource.
|
91
|
-
#
|
92
|
-
# https://basespace.illumina.com/datacentral
|
77
|
+
### Querying BAM and VCF Files ###
|
78
|
+
|
93
79
|
#
|
94
|
-
#
|
95
|
-
# AppResult: 31193
|
96
|
-
# L2I_S1.bam - id: '5595005', size: '673519149'
|
80
|
+
# Request privileges
|
97
81
|
#
|
98
|
-
|
99
|
-
#
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
82
|
+
|
83
|
+
# NOTE THAT YOUR PROJECT ID (469469 here) WILL MOST LIKELY BE DIFFERENT!
|
84
|
+
puts 'NOTE: CHANGE THE PROJECT ID IN THE EXAMPLE TO MATCH A PROJECT OF YOURS!'
|
85
|
+
device_info = bs_api.get_verification_code('read project 469469')
|
86
|
+
link = device_info['verification_with_code_uri']
|
87
|
+
puts "Visit the URI within 15 seconds and grant access:"
|
88
|
+
puts link
|
89
|
+
host = RbConfig::CONFIG['host_os']
|
90
|
+
case host
|
91
|
+
when /mswin|mingw|cygwin/
|
92
|
+
system("start #{link}")
|
93
|
+
when /darwin/
|
94
|
+
system("open #{link}")
|
95
|
+
when /linux/
|
96
|
+
system("xdg-open #{link}")
|
97
|
+
end
|
98
|
+
sleep(15)
|
99
|
+
|
100
|
+
code = device_info['device_code']
|
101
|
+
bs_api.update_privileges(code)
|
105
102
|
|
106
103
|
#
|
107
|
-
#
|
104
|
+
# Get the coverage for an interval + accompanying meta-data
|
108
105
|
#
|
109
106
|
|
110
|
-
#
|
111
|
-
|
112
|
-
puts
|
113
|
-
|
114
|
-
puts
|
115
|
-
cov = my_bam.get_interval_coverage(
|
116
|
-
puts cov
|
117
|
-
|
118
|
-
#
|
119
|
-
|
120
|
-
|
121
|
-
puts
|
122
|
-
|
123
|
-
var_meta = my_vcf.get_variant_meta(
|
107
|
+
# NOTE THAT YOUR FILE ID (here 7823816) WILL MOST LIKELY BE DIFFERENT!
|
108
|
+
# A FILE ID CAN BE OBTAINED, E.G., USING: samples.first.get_files(bs_api).first.id
|
109
|
+
puts 'NOTE: CHANGE THE FILE ID IN THE EXAMPLE TO MATCH A BAM FILE OF YOURS!'
|
110
|
+
my_bam = bs_api.get_file_by_id('7823816')
|
111
|
+
puts "BAM: #{my_bam}"
|
112
|
+
cov = my_bam.get_interval_coverage(bs_api, 'chr1', '50000', '60000')
|
113
|
+
puts " #{cov.to_s}"
|
114
|
+
cov_meta = my_bam.get_coverage_meta(bs_api, 'chr1')
|
115
|
+
puts " #{cov_meta.to_s}"
|
116
|
+
|
117
|
+
# For VCF-files we can filter variant calls based on chromosome and location as well:
|
118
|
+
puts 'NOTE: CHANGE THE FILE ID IN THE EXAMPLE TO MATCH A VCF FILE OF YOURS!'
|
119
|
+
my_vcf = bs_api.get_file_by_id('7823817')
|
120
|
+
var_meta = my_vcf.get_variant_meta(bs_api)
|
124
121
|
puts var_meta
|
125
|
-
|
126
|
-
var
|
127
|
-
puts var
|
128
|
-
|
122
|
+
var = my_vcf.filter_variant(bs_api, '1', '20000', '30000') # no value. need verification
|
123
|
+
puts " #{var.map { |v| v.to_s }.join(', ')}"
|
129
124
|
|