gsc-weighting 0.1.0.2 → 0.1.1
raw patch · 2 files changed
+27/−6 lines, 2 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.Weighting.GSC: gsc :: (Fractional d) => Dendrogram d a -> Dendrogram d (a, d)
+ Data.Weighting.GSC: gsc :: Fractional d => Dendrogram d a -> Dendrogram d (a, d)
Files
- Data/Weighting/GSC.hs +20/−5
- gsc-weighting.cabal +7/−1
Data/Weighting/GSC.hs view
@@ -42,16 +42,18 @@ -- -- which is exactly what they calculated. gsc :: Fractional d => Dendrogram d a -> Dendrogram d (a, d)-gsc (Leaf x) = Leaf (x,1)-gsc dendrogram = ret+gsc (Leaf x) = Leaf (x,1)+gsc b@(Branch d _ _) | d == 0 = fmap (flip (,) 1) b+gsc dendrogram = ret where- (wsum, nsum, ret) = go undefined [] dendrogram- wfinal = (wsum / fromIntegral nsum)+ (wsumF, nsumF, ret) = go undefined [] dendrogram+ wfinal = (wsumF / fromIntegral nsumF) position (Leaf _) = 0 -- no difference from itself position (Branch d _ _) = d - go _ cs (Branch d l r) =+ go d' cs b@(Branch d _ _) | d == 0 = zeroBranch d' cs b+ go _ cs (Branch d l r) = let (wl, nl, l') = go d ((el / wl) : cs) l (wr, nr, r') = go d ((er / wr) : cs) r @@ -65,3 +67,16 @@ -- O(n) worst case, O(log n) best case (balanced dendrogram) let w = foldl' (\curw c -> curw + curw * c) d (tail cs) in (0, 1 :: Int, Leaf (x, w / wfinal))++ -- special case for branches where the distance is zero.+ zeroBranch d' cs b =+ let w = foldl' (\curw c -> curw + curw * c) d' (tail cs)+ wf = w / (wfinal * fromIntegral nsum)+ setWeights (Leaf x) = (1, Leaf (x, wf))+ setWeights (Branch d l r) =+ let (nl, l') = setWeights l+ (nr, r') = setWeights r+ ns = nl + nr+ in ns `seq` (ns, Branch d l' r')+ (nsum, ret) = setWeights b+ in (0, nsum, ret)
gsc-weighting.cabal view
@@ -1,5 +1,5 @@ Name: gsc-weighting-Version: 0.1.0.2+Version: 0.1.1 Synopsis: Generic implementation of Gerstein/Sonnhammer/Chothia weighting. License: BSD3 License-file: LICENSE@@ -21,6 +21,12 @@ dendrogram. If you want to recreate their algorithm, then just use @UPGMA@ as linkage and residue identity as distance function when creating the dendrogram.+ .+ Changes in version 0.1.1:+ .+ * Now works even when some (or all) branches have distance zero+ (i.e. elements below that branches are all equal with respect+ to distance metric that was used to create the dendrogram). Library Exposed-modules: