packages feed

too-many-cells 0.1.2.1 → 0.1.3.0

raw patch · 4 files changed

+88/−32 lines, 4 filesdep +temporarydep +zlibdep ~birch-beerdep ~hierarchical-spectral-clusteringdep ~spectral-clustering

Dependencies added: temporary, zlib

Dependency ranges changed: birch-beer, hierarchical-spectral-clustering, spectral-clustering

Files

app/Main.hs view
@@ -84,7 +84,7 @@  -- | Command line arguments data Options-    = MakeTree { matrixPath :: [String] <?> "(PATH) The path to the input directory containing the matrix output of cellranger (matrix.mtx, genes.tsv, and barcodes.tsv) or an input csv file containing gene row names and cell column names. If given as a list (--matrixPath input1 --matrixPath input2 etc.) then will join all matrices together. Assumes the same number and order of genes in each matrix, so only cells are added."+    = MakeTree { matrixPath :: [String] <?> "(PATH) The path to the input directory containing the matrix output of cellranger (cellranger < 3 (matrix.mtx, genes.tsv, and barcodes.tsv) or cellranger >= 3 (matrix.mtx.gz, features.tsv.gz, and barcodes.tsv.gz) or an input csv file containing gene row names and cell column names. If given as a list (--matrixPath input1 --matrixPath input2 etc.) then will join all matrices together. Assumes the same number and order of genes in each matrix, so only cells are added."                , projectionFile :: Maybe String <?> "([Nothing] | FILE) The input file containing positions of each cell for plotting. Format is \"barcode,x,y\" and matches column order in the matrix file. Useful for 10x where a TNSE projection is generated in \"projection.csv\". Cells without projections will not be plotted. If not supplied, no plot will be made."                , cellWhitelistFile :: Maybe String <?> "([Nothing] | FILE) The input file containing the cells to include. No header, line separated list of barcodes."                , labelsFile :: Maybe String <?> "([Nothing] | FILE) The input file containing the label for each cell barcode, with \"item,label\" header."@@ -119,7 +119,7 @@                , clumpinessMethod :: Maybe String <?> "([Majority] | Exclusive | AllExclusive) The method used when calculating clumpiness: Majority labels leaves according to the most abundant label, Exclusive only looks at leaves consisting of cells solely from one label, and AllExclusive treats the leaf as containing both labels."                , dense :: Bool <?> "Whether to use dense matrix algorithms for clustering. Should be faster for dense matrices, so if batch correction, PCA, or other algorithms are applied upstream to the input matrix, consider using this option to speed up the tree generation."                , output :: Maybe String <?> "([out] | STRING) The folder containing output."}-    | Interactive { matrixPath :: [String] <?> "(PATH) The path to the input directory containing the matrix output of cellranger (matrix.mtx, genes.tsv, and barcodes.tsv) or an input csv file containing gene row names and cell column names. If given as a list (--matrixPath input1 --matrixPath input2 etc.) then will join all matrices together. Assumes the same number and order of genes in each matrix, so only cells are added."+    | Interactive { matrixPath :: [String] <?> "(PATH) The path to the input directory containing the matrix output of cellranger (cellranger < 3 (matrix.mtx, genes.tsv, and barcodes.tsv) or cellranger >= 3 (matrix.mtx.gz, features.tsv.gz, and barcodes.tsv.gz) or an input csv file containing gene row names and cell column names. If given as a list (--matrixPath input1 --matrixPath input2 etc.) then will join all matrices together. Assumes the same number and order of genes in each matrix, so only cells are added."                   , cellWhitelistFile :: Maybe String <?> "([Nothing] | FILE) The input file containing the cells to include. No header, line separated list of barcodes."                   , labelsFile :: Maybe String <?> "([Nothing] | FILE) The input file containing the label for each cell barcode, with \"item,label\" header."                   , delimiter :: Maybe Char <?> "([,] | CHAR) The delimiter for the csv file if using a normal csv rather than cellranger output and for --labels-file."@@ -128,7 +128,7 @@                   , noFilter :: Bool <?> "Whether to bypass filtering genes and cells by low counts."                   , filterThresholds :: Maybe String <?> "([(250, 1)] | (DOUBLE, DOUBLE)) The minimum filter thresholds for (MINCELL, MINFEATURE) when filtering cells and features by low read counts. See also --no-filter."                   , prior :: Maybe String <?> "([Nothing] | STRING) The input folder containing the output from a previous run. If specified, skips clustering by using the previous clustering files."}-    | Differential { matrixPath :: [String] <?> "(PATH) The path to the input directory containing the matrix output of cellranger (matrix.mtx, genes.tsv, and barcodes.tsv) or an input csv file containing gene row names and cell column names. If given as a list (--matrixPath input1 --matrixPath input2 etc.) then will join all matrices together. Assumes the same number and order of genes in each matrix, so only cells are added."+    | Differential { matrixPath :: [String] <?> "(PATH) The path to the input directory containing the matrix output of cellranger (cellranger < 3 (matrix.mtx, genes.tsv, and barcodes.tsv) or cellranger >= 3 (matrix.mtx.gz, features.tsv.gz, and barcodes.tsv.gz) or an input csv file containing gene row names and cell column names. If given as a list (--matrixPath input1 --matrixPath input2 etc.) then will join all matrices together. Assumes the same number and order of genes in each matrix, so only cells are added."                    , cellWhitelistFile :: Maybe String <?> "([Nothing] | FILE) The input file containing the cells to include. No header, line separated list of barcodes."                    , labelsFile :: Maybe String <?> "([Nothing] | FILE) The input file containing the label for each cell barcode, with \"item,label\" header."                    , pca :: Maybe Double <?> "([Nothing] | DOUBLE) The percent variance to retain for PCA dimensionality reduction before clustering. Default is no PCA at all in order to keep all information."@@ -236,29 +236,38 @@ -- | Load the single cell matrix. loadSSM :: Options -> FilePath -> IO SingleCells loadSSM opts matrixPath' = do-    fileExist      <- FP.doesFileExist matrixPath'-    directoryExist <- FP.doesDirectoryExist matrixPath'+  fileExist      <- FP.doesFileExist matrixPath'+  directoryExist <- FP.doesDirectoryExist matrixPath'+  compressedFileExist <- FP.doesFileExist $ matrixPath' FP.</> "matrix.mtx.gz" -    let matrixFile' =-            case (fileExist, directoryExist) of-                (False, False) -> error "\nMatrix path does not exist."-                (True, False)  -> Left $ MatrixFile matrixPath'-                (False, True)  ->-                    Right . MatrixFile $ matrixPath' FP.</> "matrix.mtx"-        genesFile'  = GeneFile $ matrixPath' FP.</> "genes.tsv"-        cellsFile'  = CellFile $ matrixPath' FP.</> "barcodes.tsv"-        delimiter'      =-            Delimiter . fromMaybe ',' . unHelpful . delimiter $ opts-        unFilteredSc   =-            case matrixFile' of-                (Left file) -> loadSparseMatrixDataStream-                                delimiter'-                                file-                (Right file) -> loadCellrangerData-                                    genesFile'-                                    cellsFile'-                                    file-    unFilteredSc+  let matrixFile' =+        case (fileExist, directoryExist, compressedFileExist) of+          (False, False, False) -> error "\nMatrix path does not exist."+          (True, False, False)  ->+            Left . DecompressedMatrix . MatrixFile $ matrixPath'+          (False, True, False)  ->+            Right . DecompressedMatrix . MatrixFile $ matrixPath' FP.</> "matrix.mtx"+          (False, True, True)  ->+            Right . CompressedMatrix . MatrixFile $ matrixPath' FP.</> "matrix.mtx.gz"+          _                     -> error "Cannot determine matrix pointed to, are there too many matrices here?"+      genesFile'  = GeneFile+                  $ matrixPath'+             FP.</> (bool "genes.tsv" "features.tsv.gz" compressedFileExist)+      cellsFile'  = CellFile+                  $ matrixPath'+             FP.</> (bool "barcodes.tsv" "barcodes.tsv.gz" compressedFileExist)+      delimiter'      =+          Delimiter . fromMaybe ',' . unHelpful . delimiter $ opts+      unFilteredSc   =+          case matrixFile' of+              (Left (DecompressedMatrix file))  ->+                loadSparseMatrixDataStream delimiter' file+              (Right (DecompressedMatrix file)) ->+                loadCellrangerData genesFile' cellsFile' file+              (Right (CompressedMatrix file))   ->+                loadCellrangerDataFeatures genesFile' cellsFile' file+              _ -> error "Does not supported this matrix type. See too-many-cells -h for each entry point for more information"+  unFilteredSc  -- | Load all single cell matrices. loadAllSSM :: Options -> IO (Maybe SingleCells)@@ -301,6 +310,9 @@                     . normMat normalization'                     . _matrix         processedSc = sc { _matrix = processMat sc }++    -- Check for empty matrix.+    when (V.null . getRowNames $ processedSc) $ error "Matrix is empty. Check --filter-thresholds, --normalization, or the input matrix for over filtering or incorrect input format."      return processedSc 
src/TooManyCells/File/Types.hs view
@@ -48,3 +48,5 @@  -- Advanced data MatrixFileFolder = MatrixFile FilePath | MatrixFolder FilePath+data MatrixFileType = DecompressedMatrix MatrixFileFolder+                    | CompressedMatrix MatrixFileFolder
src/TooManyCells/Matrix/Load.hs view
@@ -12,6 +12,7 @@     ( matToSpMat     , spMatToMat     , loadCellrangerData+    , loadCellrangerDataFeatures     , loadHMatrixData     , loadSparseMatrixData     , loadSparseMatrixDataStream@@ -20,6 +21,7 @@  -- Remote import BirchBeer.Types+import Codec.Compression.GZip (decompress) import Control.DeepSeq (force) import Control.Exception (evaluate) import Control.Monad.Except (runExceptT, ExceptT (..))@@ -30,6 +32,7 @@ import Data.Monoid ((<>)) import Data.Vector (Vector) import Safe+import System.IO.Temp (withSystemTempFile) import qualified Control.Lens as L import qualified Data.ByteString.Lazy.Char8 as B import qualified Data.ByteString.Streaming.Char8 as BS@@ -45,6 +48,7 @@ import qualified Streaming.Cassava as S import qualified Streaming.Prelude as S import qualified Streaming.With.Lifted as SW+import qualified System.IO as IO  -- Local import TooManyCells.File.Types@@ -73,6 +77,42 @@        . unGeneFile        $ gf     c <- fmap (\ x -> either error (fmap (Cell . head)) ( CSV.decodeWith csvOptsTabs CSV.NoHeader x+                                       :: Either String (Vector [T.Text])+                                        )+              )+       . B.readFile+       . unCellFile+       $ cf++    return $+        SingleCells { _matrix   = m -- We want observations as rows.+                    , _rowNames = c+                    , _colNames = g+                    }++-- | Load output of cellranger >= 3.0.0+loadCellrangerDataFeatures+    :: GeneFile+    -> CellFile+    -> MatrixFileFolder+    -> IO SingleCells+loadCellrangerDataFeatures _ _ (MatrixFolder mf) = error "Expected matrix.mtx.gz, impossible error."+loadCellrangerDataFeatures gf cf (MatrixFile mf) = withSystemTempFile "temp_mat.mtx" $ \tempMatFile h -> do+    let csvOptsTabs = CSV.defaultDecodeOptions { CSV.decDelimiter = fromIntegral (ord '\t') }++    B.readFile mf >>= B.hPut h . decompress >> IO.hClose h++    m <- fmap (MatObsRow . HS.transposeSM . matToSpMat)  -- We want observations as rows+       . readMatrix+       $ tempMatFile+    g <- fmap (\ x -> either error (fmap (Gene . L.view L._1)) ( CSV.decodeWith csvOptsTabs CSV.NoHeader (decompress x)+                                       :: Either String (Vector (T.Text, T.Text, T.Text))+                                        )+              )+       . B.readFile+       . unGeneFile+       $ gf+    c <- fmap (\ x -> either error (fmap (Cell . head)) ( CSV.decodeWith csvOptsTabs CSV.NoHeader (decompress x)                                        :: Either String (Vector [T.Text])                                         )               )
too-many-cells.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: too-many-cells-version: 0.1.2.1+version: 0.1.3.0 license: GPL-3 license-file: LICENSE copyright: 2019 Gregory W. Schwartz@@ -46,7 +46,7 @@     build-depends:         base >=4.7 && <5,         aeson >=1.4.0.0,-        birch-beer >=0.1.0.0,+        birch-beer >=0.1.0.1,         bytestring >=0.10.8.2,         cassava >=0.5.1.0,         colour >=2.3.4,@@ -65,7 +65,7 @@         foldl >=1.4.2,         graphviz >=2999.20.0.2,         hierarchical-clustering >=0.4.6,-        hierarchical-spectral-clustering >=0.2.2.0,+        hierarchical-spectral-clustering >=0.3.0.0,         hmatrix >=0.19.0.0,         inline-r >=0.9.2,         lens >=4.16.1,@@ -87,10 +87,12 @@         streaming-cassava >=0.1.0.1,         streaming-with >=0.2.2.1,         SVGFonts >=1.6.0.3,+        temporary >=1.3,         text >=1.2.3.0,         text-show >=3.7.4,         vector >=0.12.0.1,-        vector-algorithms >=0.7.0.1+        vector-algorithms >=0.7.0.1,+        zlib >=0.6.2  executable too-many-cells     main-is: Main.hs@@ -101,7 +103,7 @@         base >=4.11.1.0,         too-many-cells -any,         aeson >=1.4.0.0,-        birch-beer >=0.1.0.0,+        birch-beer >=0.1.0.1,         bytestring >=0.10.8.2,         cassava >=0.5.1.0,         colour >=2.3.4,@@ -113,7 +115,7 @@         filepath >=1.4.2,         find-clumpiness >=0.2.3.1,         graphviz >=2999.20.0.2,-        hierarchical-spectral-clustering >=0.2.2.0,+        hierarchical-spectral-clustering >=0.3.0.0,         inline-r >=0.9.2,         lens >=4.16.1,         matrix-market-attoparsec >=0.1.0.8,@@ -121,7 +123,7 @@         optparse-generic >=1.3.0,         palette >=0.3.0.1,         plots >=0.1.0.2,-        spectral-clustering >=0.2.2.3,+        spectral-clustering >=0.3.0.1,         streaming >=0.2.1.0,         streaming-bytestring >=0.1.6,         streaming-utils >=0.1.4.7,