Skip to content

Instantly share code, notes, and snippets.

@neuromusic
Created March 12, 2019 09:56
Show Gist options
  • Save neuromusic/4185c7b0cde5eac1f18a7763f125c366 to your computer and use it in GitHub Desktop.
Save neuromusic/4185c7b0cde5eac1f18a7763f125c366 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"import loompy"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"# this creates a handle to access the data\n",
"ds = loompy.connect(\"l5_all.agg.loom\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(27998, 265)"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# this is the shape of the data\n",
"ds.shape"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['Accession', 'Gene', '_LogCV', '_LogMean', '_Selected', '_Total', '_Valid']"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ds.row_attrs.keys()"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n",
" 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n",
" 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n",
" 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n",
" 0.00000000e+00, 1.13574905e-02, 2.54719808e-02, 3.82736156e-02,\n",
" 2.35226621e-02, 2.31884058e-02, 3.10173697e-02, 3.86740331e-02,\n",
" 5.51181102e-02, 1.56657963e-01, 3.66972477e-02, 9.52380952e-03,\n",
" 0.00000000e+00, 8.33333333e-02, 3.12500000e-02, 5.37634409e-03,\n",
" 0.00000000e+00, 0.00000000e+00, 9.78915663e-02, 2.08768267e-03,\n",
" 8.26446281e-03, 6.87285223e-03, 2.16836735e-02, 9.58904110e-02,\n",
" 4.49438202e-02, 2.18978102e-02, 3.32845647e-02, 2.85714286e-02,\n",
" 7.87401575e-03, 9.61538462e-03, 2.30946882e-02, 4.03005464e-02,\n",
" 0.00000000e+00, 1.81347150e-02, 2.47524752e-02, 4.03777271e-02,\n",
" 5.42094456e-02, 8.08950086e-02, 1.54545455e-01, 1.82142857e-01,\n",
" 8.64197531e-02, 6.12500000e+00, 6.68151448e-02, 3.44827586e-02,\n",
" 8.82352941e-02, 3.50877193e-02, 5.27131783e-02, 8.63309353e-02,\n",
" 1.65644172e-01, 4.26540284e-02, 9.78260870e-02, 7.01590271e-02,\n",
" 4.25961538e-01, 2.59740260e-03, 0.00000000e+00, 3.12500000e-02,\n",
" 8.33333333e-03, 0.00000000e+00, 3.17460317e-02, 6.38297872e-02,\n",
" 3.40562249e+00, 5.01193317e-02, 1.35802469e-01, 3.27868852e-02,\n",
" 2.10144928e-01, 1.39860140e-02, 5.16431925e-01, 2.97619048e-02,\n",
" 2.84671533e-01, 1.41444867e+00, 1.75800712e+00, 3.30882353e-01,\n",
" 1.28712871e-01, 2.06648697e-02, 1.43884892e-02, 9.67741935e-02,\n",
" 1.13814433e+01, 8.84615385e-01, 9.50000000e-01, 3.33823529e+00,\n",
" 8.50000000e-02, 2.80373832e-02, 0.00000000e+00, 4.61538462e-01,\n",
" 3.50194553e-02, 5.48204159e-02, 5.75373993e-03, 9.14076782e-04,\n",
" 2.40577386e-03, 2.68817204e-03, 1.38888889e-02, 7.61904762e-03,\n",
" 1.47710487e-03, 0.00000000e+00, 3.05810398e-03, 1.32275132e-03,\n",
" 2.19512195e-02, 6.17919670e-03, 5.21739130e-01, 4.50450450e-02,\n",
" 0.00000000e+00, 1.11111111e-03, 0.00000000e+00, 2.83286119e-03,\n",
" 0.00000000e+00, 1.91111111e-01, 6.68896321e-03, 9.20398010e-02,\n",
" 1.77252585e-03, 1.11902340e-02, 0.00000000e+00, 2.76816609e-03,\n",
" 1.33928571e-03, 6.57894737e-03, 0.00000000e+00, 5.23560209e-03,\n",
" 2.08191126e-01, 1.96756499e-01, 4.50450450e-03, 1.16564417e-01,\n",
" 0.00000000e+00, 2.29621125e-03, 0.00000000e+00, 2.89855072e-02,\n",
" 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 3.63636364e+00,\n",
" 6.82539683e-01, 2.20727273e+00, 1.30000000e+00, 1.28571429e+00,\n",
" 1.72727273e+00, 0.00000000e+00, 8.33333333e-02, 2.50000000e-02,\n",
" 9.61538462e-02, 8.26446281e-03, 8.77192982e-03, 8.61111111e+00,\n",
" 1.00909091e+01, 7.76000000e+00, 2.75000000e+00, 7.05882353e-01,\n",
" 1.71190476e+01, 1.74290030e+01, 1.06976744e+01, 8.52592593e+00,\n",
" 1.47970750e+01, 2.01736527e+01, 2.51563422e+01, 0.00000000e+00,\n",
" 0.00000000e+00, 1.40845070e-02, 0.00000000e+00, 3.50877193e-02,\n",
" 3.24675325e-03, 2.68857356e-02, 5.10416667e-01, 8.00000000e-02,\n",
" 7.87401575e-03, 0.00000000e+00, 0.00000000e+00, 2.48062016e-01,\n",
" 5.24691358e-01, 1.64086687e+00, 4.07809111e+00, 2.00000000e+00,\n",
" 4.68831169e+00, 8.16326531e-02, 2.97029703e-02, 3.00000000e-02,\n",
" 2.02020202e-02, 2.10638298e+00, 5.50000000e+00, 9.09090909e-02,\n",
" 0.00000000e+00, 2.59740260e-02, 0.00000000e+00, 2.25563910e-02,\n",
" 1.61290323e-02, 0.00000000e+00, 0.00000000e+00, 5.95238095e-02,\n",
" 3.18181818e+00, 4.59770115e-02, 0.00000000e+00, 2.44897959e-01,\n",
" 1.18803419e+00, 2.70270270e-02, 1.51515152e-02, 1.53846154e-02,\n",
" 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.61725067e-02,\n",
" 0.00000000e+00, 0.00000000e+00, 1.51057402e-02, 1.56695157e-02,\n",
" 1.06470106e-02, 2.68456376e-02, 1.83486239e-02, 1.63934426e-02,\n",
" 1.18518519e-02, 9.71223022e-03, 1.26829268e-02, 1.10132159e-02,\n",
" 1.42857143e-02, 1.87265918e-02, 6.25978091e-03, 8.63309353e-03,\n",
" 4.25531915e-02, 4.74006116e-02, 3.33333333e-02, 1.90010858e-01,\n",
" 4.17246175e-03, 9.75117687e-03, 4.78228039e-03, 1.41523637e-02,\n",
" 1.51869159e-02, 5.57491289e-02, 1.20801034e+00, 4.49275362e-01,\n",
" 1.31004367e-02, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n",
" 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,\n",
" 1.79487179e-01, 0.00000000e+00, 0.00000000e+00, 2.56410256e-02,\n",
" 3.33333333e-02, 5.55555556e-02, 3.12500000e-02, 1.14285714e+00,\n",
" 1.52631579e+01, 3.54838710e-01, 2.63157895e-02, 7.09219858e-03,\n",
" 3.33333333e-02, 1.38888889e-02, 1.13636364e-02, 2.22222222e-02,\n",
" 1.51515152e-02]])"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ds[ds.ra.Gene=='Pvalb',:]"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['ENT9', 'ENT8', 'ENT6', 'ENT5', 'ENT4', 'ENT7', 'ENT3', 'ENT2',\n",
" 'ENT1', 'ENTG1', 'ENTG4', 'ENTG2', 'ENTG3', 'ENTG6', 'ENTG5',\n",
" 'ENTG7', 'ENMFB', 'MOL3', 'MOL2', 'MFOL1', 'MOL1', 'MFOL2',\n",
" 'NFOL1', 'NFOL2', 'COP2', 'COP1', 'HBSER2', 'HBSER1', 'HBSER3',\n",
" 'HBSER4', 'HBSER5', 'TEGLU15', 'TEGLU16', 'TEGLU5', 'TEGLU4',\n",
" 'TEGLU22', 'TEGLU23', 'TEGLU24', 'TEGLU17', 'TEGLU18', 'TEGLU19',\n",
" 'TEGLU2', 'TEGLU3', 'TEGLU14', 'TEGLU13', 'TEGLU21', 'TEGLU10',\n",
" 'TEGLU11', 'TEGLU20', 'TEGLU12', 'TEGLU9', 'TEGLU8', 'TEGLU7',\n",
" 'TEINH10', 'TEINH11', 'TEINH12', 'TEINH9', 'OBINH5', 'TEINH5',\n",
" 'TEINH6', 'TEINH7', 'TEINH8', 'TEINH4', 'TEINH20', 'TEINH13',\n",
" 'TEINH14', 'TEINH16', 'TEINH15', 'TEINH19', 'TEINH21', 'HYPEP7',\n",
" 'HYPEP6', 'DEINH8', 'MBDOP1', 'MBDOP2', 'MEGLU14', 'MEGLU11',\n",
" 'MEGLU10', 'MEGLU9', 'MEGLU8', 'MEGLU7', 'MEGLU6', 'DEGLU5',\n",
" 'MEGLU2', 'MEGLU3', 'MEGLU1', 'MEGLU5', 'MEGLU4', 'DEGLU4',\n",
" 'DEGLU3', 'OBNBL1', 'MBCHO1', 'HBGLU9', 'SCGLU1', 'HBGLU10',\n",
" 'SCGLU10', 'HBGLU2', 'HBGLU3', 'HBNOR', 'HBGLU1', 'DEGLU2',\n",
" 'DEGLU1', 'MSN1', 'MSN2', 'MSN3', 'MSN5', 'MSN4', 'MSN6', 'OEC',\n",
" 'DETPH', 'RGDG', 'RGSZ', 'OPC', 'SZNBL', 'EPMB', 'HYPEN', 'OBDOP2',\n",
" 'OBINH2', 'OBINH3', 'OBINH1', 'OBINH4', 'OBNBL2', 'TEGLU6',\n",
" 'TEGLU1', 'DGGRC2', 'DGGRC1', 'DGNBL1', 'DGNBL2', 'OBNBL3',\n",
" 'HYPEP3', 'HYPEP2', 'HYPEP1', 'CBNBL2', 'CBGRC', 'CR', 'CBNBL1',\n",
" 'SEPNBL', 'OBNBL5', 'OBNBL4', 'DECHO2', 'HYPEP5', 'DEINH7',\n",
" 'HYPEP4', 'HBGLU8', 'HBGLU6', 'HBGLU7', 'HBGLU5', 'HBGLU4',\n",
" 'HBCHO2', 'HBCHO1', 'HBCHO3', 'HBADR', 'HBCHO4', 'TECHO', 'DECHO1',\n",
" 'SCINH1', 'HBINH8', 'HBINH7', 'HBINH5', 'CBINH2', 'CBPC', 'CBINH1',\n",
" 'MEINH1', 'TEINH17', 'TEINH18', 'DEINH2', 'DEINH1', 'DEINH6',\n",
" 'MEINH13', 'MEINH8', 'MEINH14', 'DEINH4', 'DEINH5', 'TEINH2',\n",
" 'TEINH1', 'HBINH4', 'HBINH3', 'HBINH1', 'SCINH11', 'MEINH3',\n",
" 'MEINH4', 'DEINH3', 'MEINH2', 'MEINH7', 'MEINH5', 'MEINH12',\n",
" 'MEINH11', 'MEINH9', 'MEINH10', 'MEINH6', 'HBINH6', 'HBINH2',\n",
" 'SCGLU8', 'SCGLU9', 'SCGLU7', 'SCGLU2', 'SCGLU3', 'SCGLU4',\n",
" 'SCGLU6', 'SCGLU5', 'SCINH5', 'SCINH6', 'SCINH7', 'HBINH9',\n",
" 'SCINH2', 'SCINH4', 'SCINH3', 'SCINH10', 'SCINH9', 'SCINH8',\n",
" 'TEINH3', 'OBDOP1', 'HYPEP8', 'ABC', 'VLMC2', 'VLMC1', 'VSMCA',\n",
" 'PER3', 'VECA', 'PER2', 'PER1', 'VECV', 'VECC', 'MGL1', 'MGL2',\n",
" 'MGL3', 'PVM2', 'PVM1', 'SCHW', 'SATG2', 'SATG1', 'ACBG', 'ACOB',\n",
" 'ACTE1', 'ACTE2', 'ACNT1', 'ACNT2', 'ACMB', 'EPEN', 'EPSC', 'CHOR',\n",
" 'SYNOR3', 'SYNOR2', 'SYNOR1', 'SYNOR4', 'SYNOR5', 'SYCHO2',\n",
" 'SYCHO1', 'PSPEP1', 'PSPEP3', 'PSPEP2', 'PSPEP4', 'PSPEP5',\n",
" 'PSPEP6', 'PSPEP7', 'PSPEP8', 'PSNF2', 'PSNF3', 'PSNF1', 'PSNP1',\n",
" 'PSNP3', 'PSNP2', 'PSNP5', 'PSNP4', 'PSNP6'], dtype=object)"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ds.ca['ClusterName']"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"# we can access the full matrix using numpy-style slicing\n",
"matrix = ds[:,:]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"numpy.ndarray"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# now we have a numpy array\n",
"type(matrix)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"ds.close()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "loom",
"language": "python",
"name": "loom"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment