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.

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{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.
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.3
1
+ 0.1.5
@@ -14,19 +14,12 @@
14
14
  # limitations under the License.
15
15
 
16
16
  # Application triggering
17
- # https://developer.basespace.illumina.com/docs/content/documentation/sdk-samples/python-sdk-overview#Application_triggering
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
- # First we will initialize a BaseSpace API object using our app information and the appSessionId.
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 the bmy_app_session.spaceApi we can request the appSession object corresponding to the AppSession id supplied.
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 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
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
- # 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')
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 appSessionLaunchObject.
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 "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')
63
+ puts "href to the launch object:"
64
+ puts my_reference.href_content
70
65
  puts
71
- puts "and the specific type of that object:"
72
- puts my_reference.type # same as my_reference.get_attr('Type')
66
+ puts "Type of that object:"
67
+ puts my_reference.type
73
68
  puts
74
69
 
75
- # Now we will want to ask for more permission for the specific reference object.
76
- my_reference_content = my_reference.content
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 "We can get out the specific project objects by using 'content':"
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
- # 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')
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
- puts "We get the following access map for the write request"
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
- # 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).
102
+ #
103
+ # Confirm 'write' privilege request:
104
+ #
98
105
 
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']
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 #{link}")
114
+ system("start #{verification_with_code_uri}")
109
115
  when /darwin/
110
- system("open #{link}")
116
+ system("open #{verification_with_code_uri}")
111
117
  when /linux/
112
- system("xdg-open #{link}")
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
- # 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
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
- # First, get the verification code and uri for scope 'browse global'.
50
- device_info = bs_api.get_verification_code('browse global')
42
+ #
43
+ # Get the verification code and uri for scope 'browse global':
44
+ #
51
45
 
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"
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
- # 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
70
+ puts "Access-token: #{bs_api.get_access_token}"
156
71
 
@@ -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 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
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
- # 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'])
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
- # 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"
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
- 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
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 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
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
- # 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')
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
- app_results = nil
48
- samples = nil
48
+ user = bs_api.get_user_by_id('current')
49
+ my_projects = bs_api.get_project_by_user('current')
49
50
 
50
- # Let's list all the AppResults and samples for these projects.
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 "# 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
58
+ puts "Project: #{single_project}"
74
59
 
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
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 "# Sample: #{sample}"
84
- files = sample.get_files(my_api)
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
- # [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
77
+ ### Querying BAM and VCF Files ###
78
+
93
79
  #
94
- # Project: Cancer Sequencing Demo - id=4
95
- # AppResult: 31193
96
- # L2I_S1.bam - id: '5595005', size: '673519149'
80
+ # Request privileges
97
81
  #
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
- #
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
- # Working with files.
104
+ # Get the coverage for an interval + accompanying meta-data
108
105
  #
109
106
 
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)
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
- #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
-
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