diff options
Diffstat (limited to 'bin/cluster.hs')
-rw-r--r-- | bin/cluster.hs | 21 |
1 files changed, 1 insertions, 20 deletions
diff --git a/bin/cluster.hs b/bin/cluster.hs index 7da6810..6b0d917 100644 --- a/bin/cluster.hs +++ b/bin/cluster.hs @@ -88,22 +88,6 @@ model xs = do -- Tabulate list tabulate xs = M.elems $ M.fromListWith (+) [(c, 1) | c <- xs] --- Draws a phylogeny to DOT format -drawGraph :: FilePath -> [[Double]] -> [Int] -> IO () -drawGraph path ps cl = writeFile path $ "digraph{" <> edges <> "}" - where - edges = concatMap calcEdges [1 .. length tab - 1] - calcEdges idx = fmt (parent idx) <> "->" <> fmt idx <> ";" - fmt i = "\"" <> intercalate "," (map fmtDbl $ ps' !! i) <> " " <> show (tab !! i) <> "\"" - tab = tabulate cl - parent = flip div 2 . (\x -> x - 1) - fmtDbl = show . (/ 10) . fromIntegral . round . (* 1000) - ps' = transpose $ map norm ps - - -- Normalise to frequency of parent - norm :: [Double] -> [Double] - norm xxs@(x : xs) = x : zipWith (\i y -> y / xxs !! parent i) [1 ..] xs - -- Command line args data Options = Options { seed :: Int, @@ -111,8 +95,7 @@ data Options = Options mhfrac :: Double, input :: FilePath, propsPath :: FilePath, - clusterPath :: FilePath, - dotPath :: FilePath + clusterPath :: FilePath } main = run =<< execParser opts @@ -128,7 +111,6 @@ main = run =<< execParser opts <*> argument str (metavar "INPUT") <*> argument str (metavar "PROPS") <*> argument str (metavar "TREE") - <*> strOption (long "dot" <> short 'd' <> help "draw graph of phylogeny in dot format" <> value "" <> metavar "PATH") probability = eitherReader $ \arg -> case reads arg of [(r, "")] -> if r <= 1 && r > 0 then Right r else Left "mhfrac not a valid probability" @@ -142,7 +124,6 @@ run opts = do ((ps, cl), _) <- foldl1' (\a c -> if mml a < mml c then a else c) . take (nsamples opts) <$> mh (mhfrac opts) 0.5 (model $ getCompact parsed) writeFile (propsPath opts) . unlines $ map (intercalate "," . map show) ps writeFile (clusterPath opts) . unlines $ map show cl - when (dotPath opts /= "") $ drawGraph (dotPath opts) ps cl where mml ((ps, cl), lik) = sum' (sum' (log . (+ 1))) ps + sum' (log . (+ 1)) tab - sum' (ln . stirling) tab - ln lik where |