packages feed

too-many-cells 0.1.3.1 → 0.1.4.0

raw patch · 4 files changed

+28/−14 lines, 4 files

Files

app/Main.hs view
@@ -89,6 +89,7 @@                , 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."+               , featureColumn :: Maybe Int <?> "([1] | COLUMN) The column (1-indexed) in the features.tsv.gz file to use for feature names. If using matrix market format, cellranger stores multiple columns in the features file, usually the first column for the Ensembl identifier and the second column for the gene symbol. If the Ensembl identifier is not quickly accessible, use --feature-column 2 for the second column, which is usually more ubiquitous. Useful for overlaying gene expression so you can say --draw-leaf \"DrawItem (DrawContinuous \\\"CD4\\\")\") instead of --draw-leaf \"DrawItem (DrawContinuous \\\"ENSG00000010610\\\")\"). Does not affect CSV format (the column names will be the feature names)."                , normalization :: Maybe String <?> "([TfIdfNorm] | UQNorm | MedNorm | TotalMedNorm | BothNorm | NoneNorm) Type of normalization before clustering. TfIdfNorm normalizes based on the prevalence of each feature. UQNorm normalizes each observation by the upper quartile non-zero counts of that observation. MedNorm normalizes each observation by the median non-zero counts of that observation. TotalMedNorm normalized first each observation by total count then by median of non-zero counts across features. BothNorm uses both normalizations (first TotalMedNorm for all analysis then additionally TfIdfNorm during clustering). NoneNorm does not normalize. Default is TfIdfNorm for clustering and NoneNorm for differential (which instead uses the recommended edgeR single cell preprocessing including normalization and filtering, any normalization provided here will result in edgeR preprocessing on top). Cannot use TfIdfNorm for any other process as NoneNorm will become the default."                , eigenGroup :: Maybe String <?> "([SignGroup] | KMeansGroup) Whether to group the eigenvector using the sign or kmeans while clustering. While the default is sign, kmeans may be more accurate (but starting points are arbitrary)."                , numEigen :: Maybe Int <?> "([1] | INT) Number of eigenvectors to use while clustering with kmeans. Takes from the second to last eigenvector. Recommended to start at 1 and work up from there if needed. May help offset the possible instability and inaccuracy of SVDLIBC."@@ -123,6 +124,7 @@                   , 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."+                  , featureColumn :: Maybe Int <?> "([1] | COLUMN) The column (1-indexed) in the features.tsv.gz file to use for feature names. If using matrix market format, cellranger stores multiple columns in the features file, usually the first column for the Ensembl identifier and the second column for the gene symbol. If the Ensembl identifier is not quickly accessible, use --feature-column 2 for the second column, which is usually more ubiquitous. Useful for overlaying gene expression so you can say --draw-leaf \"DrawItem (DrawContinuous \\\"CD4\\\")\") instead of --draw-leaf \"DrawItem (DrawContinuous \\\"ENSG00000010610\\\")\"). Does not affect CSV format (the column names will be the feature names)."                   , normalization :: Maybe String <?> "([TfIdfNorm] | UQNorm | MedNorm | TotalMedNorm | BothNorm | NoneNorm) Type of normalization before clustering. TfIdfNorm normalizes based on the prevalence of each feature. UQNorm normalizes each observation by the upper quartile non-zero counts of that observation. MedNorm normalizes each observation by the median non-zero counts of that observation. TotalMedNorm normalized first each observation by total count then by median of non-zero counts across features. BothNorm uses both normalizations (first TotalMedNorm for all analysis then additionally TfIdfNorm during clustering). NoneNorm does not normalize. Default is TfIdfNorm for clustering and NoneNorm for differential (which instead uses the recommended edgeR single cell preprocessing including normalization and filtering, any normalization provided here will result in edgeR preprocessing on top). Cannot use TfIdfNorm for any other process as NoneNorm will become the default."                   , 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."                   , noFilter :: Bool <?> "Whether to bypass filtering genes and cells by low counts."@@ -131,6 +133,7 @@     | 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."+                   , featureColumn :: Maybe Int <?> "([1] | COLUMN) The column (1-indexed) in the features.tsv.gz file to use for feature names. If using matrix market format, cellranger stores multiple columns in the features file, usually the first column for the Ensembl identifier and the second column for the gene symbol. If the Ensembl identifier is not quickly accessible, use --feature-column 2 for the second column, which is usually more ubiquitous. Useful for overlaying gene expression so you can say --draw-leaf \"DrawItem (DrawContinuous \\\"CD4\\\")\") instead of --draw-leaf \"DrawItem (DrawContinuous \\\"ENSG00000010610\\\")\"). Does not affect CSV format (the column names will be the feature names)."                    , 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."                    , 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."@@ -179,6 +182,7 @@     short "drawPalette"          = Just 'Y'     short "drawScaleSaturation"  = Just 'V'     short "eigenGroup"           = Just 'B'+    short "featureColumn"        = Nothing     short "filterThresholds"     = Just 'H'     short "labels"               = Nothing     short "matrixOutput"         = Nothing@@ -258,14 +262,16 @@              FP.</> (bool "barcodes.tsv" "barcodes.tsv.gz" compressedFileExist)       delimiter'      =           Delimiter . fromMaybe ',' . unHelpful . delimiter $ opts+      featureColumn'  =+          FeatureColumn . fromMaybe 1 . unHelpful . featureColumn $ opts       unFilteredSc   =           case matrixFile' of               (Left (DecompressedMatrix file))  ->                 loadSparseMatrixDataStream delimiter' file               (Right (DecompressedMatrix file)) ->-                loadCellrangerData genesFile' cellsFile' file+                loadCellrangerData featureColumn' genesFile' cellsFile' file               (Right (CompressedMatrix file))   ->-                loadCellrangerDataFeatures genesFile' cellsFile' file+                loadCellrangerDataFeatures featureColumn' genesFile' cellsFile' file               _ -> error "Does not supported this matrix type. See too-many-cells -h for each entry point for more information"   unFilteredSc 
src/TooManyCells/Matrix/Load.hs view
@@ -55,22 +55,28 @@ import TooManyCells.Matrix.Types import TooManyCells.Matrix.Utility +-- | Get feature from feature file row with informative error.+getFeature :: FeatureColumn -> [a] -> a+getFeature (FeatureColumn fc) =+  fromMaybe (error "Feature column selected not present in feature file (too few columns in feature file.)")+    . flip atMay (fc - 1) -- Convert to 0-index.+ -- | Load output of cellranger. loadCellrangerData-    :: GeneFile+    :: FeatureColumn+    -> GeneFile     -> CellFile     -> MatrixFileFolder     -> IO SingleCells-loadCellrangerData _ _ (MatrixFolder mf) = error "Expected matrix.mtx, impossible error."-loadCellrangerData gf cf (MatrixFile mf) = do+loadCellrangerData _ _ _ (MatrixFolder mf) = error "Expected matrix.mtx, impossible error."+loadCellrangerData fc gf cf (MatrixFile mf) = do     let csvOptsTabs = CSV.defaultDecodeOptions { CSV.decDelimiter = fromIntegral (ord '\t') }      m <- fmap (MatObsRow . HS.transposeSM . matToSpMat)  -- We want observations as rows        . readMatrix        $ mf-    -- m <- fmap (MatObsRow . HS.transposeSM) . loadMatrixMarket $ mf -- We want observations as rows-    g <- fmap (\ x -> either error (fmap (Gene . fst)) ( CSV.decodeWith csvOptsTabs CSV.NoHeader x-                                       :: Either String (Vector (T.Text, T.Text))+    g <- fmap (\ x -> either error (fmap (Gene . getFeature fc)) ( CSV.decodeWith csvOptsTabs CSV.NoHeader x+                                       :: Either String (Vector [T.Text])                                         )               )        . B.readFile@@ -92,12 +98,13 @@  -- | Load output of cellranger >= 3.0.0 loadCellrangerDataFeatures-    :: GeneFile+    :: FeatureColumn+    -> 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+loadCellrangerDataFeatures _ _ _ (MatrixFolder mf) = error "Expected matrix.mtx.gz, impossible error."+loadCellrangerDataFeatures fc 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@@ -105,8 +112,8 @@     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))+    g <- fmap (\ x -> either error (fmap (Gene . getFeature fc)) ( CSV.decodeWith csvOptsTabs CSV.NoHeader (decompress x)+                                       :: Either String (Vector [T.Text])                                         )               )        . B.readFile
src/TooManyCells/Matrix/Types.hs view
@@ -47,6 +47,7 @@ newtype Cols            = Cols { unCols :: [Double] } newtype Gene            = Gene { unGene :: Text } deriving (Eq, Ord, Read, Show, Generic) instance NFData Gene+newtype FeatureColumn   = FeatureColumn { unFeatureColumn :: Int } newtype CellWhitelist = CellWhitelist     { unCellWhitelist :: Set.Set Cell     } deriving (Eq,Ord,Read,Show)
too-many-cells.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: too-many-cells-version: 0.1.3.1+version: 0.1.4.0 license: GPL-3 license-file: LICENSE copyright: 2019 Gregory W. Schwartz