mx is command line tool (and python library) to facilitate the analysis of single-cell RNAseq data.
The development version can be installed with
pip install git+https://github.com/sbooeshaghi/mxmx consists of 10 subcommands:
usage: mx [-h] [--verbose] <CMD> ...
mx 0.0.0: handle with mx files
positional arguments:
<CMD>
assign Run assignment algorithm
clean Drop rows/cols with all zeros
convert Convert matrix
diff Differential Expression
extract Extract submatrix of genes
filter Filter cells from matrix
inspect Inspect matrix
normalize Normalize matrix with PFlog1pPF
plot Plot figures for a matrix
split Split matrix by assignments
optional arguments:
-h, --help show this help message and exit
--verbose Print debugging informationmx operates on mtx files. Objects must be compatible with each other when running mx and the following assumptions must hold
matrix.mtxis a CSR Matrix Market file (rows correspond to barcodes, columns to genes)barcodes.txtis a single column text file that must have the same length as the number of rows inmatrix.mtxgenes.txtis a single column text file that must have the same length as the number of columns inmatrix.mtxassignments.txtis a single column text file that must have the same length as the number of barcodes in thematrix.mtxused inmx assigntargets.txta single column text file of genes corresponding to genes in thegenes.txtfile (used in the extract command)groups.txta single column text file of cell types corresponding to the same number of rows in theec fileused in themx assigncommand.
Run a modified Gaussian Mixture model to assign cells to cell types defined in a markers.txt file.
mx assign -g GROUPS -gi GENES_IN -bi BCS_IN -e EC -o OUTPUT matrix.mtx-g GROUPSis the list of cell types-gi GENES_INis a single column text file containing a list of marker genes (same length as matrix width)-bi BCS_INis a single column text file containing barcodes (same length as matrix length)-e ECis the mapping of celltype groups to marker genes in theecformat (see ec for more information)-o OUTPUTis a path to save the output file for the assignments (one per barcode)matrix.mtxpath to sparse matrix file
$ mx assign -g groups.txt -gi genes.txt -bi barcodes.txt -e matrix.ec -o assignments.txt matrix.mtxRemove rows and columns with all zeros from matrix.mtx.
mx clean -gi GENES_IN -go GENES_OUT -bi BCS_IN -bo BCS_OUT -o OUTPUT [--bad] matrix.mtx- optionally,
--badoutputs txt file with bad genes and barcodes -gi GENES_INis a single column text file containing genes (same length as matrix width)-go GENES_OUTis the path to save a single column text file containing genes that pass the cleaning step-bi BCS_INis a single column text file containing barcodes (same length as matrix length)-bo BCS_OUTis the path to save a single column text file containing barcodes that pass the cleaning step-o OUTPUTis the path to save the matrix with rows and columns that pass the cleaning stepmatrix.mtxpath to sparse matrix file
$ mx clean -gi genes.txt -go clean_genes.txt -bi barcodes.txt -bo clean_barcodes.txt -o clean.mtx matrix.mtxConvert the text representation of the gene count matrix to an h5ad object.
mx convert -o OUTPUT -bi BARCODES_IN -gi GENES_IN [-t filetype] matrix.mtx-o OUTPUTis the path to save the output converted matrix file-bi BARCODES_INis a single column text file containing barcodes (same length as matrix length)-gi GENES_INis a single column text file containing genes (same length as matrix width)-t filetypeselect the filetype to convert the matrix to (defeault:h5ad)matrix.mtxpath to sparse matrix file
$ mx convert -o adata.h5ad -bi barcodes.txt -gi genes.txt matrix.mtxPerform differential expression with a t-test given a set of cell assignments
mx diff -a ASSIGNMENTS -gi GENES_IN -bi BCS_IN -o OUTPUT matrix.mtx-a ASSIGNMENTSis a single column text file of barcode assignments (same length asBCS_IN)-bi BCS_INis a single column text file containing barcodes (same length as matrix length)-gi GENES_INis a single column text file containing genes (same length as matrix width)-o OUTPUTis a path to save the differential expression tablematrix.mtxpath to sparse matrix file
The table output by mx diff has the following columns:
index: the cell typetarget: the gene being testedrank: the rank of the expression of that gene within the cell typennz: the number of non-zero cells within that cell type for thetargetgenennz_frac: the fraction of non-zero cells within that cell type for thetargetgenemean: the mean expression of thetargetgene within that cell typelog_fc: the log fold change for thetargetgene betwen the cells in the cell type and the rest of the cellsp_raw: the raw pvalue from the t-testp_corr: the bonferroni corrected pvalues
$ mx diff -a assignments.txt -gi genes.txt -b barcodes.txt -o diff.txt norm.mtxExtract a submatrix on a given list of target genes.
mx extract -t TARGETS -gi GENES_IN -go GENES_OUT -o OUTPUT matrix.mtx-t TARGETSis a single column text file corresponding to the list of genes you wish to have in the submatrix (extracted from the full matrix)-gi GENES_INis a single column text file containing genes in the matrix-go GENES_OUTis the path to save a single column text file of the extracted genes (should correspond to the targets file)-o OUTPUTis the path to save the submatrix containing on the genes in the targets filematrix.mtxpath to sparse matrix file
$ mx extract -t targets.txt -gi genes.txt -go extract_genes.txt -o extract.mtx matrix.mtxFilter cells based on the maximum entropy of a 1-D Gaussain Mixture model.
mx filter -bi BCS_IN -bo BCS_OUT -o OUTPUT matrix.mtx-bi BCS_INa single column text file containing barcodes (same length as matrix length)-bo BCS_OUTis the path to save the filtered barcodes.txt file-o OUTPUTis the path to save the matrix containing only the filtered barcodes.txtmatrix.mtxpath to sparse matrix file
$ mx filter -bi barcodes.txt -bo filter_barcodes.txt -o filter.mtx matrix.mtxGenerate matrix level quality control metrics.
mx inspect -o OUTPUT -gi GENES_IN -a {rows,cols,all} -bi BCS_IN matrix.mtx-o OUTPUTis the path to save the inspect file (either json or txt file depending on-a)-gi GENES_INa single column text file containing genes (same length as matrix width)-bi BCS_INa single column text file containing barcodes (same length as matrix length)-a {rows,cols,all}the axis along which to inspect the matrix (default:all)matrix.mtxpath to sparse matrix file
The output file has the following structure
- when
-a allncells: number of rows in the matrix,ngenes: number of columns in the matrix,nvals: number of non-zero values in the matrix,density:nvals/(ncells*ngenes),avg_counts_per_cell: average total counts per cell,avg_counts_per_gene: average total counts per cell,avg_nnzero_per_cell: average number of nonzero entries per cell,avg_nnzero_per_gene: average number of nonzero entries per gene,min_cell: minimum count for cell with fewest counts,max_cell: maximum count for cell with most counts,total_counts: total count sum across all entries,overdispersion:alphaparameter for a polynomial fit to the mean variance relation for negative binomial data (sigma=alpha*mu^2 +mu),s_index: the number of cells with at least that many number of counts,
- when
-a rows/colscounts_min: The minimum count in that row/columncounts_max: The maximum count in that row/columncounts_sum: The sum of counts in that row/columncounts_mean: The mean of counts in that row/columncounts_nnzero: The number of non-zero entries in that row/columncounts_variance: The variance of counts in that row/column
# inspect columns
$ mx inspect -a cols -o md_genes.txt -gi genes.txt -bi barcodes.txt matrix.mtx
# inspect rows
$ mx inspect -a rows -o md_bcs.txt -gi genes.txt -bi barcodes.txt matrix.mtx
# inspect whole matrix
$ mx inspect -a all -o inspect.json -gi genes.txt -bi barcodes.txt matrix.mtxNormalize the counts of the matrix.
mx normalize -o OUTPUT [-m {PF,log1pPF,rank}] matrix.mtx-o OUTPUTis the path to save the normalized matrix[-m {PF,log1pPF,rank}]is the method to employed to normalize the matrixPF: proportional fitting (row normalize to unity, multiply by avg. UMI count across all cells)log1pPF: proportional fitting followed by log1prank: ranking procedure along the cells
matrix.mtxpath to sparse matrix file
$ mx norm -o normalize.mtx -m log1pPF matrix.mtxPlot figures.
mx plot -o OUTPUT -gi GENES_IN -bi BCS_IN [-m {knee}] matrix.mtx-o OUTPUTis the path to write the figure (png)-gi GENES_INa single column text file containing genes (same length as matrix width)-bi BCS_INa single column text file containing barcodes (same length as matrix length)[-m {knee}]is the method used to generate the plot (currently only implementknee)matrix.mtxpath to sparse matrix file
$ mx plot -o knee.png -m knee -gi genes.txt -bi barcodes.txt matrix.mtxSplit the matrix by assignments.
mx split -a ASSIGNMENTS -gi GENES_IN -bi BCS_IN -o OUTPUT matrix.mtx-a ASSIGNMENTSa single column text file containing assignments (single column, same length asBCS_IN)-gi GENES_INa single column text file containing genes (same length as matrix width)-bi BCS_INa single column text file containing barcodes (same length as matrix length)-o OUTPUTa folder where matrix will be splitmatrix.mtxa sparse matrix file
$ mx split -a assignments.txt -gi genes.txt -bi barcodes.txt -o ./ matrix.mtx