megaqc.rest_api package¶
Submodules¶
megaqc.rest_api.content module¶
Utilities to help with content negotiation.
megaqc.rest_api.fields module¶
-
class
megaqc.rest_api.fields.
FilterReference
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.fields.ModelAssociation
Dumps as a SampleFilter foreign key, e.g. “3”, and loads as a filter array.
megaqc.rest_api.filters module¶
-
megaqc.rest_api.filters.
add_operator
(lhs, op, rhs)[source]¶ Returns an SQLAlchemy expression comparing two values.
-
megaqc.rest_api.filters.
build_filter_query
(filters)[source]¶ Returns an SQLAlchemy query with the provided filters applied. This filter will only select Sample IDs that meet the filter, so you should only use this as a subquery.
- Parameters
filters (list) – Array of filters in the MegaQC filter format (each filter is a dictionary)
- Return type
Query
megaqc.rest_api.outlier module¶
megaqc.rest_api.plot module¶
-
megaqc.rest_api.plot.
encode_to_numeric
(y: Iterable, chunk_size: int) → Iterable[numpy.ndarray][source]¶
-
megaqc.rest_api.plot.
extract_query_data
(query: sqlalchemy.orm.query.Query, ncol: int) → Tuple[numpy.ndarray[Any, numpy.dtype[numpy.bytes_]], numpy.ndarray[Any, numpy.dtype[numpy.bytes_]], numpy.ndarray[Any, numpy.dtype[numpy.datetime64]], numpy.ndarray[Any, numpy.dtype[numpy.float64]]][source]¶
-
megaqc.rest_api.plot.
isolation_forest_trend
(query: Any, fields: collections.abc.Sequence[str], plot_prefix: str, statistic_options: dict) → Iterator[dict][source]¶ Yields plotly series for the “Isolation Forest” statistic.
-
megaqc.rest_api.plot.
rgb_to_rgba
(rgb, alpha)[source]¶ Appends an alpha (transparency) value to an RGB string.
megaqc.rest_api.schemas module¶
These schemas describe the format of the web requests to and from the API.
They incidentally share most fields with the database models, but they can be opinionated about REST-specific fields
-
class
megaqc.rest_api.schemas.
ControlLimitSchema
(*, only: types.StrSequenceOrSet | None = None, exclude: types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: types.StrSequenceOrSet = (), dump_only: types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet = False, unknown: str | None = None)[source]¶ Bases:
marshmallow.schema.Schema
Defines “control limits” for a control chart.
-
class
megaqc.rest_api.schemas.
DashboardSchema
(use_links=True, *args, **kwargs)[source]¶ Bases:
megaqc.rest_api.schemas.OptionalLinkSchema
-
class
Meta
[source]¶ Bases:
object
-
model
[source]¶ alias of
megaqc.model.models.Dashboard
-
-
class
-
class
megaqc.rest_api.schemas.
FavouritePlotSchema
(use_links=True, *args, **kwargs)[source]¶ Bases:
megaqc.rest_api.schemas.OptionalLinkSchema
-
class
Meta
[source]¶ Bases:
object
-
model
[source]¶ alias of
megaqc.model.models.PlotFavourite
-
-
class
-
class
megaqc.rest_api.schemas.
FilterGroupSchema
(use_links=True, *args, **kwargs)[source]¶ Bases:
megaqc.rest_api.schemas.OptionalLinkSchema
Fake schema (no underlying model) for filter groups, which dump from a filter object.
-
class
Meta
[source]¶ Bases:
object
-
model
[source]¶ alias of
megaqc.model.models.SampleFilter
-
-
class
-
class
megaqc.rest_api.schemas.
FilterObjectSchema
(*, only: types.StrSequenceOrSet | None = None, exclude: types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: types.StrSequenceOrSet = (), dump_only: types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet = False, unknown: str | None = None)[source]¶ Bases:
marshmallow.schema.Schema
A single filter object, e.g. { ‘type’: ‘daterange’, ‘value’: [], ‘cmp’:
‘in’ }
-
class
megaqc.rest_api.schemas.
IsolationForestSchema
(*, only: types.StrSequenceOrSet | None = None, exclude: types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: types.StrSequenceOrSet = (), dump_only: types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet = False, unknown: str | None = None)[source]¶ Bases:
marshmallow.schema.Schema
Schema for the isolation forest statistic option.
-
class
megaqc.rest_api.schemas.
OptionalLinkSchema
(use_links=True, *args, **kwargs)[source]¶ Bases:
marshmallow_jsonapi.flask.Schema
-
class
megaqc.rest_api.schemas.
PlotSchema
(*args, **kwargs)[source]¶ Bases:
marshmallow_jsonapi.flask.Schema
Data that can be used to generate a plot.
-
class
megaqc.rest_api.schemas.
RawMeasurementSchema
(*, only: types.StrSequenceOrSet | None = None, exclude: types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: types.StrSequenceOrSet = (), dump_only: types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet = False, unknown: str | None = None)[source]¶ Bases:
marshmallow.schema.Schema
For when the user has chosen the raw measurement option.
-
class
megaqc.rest_api.schemas.
Relationship
(related_view=None, related_view_kwargs=None, *, self_view=None, self_view_kwargs=None, **kwargs)[source]¶ Bases:
marshmallow_jsonapi.flask.Relationship
-
class
megaqc.rest_api.schemas.
ReportMetaSchema
(use_links=True, *args, **kwargs)[source]¶ Bases:
megaqc.rest_api.schemas.OptionalLinkSchema
-
class
Meta
[source]¶ Bases:
object
-
model
[source]¶ alias of
megaqc.model.models.ReportMeta
-
-
class
-
class
megaqc.rest_api.schemas.
ReportMetaTypeSchema
(use_links=True, *args, **kwargs)[source]¶ Bases:
megaqc.rest_api.schemas.OptionalLinkSchema
This is an artificial type that doesn’t have a backing model.
-
class
Meta
[source]¶ Bases:
object
-
model
[source]¶ alias of
megaqc.model.models.ReportMeta
-
-
class
-
class
megaqc.rest_api.schemas.
ReportSchema
(use_links=True, *args, **kwargs)[source]¶ Bases:
megaqc.rest_api.schemas.OptionalLinkSchema
This is an abstraction of Report + ReportMeta.
-
class
Meta
[source]¶ Bases:
object
-
model
[source]¶ alias of
megaqc.model.models.Report
-
-
class
-
class
megaqc.rest_api.schemas.
SampleDataSchema
(use_links=True, *args, **kwargs)[source]¶ Bases:
megaqc.rest_api.schemas.OptionalLinkSchema
-
class
Meta
[source]¶ Bases:
object
-
model
[source]¶ alias of
megaqc.model.models.SampleData
-
-
class
-
class
megaqc.rest_api.schemas.
SampleDataTypeSchema
(use_links=True, *args, **kwargs)[source]¶ Bases:
megaqc.rest_api.schemas.OptionalLinkSchema
-
class
Meta
[source]¶ Bases:
object
-
model
[source]¶ alias of
megaqc.model.models.SampleDataType
-
-
class
-
class
megaqc.rest_api.schemas.
SampleFilterSchema
(use_links=True, *args, **kwargs)[source]¶ Bases:
megaqc.rest_api.schemas.OptionalLinkSchema
-
class
Meta
[source]¶ Bases:
object
-
model
[source]¶ alias of
megaqc.model.models.SampleFilter
-
-
class
-
class
megaqc.rest_api.schemas.
SampleSchema
(use_links=True, *args, **kwargs)[source]¶ Bases:
megaqc.rest_api.schemas.OptionalLinkSchema
-
class
Meta
[source]¶ Bases:
object
-
model
[source]¶ alias of
megaqc.model.models.Sample
-
-
class
-
class
megaqc.rest_api.schemas.
TrendInputSchema
(*, only: types.StrSequenceOrSet | None = None, exclude: types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: types.StrSequenceOrSet = (), dump_only: types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet = False, unknown: str | None = None)[source]¶ Bases:
marshmallow.schema.Schema
Schema for the request for trend data (not the response)
-
class
megaqc.rest_api.schemas.
TrendSchema
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.schemas.PlotSchema
Data that can be used to generate a trend plot.
-
class
megaqc.rest_api.schemas.
UploadSchema
(use_links=True, *args, **kwargs)[source]¶ Bases:
megaqc.rest_api.schemas.OptionalLinkSchema
-
class
Meta
[source]¶ Bases:
object
-
model
[source]¶ alias of
megaqc.model.models.Upload
-
-
class
-
class
megaqc.rest_api.schemas.
UserSchema
(use_links=True, *args, **kwargs)[source]¶ Bases:
megaqc.rest_api.schemas.OptionalLinkSchema
-
class
Meta
[source]¶ Bases:
object
-
model
[source]¶ alias of
megaqc.user.models.User
-
-
class
megaqc.rest_api.utils module¶
-
megaqc.rest_api.utils.
api_perms
(min_level: megaqc.rest_api.utils.Permission = <Permission.NONUSER: 1>)[source]¶ Adds a “user” and “permission” kwarg to the view function. Also verifies a minimum permissions level.
- Parameters
min_level – If provided, this is the minimum permission level required by this endpoint
megaqc.rest_api.views module¶
Location of a rewritten API in a RESTful style, with appropriate resources Following the JSON API standard where relevant: https://jsonapi.org/format/
-
class
megaqc.rest_api.views.
CurrentUser
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceDetail
-
data_layer
= {'model': <class 'megaqc.user.models.User'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
get
(**kwargs)[source]¶ Get details about the current user.
This is also how the frontend can get an access token. For that reason, this endpoint is authenticated using the session, NOT the access token
-
schema
[source]¶ alias of
megaqc.rest_api.schemas.UserSchema
-
-
class
megaqc.rest_api.views.
Dashboard
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceDetail
-
data_layer
= {'model': <class 'megaqc.model.models.Dashboard'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
-
class
megaqc.rest_api.views.
DashboardList
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceList
-
data_layer
= {'model': <class 'megaqc.model.models.Dashboard'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
-
class
megaqc.rest_api.views.
DashboardRelationship
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceList
-
data_layer
= {'model': <class 'megaqc.model.models.Dashboard'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
-
class
megaqc.rest_api.views.
DataType
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceDetail
-
data_layer
= {'model': <class 'megaqc.model.models.SampleDataType'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
-
class
megaqc.rest_api.views.
DataTypeList
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceList
-
data_layer
= {'model': <class 'megaqc.model.models.SampleDataType'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
-
class
megaqc.rest_api.views.
FavouritePlot
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceDetail
-
data_layer
= {'model': <class 'megaqc.model.models.PlotFavourite'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
-
class
megaqc.rest_api.views.
FavouritePlotList
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceList
-
data_layer
= {'model': <class 'megaqc.model.models.PlotFavourite'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
-
class
megaqc.rest_api.views.
FavouritePlotRelationship
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceRelationship
-
data_layer
= {'model': <class 'megaqc.model.models.PlotFavourite'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
-
class
megaqc.rest_api.views.
Filter
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceDetail
-
data_layer
= {'model': <class 'megaqc.model.models.SampleFilter'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
-
class
megaqc.rest_api.views.
FilterGroupList
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceList
-
data_layer
= {'model': <class 'megaqc.model.models.SampleFilter'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
-
class
megaqc.rest_api.views.
FilterList
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceList
-
data_layer
= {'model': <class 'megaqc.model.models.SampleFilter'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
-
class
megaqc.rest_api.views.
FilterRelationship
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceRelationship
-
data_layer
= {'model': <class 'megaqc.model.models.SampleFilter'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
-
class
megaqc.rest_api.views.
PermissionsMixin
[source]¶ Bases:
object
Adds shared config to all views.
Logged-out users shouldn’t be able to access the API at all, logged in users should be able to only GET, and only admins should be able to POST, PATCH or DELETE. These decorators can be overriden by child classes, however
-
class
megaqc.rest_api.views.
Report
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceDetail
-
data_layer
= {'model': <class 'megaqc.model.models.Report'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
schema
[source]¶ alias of
megaqc.rest_api.schemas.ReportSchema
-
-
class
megaqc.rest_api.views.
ReportList
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceList
-
data_layer
= {'model': <class 'megaqc.model.models.Report'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
schema
[source]¶ alias of
megaqc.rest_api.schemas.ReportSchema
-
-
class
megaqc.rest_api.views.
ReportMeta
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceDetail
-
data_layer
= {'model': <class 'megaqc.model.models.ReportMeta'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
-
class
megaqc.rest_api.views.
ReportMetaList
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceList
-
data_layer
= {'model': <class 'megaqc.model.models.ReportMeta'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
-
class
megaqc.rest_api.views.
ReportMetaRelationship
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceRelationship
-
data_layer
= {'model': <class 'megaqc.model.models.ReportMeta'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
-
class
megaqc.rest_api.views.
ReportMetaTypeList
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceList
-
data_layer
= {'model': <class 'megaqc.model.models.ReportMeta'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
-
class
megaqc.rest_api.views.
ReportRelationship
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceRelationship
-
data_layer
= {'model': <class 'megaqc.model.models.Report'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
schema
[source]¶ alias of
megaqc.rest_api.schemas.ReportSchema
-
-
class
megaqc.rest_api.views.
Sample
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceDetail
-
data_layer
= {'model': <class 'megaqc.model.models.Sample'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
schema
[source]¶ alias of
megaqc.rest_api.schemas.SampleSchema
-
-
class
megaqc.rest_api.views.
SampleData
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceDetail
-
data_layer
= {'model': <class 'megaqc.model.models.SampleData'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
-
class
megaqc.rest_api.views.
SampleDataList
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceList
-
data_layer
= {'model': <class 'megaqc.model.models.SampleData'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
-
class
megaqc.rest_api.views.
SampleDataRelationship
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceRelationship
-
data_layer
= {'model': <class 'megaqc.model.models.SampleData'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
-
class
megaqc.rest_api.views.
SampleList
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceList
-
data_layer
= {'model': <class 'megaqc.model.models.Sample'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
schema
[source]¶ alias of
megaqc.rest_api.schemas.SampleSchema
-
-
class
megaqc.rest_api.views.
SampleRelationship
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceRelationship
-
data_layer
= {'model': <class 'megaqc.model.models.Sample'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
schema
[source]¶ alias of
megaqc.rest_api.schemas.SampleSchema
-
-
class
megaqc.rest_api.views.
TrendSeries
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceList
-
class
megaqc.rest_api.views.
Upload
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceDetail
-
data_layer
= {'model': <class 'megaqc.model.models.Upload'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
schema
[source]¶ alias of
megaqc.rest_api.schemas.UploadSchema
-
-
class
megaqc.rest_api.views.
UploadList
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceList
-
data_layer
= {'model': <class 'megaqc.model.models.Upload'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
post
(**kwargs)[source]¶ Upload a new report.
This is rare in that average users can do this, even though they aren’t allowed to edit arbitrary data
-
schema
[source]¶ alias of
megaqc.rest_api.schemas.UploadSchema
-
-
class
megaqc.rest_api.views.
UploadRelationship
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceRelationship
-
data_layer
= {'model': <class 'megaqc.model.models.Upload'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
schema
[source]¶ alias of
megaqc.rest_api.schemas.UploadSchema
-
-
class
megaqc.rest_api.views.
User
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceDetail
-
data_layer
= {'model': <class 'megaqc.user.models.User'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
schema
[source]¶ alias of
megaqc.rest_api.schemas.UserSchema
-
-
class
megaqc.rest_api.views.
UserList
(*args, **kwargs)[source]¶ Bases:
flapison.resource.ResourceList
-
data_layer
= {'model': <class 'megaqc.user.models.User'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
schema
[source]¶ alias of
megaqc.rest_api.schemas.UserSchema
-
-
class
megaqc.rest_api.views.
UserRelationship
(*args, **kwargs)[source]¶ Bases:
megaqc.rest_api.views.PermissionsMixin
,flapison.resource.ResourceRelationship
-
data_layer
= {'model': <class 'megaqc.user.models.User'>, 'session': <sqlalchemy.orm.scoping.scoped_session object>}[source]¶
-
schema
[source]¶ alias of
megaqc.rest_api.schemas.UserSchema
-