bio-basespace-sdk 0.1.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bio-basespace-sdk might be problematic. Click here for more details.

Files changed (65) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +11 -0
  4. data/Gemfile +16 -0
  5. data/License.txt +275 -0
  6. data/README.md +671 -0
  7. data/Rakefile +54 -0
  8. data/VERSION +1 -0
  9. data/examples/0_app_triggering.rb +135 -0
  10. data/examples/1_authentication.rb +156 -0
  11. data/examples/2_browsing.rb +84 -0
  12. data/examples/3_accessing_files.rb +129 -0
  13. data/examples/4_app_result_upload.rb +102 -0
  14. data/examples/5_purchasing.rb +119 -0
  15. data/lib/basespace.rb +126 -0
  16. data/lib/basespace/api/api_client.rb +313 -0
  17. data/lib/basespace/api/base_api.rb +242 -0
  18. data/lib/basespace/api/basespace_api.rb +789 -0
  19. data/lib/basespace/api/basespace_error.rb +80 -0
  20. data/lib/basespace/api/billing_api.rb +115 -0
  21. data/lib/basespace/model.rb +78 -0
  22. data/lib/basespace/model/app_result.rb +158 -0
  23. data/lib/basespace/model/app_result_response.rb +40 -0
  24. data/lib/basespace/model/app_session.rb +99 -0
  25. data/lib/basespace/model/app_session_compact.rb +43 -0
  26. data/lib/basespace/model/app_session_launch_object.rb +58 -0
  27. data/lib/basespace/model/app_session_response.rb +41 -0
  28. data/lib/basespace/model/application.rb +47 -0
  29. data/lib/basespace/model/application_compact.rb +44 -0
  30. data/lib/basespace/model/basespace_model.rb +60 -0
  31. data/lib/basespace/model/coverage.rb +48 -0
  32. data/lib/basespace/model/coverage_meta_response.rb +40 -0
  33. data/lib/basespace/model/coverage_metadata.rb +43 -0
  34. data/lib/basespace/model/coverage_response.rb +40 -0
  35. data/lib/basespace/model/file.rb +172 -0
  36. data/lib/basespace/model/file_response.rb +40 -0
  37. data/lib/basespace/model/genome_response.rb +40 -0
  38. data/lib/basespace/model/genome_v1.rb +56 -0
  39. data/lib/basespace/model/list_response.rb +53 -0
  40. data/lib/basespace/model/multipart_upload.rb +288 -0
  41. data/lib/basespace/model/product.rb +50 -0
  42. data/lib/basespace/model/project.rb +103 -0
  43. data/lib/basespace/model/project_response.rb +40 -0
  44. data/lib/basespace/model/purchase.rb +89 -0
  45. data/lib/basespace/model/purchase_response.rb +39 -0
  46. data/lib/basespace/model/purchased_product.rb +56 -0
  47. data/lib/basespace/model/query_parameters.rb +86 -0
  48. data/lib/basespace/model/query_parameters_purchased_product.rb +67 -0
  49. data/lib/basespace/model/refund_purchase_response.rb +40 -0
  50. data/lib/basespace/model/resource_list.rb +48 -0
  51. data/lib/basespace/model/response_status.rb +42 -0
  52. data/lib/basespace/model/run_compact.rb +55 -0
  53. data/lib/basespace/model/sample.rb +127 -0
  54. data/lib/basespace/model/sample_response.rb +40 -0
  55. data/lib/basespace/model/user.rb +80 -0
  56. data/lib/basespace/model/user_compact.rb +45 -0
  57. data/lib/basespace/model/user_response.rb +40 -0
  58. data/lib/basespace/model/variant.rb +57 -0
  59. data/lib/basespace/model/variant_header.rb +44 -0
  60. data/lib/basespace/model/variant_info.rb +48 -0
  61. data/lib/basespace/model/variants_header_response.rb +40 -0
  62. data/spec/basespaceapi_spec.rb +26 -0
  63. data/spec/basespaceerror_spec.rb +87 -0
  64. data/spec/basespacemodel_spec.rb +57 -0
  65. metadata +239 -0
@@ -0,0 +1,80 @@
1
+ # Copyright 2012-2013 Joachim Baran
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+
14
+ module Bio
15
+ module BaseSpace
16
+
17
+ # Raised when a parameter in a call was not defined.
18
+ class UndefinedParameterError < StandardError
19
+ # Create a new instance of the error.
20
+ #
21
+ # +parameter+:: Name of the parameter that is not defined.
22
+ def initialize(parameter)
23
+ super("The following parameter must be defined: #{parameter}")
24
+ end
25
+ end
26
+
27
+ # Raised when a parameter was provided that is unknown to the implementation.
28
+ class UnknownParameterError < StandardError
29
+ # Create a new instance of the error.
30
+ #
31
+ # +parameter+:: Name of the parameter that is not recognized.
32
+ def initialize(parameter)
33
+ super("#{parameter} is not regcognized as a parameter for this call")
34
+ end
35
+ end
36
+
37
+ # Raised when a parameter was set to an invalid value.
38
+ class IllegalParameterError < StandardError
39
+ # Create a new instance of the error.
40
+ #
41
+ # +value+:: Value that was passed and which is of an invalid value.
42
+ # +legal+:: Listing of valid values.
43
+ def initialize(value, legal)
44
+ super("#{value} is not well-defined, legal options are #{legal}")
45
+ end
46
+ end
47
+
48
+ # Raised when an unsupported or unsuitable file type is encountered.
49
+ class WrongFiletypeError < StandardError
50
+ # Create a new instance of the error.
51
+ #
52
+ # +filetype+:: Filetype that was intended to be used.
53
+ def initialize(filetype)
54
+ super("This data request is not available for file #{filetype}")
55
+ end
56
+ end
57
+
58
+ # Raised when no response has been received from the API server (in a certain amount of time).
59
+ class NoResponseError < StandardError
60
+ # Create a new instance of the error.
61
+ #
62
+ # +value+:: Value that was provided with the request.
63
+ def initialize(value)
64
+ super("No response was returned from the server for this request - #{value}")
65
+ end
66
+ end
67
+
68
+ # Raised when the model for holding data has not been initialized yet.
69
+ class ModelNotInitializedError < StandardError
70
+ # Create a new instance of the error.
71
+ #
72
+ # +value+:: Value that was provided with the request.
73
+ def initialize(value)
74
+ super("The request cannot be completed as model has not been initialized - #{value}")
75
+ end
76
+ end
77
+
78
+ end # module BaseSpace
79
+ end # module Bio
80
+
@@ -0,0 +1,115 @@
1
+ # Copyright 2013 Toshiaki Katayama, Joachim Baran
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+
14
+ require 'basespace/api/base_api'
15
+ require 'basespace/api/basespace_error'
16
+ require 'basespace/model/query_parameters_purchased_product'
17
+
18
+ module Bio
19
+ module BaseSpace
20
+
21
+ # The API class used for all communication with the BaseSpace Billng server.
22
+ class BillingAPI < BaseAPI
23
+ # Create a new BillingAPI object.
24
+ #
25
+ # +api_server+:: URI of the BaseSpace API server.
26
+ # +version+:: Version of the API to use.
27
+ # +app_session_id+:: AppSession ID.
28
+ # +access_token+:: Access token that is provided by App triggering.
29
+ def initialize(api_server, version, app_session_id = nil, access_token = nil)
30
+ end_with_slash = %r(/$)
31
+ unless api_server[end_with_slash]
32
+ api_server += '/'
33
+ end
34
+
35
+ @app_session_id = app_session_id
36
+ @api_server = api_server + version
37
+ @version = version
38
+
39
+ super(access_token)
40
+ end
41
+
42
+ # Creates a purchase with the specified products.
43
+ #
44
+ # +products+:: List of dicts to purchase, each of which has a product 'id' and 'quantity' to purchase.
45
+ # +app_session_id+:: AppSession ID.
46
+ def create_purchase(products, app_session_id = nil)
47
+ my_model = 'PurchaseResponse'
48
+ resource_path = '/purchases/'
49
+ resource_path = resource_path.sub('{format}', 'json')
50
+ method = 'POST'
51
+ query_params = {}
52
+ header_params = {}
53
+ post_data = {}
54
+ # 'Products' is list of dicts with 'id', 'quantity', and optnl 'tags[]'
55
+ post_data['Products'] = products
56
+ if app_session_id
57
+ post_data['AppSessionId'] = app_session_id
58
+ end
59
+ verbose = false
60
+ return single_request(my_model, resource_path, method, query_params, header_params, post_data, verbose)
61
+ end
62
+
63
+ # Request a purchase object by ID.
64
+ #
65
+ # +id+:: The ID of the purchase.
66
+ def get_purchase_by_id(id)
67
+ my_model = 'PurchaseResponse'
68
+ resource_path = '/purchases/{Id}'
69
+ resource_path = resource_path.sub('{format}', 'json')
70
+ resource_path = resource_path.sub('{Id}', id)
71
+ method = 'GET'
72
+ query_params = {}
73
+ header_params = {}
74
+ return single_request(my_model, resource_path, method, query_params, header_params)
75
+ end
76
+
77
+ # Returns the Products for the current user.
78
+ #
79
+ # +id+:: The ID of the user.
80
+ # +qps+:: Query parameters, a dictionary for filtering by 'Tags' and/or 'ProductIds'.
81
+ def get_user_products(id = 'current', qps = {})
82
+ query_pars = QueryParametersPurchasedProduct.new(qps)
83
+ my_model = 'PurchasedProduct'
84
+ resource_path = '/users/{Id}/products'
85
+ resource_path = resource_path.sub('{Id}', id.to_s)
86
+ method = 'GET'
87
+ query_params = query_pars.get_parameter_dict
88
+ header_params = {}
89
+ return self.__listRequest__(my_model, resource_path, method, query_params, header_params)
90
+ end
91
+
92
+ # Creates a purchase with the specified products.
93
+ #
94
+ # +purchase_id+:: The ID of the purchase.
95
+ # +refund_secret+:: The RefundSecret that was provided in the Response from createPurchase.
96
+ # +comment+:: An optional comment about the refund.
97
+ def refund_purchase(purchase_id, refund_secret, comment = nil)
98
+ my_model = 'RefundPurchaseResponse'
99
+ resource_path = '/purchases/{id}/refund'
100
+ resource_path = resource_path.sub('{id}', purchase_id)
101
+ method = 'POST'
102
+ query_params = {}
103
+ header_params = {}
104
+ post_data = {}
105
+ post_data['RefundSecret'] = refund_secret
106
+ if comment
107
+ post_data['Comment'] = comment
108
+ end
109
+ verbose = 0
110
+ return single_request(my_model, resource_path, method, query_params, header_params, post_data, verbose)
111
+ end
112
+ end
113
+
114
+ end # module BaseSpace
115
+ end # module Bio
@@ -0,0 +1,78 @@
1
+ # Copyright 2013 Toshiaki Katayama, Joachim Baran
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+
14
+ module Bio
15
+ module BaseSpace
16
+
17
+ # Base class for all BaseSpace Ruby SDK model classes. Implements a
18
+ # basic key/value store and provides convenience methods for accessing
19
+ # the key/value store using `method_missing` magic.
20
+ #
21
+ # Keys in this model are referred to as "attribute names", whereas
22
+ # values are called "attributes".
23
+ class Model
24
+ attr_reader :swagger_types, :attributes
25
+
26
+ # Create a new (empty) model.
27
+ def initialize
28
+ @swagger_types = {}
29
+ @attributes = {}
30
+ end
31
+
32
+ # If a method was called on the object for which no implementations is
33
+ # provided, then execute this method and try to return the attribute
34
+ # value whose attribute key matches the method call's name.
35
+ #
36
+ # +method+:: Method call for which no implementation could be found.
37
+ # +args+:: Arguments that were provided to the method call.
38
+ # +block+:: If not nil, code block that follows the method call.
39
+ def method_missing(method, *args, &block)
40
+ attr_name = method.to_s.downcase.gsub('_', '')
41
+ attr_value = false
42
+ self.attributes.each do |key, value|
43
+ if key.downcase == attr_name
44
+ attr_value = value # can be an object or nil
45
+ end
46
+ end
47
+ if attr_value == false
48
+ super
49
+ else
50
+ return attr_value
51
+ end
52
+ end
53
+
54
+ # Sets the value of a named attribute. Overrides the value of
55
+ # a previous assignment.
56
+ #
57
+ # +key+:: Attribute name whose value should be set.
58
+ # +value+:: Value that should be assigned.
59
+ def set_attr(key, value)
60
+ @attributes[key] = value
61
+ return @attributes
62
+ end
63
+
64
+ # Returns the value, if any, of the given attribute name.
65
+ #
66
+ # +key+:: Attribute name whose value should be returned.
67
+ def get_attr(key)
68
+ return @attributes[key]
69
+ end
70
+
71
+ # Returns a string representation of the model.
72
+ def to_str
73
+ return self.inspect
74
+ end
75
+ end
76
+
77
+ end # module BaseSpace
78
+ end # module Bio
@@ -0,0 +1,158 @@
1
+ # Copyright 2013 Toshiaki Katayama, Joachim Baran
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+
14
+ require 'basespace/api/basespace_error'
15
+ require 'basespace/model'
16
+ require 'basespace/model/query_parameters'
17
+
18
+ module Bio
19
+ module BaseSpace
20
+
21
+ # Contains the files that are output by an App.
22
+ #
23
+ # App results are usually BAM or VCF files, even though other file types
24
+ # may also be provided.
25
+ class AppResult < Model
26
+
27
+ # Create a new AppResult instance.
28
+ def initialize
29
+ @swagger_types = {
30
+ 'Name' => 'str',
31
+ #'Status' => 'str', # will be deprecated
32
+ 'Description' => 'str',
33
+ 'StatusSummary' => 'str',
34
+ 'HrefFiles' => 'str',
35
+ 'DateCreated' => 'datetime',
36
+ 'Id' => 'str',
37
+ 'Href' => 'str',
38
+ 'UserOwnedBy' => 'UserCompact',
39
+ 'StatusDetail' => 'str',
40
+ 'HrefGenome' => 'str',
41
+ 'AppSession' => 'AppSession',
42
+ 'References' => 'dict',
43
+ }
44
+ @attributes = {
45
+ 'Name' => nil,
46
+ 'Description' => nil,
47
+ 'StatusSummary' => nil,
48
+ 'HrefFiles' => nil,
49
+ 'DateCreated' => nil,
50
+ 'Id' => nil,
51
+ 'Href' => nil,
52
+ 'UserOwnedBy' => nil, # UserCompact
53
+ 'StatusDetail' => nil,
54
+ 'HrefGenome' => nil,
55
+ 'AppSession' => nil, # AppSession
56
+ 'References' => nil,
57
+ }
58
+ end
59
+
60
+ # Return the name of the AppResult.
61
+ def to_s
62
+ # NOTE Simplified in Ruby to align with the Sample class.
63
+ # See example 3_accessing_files.rb (3_AccessingFiles.py)
64
+ #return "AppResult: #{get_attr('Name')}" #+ " - #{get_attr('Status')"
65
+ return get_attr('Name')
66
+ end
67
+
68
+ # Returns the scope-string to be used for requesting BaseSpace access to the object.
69
+ #
70
+ # +scope+:: The scope-type that is request (write|read).
71
+ def get_access_str(scope = 'write')
72
+ is_init
73
+ return "#{scope} appresult #{get_attr('Id')}"
74
+ end
75
+
76
+ # Tests if the Project instance has been initialized.
77
+ #
78
+ # Throws ModelNotInitializedError, if the instance has not been populated.
79
+ def is_init
80
+ raise ModelNotInitializedError.new('The AppResult model has not been initialized yet') unless get_attr('Id')
81
+ end
82
+
83
+ # Return a list of sample IDs for the samples referenced.
84
+ def get_referenced_samples_ids
85
+ res= []
86
+ get_attr('References').each do |s|
87
+ # [TODO] check this Hash contains the key :type (or should we use 'Type'?)
88
+ if s[:type] == 'Sample'
89
+ id = s[:href_content].split('/').last
90
+ res << id
91
+ end
92
+ end
93
+ return res
94
+ end
95
+
96
+ # Returns a list of sample objects references by the AppResult.
97
+ #
98
+ # NOTE This method makes one request to REST server per sample.
99
+ #
100
+ # +api+:: BaseSpaceAPI instance.
101
+ def get_referenced_samples(api)
102
+ res = []
103
+ ids = get_referenced_samples_ids
104
+ ids.each do |id|
105
+ begin
106
+ sample = api.get_sample_by_id(id)
107
+ res << sample
108
+ rescue => err
109
+ # [TODO] What to do with this 'err'?
110
+ $stderr.puts " # ----- AppResult#get_referenced_samples ----- "
111
+ $stderr.puts " # Error: #{err}"
112
+ $stderr.puts " # "
113
+ end
114
+ end
115
+ return res
116
+ end
117
+
118
+ # Returns a list of file objects in the result set.
119
+ #
120
+ # +api+:: BaseSpaceAPI instance.
121
+ # +my_qp+:: QueryParameters for sorting and filtering the file list.
122
+ def get_files(api, my_qp = {})
123
+ is_init
124
+ query_pars = QueryParameters.new(my_qp)
125
+ return api.get_app_result_files(get_attr('Id'), query_pars)
126
+ end
127
+
128
+ # Uploads a local file to the BaseSpace AppResult.
129
+ #
130
+ # +api+:: BaseSpaceAPI instance.
131
+ # +local_path+: Local path of the file.
132
+ # +file_name+:: Filename.
133
+ # +directory+: The remote directory that the file is uploaded to.
134
+ # +param content_type+:: Content-type of the file.
135
+ def upload_file(api, local_path, file_name, directory, content_type)
136
+ is_init
137
+ return api.app_result_file_upload(get_attr('Id'), local_path, file_name, directory, content_type)
138
+ end
139
+
140
+ # Upload a file in multi-part mode. Returns an object of type MultipartUpload used for managing the upload.
141
+ #
142
+ # +api+:: BaseSpaceAPI instance.
143
+ # +local_path+:: Local path of the file.
144
+ # +file_name+ Filename.
145
+ # +directory+:: The remote directory that the file is uploaded to.
146
+ # +content_type+:: Content-type of the file.
147
+ # +cpu_count+:: Number of CPUs to used for the upload.
148
+ # +part_size+:: Size of each upload chunk.
149
+ # def upload_multipart_file(api, local_path, file_name, directory, content_type,temp_dir = '', cpu_count = 1, part_size = 10, verbose = 0)
150
+ # is_init
151
+ # return api.multipart_file_upload(get_attr('Id'), local_path, file_name, directory, content_type, temp_dir, cpu_count, part_size, verbose)
152
+ # end
153
+
154
+ end
155
+
156
+ end # module BaseSpace
157
+ end # module Bio
158
+
@@ -0,0 +1,40 @@
1
+ # Copyright 2013 Toshiaki Katayama, Joachim Baran
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+
14
+ require 'basespace/model'
15
+
16
+ module Bio
17
+ module BaseSpace
18
+
19
+ # An AppResultResponse is used to initiate the creation of an AppResults object.
20
+ class AppResultResponse < Model
21
+
22
+ # Create a new result response instance.
23
+ def initialize
24
+ @swagger_types = {
25
+ 'ResponseStatus' => 'ResponseStatus',
26
+ 'Response' => 'AppResult',
27
+ 'Notifications' => 'list<Str>',
28
+ }
29
+ @attributes = {
30
+ 'ResponseStatus' => nil, # ResponseStatus
31
+ 'Response' => nil, # Analysis
32
+ 'Notifications' => nil, # list<Str>
33
+ }
34
+ end
35
+
36
+ end
37
+
38
+ end # module BaseSpace
39
+ end # module Bio
40
+