macpepdb 1.1.0

Large peptide database for mass spectrometry
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
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
595
596
597
598
599
600
601
602
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
635
636
637
638
639
640
641
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
682
683
684
685
686
687
688
689
690
691
692
693
// std imports
use std::sync::Arc;

// 3rd party imports
use anyhow::Result;
use async_stream::stream;
use axum::body::Body;
use axum::extract::{Json, Path, Query, State};
use axum::http::header::ACCEPT;
use axum::http::{HeaderMap, HeaderValue, StatusCode};
use axum::response::{IntoResponse, Response};
use base64::{engine::general_purpose::STANDARD as Base64Standard, Engine as _};
use dihardts_omicstools::mass_spectrometry::unit_conversions::mass_to_charge_to_dalton;
use dihardts_omicstools::proteomics::post_translational_modifications::PostTranslationalModification as PTM;
use dihardts_omicstools::proteomics::proteases::functions::get_by_name as get_protease_by_name;
use futures::TryStreamExt;
use http::header;
use scylla::value::CqlValue;
use tracing::error;
use urlencoding::decode as urldecode;

// internal imports
use crate::chemistry::amino_acid::calc_sequence_mass_int;
use crate::database::scylla::peptide_table::PeptideTable;
use crate::database::scylla::protein_table::ProteinTable;
use crate::entities::peptide::TsvPeptide;
use crate::entities::protein::Protein;
use crate::functions::post_translational_modification::PTMCollection;
use crate::mass::convert::to_int as mass_to_int;
use crate::tools::peptide_partitioner::get_mass_partition;
use crate::web::app_state::AppState;
use crate::web::web_error::WebError;

const DEFAULT_POST_SEARCH_ACCEPT_HEADER: &str = "application/json";

/// Struct to deserialize the query parameters for get peptide
///
#[derive(serde::Deserialize)]
pub struct GetPeptideRequestQuery {
    #[serde(default)]
    include_protein_peptides_sequences: bool,
}

/// Returns the peptide for given sequence.
/// Important: This endpoint will return the the peptide inclduing a list of full records of the proteins of origin. The proteins will include only the contained peptide sequences. Not the entire peptide records.
///
/// # Arguments
/// * `db_client` - The database client
/// * `configuration` - MaCPepDB configuration
/// * `accession` - Protein accession extracted from URL path
///
/// # API
/// ## Request
/// * Path: `/api/peptides/:sequence`
/// * Method: `GET`
///
/// ## Query
/// * `include_protein_peptides_sequences`: `bool` (optional, default: `false`, if true, the peptide sequence will be included in the proteins)
///
/// ## Response
/// ```json
/// {
///     "partition": 19,
///     "mass": 1015475679562,
///     "sequence": "HMENEKTK",
///     "missed_cleavages": 1,
///     # Amino acid counts, the amino acid at index 0 is A, at index 1 is B, ...
///     "aa_counts": [
///         0, 0, 0, 0, 2, 0, 0, 1, 0, 0, 2, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0
///     ],
///     "proteins": [
///          {
///             "accession": "Q924W6",
///             "domains": [],
///             "entry_name": "TRI66_MOUSE",
///             "genes": [
///                 ...
///             ],
///             "is_reviewed": true,
///             "name": "Tripartite motif-containing protein 66",
///             "peptides": [
///                 "MSPGLPVSIPSQPHCSTDERVEALAPTCSMCGRDLQAEGSR",
///                 ...
///             ],
///             "proteome_id": "UP000000589",
///             "secondary_accessions": [
///                 ...
///             ],
///             "sequence": "...",
///             "taxonomy_id": 10090,
///             "updated_at": 1687910400
///         },
///         ...
///     ],
///     "is_swiss_prot": true,
///     "is_trembl": false,
///     "taxonomy_ids": [
///         10090
///     ],
///     "unique_taxonomy_ids": [
///         10090
///     ],
///     "proteome_ids": [
///         "UP000000589"
///     ]
/// }
///
pub async fn get_peptide(
    State(app_state): State<Arc<AppState>>,
    Path(sequence): Path<String>,
    Query(query): Query<GetPeptideRequestQuery>,
) -> Result<Json<serde_json::Value>, WebError> {
    let sequence = sequence.to_uppercase();
    let mass = calc_sequence_mass_int(sequence.as_str())?;
    let partition = get_mass_partition(
        app_state.get_configuration_as_ref().get_partition_limits(),
        mass,
    )?;

    let peptide_opt = PeptideTable::select(
        app_state.get_db_client_as_ref(),
        "WHERE partition = ? AND mass = ? and sequence = ?",
        &[
            &CqlValue::BigInt(partition as i64),
            &CqlValue::BigInt(mass),
            &CqlValue::Text(sequence),
        ],
    )
    .await?
    .try_collect::<Vec<_>>()
    .await?
    .pop();

    if peptide_opt.is_none() {
        return Err(WebError::new(
            StatusCode::NOT_FOUND,
            "Peptide not found".to_string(),
        ));
    }

    let protease = get_protease_by_name(
        app_state.get_configuration_as_ref().get_protease_name(),
        app_state
            .get_configuration_as_ref()
            .get_min_peptide_length(),
        app_state
            .get_configuration_as_ref()
            .get_max_peptide_length(),
        app_state
            .get_configuration_as_ref()
            .get_max_number_of_missed_cleavages(),
    )?;

    let peptide = peptide_opt.unwrap();

    let proteins: Vec<Protein> =
        ProteinTable::get_proteins_of_peptide(app_state.get_db_client_as_ref(), &peptide)
            .await?
            .try_collect()
            .await?;

    let protein_jsons = if !query.include_protein_peptides_sequences {
        proteins
            .into_iter()
            .map(|protein| protein.to_json_without_peptides())
            .collect::<Result<Vec<_>>>()?
    } else {
        proteins
            .into_iter()
            .map(|protein| protein.to_json_with_peptide_sequences(protease.as_ref()))
            .collect::<Result<Vec<_>>>()?
    };

    let mut peptide_json = match serde_json::to_value(peptide) {
        Ok(json) => json,
        Err(err) => {
            return Err(WebError::new(
                StatusCode::INTERNAL_SERVER_ERROR,
                format!("Error while serializing peptide: {:?}", err),
            ))
        }
    };
    peptide_json["proteins"] = match serde_json::to_value(protein_jsons) {
        Ok(json) => json,
        Err(err) => {
            return Err(WebError::new(
                StatusCode::INTERNAL_SERVER_ERROR,
                format!("Error while serializing proteins: {:?}", err),
            ))
        }
    };
    Ok(Json(peptide_json))
}

/// Returns if a peptide exists.
///
/// # Arguments
/// * `db_client` - The database client
/// * `configuration` - MaCPepDB configuration
/// * `sequence` - Peptide sequence from path
///
/// # API
/// ## Request
/// * Path: `/api/peptides/:sequence/exists`
/// * Method: `GET`
///
/// ## Response
/// Response will be empty.
/// Statuscode 200 if peptide exists, otherwise 404
///
pub async fn get_peptide_existence(
    State(app_state): State<Arc<AppState>>,
    Path(sequence): Path<String>,
) -> Result<Response, WebError> {
    if PeptideTable::exists_by_sequence(
        app_state.get_db_client_as_ref(),
        sequence.as_str(),
        app_state.get_configuration_as_ref(),
    )
    .await?
    {
        Ok((StatusCode::OK, "").into_response())
    } else {
        Ok((StatusCode::NOT_FOUND, "").into_response())
    }
}

/// Struct for mass as thompson & charge or dalton
#[derive(serde::Deserialize)]
#[serde(untagged)]
pub enum SearchRequestMass {
    ThompsonCharge(f64, u8),
    Dalton(f64),
}

/// Simple struct to deserialize the request body for peptide search
///
#[derive(serde::Deserialize)]
pub struct SearchRequestBody {
    mass: SearchRequestMass,
    lower_mass_tolerance_ppm: i64,
    upper_mass_tolerance_ppm: i64,
    max_variable_modifications: i16,
    modifications: Vec<PTM>,
    taxonomy_id: Option<i64>,
    proteome_id: Option<String>,
    is_reviewed: Option<bool>,
    resolve_modifications: Option<bool>,
}

/// Struct to deserialize the query parameters for peptide search
///
#[derive(serde::Deserialize)]
pub struct SearchRequestQuery {
    #[serde(default)]
    is_download: bool,
}

#[allow(clippy::tabs_in_doc_comments)]
/// Returns a stream of peptides matching the given parameters.
/// If the taxonomy ID is given and has sub taxonomies, the sub taxonomies are also searched.
/// Important: Peptides only contain the accession of the proteins of origin.
///
/// # Arguments
/// * `db_client` - The database client
/// * `configuration` - The configuration
/// * `payload` - The request body
///
/// # API
/// ## Request
/// * Path: `/api/peptides/search`
/// * Method: `POST`
/// * Headers:
///     * `Content-Type`: `application/json`
///     * `Accept`: `application/json`, `text/tab-separated-values`, `text/plain`, `text/proforma` (optional, default: `application/json`, controls the output format)
/// * Query:
///     * `is_download`: `bool` (optional, default: `false`, if true set the Content-Disposition header to download the response instead of showing it in the browser)
/// * Body:
///     ```json
///     {
///         # Mass to search for
///         "mass": 2006.988396539,
///         # Mass can also be given as tuple of m/z and charge
///         # "mass": [2006.988396539, 2],
///         # Lower mass tolerance in ppm
///         "lower_mass_tolerance_ppm": 5,
///         # Upper mass tolerance in ppm
///         "upper_mass_tolerance_ppm": 5,
///         # Optional parameters for digestion, if one of them is skipped
///         "max_variable_modifications": 3,
///         # List of post translational modifications
///         "modifications": [
///             {
///                 "name": "Mod something",
///                 "amino_acid": "C",
///                 "mass_delta": 42.0,
///                 "mod_type": Static,     # Type: Static, Variable
///                 "position": Anywhere    # Position: Anywhere, Terminus-N, Terminus-C, Bond-C, Bond-N
///             }
///         ],
///         # Optional taxonomy ID to search for
///         "taxonomy_id": 10090,
///         # Optional proteome ID to search for
///         "proteome_id": "UP000000589",
///         # Optional flag to search only reviewed proteins
///         "is_reviewed": true
///         # Optional: If the PTMs in seqeunces should be resolved
///         "resolve_modifications": true
///     }
///     ```
///     Deserialized into [SearchRequestBody]
///
/// ## Response
/// ### `application/json`
/// ```json
/// [
///    peptide_1,
///    peptide_2,
///    ...
/// ]
/// ```
/// Peptides are formatted as mentioned in the [`get_peptide`-endpoint](get_peptide) + attribute `additional_sequences` if `resolve_modifications` is true.
///
/// ### `text/tsv`
/// ```tsv
/// partition	mass	sequence	missed_cleavages	aa_counts	proteins	is_swiss_prot	is_trembl	taxonomy_ids	unique_taxonomy_ids	proteome_ids
/// 51\t2006.988396539\tNLETPSCKNGFLLDGFPR\t1,0,0,1,1,1,2,2,0,0,0,1,3,0,2,0,2,0,1,1,1,0,0,0,0,0,0\tQ9WTP6\ttrue\tfalse\t10090\t10090\tUP000000589
/// ...
/// ```
///
/// ### `text/plain`
/// ```text
/// sequence_1
/// sequence_2
/// ...
///
/// ### `text/proforma`
/// Note: The output will only contain the mass shifts but not the modification ID.
///
/// ```text
/// <57.021464@C>NCLETPSCKNGFLLDGFPR
/// <57.021464@C>NCLETPSCKNGFLLM[+15.994915]DGFPR
/// ...
/// ```
///
pub async fn post_search(
    State(app_state): State<Arc<AppState>>,
    headers: HeaderMap,
    Query(query): Query<SearchRequestQuery>,
    Json(payload): Json<SearchRequestBody>,
) -> Result<(StatusCode, HeaderMap, Body), WebError> {
    let default_header: HeaderValue = match HeaderValue::from_str(DEFAULT_POST_SEARCH_ACCEPT_HEADER)
    {
        Ok(header) => header,
        Err(err) => {
            return Ok((
                StatusCode::INTERNAL_SERVER_ERROR,
                HeaderMap::new(),
                Body::from(format!("!!! Error while setting default header: {:?}", err)),
            ));
        }
    };

    let accept_header = headers
        .get(ACCEPT)
        .unwrap_or(&default_header)
        .to_str()
        .unwrap_or(DEFAULT_POST_SEARCH_ACCEPT_HEADER)
        .to_string();

    search(app_state, payload, accept_header, query.is_download).await
}

/// This is basically the same as [post_search], but the payload and mime type are base64 encoded in the URL.
/// This is useful for GET requests, where the body is not allowed. E.g. for initializing browser downloads via JS or WASM
/// where the usual blob-download is not possible or would be too large
///
/// # API
/// ## Request
/// * Path: `/api/peptides/search/:playload/:accept`
///     * `:accept`: Allowed are the same values like in [post_search] Accept-header, but urlsafe encoded
///     * `:payload`: The payload as urlsafe base64 encoded JSON string, see [post_search]
/// * Method: `GET`
///
///
pub async fn get_search(
    State(app_state): State<Arc<AppState>>,
    Query(query): Query<SearchRequestQuery>,
    Path((payload, accept)): Path<(String, String)>,
) -> Result<(StatusCode, HeaderMap, Body), WebError> {
    // Decode payload from URL saftyness
    let payload: String = match urldecode(payload.as_str()) {
        Ok(payload) => payload.into_owned(),
        Err(err) => {
            return Ok((
                StatusCode::BAD_REQUEST,
                HeaderMap::new(),
                Body::from(format!(
                    "!!! Error while decoding payload form URL: {:?}",
                    err
                )),
            ));
        }
    };

    // Decode payload from base64
    let payload: Vec<u8> = match Base64Standard.decode(payload.as_bytes()) {
        Ok(payload) => payload,
        Err(err) => {
            return Ok((
                StatusCode::BAD_REQUEST,
                HeaderMap::new(),
                Body::from(format!(
                    "!!! Error while decoding payload from base64: {:?}",
                    err
                )),
            ));
        }
    };

    // Create string from decoded bytes
    let payload = match String::from_utf8(payload) {
        Ok(payload) => payload,
        Err(err) => {
            return Ok((
                StatusCode::BAD_REQUEST,
                HeaderMap::new(),
                Body::from(format!(
                    "!!! Error while decoding payload from bytes: {:?}",
                    err
                )),
            ));
        }
    };

    // Deserialize payload
    let payload: SearchRequestBody = match serde_json::from_str(payload.as_str()) {
        Ok(payload) => payload,
        Err(err) => {
            return Ok((
                StatusCode::BAD_REQUEST,
                HeaderMap::new(),
                Body::from(format!("!!! Error while deserializing payload: {:?}", err)),
            ));
        }
    };

    // Decode accept from URL saftyness
    let accept: String = match urldecode(accept.as_str()) {
        Ok(accept) => accept.into_owned(),
        Err(err) => {
            return Ok((
                StatusCode::BAD_REQUEST,
                HeaderMap::new(),
                Body::from(format!(
                    "!!! Error while decoding payload form URL: {:?}",
                    err
                )),
            ));
        }
    };

    search(app_state, payload, accept, query.is_download).await
}

async fn search(
    app_state: Arc<AppState>,
    payload: SearchRequestBody,
    accept_header: String,
    is_download: bool,
) -> Result<(StatusCode, HeaderMap, Body), WebError> {
    let calculated_mass = match payload.mass {
        SearchRequestMass::ThompsonCharge(mass, charge) => mass_to_charge_to_dalton(mass, charge),
        SearchRequestMass::Dalton(mass) => mass,
    };

    let mut taxonomy_ids: Option<Vec<i64>> = None;
    if let Some(taxonomy_id) = payload.taxonomy_id {
        // Check if taxonomy exists
        if app_state
            .get_taxonomy_tree_as_ref()
            .get_taxonomy(taxonomy_id as u64)
            .is_none()
        {
            return Ok((
                StatusCode::BAD_REQUEST,
                HeaderMap::new(),
                Body::from(format!(
                    "!!! Taxonomy with id {} does not exist",
                    taxonomy_id
                )),
            ));
        }

        let mut ids: Vec<i64> = match app_state
            .get_taxonomy_tree_as_ref()
            .get_sub_taxonomies(taxonomy_id as u64)
        {
            Some(taxonomies) => taxonomies.iter().map(|tax| tax.get_id() as i64).collect(),
            None => Vec::new(),
        };
        ids.push(taxonomy_id);
        taxonomy_ids = Some(ids);
    }

    let proteome_ids = payload.proteome_id.map(|proteome_id| vec![proteome_id]);

    let ptm_collection = match PTMCollection::new(&payload.modifications) {
        Ok(collection) => collection,
        Err(err) => {
            return Ok((
                StatusCode::UNPROCESSABLE_ENTITY,
                HeaderMap::new(),
                Body::from(format!("Error while validating PTMs: {:?}", err)),
            ));
        }
    };

    let peptide_stream = match PeptideTable::search(
        app_state.get_db_client(),
        app_state.get_configuration(),
        mass_to_int(calculated_mass),
        payload.lower_mass_tolerance_ppm,
        payload.upper_mass_tolerance_ppm,
        payload.max_variable_modifications as usize,
        taxonomy_ids,
        proteome_ids,
        payload.is_reviewed,
        &ptm_collection,
        payload.resolve_modifications.unwrap_or(false),
    )
    .await
    {
        Ok(peptide_stream) => peptide_stream,
        Err(err) => {
            return Ok((
                StatusCode::INTERNAL_SERVER_ERROR,
                HeaderMap::new(),
                Body::from(format!("Error while searching for peptides: {:?}", err)),
            ));
        }
    };

    let mut headers = HeaderMap::new();
    if is_download {
        let file_extension = match accept_header.as_str() {
            "application/json" => ".json",
            "text/tab-separated-values" => ".tsv",
            "text/plain" => ".txt",
            _ => "",
        };

        headers.insert(
            header::CONTENT_DISPOSITION,
            HeaderValue::from_str(
                format!(
                    "attachment; filename=\"macpepdb_peptides_download{}\"",
                    file_extension
                )
                .as_str(),
            )
            .unwrap(),
        );
    }

    let (status_code, headers, body) = match accept_header.as_str() {
        "application/json" => (
            StatusCode::OK,
            headers,
            Body::from_stream(stream! {
                // start json array
                yield Ok("[".to_string());
                // set delimiter to empty string for first element
                let mut delimiter = "".to_string();
                // stream peptides
                for await peptide in peptide_stream {
                    yield Ok(delimiter.to_owned());
                    // handle error on underlaying stream
                    if let Err(err) = peptide {
                        error!("{:?}", err);
                        yield Err(format!("!!! {:?}", err));
                        break;
                    }
                    let peptide = peptide.unwrap();
                    match serde_json::to_string(&peptide) {
                        Ok(json) => yield Ok(json),
                        Err(err) => {
                            error!("{:?}", err);
                            yield Err(format!("!!! {:?}", err));
                            break;
                        }
                    };
                    // set delimiter to comma after first element
                    delimiter = ",".to_string();
                }
                // end json array
                yield Ok("]".to_string());
            }),
        ),
        "text/tab-separated-values" => (
            StatusCode::OK,
            headers,
            Body::from_stream(stream! {
                let mut has_headers = true;
                for await peptide in peptide_stream {
                    // handle error on underlaying stream
                    if let Err(err) = peptide {
                        error!("{:?}", err);
                        yield Err(format!("!!! {:?}", err));
                        break;
                    }
                    let peptide = match peptide {
                        Ok(peptide) => peptide,
                        Err(err) => {
                            error!("{:?}", err);
                            yield Err(format!("!!! {:?}", err));
                            break;
                        }
                    };
                    let peptide = TsvPeptide::from(peptide);
                    let mut writer = csv::WriterBuilder::new().has_headers(has_headers).delimiter(b'\t').from_writer(vec![]);
                    match writer.serialize(peptide) {
                        Ok(_) => (),
                        Err(err) => {
                            error!("{:?}", err);
                            yield Err(format!("!!! {:?}", err));
                            break;
                        }
                    };
                    match writer.into_inner() {
                        Ok(csv) => yield Ok(csv),
                        Err(err) => {
                            error!("{:?}", err);
                            yield Err(format!("!!! {:?}", err));
                            break;
                        }
                    };
                    has_headers = false;
                }
                yield Ok(vec![b'\n']);
            }),
        ),
        "text/plain" => (
            StatusCode::OK,
            headers,
            Body::from_stream(stream! {
                let mut delimiter = "".to_string();
                for await peptide in peptide_stream {
                    yield Ok(delimiter.to_owned());
                    yield match peptide {
                        Ok(peptide) => Ok(peptide.get_sequence().to_owned()),
                        Err(err) => Err(format!("!!! {:?}", err)),
                    };
                    delimiter = "\n".to_string();
                }
                yield Ok(delimiter);
            }),
        ),
        "text/proforma" => (
            StatusCode::OK,
            headers,
            Body::from_stream(stream! {
                let mut delimiter = "".to_string();
                for await peptide in peptide_stream {
                    yield Ok(delimiter.to_owned());
                    match peptide {
                        Ok(peptide) => {
                            if !peptide.get_additional_sequences().is_empty() {
                                yield Ok(peptide.get_additional_sequences().join("\n"));
                            } else {
                                yield Ok(peptide.get_sequence().to_owned());
                            }
                        }
                        Err(err) => {
                            error!("{:?}", err);
                            yield Err(format!("!!! {:?}", err));
                            break;
                        }
                    };
                    delimiter = "\n".to_string();
                }
            }),
        ),
        _ => (
            StatusCode::NOT_ACCEPTABLE,
            HeaderMap::new(),
            Body::from_stream(stream! {
                yield Err::<String, String>("!!! Unsupported accept header".to_string());
            }),
        ),
    };
    Ok((status_code, headers, body))
}