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,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
+ # Meta response about coverage data.
20
+ class CoverageMetaResponse < Model
21
+
22
+ # Create a new CoverageMetaResponse instance.
23
+ def initialize
24
+ @swagger_types = {
25
+ 'ResponseStatus' => 'ResponseStatus',
26
+ 'Response' => 'CoverageMetadata',
27
+ 'Notifications' => 'list<Str>',
28
+ }
29
+ @attributes = {
30
+ 'ResponseStatus' => nil, # ResponseStatus'
31
+ 'Response' => nil, # CoverageMetadata'
32
+ 'Notifications' => nil, # list<Str>'
33
+ }
34
+ end
35
+
36
+ end
37
+
38
+ end # module BaseSpace
39
+ end # module Bio
40
+
@@ -0,0 +1,43 @@
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
+ # Models coverage metadata.
20
+ class CoverageMetadata < Model
21
+
22
+ # Create a new CoeverageMetadata instance.
23
+ def initialize
24
+ @swagger_types = {
25
+ 'MaxCoverage' => 'int',
26
+ 'CoverageGranularity' => 'int',
27
+ }
28
+ @attributes = {
29
+ 'MaxCoverage' => nil, # int Maximum coverage value of any base, on a per-base level, for the entire chromosome. Useful for scaling
30
+ 'CoverageGranularity' => nil, # int Supported granularity of queries
31
+ }
32
+ end
33
+
34
+ # Return a string denoting the maximum coverage and coverage granularity.
35
+ def to_s
36
+ return "CoverageMeta: max=#{get_attr('MaxCoverage')} gran=#{get_attr('CoverageGranularity')}"
37
+ end
38
+
39
+ end
40
+
41
+ end # module BaseSpace
42
+ end # module Bio
43
+
@@ -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
+ # Response of a coverage object.
20
+ class CoverageResponse < Model
21
+
22
+ # Create a new CoverageResponse.
23
+ def initialize
24
+ @swagger_types = {
25
+ 'ResponseStatus' => 'ResponseStatus',
26
+ 'Response' => 'Coverage',
27
+ 'Notifications' => 'list<Str>',
28
+ }
29
+ @attributes = {
30
+ 'ResponseStatus' => nil, # ResponseStatus
31
+ 'Response' => nil, # Coverage
32
+ 'Notifications' => nil, # list<Str>
33
+ }
34
+ end
35
+
36
+ end
37
+
38
+ end # module BaseSpace
39
+ end # module Bio
40
+
@@ -0,0 +1,172 @@
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
+
17
+ module Bio
18
+ module BaseSpace
19
+
20
+ # Represents a BaseSpace file object.
21
+ class File < Model
22
+
23
+ # Create a new File instance.
24
+ def initialize
25
+ @swagger_types = {
26
+ 'Name' => 'str',
27
+ 'HrefCoverage' => 'str',
28
+ 'HrefParts' => 'str',
29
+ 'DateCreated' => 'datetime',
30
+ 'UploadStatus' => 'str',
31
+ 'Id' => 'str',
32
+ 'Href' => 'str',
33
+ 'HrefContent' => 'str',
34
+ 'HrefVariants' => 'str',
35
+ 'ContentType' => 'str',
36
+ 'Path' => 'str',
37
+ 'Size' => 'int',
38
+ }
39
+ @attributes = {
40
+ 'Name' => nil, # str
41
+ # If set, provides the relative Uri to fetch the mean coverage statistics for data stored in the file
42
+ 'HrefCoverage' => nil, # str
43
+ # If set, provides the relative Uri to fetch a list of completed file parts for multi-part file uploads in progress
44
+ 'HrefParts' => nil, # str
45
+ 'DateCreated' => nil, # datetime
46
+ 'UploadStatus' => nil, # str
47
+ 'Id' => nil, # str
48
+ 'Href' => nil, # str
49
+ 'HrefContent' => nil, # str
50
+ # If set, provides the relative Uri to fetch the variants stored in the file
51
+ 'HrefVariants' => nil, # str
52
+ 'ContentType' => nil, # str
53
+ 'Path' => nil, # str
54
+ 'Size' => nil, # int
55
+ }
56
+ end
57
+
58
+ # Returns the name of the file, its ID, size and upload status.
59
+ def to_s
60
+ str = get_attr('Name')
61
+ begin
62
+ str += " - id: '#{get_attr('Id')}', size: '#{get_attr('Size')}'"
63
+ str += ", status: '#{get_attr('UploadStatus')}'" if get_attr('UploadStatus')
64
+ rescue => err
65
+ # [TODO] What to do with this 'err'?
66
+ $stderr.puts " # ----- File#to_s ----- "
67
+ $stderr.puts " # Error: #{err}"
68
+ $stderr.puts " # "
69
+ end
70
+ return str
71
+ end
72
+
73
+ # Tests if the File instance has been initialized.
74
+ #
75
+ # Throws ModelNotInitializedError, if the instance has not been populated yet.
76
+ def is_init
77
+ raise ModelNotInitializedError.new('The File model has not been initialized yet') unless get_attr('Id')
78
+ end
79
+
80
+ # Tests if the File instance matches the filetype parameter.
81
+ #
82
+ # +filetype+:: The filetype for coverage or variant requests (bam|vcf).
83
+ def is_valid_file_option(filetype)
84
+ if filetype == 'bam'
85
+ raise WrongFiletypeError.new(get_attr('Name')) unless get_attr('HrefCoverage')
86
+ end
87
+ if filetype == 'vcf'
88
+ raise WrongFiletypeError.new(get_attr('Name')) unless get_attr('HrefVariants')
89
+ end
90
+ end
91
+
92
+ # Download the file object to the specified local directory or a byte range of the file,
93
+ # by specifying the start and stop byte in the range.
94
+ #
95
+ # +api+:: A BaseSpaceAPI instance with read access to the file object.
96
+ # +local_dir+:: The local directory to place the file in.
97
+ # :range+:: Two-item array with start and stop byte of the file chunk that needs retrieved.
98
+ def download_file(api, local_dir, range = [])
99
+ if range.empty?
100
+ return api.file_download(get_attr('Id'),local_dir, get_attr('Name'))
101
+ else
102
+ return api.file_download(get_attr('Id'),local_dir, get_attr('Name'), range)
103
+ end
104
+ end
105
+
106
+ # Return the S3 URL of the file.
107
+ #
108
+ # +api+:: A BaseSpaceAPI instance with read access to the file object.
109
+ def get_file_url(api)
110
+ return api.file_url(get_attr('Id'))
111
+ end
112
+
113
+ # Delete the file; not implemented yet.
114
+ #
115
+ # +api+:: A BaseSpaceAPI instance with delete permissions on the file object.
116
+ def delete_file(api)
117
+ raise 'Not yet implemented'
118
+ end
119
+
120
+ # Return a coverage object for the specified region and chromosome.
121
+ #
122
+ # +api+:: BaseSpaceAPI instance.
123
+ # +chrom+:: Chromosome as a string - for example 'chr2'.
124
+ # +start_pos+:: The start position of region of interest as a string.
125
+ # +end_pos+:: The end position of region of interest as a string.
126
+ def get_interval_coverage(api, chrom, start_pos, end_pos)
127
+ is_init
128
+ is_valid_file_option('bam')
129
+ set_attr('Id', get_attr('HrefCoverage').split('/').last)
130
+ return api.get_interval_coverage(get_attr('Id'), chrom, start_pos, end_pos)
131
+ end
132
+
133
+ # Returns a list of Variant objects available in the specified region.
134
+ #
135
+ # +api+:: BaseSpaceAPI instance.
136
+ # +chrom+:: Chromosome as a string - for example 'chr2'.
137
+ # +start_pos+:: The start position of region of interest as a string.
138
+ # +end_pos+:: The end position of region of interest as a string.
139
+ # +qp+: TODO queryParameters object for custom filtering.
140
+ def filter_variant(api, chrom, start_pos, end_pos, qp = nil)
141
+ is_init
142
+ is_valid_file_option('vcf')
143
+ set_attr('Id', get_attr('HrefVariants').split('/').last)
144
+ return api.filter_variant_set(get_attr('Id'), chrom, start_pos, end_pos, 'txt')
145
+ end
146
+
147
+ # Return an object of CoverageMetadata for the selected region.
148
+ #
149
+ # +api+:: BaseSpaceAPI instance.
150
+ # +chrom+:: Chromosome as a string - for example 'chr2'.
151
+ def get_coverage_meta(api, chrom)
152
+ is_init
153
+ is_valid_file_option('bam')
154
+ set_attr('Id', get_attr('HrefCoverage').split('/').last)
155
+ return api.get_coverage_meta_info(get_attr('Id'), chrom)
156
+ end
157
+
158
+ # Return the the meta info for a VCF file as a VariantInfo object.
159
+ #
160
+ # +api+:: BaseSpaceAPI instance.
161
+ def get_variant_meta(api)
162
+ is_init
163
+ is_valid_file_option('vcf')
164
+ set_attr('Id', get_attr('HrefVariants').split('/').last)
165
+ return api.get_variant_metadata(get_attr('Id'), 'txt')
166
+ end
167
+
168
+ end
169
+
170
+ end # module BaseSpace
171
+ end # module Bio
172
+
@@ -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
+ # File response object.
20
+ class FileResponse < Model
21
+
22
+ # Create a new FileResponse instance.
23
+ def initialize
24
+ @swagger_types = {
25
+ 'ResponseStatus' => 'ResponseStatus',
26
+ 'Response' => 'File',
27
+ 'Notifications' => 'list<Str>'
28
+ }
29
+ @attributes = {
30
+ 'ResponseStatus' => nil, # ResponseStatus
31
+ 'Response' => nil, # File
32
+ 'Notifications' => nil, # list<Str>
33
+ }
34
+ end
35
+
36
+ end
37
+
38
+ end # module BaseSpace
39
+ end # module Bio
40
+
@@ -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
+ # Genome response object.
20
+ class GenomeResponse < Model
21
+
22
+ # Create a new GenomeResponse instance.
23
+ def initialize
24
+ @swagger_types = {
25
+ 'ResponseStatus' => 'ResponseStatus',
26
+ 'Response' => 'GenomeV1',
27
+ 'Notifications' => 'list<Str>',
28
+ }
29
+ @attributes = {
30
+ 'ResponseStatus' => nil, # ResponseStatus
31
+ 'Response' => nil, # GenomeV1
32
+ 'Notifications' => nil, # list<Str>
33
+ }
34
+ end
35
+
36
+ end
37
+
38
+ end # module BaseSpace
39
+ end # module Bio
40
+
@@ -0,0 +1,56 @@
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
+ # Genome model.
20
+ class GenomeV1 < Model
21
+
22
+ # Create a new GenomeV1 instance.
23
+ def initialize
24
+ @swagger_types = {
25
+ 'Source' => 'str',
26
+ 'SpeciesName' => 'str',
27
+ 'Build' => 'str',
28
+ 'Id' => 'str',
29
+ 'Href' => 'str',
30
+ 'DisplayName' => 'str',
31
+ }
32
+ @attributes = {
33
+ 'Source' => nil, # str
34
+ 'SpeciesName' => nil, # str
35
+ 'Build' => nil, # str
36
+ 'Id' => nil, # str
37
+ 'Href' => nil, # str
38
+ 'DisplayName' => nil, # str
39
+ }
40
+ end
41
+
42
+ # Return species name, or if absent, return display name, or if absent too, return the Href.
43
+ def to_s
44
+ if get_attr('SpeciesName')
45
+ return get_attr('SpeciesName')
46
+ elsif get_attr('DisplayName')
47
+ return get_attr('DisplayName')
48
+ else
49
+ return "Genome @ #{get_attr('Href')}"
50
+ end
51
+ end
52
+ end
53
+
54
+ end # module BaseSpace
55
+ end # module Bio
56
+
@@ -0,0 +1,53 @@
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 'json'
15
+ require 'basespace/model'
16
+
17
+ module Bio
18
+ module BaseSpace
19
+
20
+ # A list response object.
21
+ class ListResponse < Model
22
+
23
+ # Create a new ListResponse instance.
24
+ def initialize
25
+ @swagger_types = {
26
+ 'ResponseStatus' => 'ResponseStatus',
27
+ 'Response' => 'ResourceList',
28
+ 'Notifications' => 'list<Str>',
29
+ }
30
+ @attributes = {
31
+ 'ResponseStatus' => nil, # ResponseStatus
32
+ 'Response' => nil, # ResourceList
33
+ 'Notifications' => nil, # list<Str>
34
+ }
35
+ end
36
+
37
+ # Converts the object to a Ruby Array.
38
+ def convert_to_object_list
39
+ l = []
40
+ get_attr('Response').items.each do |m|
41
+ io = eval(m)
42
+ s = io.to_json
43
+ mj = JSON.parse(s)
44
+ l << mj
45
+ end
46
+ return l
47
+ end
48
+
49
+ end
50
+
51
+ end # module BaseSpace
52
+ end # module Bio
53
+