Skip to content

Directory structure outs/ - #87

Merged
lmweber merged 10 commits into
masterfrom
directory_structure
Nov 24, 2021
Merged

lmweber merged 10 commits into
masterfrom
directory_structure

Conversation

@lmweber

@lmweber lmweber commented Oct 27, 2021

Copy link
Copy Markdown
Collaborator

Here is my updated solution for the outs/ directory structure issue discussed in #76 and #78.

This is now much simpler and shouldn't break anyone's existing code. The main change is to add the following in read10xVisium(), i.e. add the outs/ directory automatically if it is not included by the user in the samples input:

# add "outs/" directory if not already included
if (!(all(basename(samples) == "outs"))) {
    samples <- file.path(samples, "outs")
}

This will make things easier for new users who are not familiar with the outs/ directory structure from Space Ranger. At the same time, all existing code (where users include the outs/ manually) will still work.

The rest of the updates are:

  • move example files in extdata to include the outs/ directory in the correct place (e.g. section1/outs/raw_feature_bc_matrix instead of section1/raw_feature_bc_matrix) so all the examples still work. Previously the outs/ was missing here, which is inconsistent with the directory structure that Space Ranger generates (for a sample named section1).
  • update all examples and tests to include the outs/ directory manually, as was previously required when users used read10xVisium() but was not required in these examples / tests because our example paths in extdata did not have the outs/
  • clarification in the docs on the choice of raw/filtered and .h5 files as suggested by @LTLA in read10xVisium describes the wrong directory structure #76

Since quite a few files are affected, could you please both @drighelli and @HelenaLC have a look and review the changes. Thanks!

@lmweber
lmweber requested review from HelenaLC and drighelli October 27, 2021 23:14
Comment thread R/read10xVisium.R Outdated
#' refers to either "raw" or "filtered" to match the `data` argument.)
#' The base directory "outs/" from Space Ranger can either be included
#' manually in the paths provided in `samples`, or can be ignored;
#' if ignored it will be added automatically. The `.h5` files are

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comma after ignored

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done (here and in vignette)

Comment thread R/read10xVisium.R Outdated
#' · · · · |—scalefactors_json.json \cr
#' · · · · |—tissue_lowres_image.png \cr
#' · · · · |—tissue_positions_list.csv \cr
#' · |—outs \cr

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at this after a long time, I think it would be nice if the - and | aligned, i.e.

#' sample \cr
#' · | — outs \cr
#' · · | — raw/filtered_feature_bc_matrix.h5 \cr
#' · · | — raw/filtered_feature_bc_matrix    \cr
#' · · · | — barcodes.tsv.gz \cr
#' · · · | — features.tsv.gz \cr
#' · · · | — matrix.mtx.gz   \cr
#' · · | — spatial \cr
#' · · · | — scalefactors_json.json    \cr
#' · · · | — tissue_lowres_image.png   \cr
#' · · · | — tissue_positions_list.csv \cr

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done (here and in vignette)

Comment thread R/read10xVisium.R
stop("names of 'samples' should be unique")
names(samples) <- sids

# add "outs/" directory if not already included

@HelenaLC HelenaLC Oct 29, 2021 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks buggy to me - what if one of the basenames is missing the outs, but all others have it? I think we want

i <- basename(samples) != "outs"
samples[i] <- file.path(samples[i], "outs")
# this does nothing if `!any(i)`, 
# so no need for an `if`-statement

Test example:

# old
samples <- c("dir/dir", "dir/dir/outs")
if (!(all(basename(samples) == "outs")))
  samples <- file.path(samples, "outs")
# samples
# > "dir/dir/outs" "dir/dir/outs/outs"

# new
samples <- c("dir/dir", "dir/dir/outs")
i <- basename(samples) != "outs"
samples[i] <- file.path(samples[i], "outs")
# samples
# > "dir/dir/outs" "dir/dir/outs"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is true. I think in practice people will either have added outs/ or not for all samples. But you are right it is better to be more robust to the edge case. Will add unit test too.

@HelenaLC

Copy link
Copy Markdown
Collaborator

General comment: The purpose is to support both with and without the outs subdir specified, and we make a point that both is fine in the documentation.

Perhaps I missed something, but could we actually have i) and example and ii) unit-tests for this? Currently, you added "outs" everywhere in the examples and unit-tests, so we're not actually testing this, and I already found a bug (see above).

@lmweber

lmweber commented Oct 29, 2021

Copy link
Copy Markdown
Collaborator Author

Thanks for comments above @HelenaLC . Agree this is better and more robust. I had thought about an if statement for checking how many samples are affected, but your solution is nice and clean, so have used this.

I have also added examples and a unit test. All the other examples updated in the earlier commits should be consistent with existing code from our users (i.e. outs/ needed to be added manually).

@HelenaLC

Copy link
Copy Markdown
Collaborator

Looks all good to me now. Ready to merge. However, this is v1.3.5 & the current master is at v1.3.6?

@lmweber

lmweber commented Nov 24, 2021

Copy link
Copy Markdown
Collaborator Author

Great, thanks for checking it! I think I left DESCRIPTION alone because it was going to create a merge conflict since I had branched it from an earlier version (1.3.5 vs. 1.3.6). I'll merge it and then check DESCRIPTION again.

@lmweber
lmweber merged commit bf1933f into master Nov 24, 2021
@lmweber
lmweber deleted the directory_structure branch November 24, 2021 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants