birch-beer 0.1.2.1 → 0.1.3.0
raw patch · 7 files changed
+75/−56 lines, 7 files
Files
- app/Main.hs +1/−1
- birch-beer.cabal +1/−1
- src/BirchBeer/ColorMap.hs +36/−17
- src/BirchBeer/Interactive.hs +4/−4
- src/BirchBeer/MainDiagram.hs +8/−2
- src/BirchBeer/Plot.hs +24/−30
- src/BirchBeer/Types.hs +1/−1
app/Main.hs view
@@ -57,7 +57,7 @@ , smartCutoff :: Maybe Double <?> "([Nothing] | DOUBLE) Whether to set the cutoffs for --min-size, --max-proportion, and --min-distance based off of the distributions (median + (DOUBLE * MAD)) of all nodes. To use smart cutoffs, use this argument and then set one of the three arguments to an arbitrary number, whichever cutoff type you want to use. --min-size distribution is log2 transformed." , customCut :: [Int] <?> "([Nothing] | NODE) List of nodes to prune (make these nodes leaves). Invoked by --custom-cut 34 --custom-cut 65 etc." , order :: Maybe Double <?> "([1] | DOUBLE) The order of diversity for DrawItem DrawDiversity."- , drawLeaf :: Maybe String <?> "([DrawText] | DrawItem DrawItemType) How to draw leaves in the dendrogram. DrawText is the number of items in that leaf. DrawItem is the collection of items represented by circles, consisting of: DrawItem DrawLabel, where each item is colored by its label, DrawItem (DrawContinuous FEATURE), where each item is colored by the expression of FEATURE (corresponding to a feature name in the input matrix), DrawItem (DrawThresholdContinuous [(FEATURE, DOUBLE)]), where each item is colored by the binary high / low expression of FEATURE based on DOUBLE and multiple FEATUREs can be used to combinatorically label items (FEATURE1 high / FEATURE2 low, etc.), DrawItem DrawSumContinuous, where each item is colored by the sum of the post-normalized columns (use --normalization NoneNorm for UMI counts, default), and DrawItem DrawDiversity, where each node is colored by the diversity based on the labels of each item and the color is normalized separately for the leaves and the inner nodes. The default is DrawText, unless --labels-file is provided, in which DrawItem DrawLabel is the default. If the label or feature cannot be found, the default color will be black (check your spelling!)."+ , drawLeaf :: Maybe String <?> "([DrawText] | DrawItem DrawItemType) How to draw leaves in the dendrogram. DrawText is the number of items in that leaf. DrawItem is the collection of items represented by circles, consisting of: DrawItem DrawLabel, where each item is colored by its label, DrawItem (DrawContinuous [FEATURE]), where each item is colored by the expression of FEATURE (corresponding to a feature name in the input matrix, [FEATURE] is a list, so if more than one FEATURE is listed, uses the average of the feature values), DrawItem (DrawThresholdContinuous [(FEATURE, DOUBLE)]), where each item is colored by the binary high / low expression of FEATURE based on DOUBLE and multiple FEATUREs can be used to combinatorically label items (FEATURE1 high / FEATURE2 low, etc.), DrawItem DrawSumContinuous, where each item is colored by the sum of the post-normalized columns (use --normalization NoneNorm for UMI counts, default), and DrawItem DrawDiversity, where each node is colored by the diversity based on the labels of each item and the color is normalized separately for the leaves and the inner nodes. The default is DrawText, unless --labels-file is provided, in which DrawItem DrawLabel is the default. If the label or feature cannot be found, the default color will be black (check your spelling!)." , drawCollection :: Maybe String <?> "([PieChart] | PieRing | PieNone | CollectionGraph MAXWEIGHT THRESHOLD [NODE]) How to draw item leaves in the dendrogram. PieRing draws a pie chart ring around the items. PieChart only draws a pie chart instead of items. PieNone only draws items, no pie rings or charts. (CollectionGraph MAXWEIGHT THRESHOLD [NODE]) draws the nodes and edges within leaves that are descendents of NODE (empty list [] indicates draw all leaf networks) based on the input matrix, normalizes edges based on the MAXWEIGHT, and removes edges for display less than THRESHOLD (after normalization, so for CollectionGraph 2 0.5 [26], draw the leaf graphs for all leaves under node 26, then a edge of 0.7 would be removed because (0.7 / 2) < 0.5). For CollectionGraph with no colors, use --draw-leaf \"DrawItem DrawLabel\" and all nodes will be black. If you don't specify this option, DrawText from --draw-leaf overrides this argument and only the number of cells will be plotted." , drawMark :: Maybe String <?> "([MarkNone] | MarkModularity) How to draw annotations around each inner node in the tree. MarkNone draws nothing and MarkModularity draws a black circle representing the modularity at that node, darker black means higher modularity for that next split." , drawNodeNumber :: Bool <?> "Draw the node numbers on top of each node in the graph."
birch-beer.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: birch-beer-version: 0.1.2.1+version: 0.1.3.0 license: GPL-3 license-file: LICENSE copyright: 2019 Gregory W. Schwartz
src/BirchBeer/ColorMap.hs view
@@ -17,6 +17,7 @@ , labelToItemColorMap , getItemColorMapContinuous , getItemColorMapSumContinuous+ , getCombinedFeatures , getMarkColorMap , getNodeColorMapFromItems , getNodeColorMapFromDiversity@@ -187,27 +188,45 @@ where getExist = fromMaybe (error "Feature does not exist or no cells found.") --- | Get the colors of each item, where the color is determined by features.+-- | Get the colors of each item, where the color is determined by the average+-- of features. getItemColorMapContinuous :: (MatrixLike a)- => Maybe CustomColors -> Feature -> a -> ItemColorMap-getItemColorMapContinuous customColors g mat- | isNothing col = ItemColorMap Map.empty- | otherwise = ItemColorMap- . Map.fromList- . zip (fmap Id . V.toList . getRowNames $ mat)- . getContinuousColor highColor lowColor- . S.toDenseListSV- . flip S.extractCol (colErr col)- . getMatrix- $ mat+ => Maybe CustomColors -> [Feature] -> a -> Either String ItemColorMap+getItemColorMapContinuous customColors gs mat =+ fmap ( ItemColorMap+ . Map.fromList+ . zip (fmap Id . V.toList . getRowNames $ mat)+ . getContinuousColor highColor lowColor+ )+ . getCombinedFeatures gs+ $ mat where- colErr = fromMaybe (error $ "Feature " <> T.unpack (unFeature g) <> " does not exist.")- col = V.elemIndex g- . fmap Feature- . getColNames- $ mat (highColor, lowColor) = getHighLowColors customColors++-- | For items with several needed features, combine together by averages.+getCombinedFeatures :: (MatrixLike a)+ => [Feature]+ -> a+ -> Either String [Double]+getCombinedFeatures gs mat+ | V.length cols < truncate n = Left+ $ "One of the features in "+ <> (show . fmap unFeature $ gs)+ <> " does not exist."+ | otherwise = Right+ . fmap ((/ n) . sum)+ . S.toRowsL+ . S.fromColsV+ . fmap (S.extractCol (getMatrix mat))+ $ cols+ where+ cols = V.findIndices (flip Set.member gsSet)+ . fmap Feature+ . getColNames+ $ mat+ gsSet = Set.fromList gs+ n = fromIntegral $ Set.size gsSet -- | Get the labels of each item, where the label is determined by a binary high -- / low features determined by a threshold. Multiple features can be used
src/BirchBeer/Interactive.hs view
@@ -16,7 +16,7 @@ -- Remote import Data.Bool (bool) import Data.Colour.SRGB (sRGB24reads)-import Data.Maybe (catMaybes)+import Data.Maybe (catMaybes, fromMaybe) import Data.Tree (Tree (..)) import Safe (headMay) import Text.Read (readMaybe)@@ -56,10 +56,10 @@ DrawText [ DrawItem DrawLabel , DrawItem DrawSumContinuous- , DrawItem (DrawContinuous "GENE")+ , DrawItem (DrawContinuous ["GENE"]) , DrawItem DrawDiversity ]- drawContinuousGene' <- TS.entry "GENE for DrawItem DrawContinuous"+ drawContinuousGene' <- TS.entry "[GENE] for DrawItem DrawContinuous" drawCollection' <- TS.radioButton "Leaf shape" PieChart [PieRing, PieNone, CollectionGraph 1 0 []] drawMark' <- TS.radioButton "Node mark" MarkNone [MarkModularity]@@ -95,7 +95,7 @@ return $ let drawLeaf' = case drawLeafTemp of DrawItem (DrawContinuous _) ->- DrawItem (DrawContinuous drawContinuousGene')+ DrawItem (DrawContinuous (fromMaybe [] $ readMaybe (T.unpack drawContinuousGene') :: [T.Text])) x -> x config = Config { _birchLabelMap = labelMap , _birchMinSize = Just minSize'
src/BirchBeer/MainDiagram.hs view
@@ -18,6 +18,7 @@ import qualified Control.Lens as L import qualified Data.Clustering.Hierarchical as HC import qualified Data.Foldable as F+import qualified Data.Map.Strict as Map import qualified Data.Set as Set import qualified Data.Text as T import qualified Data.Vector as V@@ -131,7 +132,12 @@ case drawLeaf' of DrawItem (DrawContinuous x) -> fmap- (fmap (getItemColorMapContinuous drawColors' (Feature x)))+ ( fmap ( either (const (ItemColorMap Map.empty)) id+ . getItemColorMapContinuous+ drawColors'+ (fmap Feature x)+ )+ ) mat DrawItem DrawSumContinuous -> fmap (fmap (getItemColorMapSumContinuous drawColors')) mat@@ -180,7 +186,7 @@ ( fmap ( plotContinuousLegend drawColors' (fromMaybe (DrawScaleSaturation 1) drawScaleSaturation')- (Feature x)+ (fmap Feature x) ) ) mat
src/BirchBeer/Plot.hs view
@@ -27,6 +27,7 @@ import Data.Colour.Palette.BrewerSet (brewerSet, ColorCat(..), Kolor) import qualified Data.Colour.Palette.BrewerSet as Brewer import Data.Colour.SRGB (RGB (..), toSRGB)+import Data.Either (isLeft, isRight) import Data.Function (on) import Data.List (nub, sort, sortBy, foldl1', transpose) import Data.Maybe (fromMaybe, isNothing)@@ -275,38 +276,31 @@ plotContinuousLegend :: (MatrixLike a) => Maybe CustomColors -> DrawScaleSaturation- -> Feature+ -> [Feature] -> a -> Diagram B-plotContinuousLegend customColors sat g mat- | isNothing col = mempty- | otherwise = vsep- (legendFontSize * 1.2)- [ text (T.unpack . unFeature $ g)- # font "Arial"- # fontSizeL legendFontSize- , rotateBy (3 / 4)- $ renderColourBar- cbOpts- cm- (fromMaybe 0 minVal, fromMaybe 0 maxVal)- 100- ]- where- cm = colourMap- . zip [1..]- . fmap (\x -> saturateColor sat $ blend x highColor lowColor)- $ [0,0.1..1]- (minVal, maxVal) = Fold.fold ((,) <$> Fold.minimum <*> Fold.maximum)- . flip S.extractCol (colErr col)- . getMatrix- $ mat- colErr = fromMaybe (error $ "Feature " <> T.unpack (unFeature g) <> " does not exist.")- col = V.elemIndex g- . fmap Feature- . getColNames- $ mat- (highColor, lowColor) = getHighLowColors customColors+plotContinuousLegend customColors sat gs mat =+ either text dia $ getCombinedFeatures gs $ mat+ where+ dia fs = vsep+ (legendFontSize * 1.2)+ [ text (T.unpack . T.intercalate " " . fmap unFeature $ gs)+ # font "Arial"+ # fontSizeL legendFontSize+ , rotateBy (3 / 4)+ $ renderColourBar+ cbOpts+ cm+ (fromMaybe 0 minVal, fromMaybe 0 maxVal)+ 100+ ]+ where+ (minVal, maxVal) = Fold.fold ((,) <$> Fold.minimum <*> Fold.maximum) fs+ cm = colourMap+ . zip [1..]+ . fmap (\x -> saturateColor sat $ blend x highColor lowColor)+ $ [0,0.1..1]+ (highColor, lowColor) = getHighLowColors customColors -- | Get the legend for the sum of all features. Bar from -- https://archives.haskell.org/projects.haskell.org/diagrams/blog/2013-12-03-Palette1.html
src/BirchBeer/Types.hs view
@@ -180,7 +180,7 @@ -- Advanced data DrawItemType = DrawLabel- | DrawContinuous T.Text+ | DrawContinuous [T.Text] | DrawThresholdContinuous [(T.Text, Double)] | DrawSumContinuous | DrawDiversity