Skip to content

Instantly share code, notes, and snippets.

@azkalot1
Created February 12, 2019 22:32
Show Gist options
  • Save azkalot1/af65d36d3b28b723506a769f5f931934 to your computer and use it in GitHub Desktop.
Save azkalot1/af65d36d3b28b723506a769f5f931934 to your computer and use it in GitHub Desktop.
#reading 10X data as stated at support.10xgenomics.com/single-cell-gene-expression/software/pipelines/latest/output/matrices
matrix_dir = "filtered_feature_bc_matrix"
mat = scipy.io.mmread(os.path.join(matrix_dir, "matrix.mtx"))
mat = np.array(mat.todense())
features_path = os.path.join(matrix_dir, "features.tsv")
annotation = pd.read_csv(features_path,sep='\t',header=None)
annotation.columns = ['feature_ids','gene_names','feature_types']
barcodes_path = os.path.join(matrix_dir, "barcodes.tsv")
barcodes = [line.strip() for line in open(barcodes_path, 'r')]
print('Matrix dimensionality {}'.format(mat.shape))
mat = mat.T #becase we want (samples,features) matrix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment