Class: Bio::BaseSpace::BaseSpaceAPI
- Defined in:
- lib/basespace/api/basespace_api.rb
Overview
The main API class used for all communication with the BaseSpace REST server.
Constant Summary collapse
- TOKEN_URL =
URIs for obtaining a access token, user verification code, and app trigger information.
'/oauthv2/token'
- DEVICE_URL =
"/oauthv2/deviceauthorization"
- WEB_AUTHORIZE =
'/oauth/authorize'
Instance Attribute Summary collapse
-
#app_session_id ⇒ Object
readonly
Returns the value of attribute app_session_id.
Class Method Summary collapse
-
.start ⇒ Object
Load credentials and start a new BaseSpace session.
Instance Method Summary collapse
-
#app_result_file_upload(id, local_path, file_name, directory, content_type, multipart = 0) ⇒ Object
Uploads a file associated with an AppResult to BaseSpace and returns the corresponding file object.
-
#create_app_result(id, name, desc, samples = [], app_session_id = nil) ⇒ Object
Create an AppResult object.
-
#create_project(name) ⇒ Object
Creates a project with the specified name and returns a project object.
-
#file_download(id, local_dir, name, range = []) ⇒ Object
Downloads a BaseSpace file to a local directory.
-
#file_url(id) ⇒ Object
Returns URL of a file on S3.
-
#filter_variant_set(id, chrom, start_pos, end_pos, format, qp = {'SortBy' => 'Position'}) ⇒ Object
List the variants in a set of variants.
-
#get_access(obj, access_type = 'write', web = nil, redirect_url = nil, state = nil) ⇒ Object
Request access to a data object.
-
#get_accessible_runs_by_user(id, qp = {}) ⇒ Object
Returns a list of accessible runs for the User with the given ID.
-
#get_app_result_by_id(id) ⇒ Object
Returns an AppResult object corresponding to ID.
-
#get_app_result_files(id, qp = {}) ⇒ Object
Returns a list of File objects for the AppResult with the given ID.
-
#get_app_results_by_project(id, qp = {}, statuses = []) ⇒ Object
Returns a list of AppResult object associated with the project with ID.
-
#get_app_session(id = nil) ⇒ Object
Returns an AppSession instance containing user and data-type the app was triggered by/on.
-
#get_app_session_by_id(id) ⇒ Object
Returns the AppSession instance identified by the given ID.
-
#get_available_genomes(qp = {}) ⇒ Object
Returns a list of all available genomes.
-
#get_coverage_meta_info(id, chrom) ⇒ Object
Returns Metadata about coverage as a CoverageMetadata instance.
-
#get_file_by_id(id) ⇒ Object
Returns a file object by ID.
-
#get_files_by_sample(id, qp = {}) ⇒ Object
Returns a list of File objects associated with sample with ID.
-
#get_genome_by_id(id) ⇒ Object
Returns an instance of Genome with the specified ID.
-
#get_interval_coverage(id, chrom, start_pos = nil, end_pos = nil) ⇒ Object
Mean coverage levels over a sequence interval.
-
#get_project_by_id(id) ⇒ Object
Request a project object by ID.
-
#get_project_by_user(id, qp = {}) ⇒ Object
Returns a list available projects for a User with the specified ID.
-
#get_sample_by_id(id) ⇒ Object
Returns a Sample object.
-
#get_samples_by_project(id, qp = {}) ⇒ Object
Returns a list of samples associated with a project with ID.
-
#get_trigger_object(obj) ⇒ Object
This method is not for general use and should only be called from ‘get_app_session’.
-
#get_user_by_id(id) ⇒ Object
Returns the User object corresponding to ID.
-
#get_variant_metadata(id, format) ⇒ Object
Returns a VariantMetadata object for a variant file.
-
#get_verification_code(scope) ⇒ Object
Returns the BaseSpace dictionary containing the verification code and verification URL for the user to approve access to a specific data scope.
-
#get_web_verification_code(scope, redirect_url, state = nil) ⇒ Object
Generates the URL the user should be redirected to for web-based authentication.
-
#initialize(client_key, client_secret, api_server, version, app_session_id = nil, access_token = nil) ⇒ BaseSpaceAPI
constructor
Create a new object for communicating with the BaseSpace REST server; preferred method of calling is through the ‘start’ class method.
-
#obtain_access_token(device_code) ⇒ Object
Returns a user specific access token.
- #serialize_object(d, type) ⇒ Object
-
#set_app_session_state(id, status, summary) ⇒ Object
Set the status of an AppResult object.
- #update_privileges(code) ⇒ Object
-
#upload_multipart_unit(id, part_number, md5, data) ⇒ Object
Helper method for uploading multipart files, do not call directly.
Methods inherited from BaseAPI
#get_access_token, #get_server_uri, #hash2urlencode, #list_request, #make_curl_request, #set_access_token, #set_timeout, #single_request, #to_s, #to_str, #update_access_token
Constructor Details
#initialize(client_key, client_secret, api_server, version, app_session_id = nil, access_token = nil) ⇒ BaseSpaceAPI
Create a new object for communicating with the BaseSpace REST server; preferred method of calling is through the ‘start’ class method.
client_key
-
Client key to use for authentication (provided when registering an App).
client_secret
-
Client secret key to use for authentication (provided when registering an App).
api_server
-
URI of the BaseSpace API server.
version
-
API version to use.
app_session_id
-
App session ID that was generated by application triggering.
access_token
-
Access token provided by App triggering.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/basespace/api/basespace_api.rb', line 56 def initialize(client_key, client_secret, api_server, version, app_session_id = nil, access_token = nil) end_with_slash = %r(/$) unless api_server[end_with_slash] api_server += '/' end @app_session_id = app_session_id @key = client_key @secret = client_secret @api_server = api_server + version @version = version @weburl = api_server.sub('api.', '') @timeout = nil super(access_token) end |
Instance Attribute Details
#app_session_id ⇒ Object (readonly)
Returns the value of attribute app_session_id.
36 37 38 |
# File 'lib/basespace/api/basespace_api.rb', line 36 def app_session_id @app_session_id end |
Class Method Details
.start ⇒ Object
Load credentials and start a new BaseSpace session.
39 40 41 42 43 44 45 |
# File 'lib/basespace/api/basespace_api.rb', line 39 def self.start if opts = Bio::BaseSpace.load_credentials self.new(opts['client_id'], opts['client_secret'], opts['basespace_url'], opts['api_version'], opts['app_session_id'], opts['access_token']) else raise "Please specify your BaseSpace credentials in the credentials.json file or use Bio::BaseSpace::BaseSpaceAPI.new with arguments" end end |
Instance Method Details
#app_result_file_upload(id, local_path, file_name, directory, content_type, multipart = 0) ⇒ Object
Uploads a file associated with an AppResult to BaseSpace and returns the corresponding file object.
id
-
AppResult ID.
local_path
-
The local path to the file to be uploaded.
file_name
-
The desired filename in the AppResult folder on the BaseSpace server.
directory
-
The directory the file should be placed in.
content_type
-
The content-type of the file.
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 |
# File 'lib/basespace/api/basespace_api.rb', line 612 def app_result_file_upload(id, local_path, file_name, directory, content_type, multipart = 0) my_model = 'FileResponse' resource_path = '/appresults/{Id}/files' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Id}', id) method = 'POST' query_params = {} header_params = {} verbose = false query_params['name'] = file_name query_params['directory'] = directory header_params['Content-Type'] = content_type # three cases, two for multipart, starting if multipart == 1 query_params['multipart'] = 'true' post_data = nil force_post = true # Set force post as this need to use POST though no data is being streamed return single_request(my_model, resource_path, method, query_params, header_params, post_data, verbose, force_post) elsif multipart == 2 query_params = {'uploadstatus' => 'complete'} post_data = nil force_post = true # Set force post as this need to use POST though no data is being streamed return single_request(my_model, resource_path, method, query_params, header_params, post_data, verbose, force_post) else post_data = ::File.open(local_path).read return single_request(my_model, resource_path, method, query_params, header_params, post_data, verbose) end end |
#create_app_result(id, name, desc, samples = [], app_session_id = nil) ⇒ Object
Create an AppResult object.
id
-
ID of the project in which the AppResult is to be added.
name
-
The name of the AppResult.
desc
-
A describtion of the AppResult.
samples
-
List of samples (if any).
app_session_id
-
If no app_session_id is given, the id used to initialize the BaseSpaceAPI instance will be used. If app_session_id is set equal to an empty string, a new appsession will be created.
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 |
# File 'lib/basespace/api/basespace_api.rb', line 560 def create_app_result(id, name, desc, samples = [], app_session_id = nil) if (not @app_session_id) and (not app_session_id) raise "This BaseSpaceAPI instance has no app_session_id set and no alternative id was supplied for method create_app_result" end my_model = 'AppResultResponse' resource_path = '/projects/{ProjectId}/appresults' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{ProjectId}', id) method = 'POST' query_params = {} header_params = {} post_data = {} verbose = false if app_session_id query_params['appsessionid'] = app_session_id else query_params['appsessionid'] = @app_session_id # default case, we use the current appsession end # add the sample references if samples.length > 0 ref = [] samples.each do |s| d = { "Rel" => "using", "Type" => "Sample", "HrefContent" => @version + '/samples/' + s.id } ref << d end post_data['References'] = ref end # case, an appSession is provided, we need to check if the a if query_params.has_key?('appsessionid') sid = query_params['appsessionid'] session = get_app_session(sid) unless session.can_work_on raise 'AppSession status must be "running," to create and AppResults. Current status is: ' + session.status end end post_data['Name'] = name post_data['Description'] = desc return single_request(my_model, resource_path, method, query_params, header_params, post_data, verbose) end |
#create_project(name) ⇒ Object
Creates a project with the specified name and returns a project object. If a project with this name already exists, the existing project is returned.
name
-
Name of the project.
240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/basespace/api/basespace_api.rb', line 240 def create_project(name) #: v1pre3/projects, it requires 1 input parameter which is Name my_model = 'ProjectResponse' resource_path = '/projects/' resource_path = resource_path.sub('{format}', 'json') method = 'POST' query_params = {} header_params = {} post_data = {} post_data['Name'] = name verbose = false return single_request(my_model, resource_path, method, query_params, header_params, post_data, verbose) end |
#file_download(id, local_dir, name, range = []) ⇒ Object
Downloads a BaseSpace file to a local directory.
id
-
File ID.
local_dir
-
The local directory to place the file in.
name
-
The name of the local file.
range
-
The byte range of the file to retrieve (not yet implemented).
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 |
# File 'lib/basespace/api/basespace_api.rb', line 651 def file_download(id, local_dir, name, range = []) #@ReservedAssignment resource_path = '/files/{Id}/content' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Id}', id) method = 'GET' query_params = {} header_params = {} query_params['redirect'] = 'meta' # we need to add this parameter to get the Amazon link directly response = @api_client.call_api(resource_path, method, query_params, nil, header_params) if response['ResponseStatus'].has_key?('ErrorCode') raise 'BaseSpace error: ' + response['ResponseStatus']['ErrorCode'].to_s + ": " + response['ResponseStatus']['Message'] end # get the Amazon URL file_url = response['Response']['HrefContent'] header = nil unless range.empty? # puts "Case range request" header = { 'Range' => format('bytes=%s-%s', range[0], range[1]) } end # Do the download ::File.open(::File.join(local_dir, name), "wb") do |fp| http_opts = {} uri = URI.parse(file_url) if uri.scheme == "https" http_opts[:use_ssl] = true end res = Net::HTTP.start(uri.host, uri.port, http_opts) { |http| # [TODO] Do we need user and pass here also? case RUBY_VERSION when /^1.9/ if uri.query and not uri.query.empty? http.get(uri.path + '?' + uri.query, header) else http.get(uri.path, header) end else http.get(uri, header) end } fp.print res.body end return 1 end |
#file_url(id) ⇒ Object
Returns URL of a file on S3.
id
-
File ID.
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 |
# File 'lib/basespace/api/basespace_api.rb', line 704 def file_url(id) # @ReservedAssignment resource_path = '/files/{Id}/content' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Id}', id) method = 'GET' query_params = {} header_params = {} query_params['redirect'] = 'meta' # we need to add this parameter to get the Amazon link directly response = @api_client.call_api(resource_path, method, query_params, nil, header_params) if response['ResponseStatus'].has_key?('ErrorCode') raise 'BaseSpace error: ' + response['ResponseStatus']['ErrorCode'].to_s + ": " + response['ResponseStatus']['Message'] end # return the Amazon URL return response['Response']['HrefContent'] end |
#filter_variant_set(id, chrom, start_pos, end_pos, format, qp = {'SortBy' => 'Position'}) ⇒ Object
List the variants in a set of variants. Maximum returned records is 1000.
id
-
ID of the variant file.
chrom
-
The chromosome of interest.
start_pos
-
The start position of the sequence of interest.
end_pos
-
The start position of the sequence of interest.
format
-
Set to ‘vcf’ to get the results as lines in VCF format.
qp
-
An (optional) object of type QueryParameters for custom sorting and filtering.
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
# File 'lib/basespace/api/basespace_api.rb', line 495 def filter_variant_set(id, chrom, start_pos, end_pos, format, qp = {'SortBy' => 'Position'}) query_pars = qp.kind_of?(Hash) ? QueryParameters.new(qp) : qp query_pars.validate my_model = 'Variant' resource_path = '/variantset/{Id}/variants/chr{Chrom}' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Chrom}', chrom) resource_path = resource_path.sub('{Id}', id) method = 'GET' query_params = query_pars.get_parameter_dict header_params = {} query_params['StartPos'] = start_pos query_params['EndPos'] = end_pos query_params['Format'] = format verbose = false return list_request(my_model, resource_path, method, query_params, header_params, verbose) end |
#get_access(obj, access_type = 'write', web = nil, redirect_url = nil, state = nil) ⇒ Object
Request access to a data object.
obj
-
The data object we wish to get access to.
access_type
-
The type of access (read|write), default is write.
web
-
If the App is web-based, then set this parameter to ‘true’. The default value is false, which means that the request is for a device based App.
redirect_url
-
For the web-based case, a redirection URL.
state
-
(unclear from Python port)
177 178 179 180 181 182 183 184 |
# File 'lib/basespace/api/basespace_api.rb', line 177 def get_access(obj, access_type = 'write', web = nil, redirect_url = nil, state = nil) scope_str = obj.get_access_str(access_type) if web return get_web_verification_code(scope_str, redirect_url, state) else return get_verification_code(scope_str) end end |
#get_accessible_runs_by_user(id, qp = {}) ⇒ Object
Returns a list of accessible runs for the User with the given ID.
id
-
User id.
qp
-
An object of type QueryParameters for custom sorting and filtering.
335 336 337 338 339 340 341 342 343 344 345 346 |
# File 'lib/basespace/api/basespace_api.rb', line 335 def get_accessible_runs_by_user(id, qp = {}) query_pars = qp.kind_of?(Hash) ? QueryParameters.new(qp) : qp query_pars.validate my_model = 'RunCompact' resource_path = '/users/{Id}/runs' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Id}', id) method = 'GET' query_params = query_pars.get_parameter_dict header_params = {} return list_request(my_model, resource_path, method, query_params, header_params) end |
#get_app_result_by_id(id) ⇒ Object
Returns an AppResult object corresponding to ID.
- param id
-
The ID of the AppResult.
271 272 273 274 275 276 277 278 279 280 |
# File 'lib/basespace/api/basespace_api.rb', line 271 def get_app_result_by_id(id) my_model = 'AppResultResponse' resource_path = '/appresults/{Id}' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Id}', id) method = 'GET' query_params = {} header_params = {} return single_request(my_model, resource_path, method, query_params, header_params) end |
#get_app_result_files(id, qp = {}) ⇒ Object
Returns a list of File objects for the AppResult with the given ID.
id
-
The ID of the AppResult.
+qp: An object of type QueryParameters for custom sorting and filtering.
286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/basespace/api/basespace_api.rb', line 286 def get_app_result_files(id, qp = {}) query_pars = qp.kind_of?(Hash) ? QueryParameters.new(qp) : qp query_pars.validate my_model = 'File' resource_path = '/appresults/{Id}/files' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Id}', id) method = 'GET' query_params = query_pars.get_parameter_dict header_params = {} verbose = false return list_request(my_model, resource_path, method, query_params, header_params, verbose) end |
#get_app_results_by_project(id, qp = {}, statuses = []) ⇒ Object
Returns a list of AppResult object associated with the project with ID.
id
-
The project ID.
qp
-
An object of type QueryParameters for custom sorting and filtering.
statuses
-
A list of AppResult statuses to filter by.
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/basespace/api/basespace_api.rb', line 353 def get_app_results_by_project(id, qp = {}, statuses = []) query_pars = qp.kind_of?(Hash) ? QueryParameters.new(qp) : qp query_pars.validate my_model = 'AppResult' resource_path = '/projects/{Id}/appresults' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Id}', id) method = 'GET' query_params = query_pars.get_parameter_dict unless statuses.empty? query_params['Statuses'] = statuses.join(",") end header_params = {} verbose = false return list_request(my_model, resource_path, method, query_params, header_params, verbose) end |
#get_app_session(id = nil) ⇒ Object
Returns an AppSession instance containing user and data-type the app was triggered by/on.
id
-
The AppSessionId, ID not supplied the AppSessionId used for instantiating the BaseSpaceAPI instance.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/basespace/api/basespace_api.rb', line 123 def get_app_session(id = nil) if (not @app_session_id) and (not id) raise "This BaseSpaceAPI instance has no app_session_id set and no alternative id was supplied for method get_app_session" end # if (not id) and (not @key) # raise "This BaseSpaceAPI instance has no client_secret (key) set and no alternative id was supplied for method get_app_session" # end resource_path = @api_server + '/appsessions/{AppSessionId}' if id resource_path = resource_path.sub('{AppSessionId}', id) else resource_path = resource_path.sub('{AppSessionId}', @app_session_id) end if $DEBUG $stderr.puts " # ----- BaseSpaceAPI#get_app_session ----- " $stderr.puts " # resource_path: #{resource_path}" $stderr.puts " # " end uri = URI.parse(resource_path) uri.user = @key uri.password = @secret #response = Net::HTTP.get(uri) http_opts = {} if uri.scheme == "https" http_opts[:use_ssl] = true end response = Net::HTTP.start(uri.host, uri.port, http_opts) { |http| case RUBY_VERSION when /^1.9/ if uri.query and not uri.query.empty? request = Net::HTTP::Get.new(uri.path + '?' + uri.query) else request = Net::HTTP::Get.new(uri.path) end else request = Net::HTTP::Get.new(uri) end request.basic_auth uri.user, uri.password http.request(request) } obj = JSON.parse(response.body) # TODO add exception if response isn't OK, e.g. incorrect server gives path not recognized return get_trigger_object(obj) end |
#get_app_session_by_id(id) ⇒ Object
Returns the AppSession instance identified by the given ID.
id
-
The ID of the AppSession.
115 116 117 118 |
# File 'lib/basespace/api/basespace_api.rb', line 115 def get_app_session_by_id(id) # TO_DO make special case for access-token only retrieval return get_app_session(id) end |
#get_available_genomes(qp = {}) ⇒ Object
Returns a list of all available genomes.
qp
-
An object of type QueryParameters for custom sorting and filtering.
455 456 457 458 459 460 461 462 463 464 465 466 |
# File 'lib/basespace/api/basespace_api.rb', line 455 def get_available_genomes(qp = {}) query_pars = qp.kind_of?(Hash) ? QueryParameters.new(qp) : qp query_pars.validate my_model = 'GenomeV1' resource_path = '/genomes' resource_path = resource_path.sub('{format}', 'json') method = 'GET' query_params = query_pars.get_parameter_dict header_params = {} verbose = false return list_request(my_model, resource_path, method, query_params, header_params, verbose) end |
#get_coverage_meta_info(id, chrom) ⇒ Object
Returns Metadata about coverage as a CoverageMetadata instance.
id
-
ID of a BAM file.
chrom
-
Chromosome to query.
539 540 541 542 543 544 545 546 547 548 549 550 551 |
# File 'lib/basespace/api/basespace_api.rb', line 539 def (id, chrom) my_model = 'CoverageMetaResponse' resource_path = '/coverage/{Id}/{Chrom}/meta' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Chrom}', chrom) resource_path = resource_path.sub('{Id}', id) method = 'GET' query_params = {} header_params = {} post_data = nil verbose = false return single_request(my_model, resource_path, method, query_params, header_params, post_data, verbose) end |
#get_file_by_id(id) ⇒ Object
Returns a file object by ID.
id
-
The ID of the file.
425 426 427 428 429 430 431 432 433 434 435 436 |
# File 'lib/basespace/api/basespace_api.rb', line 425 def get_file_by_id(id) my_model = 'FileResponse' resource_path = '/files/{Id}' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Id}', id) method = 'GET' query_params = {} header_params = {} post_data = nil verbose = false return single_request(my_model, resource_path, method, query_params, header_params, post_data, verbose) end |
#get_files_by_sample(id, qp = {}) ⇒ Object
Returns a list of File objects associated with sample with ID.
id
-
Sample ID.
qp
-
An object of type QueryParameters for custom sorting and filtering.
408 409 410 411 412 413 414 415 416 417 418 419 420 |
# File 'lib/basespace/api/basespace_api.rb', line 408 def get_files_by_sample(id, qp = {}) query_pars = qp.kind_of?(Hash) ? QueryParameters.new(qp) : qp query_pars.validate my_model = 'File' resource_path = '/samples/{Id}/files' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Id}', id) method = 'GET' query_params = query_pars.get_parameter_dict header_params = {} verbose = false return list_request(my_model, resource_path, method, query_params, header_params, verbose) end |
#get_genome_by_id(id) ⇒ Object
Returns an instance of Genome with the specified ID.
id
-
The genome ID.
441 442 443 444 445 446 447 448 449 450 |
# File 'lib/basespace/api/basespace_api.rb', line 441 def get_genome_by_id(id) my_model = 'GenomeResponse' resource_path = '/genomes/{Id}' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Id}', id) method = 'GET' query_params = {} header_params = {} return single_request(my_model, resource_path, method, query_params, header_params) end |
#get_interval_coverage(id, chrom, start_pos = nil, end_pos = nil) ⇒ Object
Mean coverage levels over a sequence interval. Returns an instance of CoverageResponse.
id
-
Chromosome to query.
chrom
-
The ID of the resource.
start_pos
-
Get coverage starting at this position. Default is 1.
end_pos
-
Get coverage up to and including this position. Default is start_pos + 1280.
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 |
# File 'lib/basespace/api/basespace_api.rb', line 519 def get_interval_coverage(id, chrom, start_pos = nil, end_pos = nil) my_model = 'CoverageResponse' resource_path = '/coverage/{Id}/{Chrom}' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Chrom}', chrom) resource_path = resource_path.sub('{Id}', id) method = 'GET' query_params = {} header_params = {} query_params['StartPos'] = @api_client.to_path_value(start_pos) query_params['EndPos'] = @api_client.to_path_value(end_pos) post_data = nil verbose = false return single_request(my_model, resource_path, method, query_params, header_params, post_data, verbose) end |
#get_project_by_id(id) ⇒ Object
Request a project object by ID.
id
-
The ID of the project.
303 304 305 306 307 308 309 310 311 312 |
# File 'lib/basespace/api/basespace_api.rb', line 303 def get_project_by_id(id) my_model = 'ProjectResponse' resource_path = '/projects/{Id}' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Id}', id) method = 'GET' query_params = {} header_params = {} return single_request(my_model, resource_path, method, query_params, header_params) end |
#get_project_by_user(id, qp = {}) ⇒ Object
Returns a list available projects for a User with the specified ID.
id
-
The ID of the user.
qp
-
An object of type QueryParameters for custom sorting and filtering.
318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/basespace/api/basespace_api.rb', line 318 def get_project_by_user(id, qp = {}) query_pars = qp.kind_of?(Hash) ? QueryParameters.new(qp) : qp query_pars.validate my_model = 'Project' resource_path = '/users/{Id}/projects' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Id}', id) if id != nil method = 'GET' query_params = query_pars.get_parameter_dict header_params = {} return list_request(my_model, resource_path, method, query_params, header_params) end |
#get_sample_by_id(id) ⇒ Object
Returns a Sample object.
id
-
The ID of the sample.
391 392 393 394 395 396 397 398 399 400 401 402 |
# File 'lib/basespace/api/basespace_api.rb', line 391 def get_sample_by_id(id) my_model = 'SampleResponse' resource_path = '/samples/{Id}' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Id}', id) method = 'GET' query_params = {} header_params = {} post_data = nil verbose = false return single_request(my_model, resource_path, method, query_params, header_params, post_data, verbose) end |
#get_samples_by_project(id, qp = {}) ⇒ Object
Returns a list of samples associated with a project with ID.
id
-
The ID of the project.
qp
-
An object of type QueryParameters for custom sorting and filtering.
374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/basespace/api/basespace_api.rb', line 374 def get_samples_by_project(id, qp = {}) query_pars = qp.kind_of?(Hash) ? QueryParameters.new(qp) : qp query_pars.validate my_model = 'Sample' resource_path = '/projects/{Id}/samples' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Id}', id) method = 'GET' query_params = query_pars.get_parameter_dict header_params = {} verbose = false return list_request(my_model, resource_path, method, query_params, header_params, verbose) end |
#get_trigger_object(obj) ⇒ Object
This method is not for general use and should only be called from ‘get_app_session’.
obj
-
Application trigger JSON.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/basespace/api/basespace_api.rb', line 76 def get_trigger_object(obj) if obj['ResponseStatus'].has_key?('ErrorCode') raise 'BaseSpace error: ' + obj['ResponseStatus']['ErrorCode'].to_s + ": " + obj['ResponseStatus']['Message'] end #access_token = nil # '' is false in Python but APIClient.new only raises when the value is None (not '') access_token = '' temp_api = APIClient.new(access_token, @api_server) response = temp_api.deserialize(obj, 'AppSessionResponse') # AppSessionResponse object has a response method which returns a AppSession object app_sess = response.get_attr('Response') # AppSession object has a serialize_references method which converts an array of # AppSessionLaunchObject objects by calling serialize_object method in each object. # The method in turn calls the serialize_object method of the given BaseSpaceAPI object # with @content ('dict') and @type ('str') arguments. Returns an array of serialized objects. res = app_sess.serialize_references(self) return res end |
#get_user_by_id(id) ⇒ Object
Returns the User object corresponding to ID.
id
-
The ID of the user.
257 258 259 260 261 262 263 264 265 266 |
# File 'lib/basespace/api/basespace_api.rb', line 257 def get_user_by_id(id) my_model = 'UserResponse' resource_path = '/users/{Id}' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Id}', id) method = 'GET' query_params = {} header_params = {} return single_request(my_model, resource_path, method, query_params, header_params) end |
#get_variant_metadata(id, format) ⇒ Object
Returns a VariantMetadata object for a variant file.
id
-
ID of the VCF file.
format
-
Set to ‘vcf’ to get the results as lines in VCF format.
474 475 476 477 478 479 480 481 482 483 484 485 |
# File 'lib/basespace/api/basespace_api.rb', line 474 def (id, format) my_model = 'VariantsHeaderResponse' resource_path = '/variantset/{Id}' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Id}', id) method = 'GET' query_params = {} query_params['Format'] = @api_client.to_path_value(format) header_params = {} verbose = false return single_request(my_model, resource_path, method, query_params, header_params, verbose) end |
#get_verification_code(scope) ⇒ Object
Returns the BaseSpace dictionary containing the verification code and verification URL for the user to approve access to a specific data scope.
Corresponding curl call: curlCall = ‘curl -d “response_type=device_code” -d “client_id=’ + client_key + ‘” -d “scope=’ + scope + ‘” ’ + DEVICE_URL
For details see: developer.basespace.illumina.com/docs/content/documentation/authentication/obtaining-access-tokens
scope
-
The scope that access is requested for.
196 197 198 199 200 201 202 203 204 |
# File 'lib/basespace/api/basespace_api.rb', line 196 def get_verification_code(scope) #curlCall = 'curl -d "response_type=device_code" -d "client_id=' + @key + '" -d "scope=' + scope + '" ' + @api_server + DEVICE_URL #puts curlCall unless @key raise "This BaseSpaceAPI instance has no client_secret (key) set and no alternative id was supplied for method get_verification_code." end data = {'client_id' => @key, 'scope' => scope, 'response_type' => 'device_code'} return make_curl_request(data, @api_server + DEVICE_URL) end |
#get_web_verification_code(scope, redirect_url, state = nil) ⇒ Object
Generates the URL the user should be redirected to for web-based authentication.
scope
: The scope that access is requested for.
redirect_url
-
The redirect URL.
state
-
An optional state parameter that will passed through to the redirect response.
211 212 213 214 215 216 217 |
# File 'lib/basespace/api/basespace_api.rb', line 211 def get_web_verification_code(scope, redirect_url, state = nil) if (not @key) raise "This BaseSpaceAPI instance has no client_id (key) set and no alternative id was supplied for method get_verification_code." end data = {'client_id' => @key, 'redirect_uri' => redirect_url, 'scope' => scope, 'response_type' => 'code', "state" => state} return @weburl + WEB_AUTHORIZE + '?' + hash2urlencode(data) end |
#obtain_access_token(device_code) ⇒ Object
Returns a user specific access token.
device_code
-
The device code returned by the verification code method.
222 223 224 225 226 227 228 229 |
# File 'lib/basespace/api/basespace_api.rb', line 222 def obtain_access_token(device_code) if (not @key) or (not @secret) raise "This BaseSpaceAPI instance has either no client_secret or no client_id set and no alternative id was supplied for method get_verification_code." end data = {'client_id' => @key, 'client_secret' => @secret, 'code' => device_code, 'grant_type' => 'device', 'redirect_uri' => 'google.com'} dict = make_curl_request(data, @api_server + TOKEN_URL) return dict['access_token'] end |
#serialize_object(d, type) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/basespace/api/basespace_api.rb', line 94 def serialize_object(d, type) # [TODO] None (nil) or '' ? #access_token = nil access_token = '' temp_api = APIClient.new(access_token, @api_server) if type.downcase == 'project' return temp_api.deserialize(d, 'Project') end if type.downcase == 'sample' return temp_api.deserialize(d, 'Sample') end if type.downcase == 'appresult' return temp_api.deserialize(d, 'AppResult') end return d end |
#set_app_session_state(id, status, summary) ⇒ Object
Set the status of an AppResult object.
id
-
The id of the AppResult.
status
-
Status assignment string.
summary
-
Summary string.
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 |
# File 'lib/basespace/api/basespace_api.rb', line 784 def set_app_session_state(id, status, summary) my_model = 'AppSessionResponse' resource_path = '/appsessions/{Id}' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Id}', id) method = 'POST' query_params = {} header_params = {} post_data = {} verbose = false status_allowed = ['running', 'complete', 'needsattention', 'aborted', 'error'] unless status_allowed.include?(status.downcase) raise "AppResult state must be in #{status_allowed.inspect}" end post_data['status'] = status.downcase post_data['statussummary'] = summary return single_request(my_model, resource_path, method, query_params, header_params, post_data, verbose) end |
#update_privileges(code) ⇒ Object
231 232 233 234 |
# File 'lib/basespace/api/basespace_api.rb', line 231 def update_privileges(code) token = obtain_access_token(code) set_access_token(token) end |
#upload_multipart_unit(id, part_number, md5, data) ⇒ Object
Helper method for uploading multipart files, do not call directly.
id
-
File ID.
part_number
-
File part to be uploaded.
md5
-
MD5 sum of datastream.
data
-
The data-stream to be uploaded.
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 |
# File 'lib/basespace/api/basespace_api.rb', line 730 def upload_multipart_unit(id, part_number, md5, data) resource_path = '/files/{Id}/parts/{partNumber}' resource_path = resource_path.sub('{format}', 'json') resource_path = resource_path.sub('{Id}', id) resource_path = resource_path.sub('{partNumber}', part_number.to_s) method = 'PUT' query_params = {} header_params = {'Content-MD5' => md5.strip()} force_post = false out = @api_client.call_api(resource_path, method, query_params, data, header_params, force_post) return out # curl -v -H "x-access-token: {access token}" \ # -H "Content-MD5: 9mvo6qaA+FL1sbsIn1tnTg==" \ # -T reportarchive.zipaa \ # -X PUT https://api.cloud-endor.illumina.com/v1pre2/files/7094087/parts/1 end |