tests/testthat/test-get_sample_biobank_data.R

test_that("get_sample_biobank_data() runs without error", {
  skip_if_offline()
  expect_equal(get_sample_biobank_data(itemsPerPage = 1) |>
                 suppressWarnings() |>
                 nrow(),
               1)
})

test_that("process_get_sample_biobank_data_resp_json() prints expected message/warning and returns tibble", {

  # get_sample_biobank_data(tissueSiteDetailIds = "Whole_Blood", itemsPerPage =
  # 2)
  resp_json <- list(
    page = 0,
    pageSize = 2,
    recordsTotal = 72513,
    recordsFiltered = 1329,
    numPages = 665,
    sample = list(
      list(
        materialType = "DNA:DNA Genomic",
        sampleId = "GTEX-1117F-0003-SM-4COJQ",
        sampleIdUpper = "GTEX-1117F-0003-SM-4COJQ",
        sex = "female",
        rin = NULL,
        hasGTExImage = FALSE,
        concentration = 189.67581,
        autolysisScore = NULL,
        analysisRelease = "gtex_v7",
        genotype = "",
        hardyScale = "Slow death",
        pathologyNotes = "",
        subjectId = "GTEX-1117F",
        tissueSiteDetailId = "Whole_Blood",
        hasGenotype = TRUE,
        originalMaterialType = "Whole Blood:Whole Blood",
        aliquotId = "SM-4COJQ",
        tissueSampleId = "GTEX-1117F-0003",
        ageBracket = "60-69",
        brainTissueDonor = TRUE,
        volume = 173.82494,
        hasExpressionData = FALSE,
        hasBRDImage = FALSE,
        tissueSiteDetail = "Whole Blood",
        pathologyNotesCategories = list(),
        amount = 32970.3862927014,
        mass = 0,
        tissueSite = "Blood",
        expression = NULL
      ),
      list(
        materialType = "RNA:Total RNA",
        sampleId = "GTEX-1117F-0005-SM-4COPU",
        sampleIdUpper = "GTEX-1117F-0005-SM-4COPU",
        sex = "female",
        rin = 8.257535,
        hasGTExImage = FALSE,
        concentration = 154,
        autolysisScore = NULL,
        analysisRelease = "gtex_v7",
        genotype = "",
        hardyScale = "Slow death",
        pathologyNotes = "",
        subjectId = "GTEX-1117F",
        tissueSiteDetailId = "Whole_Blood",
        hasGenotype = TRUE,
        originalMaterialType = "Whole Blood:PAXgene Preserved",
        aliquotId = "SM-4COPU",
        tissueSampleId = "GTEX-1117F-0005",
        ageBracket = "60-69",
        brainTissueDonor = TRUE,
        volume = 122.05195,
        hasExpressionData = FALSE,
        hasBRDImage = FALSE,
        tissueSiteDetail = "Whole Blood",
        pathologyNotesCategories = list(),
        amount = 18796.0003,
        mass = NULL,
        tissueSite = "Blood",
        expression = NULL
      )
    )
  )

  # expected message
  expect_message(process_get_sample_biobank_data_resp_json(resp_json) |>
                   suppressWarnings(),
                 "Paging info")

  # expected warning
  expect_warning(process_get_sample_biobank_data_resp_json(resp_json),
                 "exceeds maximum page size")

  # expected output
  expect_equal(process_get_sample_biobank_data_resp_json(resp_json) |>
                 suppressWarnings() |>
                 nrow(),
               2)

})

Try the gtexr package in your browser

Any scripts or data that you put into this service are public.

gtexr documentation built on Sept. 19, 2024, 5:06 p.m.