{"action":"created","comment":{"url":"https://api.github.com/repos/magicDGS/thaplv/pulls/comments/80377990","id":80377990,"diff_hunk":"@@ -0,0 +1,233 @@\n+/*\n+ * Copyright (c) 2016, Daniel Gomez-Sanchez <daniel.gomez.sanchez@hotmail> All rights reserved.\n+ *\n+ * Redistribution and use in source and binary forms, with or without modification, are permitted\n+ * provided that the following conditions are met:\n+ *\n+ * 1. Redistributions of source code must retain the above copyright notice, this list of conditions\n+ * and the following disclaimer.\n+ *\n+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions\n+ * and the following disclaimer in the documentation and/or other materials provided with the\n+ * distribution.\n+ *\n+ * 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse\n+ * or promote products derived from this software without specific prior written permission.\n+ *\n+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR\n+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\n+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR\n+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER\n+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF\n+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ *\n+ */\n+\n+package org.magicdgs.thaplv.utils.stats;\n+\n+import org.apache.commons.math3.stat.descriptive.moment.Variance;\n+import org.apache.commons.math3.stat.descriptive.rank.PSquarePercentile;\n+\n+import java.util.Map;\n+import java.util.TreeMap;\n+\n+/**\n+ * Class for computing running statistics including mean, standard deviation and quantiles (using\n+ * {@link PSquarePercentile}).\n+ *\n+ * @author Daniel Gomez-Sanchez (magicDGS)\n+ */\n+// TODO: unit tests\n+// TODO: synchronization could be done in a better/safer way\n+// TODO: change the implementation to use the exact implementations if the number of values added is low\n+public class RunningStats {\n+    // TODO: change the mean/stdev implementation for apache.commons.math3 methods?\n+    // TODO: will be much better for consistency\n+    private double newMean, newStdDev;\n+    private final PSquarePercentile median;\n+    private final Variance sampleVar;\n+    // the quantiles always includes the median\n+    private final TreeMap<Double, PSquarePercentile> quantiles;\n+\n+    /**\n+     * Constructs a new running statistic without quantiles. Computes the mean, variance, standard\n+     * deviation and median.\n+     */\n+    public RunningStats() {\n+        median = new PSquarePercentile(50.0D);\n+        sampleVar = new Variance();\n+        quantiles = new TreeMap<>();\n+    }\n+\n+    /**\n+     * Constructs a new running statistics with the provided quantiles.\n+     *\n+     * @param quantiles quantiles to add in the range (1, 100).\n+     */\n+    public RunningStats(final double... quantiles) {\n+        this();\n+        for (final double quan : quantiles) {\n+            if (quan != 50.0D) {\n+                this.quantiles.put(quan, new PSquarePercentile(quan));\n+            }\n+        }\n+    }\n+\n+    /**\n+     * Adds a new value to the statistics. {@link Double#NaN} will be ignored.\n+     *\n+     * @param x the value to add to the running statistics.\n+     *\n+     * @return {@code true} if the value is pushed; {@code true} otherwise\n+     */\n+    // TODO: change the name to add()\n+    public synchronized boolean push(double x) {\n+        if (!Double.isNaN(x)) {\n+            median.increment(x);\n+            // See Knuth TAOCP vol 2, 3rd edition, page 232\n+            if (median.getN() == 1) {\n+                newMean = x;\n+                newStdDev = 0.0;\n+            } else {\n+                final double oldMean = newMean;\n+                newMean = oldMean + (x - oldMean) / median.getN();\n+                newStdDev = newStdDev + (x - oldMean) * (x - newMean);\n+            }\n+            sampleVar.increment(x);\n+            for (final PSquarePercentile quan : quantiles.values()) {\n+                quan.increment(x);\n+            }\n+            return true;\n+        }\n+        return false;\n+    }\n+\n+    /** Clear all the data in this instance. */\n+    public final synchronized void clear() {\n+        median.clear();\n+        for (final PSquarePercentile q : quantiles.values()) {\n+            q.clear();\n+        }\n+        newMean = 0;\n+        newStdDev = 0;\n+    }\n+\n+    /** Get the number of data values. */\n+    public final synchronized long numDataValues() {\n+        return median.getN();\n+    }\n+\n+    /**\n+     * Gets the actual mean.\n+     *\n+     * @return the current mean; {@link Double#NaN} if no value was added.\n+     */\n+    public final synchronized double mean() {\n+        return (median.getN() > 0) ? newMean : Double.NaN;\n+    }\n+\n+    /**\n+     * Gets the actual variance.\n+     *\n+     * @return the current variance; {@link Double#NaN} if no value was added.\n+     */\n+    public final synchronized double variance() {\n+        return ((median.getN() > 1) ? newStdDev / (median.getN() - 1) : Double.NaN);","path":"src/main/java/org/magicdgs/thaplv/utils/stats/RunningStats.java","position":137,"original_position":137,"commit_id":"9bf9d4917d3eaa9aea4a51173a83333fa290b2aa","original_commit_id":"9bf9d4917d3eaa9aea4a51173a83333fa290b2aa","user":{"login":"codacy-bot","id":19940114,"avatar_url":"https://avatars.githubusercontent.com/u/19940114?v=3","gravatar_id":"","url":"https://api.github.com/users/codacy-bot","html_url":"https://github.com/codacy-bot","followers_url":"https://api.github.com/users/codacy-bot/followers","following_url":"https://api.github.com/users/codacy-bot/following{/other_user}","gists_url":"https://api.github.com/users/codacy-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/codacy-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codacy-bot/subscriptions","organizations_url":"https://api.github.com/users/codacy-bot/orgs","repos_url":"https://api.github.com/users/codacy-bot/repos","events_url":"https://api.github.com/users/codacy-bot/events{/privacy}","received_events_url":"https://api.github.com/users/codacy-bot/received_events","type":"User","site_admin":false},"body":"![Codacy](https://www.codacy.com/assets/images/favicon.png) Issue found: [Unnecessary parentheses around return value.](https://www.codacy.com/app/daniel-gomez-sanchez/thaplv/file/4031611360/issues/source?bid=3741104&fileBranchId=3741105#l137)","created_at":"2016-09-25T09:37:55Z","updated_at":"2016-09-25T09:37:55Z","html_url":"https://github.com/magicDGS/thaplv/pull/33#discussion_r80377990","pull_request_url":"https://api.github.com/repos/magicDGS/thaplv/pulls/33","_links":{"self":{"href":"https://api.github.com/repos/magicDGS/thaplv/pulls/comments/80377990"},"html":{"href":"https://github.com/magicDGS/thaplv/pull/33#discussion_r80377990"},"pull_request":{"href":"https://api.github.com/repos/magicDGS/thaplv/pulls/33"}}},"pull_request":{"url":"https://api.github.com/repos/magicDGS/thaplv/pulls/33","id":86528674,"html_url":"https://github.com/magicDGS/thaplv/pull/33","diff_url":"https://github.com/magicDGS/thaplv/pull/33.diff","patch_url":"https://github.com/magicDGS/thaplv/pull/33.patch","issue_url":"https://api.github.com/repos/magicDGS/thaplv/issues/33","number":33,"state":"open","locked":false,"title":"WIP: LD components","user":{"login":"magicDGS","id":7352559,"avatar_url":"https://avatars.githubusercontent.com/u/7352559?v=3","gravatar_id":"","url":"https://api.github.com/users/magicDGS","html_url":"https://github.com/magicDGS","followers_url":"https://api.github.com/users/magicDGS/followers","following_url":"https://api.github.com/users/magicDGS/following{/other_user}","gists_url":"https://api.github.com/users/magicDGS/gists{/gist_id}","starred_url":"https://api.github.com/users/magicDGS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/magicDGS/subscriptions","organizations_url":"https://api.github.com/users/magicDGS/orgs","repos_url":"https://api.github.com/users/magicDGS/repos","events_url":"https://api.github.com/users/magicDGS/events{/privacy}","received_events_url":"https://api.github.com/users/magicDGS/received_events","type":"User","site_admin":false},"body":"This is a temporary solution for the LD decay tool, because it should be changed by a new and cleaner implementation.","created_at":"2016-09-23T15:03:45Z","updated_at":"2016-09-25T09:37:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a18da4b99b733b41a918a3243d641de38dced70c","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/magicDGS/thaplv/pulls/33/commits","review_comments_url":"https://api.github.com/repos/magicDGS/thaplv/pulls/33/comments","review_comment_url":"https://api.github.com/repos/magicDGS/thaplv/pulls/comments{/number}","comments_url":"https://api.github.com/repos/magicDGS/thaplv/issues/33/comments","statuses_url":"https://api.github.com/repos/magicDGS/thaplv/statuses/9bf9d4917d3eaa9aea4a51173a83333fa290b2aa","head":{"label":"magicDGS:dgs_ld_components","ref":"dgs_ld_components","sha":"9bf9d4917d3eaa9aea4a51173a83333fa290b2aa","user":{"login":"magicDGS","id":7352559,"avatar_url":"https://avatars.githubusercontent.com/u/7352559?v=3","gravatar_id":"","url":"https://api.github.com/users/magicDGS","html_url":"https://github.com/magicDGS","followers_url":"https://api.github.com/users/magicDGS/followers","following_url":"https://api.github.com/users/magicDGS/following{/other_user}","gists_url":"https://api.github.com/users/magicDGS/gists{/gist_id}","starred_url":"https://api.github.com/users/magicDGS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/magicDGS/subscriptions","organizations_url":"https://api.github.com/users/magicDGS/orgs","repos_url":"https://api.github.com/users/magicDGS/repos","events_url":"https://api.github.com/users/magicDGS/events{/privacy}","received_events_url":"https://api.github.com/users/magicDGS/received_events","type":"User","site_admin":false},"repo":{"id":64378642,"name":"thaplv","full_name":"magicDGS/thaplv","owner":{"login":"magicDGS","id":7352559,"avatar_url":"https://avatars.githubusercontent.com/u/7352559?v=3","gravatar_id":"","url":"https://api.github.com/users/magicDGS","html_url":"https://github.com/magicDGS","followers_url":"https://api.github.com/users/magicDGS/followers","following_url":"https://api.github.com/users/magicDGS/following{/other_user}","gists_url":"https://api.github.com/users/magicDGS/gists{/gist_id}","starred_url":"https://api.github.com/users/magicDGS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/magicDGS/subscriptions","organizations_url":"https://api.github.com/users/magicDGS/orgs","repos_url":"https://api.github.com/users/magicDGS/repos","events_url":"https://api.github.com/users/magicDGS/events{/privacy}","received_events_url":"https://api.github.com/users/magicDGS/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/magicDGS/thaplv","description":"Tools for Haploid/Haplotype VCFs","fork":false,"url":"https://api.github.com/repos/magicDGS/thaplv","forks_url":"https://api.github.com/repos/magicDGS/thaplv/forks","keys_url":"https://api.github.com/repos/magicDGS/thaplv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/magicDGS/thaplv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/magicDGS/thaplv/teams","hooks_url":"https://api.github.com/repos/magicDGS/thaplv/hooks","issue_events_url":"https://api.github.com/repos/magicDGS/thaplv/issues/events{/number}","events_url":"https://api.github.com/repos/magicDGS/thaplv/events","assignees_url":"https://api.github.com/repos/magicDGS/thaplv/assignees{/user}","branches_url":"https://api.github.com/repos/magicDGS/thaplv/branches{/branch}","tags_url":"https://api.github.com/repos/magicDGS/thaplv/tags","blobs_url":"https://api.github.com/repos/magicDGS/thaplv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/magicDGS/thaplv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/magicDGS/thaplv/git/refs{/sha}","trees_url":"https://api.github.com/repos/magicDGS/thaplv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/magicDGS/thaplv/statuses/{sha}","languages_url":"https://api.github.com/repos/magicDGS/thaplv/languages","stargazers_url":"https://api.github.com/repos/magicDGS/thaplv/stargazers","contributors_url":"https://api.github.com/repos/magicDGS/thaplv/contributors","subscribers_url":"https://api.github.com/repos/magicDGS/thaplv/subscribers","subscription_url":"https://api.github.com/repos/magicDGS/thaplv/subscription","commits_url":"https://api.github.com/repos/magicDGS/thaplv/commits{/sha}","git_commits_url":"https://api.github.com/repos/magicDGS/thaplv/git/commits{/sha}","comments_url":"https://api.github.com/repos/magicDGS/thaplv/comments{/number}","issue_comment_url":"https://api.github.com/repos/magicDGS/thaplv/issues/comments{/number}","contents_url":"https://api.github.com/repos/magicDGS/thaplv/contents/{+path}","compare_url":"https://api.github.com/repos/magicDGS/thaplv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/magicDGS/thaplv/merges","archive_url":"https://api.github.com/repos/magicDGS/thaplv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/magicDGS/thaplv/downloads","issues_url":"https://api.github.com/repos/magicDGS/thaplv/issues{/number}","pulls_url":"https://api.github.com/repos/magicDGS/thaplv/pulls{/number}","milestones_url":"https://api.github.com/repos/magicDGS/thaplv/milestones{/number}","notifications_url":"https://api.github.com/repos/magicDGS/thaplv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/magicDGS/thaplv/labels{/name}","releases_url":"https://api.github.com/repos/magicDGS/thaplv/releases{/id}","deployments_url":"https://api.github.com/repos/magicDGS/thaplv/deployments","created_at":"2016-07-28T08:39:01Z","updated_at":"2016-07-28T12:08:08Z","pushed_at":"2016-09-25T09:35:45Z","git_url":"git://github.com/magicDGS/thaplv.git","ssh_url":"git@github.com:magicDGS/thaplv.git","clone_url":"https://github.com/magicDGS/thaplv.git","svn_url":"https://github.com/magicDGS/thaplv","homepage":null,"size":9057,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":17,"forks":0,"open_issues":17,"watchers":0,"default_branch":"master"}},"base":{"label":"magicDGS:master","ref":"master","sha":"605f93f1e7efdcce17afc9cf387f15250e4fa866","user":{"login":"magicDGS","id":7352559,"avatar_url":"https://avatars.githubusercontent.com/u/7352559?v=3","gravatar_id":"","url":"https://api.github.com/users/magicDGS","html_url":"https://github.com/magicDGS","followers_url":"https://api.github.com/users/magicDGS/followers","following_url":"https://api.github.com/users/magicDGS/following{/other_user}","gists_url":"https://api.github.com/users/magicDGS/gists{/gist_id}","starred_url":"https://api.github.com/users/magicDGS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/magicDGS/subscriptions","organizations_url":"https://api.github.com/users/magicDGS/orgs","repos_url":"https://api.github.com/users/magicDGS/repos","events_url":"https://api.github.com/users/magicDGS/events{/privacy}","received_events_url":"https://api.github.com/users/magicDGS/received_events","type":"User","site_admin":false},"repo":{"id":64378642,"name":"thaplv","full_name":"magicDGS/thaplv","owner":{"login":"magicDGS","id":7352559,"avatar_url":"https://avatars.githubusercontent.com/u/7352559?v=3","gravatar_id":"","url":"https://api.github.com/users/magicDGS","html_url":"https://github.com/magicDGS","followers_url":"https://api.github.com/users/magicDGS/followers","following_url":"https://api.github.com/users/magicDGS/following{/other_user}","gists_url":"https://api.github.com/users/magicDGS/gists{/gist_id}","starred_url":"https://api.github.com/users/magicDGS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/magicDGS/subscriptions","organizations_url":"https://api.github.com/users/magicDGS/orgs","repos_url":"https://api.github.com/users/magicDGS/repos","events_url":"https://api.github.com/users/magicDGS/events{/privacy}","received_events_url":"https://api.github.com/users/magicDGS/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/magicDGS/thaplv","description":"Tools for Haploid/Haplotype VCFs","fork":false,"url":"https://api.github.com/repos/magicDGS/thaplv","forks_url":"https://api.github.com/repos/magicDGS/thaplv/forks","keys_url":"https://api.github.com/repos/magicDGS/thaplv/keys{/key_id}","collaborators_url":"https://api.github.com/repos/magicDGS/thaplv/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/magicDGS/thaplv/teams","hooks_url":"https://api.github.com/repos/magicDGS/thaplv/hooks","issue_events_url":"https://api.github.com/repos/magicDGS/thaplv/issues/events{/number}","events_url":"https://api.github.com/repos/magicDGS/thaplv/events","assignees_url":"https://api.github.com/repos/magicDGS/thaplv/assignees{/user}","branches_url":"https://api.github.com/repos/magicDGS/thaplv/branches{/branch}","tags_url":"https://api.github.com/repos/magicDGS/thaplv/tags","blobs_url":"https://api.github.com/repos/magicDGS/thaplv/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/magicDGS/thaplv/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/magicDGS/thaplv/git/refs{/sha}","trees_url":"https://api.github.com/repos/magicDGS/thaplv/git/trees{/sha}","statuses_url":"https://api.github.com/repos/magicDGS/thaplv/statuses/{sha}","languages_url":"https://api.github.com/repos/magicDGS/thaplv/languages","stargazers_url":"https://api.github.com/repos/magicDGS/thaplv/stargazers","contributors_url":"https://api.github.com/repos/magicDGS/thaplv/contributors","subscribers_url":"https://api.github.com/repos/magicDGS/thaplv/subscribers","subscription_url":"https://api.github.com/repos/magicDGS/thaplv/subscription","commits_url":"https://api.github.com/repos/magicDGS/thaplv/commits{/sha}","git_commits_url":"https://api.github.com/repos/magicDGS/thaplv/git/commits{/sha}","comments_url":"https://api.github.com/repos/magicDGS/thaplv/comments{/number}","issue_comment_url":"https://api.github.com/repos/magicDGS/thaplv/issues/comments{/number}","contents_url":"https://api.github.com/repos/magicDGS/thaplv/contents/{+path}","compare_url":"https://api.github.com/repos/magicDGS/thaplv/compare/{base}...{head}","merges_url":"https://api.github.com/repos/magicDGS/thaplv/merges","archive_url":"https://api.github.com/repos/magicDGS/thaplv/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/magicDGS/thaplv/downloads","issues_url":"https://api.github.com/repos/magicDGS/thaplv/issues{/number}","pulls_url":"https://api.github.com/repos/magicDGS/thaplv/pulls{/number}","milestones_url":"https://api.github.com/repos/magicDGS/thaplv/milestones{/number}","notifications_url":"https://api.github.com/repos/magicDGS/thaplv/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/magicDGS/thaplv/labels{/name}","releases_url":"https://api.github.com/repos/magicDGS/thaplv/releases{/id}","deployments_url":"https://api.github.com/repos/magicDGS/thaplv/deployments","created_at":"2016-07-28T08:39:01Z","updated_at":"2016-07-28T12:08:08Z","pushed_at":"2016-09-25T09:35:45Z","git_url":"git://github.com/magicDGS/thaplv.git","ssh_url":"git@github.com:magicDGS/thaplv.git","clone_url":"https://github.com/magicDGS/thaplv.git","svn_url":"https://github.com/magicDGS/thaplv","homepage":null,"size":9057,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":17,"forks":0,"open_issues":17,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/magicDGS/thaplv/pulls/33"},"html":{"href":"https://github.com/magicDGS/thaplv/pull/33"},"issue":{"href":"https://api.github.com/repos/magicDGS/thaplv/issues/33"},"comments":{"href":"https://api.github.com/repos/magicDGS/thaplv/issues/33/comments"},"review_comments":{"href":"https://api.github.com/repos/magicDGS/thaplv/pulls/33/comments"},"review_comment":{"href":"https://api.github.com/repos/magicDGS/thaplv/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/magicDGS/thaplv/pulls/33/commits"},"statuses":{"href":"https://api.github.com/repos/magicDGS/thaplv/statuses/9bf9d4917d3eaa9aea4a51173a83333fa290b2aa"}}}}
{"actor":{"display_login":"codacy-bot"}}