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.
603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 |
# File 'lib/basespace/api/basespace_api.rb', line 603 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.
551 552 553 554 555 556 557 558 559 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 |
# File 'lib/basespace/api/basespace_api.rb', line 551 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.
231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/basespace/api/basespace_api.rb', line 231 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).
642 643 644 645 646 647 648 649 650 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 |
# File 'lib/basespace/api/basespace_api.rb', line 642 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? http.get(uri, header) } fp.print res.body end return 1 end |
#file_url(id) ⇒ Object
Returns URL of a file on S3.
id
-
File ID.
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 |
# File 'lib/basespace/api/basespace_api.rb', line 686 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.
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'lib/basespace/api/basespace_api.rb', line 486 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)
168 169 170 171 172 173 174 175 |
# File 'lib/basespace/api/basespace_api.rb', line 168 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.
326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/basespace/api/basespace_api.rb', line 326 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.
262 263 264 265 266 267 268 269 270 271 |
# File 'lib/basespace/api/basespace_api.rb', line 262 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.
277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/basespace/api/basespace_api.rb', line 277 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.
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/basespace/api/basespace_api.rb', line 344 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 |
# 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| request = Net::HTTP::Get.new(uri.path) 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.
446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'lib/basespace/api/basespace_api.rb', line 446 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.
530 531 532 533 534 535 536 537 538 539 540 541 542 |
# File 'lib/basespace/api/basespace_api.rb', line 530 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.
416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'lib/basespace/api/basespace_api.rb', line 416 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.
399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/basespace/api/basespace_api.rb', line 399 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.
432 433 434 435 436 437 438 439 440 441 |
# File 'lib/basespace/api/basespace_api.rb', line 432 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.
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'lib/basespace/api/basespace_api.rb', line 510 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.
294 295 296 297 298 299 300 301 302 303 |
# File 'lib/basespace/api/basespace_api.rb', line 294 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.
309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/basespace/api/basespace_api.rb', line 309 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.
382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/basespace/api/basespace_api.rb', line 382 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.
365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/basespace/api/basespace_api.rb', line 365 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.
248 249 250 251 252 253 254 255 256 257 |
# File 'lib/basespace/api/basespace_api.rb', line 248 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.
465 466 467 468 469 470 471 472 473 474 475 476 |
# File 'lib/basespace/api/basespace_api.rb', line 465 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.
187 188 189 190 191 192 193 194 195 |
# File 'lib/basespace/api/basespace_api.rb', line 187 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.
202 203 204 205 206 207 208 |
# File 'lib/basespace/api/basespace_api.rb', line 202 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.
213 214 215 216 217 218 219 220 |
# File 'lib/basespace/api/basespace_api.rb', line 213 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.
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 |
# File 'lib/basespace/api/basespace_api.rb', line 766 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
222 223 224 225 |
# File 'lib/basespace/api/basespace_api.rb', line 222 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.
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 |
# File 'lib/basespace/api/basespace_api.rb', line 712 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 |