Class: Api::V2::SampleResource

Inherits:
BaseResource
  • Object
show all
Defined in:
app/resources/api/v2/sample_resource.rb

Overview

TODO:

Figure out how to send a POST for a sample with sample metadata association. Currently, it is possible to create a sample and sample metadata seperately, but they are not associated with each other. How do you create the association, either in one request or after the individual requests?

Note:

Access this resource via the /api/v2/samples/ endpoint.

Provides a JSON:API representation of Sample, which represents a biological or synthetic sample used in laboratory processes. This resource allows users to retrieve and filter samples based on various attributes such as UUID, name, or Sanger Sample ID.

For more information about JSON:API see the JSON:API Specifications or look at the JSONAPI::Resources package for Sequencescape's implementation of the JSON:API standard.

Examples:

GET request for all samples

GET /api/v2/samples/

GET request for a specific sample by ID

GET /api/v2/samples/123/

POST request to create a new sample

POST /api/v2/samples/
{
  "data": {
    "type": "samples",
    "attributes": {
      "name": "Sample_A",
      "sanger_sample_id": "S12345",
      "control": false,
      "control_type": "positive"
    },
    "relationships": {
      "sample_metadata": {
        "data": {
          "type": "sample_metadata",
          "id": "1"
        }
      },
      "studies": {
        "data": [
          {
            "type": "studies",
            "id": "1"
          },
        ]
      },
      "component_samples": {
        "data": [
          {
            "type": "component_samples",
            "id": "1"
          },
        ]
      }
    }
  }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseResource

apply_includes, creatable_fields, default_includes, #fetchable_fields, inclusions, resolve_relationship_names_to_relations, updatable_fields

Instance Attribute Details

#component_samplesArray<ComponentSampleResource>

Note:

A sample may consist of multiple component samples.

Returns The component samples associated with this sample.

Returns:

  • (Array<ComponentSampleResource>)

    The component samples associated with this sample.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'app/resources/api/v2/sample_resource.rb', line 120

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#controlBoolean

Note:

Optional field.

Returns Indicates whether this sample is a control sample.

Returns:

  • (Boolean)

    Indicates whether this sample is a control sample.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/resources/api/v2/sample_resource.rb', line 89

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#control_typeString

Note:

Optional field.

Returns The type of control sample (e.g., positive control, negative control).

Returns:

  • (String)

    The type of control sample (e.g., positive control, negative control).



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'app/resources/api/v2/sample_resource.rb', line 94

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#nameString

Note:

This field is optional.

Returns The name of the sample.

Returns:

  • (String)

    The name of the sample.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/resources/api/v2/sample_resource.rb', line 74

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#sample_manifestSampleManifestResource

Note:

Optional relationship.

Returns The manifest to which this sample belongs, often linking it to a larger set of processed samples.

Returns:

  • (SampleManifestResource)

    The manifest to which this sample belongs, often linking it to a larger set of processed samples.



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/resources/api/v2/sample_resource.rb', line 110

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#sample_metadataSampleMetadataResource

Note:

Optional relationship.

Returns The metadata associated with this sample, containing additional details like collection method and donor information.

Returns:

  • (SampleMetadataResource)

    The metadata associated with this sample, containing additional details like collection method and donor information.



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/resources/api/v2/sample_resource.rb', line 104

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#sanger_sample_idString

Note:

This field is optional but commonly used for sample tracking.

Returns The unique identifier assigned to the sample within the Sanger Institute.

Returns:

  • (String)

    The unique identifier assigned to the sample within the Sanger Institute.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/resources/api/v2/sample_resource.rb', line 79

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#studiesArray<StudyResource>

Note:

A sample can be linked to multiple studies.

Returns The studies associated with this sample.

Returns:

  • (Array<StudyResource>)

    The studies associated with this sample.



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'app/resources/api/v2/sample_resource.rb', line 115

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#uuidString (readonly)

Note:

This value is automatically assigned upon creation and cannot be modified.

Returns The globally unique identifier (UUID) for this sample.

Returns:

  • (String)

    The globally unique identifier (UUID) for this sample.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'app/resources/api/v2/sample_resource.rb', line 84

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

Instance Method Details

#filter_by_nameObject

Filters samples by their name.

Examples:

GET request filtering by name

GET /api/v2/samples?filter[name]=Sample_A


142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'app/resources/api/v2/sample_resource.rb', line 142

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#filter_by_sanger_sample_idObject

Filters samples by their Sanger Sample ID.

Examples:

GET request filtering by Sanger Sample ID

GET /api/v2/samples?filter[sanger_sample_id]=S12345


136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'app/resources/api/v2/sample_resource.rb', line 136

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end

#filter_by_uuidObject

Filters samples by their UUID.

Examples:

GET request filtering by UUID

GET /api/v2/samples?filter[uuid]=550e8400-e29b-41d4-a716-446655440000


130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'app/resources/api/v2/sample_resource.rb', line 130

 do
  # NOTE: The following attribute is not required for Microarray Genotyping.
  # I think this might be broken and suggests that there should be separate classes for project: one for
  # next-gen sequencing that includes this attribute in it's metadata, and one for microarray genotyping
  # that doesn't.
  include ProjectManager::Associations
  include BudgetDivision::Associations

  custom_attribute(:project_cost_code, required: true)
  custom_attribute(:funding_comments)
  custom_attribute(:collaborators)
  custom_attribute(:external_funding_source)
  custom_attribute(:sequencing_budget_cost_centre)
  custom_attribute(:project_funding_model, in: PROJECT_FUNDING_MODELS)
  custom_attribute(:gt_committee_tracking_id)

  before_validation do |record|
    record.project_cost_code = nil if record.project_cost_code.blank?
    record.project_funding_model = nil if record.project_funding_model.blank?
  end
end