{"action":"created","comment":{"url":"https://api.github.com/repos/magicDGS/thaplv/pulls/comments/80363711","id":80363711,"diff_hunk":"@@ -0,0 +1,209 @@\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.ld;\n+\n+import org.magicdgs.thaplv.haplotypes.light.SNPpair;\n+\n+import org.apache.commons.math3.distribution.ChiSquaredDistribution;\n+\n+/**\n+ * Functions for compute LD related statistics.\n+ *\n+ * @author Daniel Gomez-Sanchez (magicDGS)\n+ */\n+public class LDfunctions {\n+\n+    /** Cannot be instantiated. */\n+    private LDfunctions() { }\n+\n+    /**\n+     * Chi-square distribution with 1 degree of fredom\n+     */\n+    private static final ChiSquaredDistribution chiSqr = new ChiSquaredDistribution(null, 1);\n+\n+    /**\n+     * Returned LD statistics with rStatistics are in the following order\n+     */\n+    public static final String[] rStatisticsOrder = new String[] {\"r2max\", \"r2\", \"r2norm\", \"rw\"};\n+\n+    /**\n+     * Compute rw (signed correlation). It needs already polarized frequencies\n+     *\n+     * @param pAB the frequency of AB\n+     * @param pA  the frequency of A\n+     * @param pB  the frequency of B\n+     *\n+     * @return rw\n+     */\n+    private static double rw(final double pAB, final double pA, final double pB) {\n+        return (pAB - pA * pB) / Math.sqrt(pA * (1 - pA) * pB * (1 - pB));\n+    }\n+\n+    /**\n+     * Compute rw for a SNPpair (it should be polarized)\n+     *\n+     * @param pair polarized pair\n+     *\n+     * @return rw\n+     */\n+    // TODO: deprecate this method\n+    public static double rw(final SNPpair pair) {\n+        return rw(pair.getFreqForHAB(), pair.getMajorAlleleFrequencyForA(), pair.getMajorAlleleFrequencyForB());\n+    }\n+\n+    /**\n+     * Compute r2 based on the signed rw\n+     *\n+     * @param rw the signed correlation\n+     *\n+     * @return r2\n+     */\n+    private static double r2(final double rw) {\n+        return Math.pow(Math.abs(rw), 2);\n+    }\n+\n+    /**\n+     * Compute r2 from allele frequencies\n+     *\n+     * @param pAB the frequency of AB\n+     * @param pA  the frequency of A\n+     * @param pB  the frequency of B\n+     *\n+     * @return rw\n+     */\n+    private static double r2(final double pAB, final double pA, final double pB) {\n+        return r2(rw(pAB, pA, pB));\n+    }\n+\n+    /**\n+     * Compute r2 for a SNPpair (it should be polarized)\n+     *\n+     * @param pair polarized pair\n+     *\n+     * @return rw\n+     */\n+    // TODO: deprecate this method\n+    public static double r2(final SNPpair pair) {\n+        return r2(pair.getFreqForHAB(), pair.getMajorAlleleFrequencyForA(), pair.getMajorAlleleFrequencyForB());\n+    }\n+\n+    /**\n+     * Compute maximumR2 with the frequencies\n+     *\n+     * @param smaller the smaller frequency\n+     * @param higher  the higher frequency\n+     *\n+     * @return the maximum R2\n+     */\n+    private static double maxR2(final double smaller, final double higher) {\n+        return (smaller * (1 - higher)) / ((1 - smaller) * higher);\n+    }\n+\n+    /**\n+     * Compute the maximumR2 for a SNPpair (it should be polarized)\n+     *\n+     * @param pair polarized pair\n+     *\n+     * @return maxR2\n+     */\n+    // TODO: deprecate this method\n+    public static double maxR2(final SNPpair pair) {\n+        // Because SNPpair is polarized, it is easier\n+        double pA = pair.getMajorAlleleFrequencyForA();\n+        double pB = pair.getMajorAlleleFrequencyForB();","path":"src/main/java/org/magicdgs/thaplv/utils/ld/LDfunctions.java","position":138,"original_position":138,"commit_id":"a99627cf0cbdff22528302b5cd18afff67461c54","original_commit_id":"a99627cf0cbdff22528302b5cd18afff67461c54","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: [Local variable 'pB' could be declared final](https://www.codacy.com/app/daniel-gomez-sanchez/thaplv/file/4031144494/issues/source?bid=3741104&fileBranchId=3741105#l138)","created_at":"2016-09-24T16:11:16Z","updated_at":"2016-09-24T16:11:16Z","html_url":"https://github.com/magicDGS/thaplv/pull/33#discussion_r80363711","pull_request_url":"https://api.github.com/repos/magicDGS/thaplv/pulls/33","_links":{"self":{"href":"https://api.github.com/repos/magicDGS/thaplv/pulls/comments/80363711"},"html":{"href":"https://github.com/magicDGS/thaplv/pull/33#discussion_r80363711"},"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-24T16:11:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1c5ae27a1d083b306526e2ea39aba4726211cb87","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/a99627cf0cbdff22528302b5cd18afff67461c54","head":{"label":"magicDGS:dgs_ld_components","ref":"dgs_ld_components","sha":"a99627cf0cbdff22528302b5cd18afff67461c54","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-24T16:09:31Z","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":9056,"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-24T16:09:31Z","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":9056,"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/a99627cf0cbdff22528302b5cd18afff67461c54"}}}}
{"actor":{"display_login":"codacy-bot"}}