Skip to content

Commit

Permalink
Space Ranger 3.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
10x Genomics authored and caluru committed Dec 6, 2024
0 parents commit 6a159d0
Show file tree
Hide file tree
Showing 784 changed files with 208,134 additions and 0 deletions.
15 changes: 15 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Copyright (c) 2023 10x Genomics

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to use, copy, modify, and/or merge copies of the Software, in both source code and object code format, solely for your internal use, subject to the following conditions:

1. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

2. The above rights granted in the Software may be exercised only in connection with a 10x Genomics Product (defined below), rightfully purchased from 10x Genomics or an authorized reseller, or data generated using such a 10x Genomics Product. A “10X Genomics Product” means, collectively, 10x Genomics branded instruments, reagents, consumables, kits, and labware used in accordance with the 10X Genomics Product Terms and Conditions of Sale or, if applicable, any written contract between you and 10x Genomics. The rights granted may also be exercised in connection with other products when doing so is an integral part of an experiment where the data is generated primarily using a 10x Genomics Product.

3. You agree not to redistribute or sublicense the Software, either in source code or object code format.

4. All derivative works, including any modifications of the Software, shall be subject to all of the restrictions set forth herein.

5. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE, THE USE OR INABILITY TO USE, OR OTHER DEALINGS IN THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

You may not use, propagate or modify the Software, or any derivatives thereof, except as expressly provided herein. Any attempt otherwise to use, propagate or modify it is void, and will automatically terminate your rights under this license.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Space Ranger is a set of analysis pipelines that process 10x Genomics Visium data with brightfield or fluorescence microscope images, allowing users to map the whole transcriptome in a variety of tissues. Space Ranger v3.1 now supports Visium HD.

Please note that this source code is made available only for informational purposes. 10x does not provide support for interpreting, modifying, building, or running this code.

The officially supported release binaries are available at <https://www.10xgenomics.com/support/software/space-ranger/downloads>. Documentation is available at <https://www.10xgenomics.com/support/software/space-ranger>.
50 changes: 50 additions & 0 deletions bin/_spaceranger_internal
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash
#
# Copyright (c) 2017 10x Genomics, Inc. All rights reserved.
#
# Main driver for all Cell Ranger subcommands.
#

PRODUCT=spaceranger
SUBCMDS=(
mkfastq
--
count
aggr
mat2csv
--
mkgtf
mkref
--
testrun
upload
sitecheck
)

TENX_SCRIPTDIR=$(readlink -f "$0")
TENX_SCRIPTDIR=$(dirname "$TENX_SCRIPTDIR")
export TENX_SCRIPTDIR

# Capture the user-supplied sub-command and export the correct
# subcommand directory
SUBCMD="$1"

if [[ "$SUBCMD" == "dry" ]]; then
export TENX_DRYMODE=true
shift 1
SUBCMD="$1"
export TENX_SUBCMD="$1"
fi

if [ -f "$TENX_SCRIPTDIR/rna/$SUBCMD" ]; then
export TENX_SUBCMDDIR="$TENX_SCRIPTDIR/rna"
elif [ -f "$TENX_SCRIPTDIR/spatial_rna/$SUBCMD" ]; then
export TENX_SUBCMDDIR="$TENX_SCRIPTDIR/spatial_rna"
else
export TENX_SUBCMDDIR=/dev/null
fi

echo "$TENX_SCRIPTDIR"

# shellcheck source=tenkit/common/_master
source "$TENX_SCRIPTDIR/tenkit/common/_master"
22 changes: 22 additions & 0 deletions bin/rna/_includes
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
#
# Copyright (c) 2017 10x Genomics, Inc. All rights reserved.
#
# Cell Ranger common docopt strings and options processing functions.
#

# shellcheck source=../tenkit/common/_includes
source "$TENX_SCRIPTDIR/tenkit/common/_includes"

function process_options_sample_info {
# --description
if [ -n "$description" ]; then
sample_desc="\"$description\""
else
sample_desc=\"\"
fi
}

read -d '' DOCOPT_OPTIONS_SAMPLE_INFO <<EOF
--description=TEXT Sample description to embed in output files.
EOF
110 changes: 110 additions & 0 deletions bin/rna/mat2csv_lib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/usr/bin/env python3
#
# Copyright (c) 2019 10X Genomics, Inc. All rights reserved.
#

"""Tool for converting feature-barcode matrices from sparse format to dense.
CSV format, for use by external programs.
The commands below should be preceded by '{cmd}':
Usage:
mat2csv <input_path> <output_csv> [--genome=GENOME]
mat2csv -h | --help | --version
Arguments:
input_path Path to a {product} feature-barcode matrix. Can be
either a feature-barcode h5 file (recommended) or a
path to a MEX {product} output folder.
output_csv Output CSV file.
Options:
--genome=GENOME Specify which genome to extract. This only applies to
multi-genome h5 input files.
-h --help Show this message.
--version Show version.
"""

from __future__ import annotations

import os
import pathlib
import sys

import docopt

import cellranger.cr_io as cr_io
from cellranger.matrix import CountMatrix
from cellranger.mtx_to_matrix_converter import load_mtx, save_dense_csv
from cellranger.products import get_cmd_names


def _parse_args(product_name):
product, cmd = get_cmd_names(product_name)

version = "{} {} {}\n{}".format(
product_name,
os.getenv("TENX_SUBCMD", ""),
os.getenv("TENX_VERSION", ""),
os.getenv("TENX_COPYRIGHT", ""),
)
return docopt.docopt(__doc__.format(cmd=cmd, product=product), version=version)


def main():
args = _parse_args(os.getenv("TENX_PRODUCT", ""))

output_csv = pathlib.Path(cr_io.get_output_path(args["<output_csv>"]))
input_path = args["<input_path>"]
genome = args["--genome"]

if input_path.endswith(".h5"):
input_path = cr_io.get_input_path(input_path)
gbm = CountMatrix.load_h5_file(input_path)
else:
input_path = pathlib.Path(cr_io.get_input_path(input_path, is_dir=True))
gbm = load_mtx(input_path)
if genome is not None:
sys.exit(
"The '--genome' argument can only be use with .h5 input files, "
"not with MEX directories"
)

if genome is None:
matrix = gbm
else:
genomes = gbm.get_genomes()
if genome not in genomes:
sys.exit(f"Genome '{genome}' not found (genomes available: {genomes})")
matrix = gbm.select_features_by_genome(genome)

num_features, num_barcodes, num_entries = (
matrix.features_dim,
matrix.bcs_dim,
matrix.get_num_nonzero(),
)
dense_size = num_features * num_barcodes
zero_frac = float(dense_size - num_entries) * 100.0 / float(dense_size)
print(
"""
WARNING: this matrix has %d x %d (%d total) elements, %f%% of which are zero.
Converting it to dense CSV format may be very slow and memory intensive.
Moreover, other programs (e.g. Excel) may be unable to load it due to its size.
To cancel this command, press <control key> + C.
If you need to inspect the data, we recommend using Loupe Browser.
"""
% (num_features, num_barcodes, dense_size, zero_frac)
)
sys.stdout.flush()

try:
save_dense_csv(matrix, output_csv)
except KeyboardInterrupt:
if output_csv.exists():
output_csv.unlink()


if __name__ == "__main__":
main()
75 changes: 75 additions & 0 deletions bin/rna/mkgtf_lib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env python3
#
# Copyright (c) 2016 10x Genomics, Inc. All rights reserved.
#

"""Genes GTF tool for 10x Genomics {product}.
Filter user-supplied GTF files for use as {product}-compatible
genes files for mkref tool.
The commands below should be preceded by '{cmd}':
Usage:
mkgtf <input_gtf> <output_gtf> [--attribute=KEY:VALUE...]
mkgtf -h | --help | --version
Arguments:
input_gtf Path to input genes GTF file.
output_gtf Path to filtered output genes GTF file.
Options:
--attribute=<key:value>
Key-value pair in attributes field to be kept in the GTF
file.
-h --help Show this message.
--version Show version.
"""

from __future__ import annotations

import collections
import os
import sys

import docopt

import cellranger.cr_io as cr_io
import cellranger.reference as cr_reference
from cellranger.products import get_cmd_names


def _parse_args(product_name):
version = "{} {} {}\n{}".format(
product_name,
os.getenv("TENX_SUBCMD", ""),
os.getenv("TENX_VERSION", ""),
os.getenv("TENX_COPYRIGHT", ""),
)
product, cmd = get_cmd_names(product_name)

return docopt.docopt(__doc__.format(product=product, cmd=cmd), version=version)


def main():
args = _parse_args(os.getenv("TENX_PRODUCT", ""))
input_genes_file = cr_io.get_input_path(args["<input_gtf>"])
output_genes_file = cr_io.get_output_path(args["<output_gtf>"])
attributes_str = args["--attribute"]

attributes = collections.defaultdict(set)
for attribute_str in attributes_str:
parts = attribute_str.split(":")
if len(parts) != 2:
sys.exit(f"Attribute option must have format <key;value>: {attribute_str}")
key, value = parts
attributes[key].add(value)

gtf_builder = cr_reference.GtfBuilder(
input_genes_file, output_genes_file, attributes=attributes
)
gtf_builder.build_gtf()


if __name__ == "__main__":
main()
Loading

0 comments on commit 6a159d0

Please sign in to comment.