tests/testthat/test-metadata.R

# Automatically generated by openapi-generator (https://openapi-generator.tech)
# Please update as you see appropriate

context("Test Metadata")

model.instance <- Metadata$new()

ref.json <- '{
    "prefix" : "MTD",
    "mzTab-version" : "2.0.0-M",
    "mzTab-ID" : "ISAS-2018-1234",
    "title" : null,
    "description" : "Minimal proposed sample file for identification and quantification of lipids",
    "contact" : null,
    "publication" : [ {
      "id" : 1,
      "publicationItems" : [ {
        "type" : "pubmed",
        "accession" : "29039908"
      }, {
        "type" : "doi",
        "accession" : "10.1021/acs.analchem.7b03576"
      } ]
    } ],
    "uri" : null,
    "external_study_uri" : [ {
      "id" : 1,
      "value" : "file:///C:/data/prm.sky.zip"
    } ],
    "instrument" : [ {
      "id" : 1,
      "name" : {
        "id" : null,
        "cv_label" : "MS",
        "cv_accession" : "MS:1001911",
        "name" : "Q Exactive",
        "value" : null
      },
      "source" : {
        "id" : null,
        "cv_label" : "MS",
        "cv_accession" : "MS:1000073",
        "name" : "electrospray ionization",
        "value" : null
      },
      "analyzer" : [ {
        "id" : null,
        "cv_label" : "MS",
        "cv_accession" : "MS:1000081",
        "name" : "quadrupole",
        "value" : null
      }, {
        "id" : null,
        "cv_label" : "MS",
        "cv_accession" : "MS:1000484",
        "name" : "orbitrap",
        "value" : null
      } ],
      "detector" : {
        "id" : null,
        "cv_label" : "MS",
        "cv_accession" : "MS:1000624",
        "name" : "inductive detector",
        "value" : null
      }
    } ],
    "quantification_method" : {
      "id" : null,
      "cv_label" : "MS",
      "cv_accession" : "MS:1001838",
      "name" : "SRM quantitation analysis",
      "value" : null
    },
    "sample" : [ {
      "id" : 1,
      "name" : "QEx-1273-prm-sp1",
      "custom" : null,
      "species" : null,
      "tissue" : null,
      "cell_type" : null,
      "disease" : null,
      "description" : "Sphingolipids with concentration reported as picomolar per mg of protein, abundances are reported after calibration correction."
    } ],
    "sample_processing" : [ {
      "id" : 1,
      "sampleProcessing" : [ {
        "id" : null,
        "cv_label" : "MSIO",
        "cv_accession" : "MSIO:0000148",
        "name" : "high performance liquid chromatography",
        "value" : null
      } ]
    } ],
    "software" : [ {
      "id" : 1,
      "parameter" : {
        "id" : null,
        "cv_label" : "MS",
        "cv_accession" : "MS:1000532",
        "name" : "Xcalibur",
        "value" : "2.8-280502/2.8.1.2806"
      },
      "setting" : [ "ScheduledSRMWindow: 2 min", "CycleTime: 2 s" ]
    }, {
      "id" : 2,
      "parameter" : {
        "id" : null,
        "cv_label" : "MS",
        "cv_accession" : "MS:1000922",
        "name" : "Skyline",
        "value" : "3.5.0.9319"
      },
      "setting" : [ "MSMSmassrange: (50.0, 1800.0)" ]
    } ],
    "derivatization_agent" : null,
    "ms_run" : [ {
      "id" : 1,
      "name" : null,
      "location" : "file:///C:/data/QEx-1273-prm-sp1.mzML",
      "instrument_ref" : 1,
      "format" : {
        "id" : null,
        "cv_label" : "MS",
        "cv_accession" : "MS:1000584",
        "name" : "mzML file",
        "value" : null
      },
      "id_format" : {
        "id" : null,
        "cv_label" : "MS",
        "cv_accession" : "MS:1000768",
        "name" : "Thermo nativeID format",
        "value" : null
      },
      "fragmentation_method" : null,
      "scan_polarity" : [ {
        "id" : null,
        "cv_label" : "MS",
        "cv_accession" : "MS:1000130",
        "name" : "positive scan",
        "value" : null
      } ],
      "hash" : null,
      "hash_method" : null
    } ],
    "assay" : [ {
      "id" : 1,
      "name" : "Description of assay 1",
      "custom" : null,
      "external_uri" : null,
      "sample_ref" : 1,
      "ms_run_ref" : [ 1 ]
    } ],
    "study_variable" : [ {
      "id" : 1,
      "name" : "Sphingolipid SRM Quantitation",
      "assay_refs" : [ 1 ],
      "average_function" : {
        "id" : null,
        "cv_label" : "MS",
        "cv_accession" : "MS:1002883",
        "name" : "median",
        "value" : null
      },
      "variation_function" : {
        "id" : null,
        "cv_label" : "MS",
        "cv_accession" : "MS:1002885",
        "name" : "standard error",
        "value" : null
      },
      "description" : "sphingolipid srm quantitation",
      "factors" : null
    } ],
    "custom" : null,
    "cv" : [ {
      "id" : 1,
      "label" : "MS",
      "full_name" : "PSI-MS controlled vocabulary",
      "version" : "4.0.18",
      "uri" : "https://github.com/HUPO-PSI/psi-ms-CV/blob/master/psi-ms.obo"
    }, {
      "id" : 2,
      "label" : "MSIO",
      "full_name" : "Metabolomics Standards Initiative Ontology (MSIO)",
      "version" : "1.0.1",
      "uri" : "https://www.ebi.ac.uk/ols/ontologies/msio"
    }, {
      "id" : 3,
      "label" : "UO",
      "full_name" : "Units of Measurement Ontology",
      "version" : "2017-09-25",
      "uri" : "http://purl.obolibrary.org/obo/uo.owl"
    } ],
    "small_molecule-quantification_unit" : {
      "id" : null,
      "cv_label" : "UO",
      "cv_accession" : "UO:0000072",
      "name" : "picomolal",
      "value" : null
    },
    "small_molecule_feature-quantification_unit" : {
      "id" : null,
      "cv_label" : "UO",
      "cv_accession" : "UO:0000072",
      "name" : "picomolal",
      "value" : null
    },
    "small_molecule-identification_reliability" : {
      "id" : null,
      "cv_label" : "MS",
      "cv_accession" : "MS:1002896",
      "name" : "compound identification confidence level",
      "value" : null
    },
    "database" : [ {
      "id" : 1,
      "param" : {
        "id" : null,
        "cv_label" : "",
        "cv_accession" : "",
        "name" : "Pubchem",
        "value" : null
      },
      "prefix" : "PUBCHEM-CPD",
      "version" : "02.12.2017",
      "uri" : "https://www.ncbi.nlm.nih.gov/pccompound"
    }, {
      "id" : 2,
      "param" : {
        "id" : null,
        "cv_label" : "",
        "cv_accession" : "",
        "name" : "LipidMaps",
        "value" : null
      },
      "prefix" : "LM",
      "version" : "2017-12",
      "uri" : "http://www.lipidmaps.org/"
    }, {
      "id" : 3,
      "param" : {
        "id" : null,
        "cv_label" : "",
        "cv_accession" : "",
        "name" : "LipidCreator Transitions",
        "value" : null
      },
      "prefix" : "LCTR",
      "version" : "2018-07",
      "uri" : "https://lifs.isas.de/lipidcreator"
    } ],
    "id_confidence_measure" : [ {
      "id" : 1,
      "cv_label" : "MS",
      "cv_accession" : "MS:1002890",
      "name" : "fragmentation score",
      "value" : null
    } ],
    "colunit-small_molecule" : null,
    "colunit-small_molecule_feature" : null,
    "colunit-small_molecule_evidence" : [ {
      "column_name" : "opt_global_mass_error",
      "param" : {
        "id" : null,
        "cv_label" : "UO",
        "cv_accession" : "UO:0000169",
        "name" : "parts per million",
        "value" : null
      }
    } ]
  }'

test_that("metadata", {
  model.instance <- model.instance$fromJSONString(ref.json)
  # expect_equal(model.instance$`id`, 1)
  # expect_equal(model.instance$`name`, "Sphingolipid SRM Quantitation")
  # expect_equal(length(model.instance$`assay_refs`), 1)
  # expect_equal(model.instance$`assay_refs`[[1]], 1)
  # expect_null(model.instance$`average_function`$id)
  # expect_equal(model.instance$`average_function`$cv_label, "MS")
  # expect_equal(model.instance$`average_function`$cv_accession, "MS:1002883")
  # expect_equal(model.instance$`average_function`$name, "median")
  # expect_null(model.instance$`average_function`$value)
  # expect_null(model.instance$`variation_function`$id)
  # expect_equal(model.instance$`variation_function`$cv_label, "MS")
  # expect_equal(model.instance$`variation_function`$cv_accession, "MS:1002885")
  # expect_equal(model.instance$`variation_function`$name, "standard error")
  # expect_null(model.instance$`variation_function`$value)
  # expect_equal(model.instance$`description`, "sphingolipid srm quantitation")
  # expect_null(model.instance$`factors`)
})

test_that("metadata$toDataFrame works", {
  model.instance <- model.instance$fromJSONString(ref.json)
  df <- model.instance$toDataFrame()
  # expect_equal(df[1,"PREFIX"], "MTD")
  # expect_equal(df[1,"KEY"], "study_variable[1]-name")
  # expect_equal(df[1,"VALUE"], "Sphingolipid SRM Quantitation")
  # expect_equal(df[2,"KEY"], "study_variable[1]-assay_refs")
  # expect_equal(df[2,"VALUE"], "assay[1]|assay[3]")
  # expect_equal(df[3,"KEY"], "study_variable[1]-average_function")
  # expect_equal(df[3,"VALUE"], "[MS, MS:1002883, median, ]")
  # expect_equal(df[4,"KEY"], "study_variable[1]-variation_function")
  # expect_equal(df[4,"VALUE"], "[MS, MS:1002885, standard error, ]")
  # expect_equal(df[5,"KEY"], "study_variable[1]-description")
  # expect_equal(df[5,"VALUE"], "sphingolipid srm quantitation")
})

test_that("metadata$fromDataFrame works", {
  #model.instance <- model.instance$fromDataFrame(ref.json)
  #df <- model.instance$toDataFrame()
  # expect_equal(df[1,"PREFIX"], "MTD")
  # expect_equal(df[1,"KEY"], "study_variable[1]-name")
  # expect_equal(df[1,"VALUE"], "Sphingolipid SRM Quantitation")
  # expect_equal(df[2,"KEY"], "study_variable[1]-assay_refs")
  # expect_equal(df[2,"VALUE"], "assay[1]|assay[3]")
  # expect_equal(df[3,"KEY"], "study_variable[1]-average_function")
  # expect_equal(df[3,"VALUE"], "[MS, MS:1002883, median, ]")
  # expect_equal(df[4,"KEY"], "study_variable[1]-variation_function")
  # expect_equal(df[4,"VALUE"], "[MS, MS:1002885, standard error, ]")
  # expect_equal(df[5,"KEY"], "study_variable[1]-description")
  # expect_equal(df[5,"VALUE"], "sphingolipid srm quantitation")
})
lifs-tools/rmzTab-m documentation built on Jan. 26, 2023, 4:45 p.m.