packages feed

Taxonomy 2.0.0 → 2.1.0

raw patch · 4 files changed

+10/−109 lines, 4 filesdep −graphvizPVP ok

version bump matches the API change (PVP)

Dependencies removed: graphviz

API changes (from Hackage documentation)

- Biobase.Taxonomy.Visualization: drawTaxonomy :: Bool -> Gr SimpleTaxon Double -> String
- Biobase.Taxonomy.Visualization: drawTaxonomyComparison :: Bool -> (Int, Gr CompareTaxon Double) -> String
- Biobase.Taxonomy.Visualization: writeDotTree :: String -> Bool -> Gr SimpleTaxon Double -> IO ()
- Biobase.Taxonomy.Visualization: writeJsonTree :: String -> Gr SimpleTaxon Double -> IO ()
- Biobase.Taxonomy.Visualization: writeTree :: String -> String -> Bool -> Gr SimpleTaxon Double -> IO ()

Files

Biobase/Taxonomy.hs view
@@ -4,10 +4,8 @@                        -- Datatypes used to represent taxonomy data                        module Biobase.Taxonomy.Types,                        module Biobase.Taxonomy.Import,-                       module Biobase.Taxonomy.Utils,-                       module Biobase.Taxonomy.Visualization+                       module Biobase.Taxonomy.Utils                       ) where import Biobase.Taxonomy.Types import Biobase.Taxonomy.Import import Biobase.Taxonomy.Utils-import Biobase.Taxonomy.Visualization
− Biobase/Taxonomy/Visualization.hs
@@ -1,100 +0,0 @@--- | Functions for  visualization of taxonomy data.-module Biobase.Taxonomy.Visualization (  -- * Datatypes-                       -- Datatypes used to represent taxonomy data-                       module Biobase.Taxonomy.Types,-                       -- * Visualization-                       drawTaxonomyComparison,-                       drawTaxonomy,-                       writeTree,-                       writeDotTree,-                       writeJsonTree-                      ) where-import Prelude-import Biobase.Taxonomy.Types-import Data.Graph.Inductive.Tree-import Data.Graph.Inductive.Basic-import qualified Data.GraphViz as GV-import qualified Data.GraphViz.Printing as GVP-import qualified Data.GraphViz.Attributes.Colors as GVAC-import qualified Data.GraphViz.Attributes.Complete as GVA-import qualified Data.ByteString.Lazy.Char8 as L-import qualified Data.Aeson as AE-import qualified Data.Text.Lazy as T-------------------------------------------- Visualisation functions---- | Draw graph in dot format. Used in Ids2Tree tool.-drawTaxonomy :: Bool -> Gr SimpleTaxon Double -> String-drawTaxonomy withRank inputGraph = do-  let nodeFormating = if withRank then nodeFormatWithRank else nodeFormatWithoutRank-  let params = GV.nonClusteredParams {GV.isDirected       = True-                       , GV.globalAttributes = [GV.GraphAttrs [GVA.Size (GVA.GSize (20 :: Double) (Just (20 :: Double)) False)]]-                       , GV.isDotCluster     = const True-                       --, GV.fmtNode = \ (_,l) -> [GV.textLabel (TL.pack (show (simpleRank l) ++ "\n" ++ T.unpack (simpleScientificName l)))]-                       , GV.fmtNode = nodeFormating-                       , GV.fmtEdge          = const []-                       }-  let dotFormat = GV.graphToDot params inputGraph-  let dottext = GVP.renderDot $ GVP.toDot dotFormat-  T.unpack dottext--nodeFormatWithRank :: (t, SimpleTaxon) -> [GVA.Attribute]-nodeFormatWithRank (_,l) = [GV.textLabel (T.concat [T.pack (show (simpleRank l)), T.pack ("\n") , simpleScientificName l])]--nodeFormatWithoutRank :: (t, SimpleTaxon) -> [GVA.Attribute]-nodeFormatWithoutRank (_,l) = [GV.textLabel (simpleScientificName l)]---- | Draw tree comparison graph in dot format. Used in Ids2TreeCompare tool.-drawTaxonomyComparison :: Bool -> (Int,Gr CompareTaxon Double) -> String-drawTaxonomyComparison withRank (treeNumber,inputGraph) = do-  let cList = makeColorList treeNumber-  let nodeFormating = if withRank then (compareNodeFormatWithRank cList) else (compareNodeFormatWithoutRank cList)-  let params = GV.nonClusteredParams {GV.isDirected = True-                       , GV.globalAttributes = []-                       , GV.isDotCluster = const True-                       --, GV.fmtNode = \ (_,l) -> [GV.textLabel (TL.pack (show (compareRank l) ++ "\n" ++ B.unpack (compareScientificName l))), GV.style GV.wedged, GVA.Color (selectColors (inTree l) cList)]-                       , GV.fmtNode = nodeFormating-                       , GV.fmtEdge = const []-                       }-  let dotFormat = GV.graphToDot params (grev inputGraph)-  let dottext = GVP.renderDot $ GVP.toDot dotFormat-  T.unpack dottext--compareNodeFormatWithRank :: [GVA.Color] -> (t, CompareTaxon) -> [GVA.Attribute]-compareNodeFormatWithRank cList (_,l) = [GV.textLabel (T.concat [T.pack (show (compareRank l) ++ "\n"),compareScientificName l]), GV.style GV.wedged, GVA.Color (selectColors (inTree l) cList)]--compareNodeFormatWithoutRank :: [GVA.Color] -> (t, CompareTaxon) -> [GVA.Attribute]-compareNodeFormatWithoutRank cList (_,l) = [GV.textLabel (compareScientificName l), GV.style GV.wedged, GVA.Color (selectColors (inTree l) cList)]---- | Colors from color list are selected according to in which of the compared trees the node is contained.-selectColors :: [Int] -> [GVA.Color] -> GVAC.ColorList-selectColors inTrees currentColorList = GVAC.toColorList (map (\i -> currentColorList !! i) inTrees)---- | A color list is sampled from the spectrum according to how many trees are compared.-makeColorList :: Int -> [GVA.Color]-makeColorList treeNumber = cList-  where cList = map (\i -> GVAC.HSV ((fromIntegral i/fromIntegral neededColors) * 0.708) 0.5 1.0) [0..neededColors]-        neededColors = treeNumber - 1---- | Write tree representation either as dot or json to provided file path-writeTree :: String -> String -> Bool -> Gr SimpleTaxon Double -> IO ()-writeTree requestedFormat outputDirectoryPath withRank inputGraph = do-  case requestedFormat of-    "dot" -> writeDotTree outputDirectoryPath withRank inputGraph-    "json"-> writeJsonTree outputDirectoryPath inputGraph-    _ -> writeDotTree outputDirectoryPath withRank inputGraph---- | Write tree representation as dot to provided file path.--- Graphviz tools like dot can be applied to the written .dot file to generate e.g. svg-format images.-writeDotTree :: String -> Bool -> Gr SimpleTaxon Double -> IO ()-writeDotTree outputDirectoryPath withRank inputGraph = do-  let diagram = drawTaxonomy withRank (grev inputGraph)-  writeFile (outputDirectoryPath ++ "taxonomy.dot") diagram---- | Write tree representation as json to provided file path.--- You can visualize the result for example with 3Djs.-writeJsonTree :: String -> Gr SimpleTaxon Double -> IO ()-writeJsonTree outputDirectoryPath inputGraph = do-  let jsonOutput = AE.encode (grev inputGraph)-  L.writeFile (outputDirectoryPath ++ "taxonomy.json") jsonOutput
ChangeLog.md view
@@ -1,5 +1,9 @@ -*-change-log-*- +2.1.0 [Florian Eggenhofer](mailto:egg@cs.uni-freiburg.de) 17. December 2019++	* Moved visualisation code to own library+ 2.0.0 [Florian Eggenhofer](mailto:egg@cs.uni-freiburg.de) 18. November 2019  	* Changed to Biobase repository layout
Taxonomy.cabal view
@@ -1,5 +1,5 @@ name:                Taxonomy-version:             2.0.0+version:             2.1.0 synopsis:            Libary for parsing, processing and vizualization of taxonomy data description:         Haskell cabal Taxonomy libary contains tools, parsers, datastructures and visualisation                      for the NCBI (National Center for Biotechnology Information) Taxonomy datasources.@@ -27,7 +27,7 @@ category:            Bioinformatics build-type:          Simple cabal-version:       >=1.10.0-Tested-With: GHC == 8.4.4, GHC == 8.6.5+Tested-With: GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.1 Extra-Source-Files:         README.md ChangeLog.md @@ -38,16 +38,15 @@  source-repository this   type:     git-  location: https://github.com/eggzilla/Taxonomy/tree/v2.0.0-  tag:      v2.0.0+  location: https://github.com/eggzilla/Taxonomy/tree/v2.1.0+  tag:      v2.1.0  Library   ghc-options:         -Wall -fno-warn-unused-do-bind   default-language:    Haskell2010-  build-depends:       base >=4.5 && <5, parsec, either-unwrap, fgl>=5.5.4.0, text, graphviz>=2999.12.0.4, bytestring, aeson, vector+  build-depends:       base >=4.5 && <5, parsec, either-unwrap, fgl>=5.5.4.0, text, bytestring, aeson, vector   Hs-source-dirs:      .   Exposed-modules:     Biobase.Taxonomy.Types                        Biobase.Taxonomy.Import-                       Biobase.Taxonomy.Visualization                        Biobase.Taxonomy.Utils                        Biobase.Taxonomy