Given a data.frame()
of sample information (sample_info
) with
columns capture_area
, group
, and fiji_xml_path
,
expected to have one unique path to Fiji XML output per group, read in
the pixel coordinates from each capture area's tissue_positions.csv
file from SpaceRanger, and transform using the rotation matrix specified
by Fiji https://imagej.net/software/fiji/.
Write one new tissue_positions.csv
file per group.
prep_fiji_coords(sample_info, out_dir)
A data.frame()
with columns capture_area
,
group
, fiji_xml_path
, fiji_image_path
,
spaceranger_dir
, intra_group_scalar
, and
group_hires_scalef
. The last two are made by rescale_fiji_inputs()
.
A character(1)
vector giving a path to a directory to
place the output pixel coordinates CSVs. Provided the parent directory
exists, out_dir
will be created if necessary.
This function returns a character()
with the file paths to the
tissue_positions.csv
files it created.
if (file.exists("sample_info.rds")) {
sample_info <- readRDS("sample_info.rds")
} else {
sample_info <- dplyr::tibble(
group = "Br2719",
capture_area = c("V13B23-283_A1", "V13B23-283_C1", "V13B23-283_D1")
)
# Add 'spaceranger_dir' column
sr_dir <- tempdir()
temp <- unzip(
spatialLIBD::fetch_data("visiumStitched_brain_spaceranger"),
exdir = sr_dir
)
sample_info$spaceranger_dir <- file.path(
sr_dir, sample_info$capture_area, "outs", "spatial"
)
# Add Fiji-output-related columns
fiji_dir <- tempdir()
temp <- unzip(
spatialLIBD::fetch_data("visiumStitched_brain_Fiji_out"),
exdir = fiji_dir
)
sample_info$fiji_xml_path <- temp[grep("xml$", temp)]
sample_info$fiji_image_path <- temp[grep("png$", temp)]
## Re-size images and add more information to the sample_info
sample_info <- rescale_fiji_inputs(sample_info, out_dir = tempdir())
saveRDS(sample_info, "sample_info.rds")
}
spe_input_dir <- tempdir()
out_file <- prep_fiji_coords(sample_info, out_dir = spe_input_dir)
out_file
#> [1] "/tmp/RtmpAA9v23/Br2719/tissue_positions.csv"
# A file of spatial coordinates for the stitched Br2719 was produced
readr::read_csv(out_file)
#> Rows: 14976 Columns: 6
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (1): key
#> dbl (5): in_tissue, array_row, array_col, pxl_row_in_fullres, pxl_col_in_ful...
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> # A tibble: 14,976 × 6
#> key in_tissue array_row array_col pxl_row_in_fullres pxl_col_in_fullres
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 ACGCCTGA… 1 0 0 52935. 1873.
#> 2 TACCGATC… 1 1 1 52797. 2115.
#> 3 ATTAAAGC… 1 0 2 52658. 1873.
#> 4 GATAAGGG… 1 1 3 52519. 2115.
#> 5 GTGCAAAT… 1 0 4 52381. 1874.
#> 6 TGTTGGCT… 1 1 5 52242. 2115.
#> 7 GCATCCTC… 1 0 6 52104. 1874.
#> 8 GCGAGGGA… 1 1 7 51965. 2115.
#> 9 TGGTACCG… 1 0 8 51826. 1874.
#> 10 GCGCGTTT… 1 1 9 51688. 2115.
#> # ℹ 14,966 more rows