{"action":"created","comment":{"url":"https://api.github.com/repos/greenelab/hetmech/pulls/comments/135596378","pull_request_review_id":59025002,"id":135596378,"diff_hunk":"@@ -1,187 +1,642 @@\n import collections\n+import copy\n import functools\n import itertools\n+import logging\n import operator\n+import time\n \n import numpy\n from scipy import sparse\n \n-from .matrix import (normalize,\n-                     metaedge_to_adjacency_matrix,\n-                     auto_convert,\n-                     copy_array)\n+from .matrix import auto_convert, copy_array, metaedge_to_adjacency_matrix, \\\n+    normalize\n \n \n-def dwwc_step(matrix, row_damping=0, column_damping=0, copy=True):\n+def dwpc(graph, metapath, damping=0.5, sparse_threshold=0, use_general=False):\n     \"\"\"\n-    Return the degree-weighted adjacency matrix produced by the input matrix\n-    with the specified row and column normalization exponents.\n+    A unified function to compute the degree-weighted path count.\n+    This function will call get_segments, then the appropriate\n+    specialized (or generalized) DWPC function.\n \n     Parameters\n-    ==========\n-    matrix : numpy.ndarray or scipy.sparse\n-        adjacency matrix for a given metaedge, where the source nodes are\n-        rows and the target nodes are columns\n-    row_damping : int or float\n-        exponent to use in scaling each node's row by its in-degree\n-    column_damping : int or float\n-        exponent to use in scaling each node's column by its column-sum\n-    copy : bool\n-        `True` guarantees matrix will not be modified in place. `False`\n-        modifies in-place if and only if matrix.dtype == numpy.float64.\n-        Users are recommended not to rely on in-place conversion, but instead\n-        use `False` when in-place modification is acceptable and efficiency\n-        is desired.\n+    ----------\n+    graph : hetio.hetnet.Graph\n+    metapath : hetio.hetnet.MetaPath\n+    damping : float\n+    sparse_threshold : float (0 <= sparse_threshold <= 1)\n+        sets the density threshold above which a sparse matrix will be\n+        converted to a dense automatically.\n+    use_general : bool\n+        if True, dwpc will call _dwpc_general_case and give a warning\n+        on metapaths which are categorized 'other' and 'long_repeat'.\n+        If False, an exception is raised when such a metapath is given.\n \n     Returns\n-    =======\n-    numpy.ndarray or scipy.sparse\n-        Normalized matrix with dtype.float64.\n+    -------\n+    numpy.ndarray, numpy.ndarray, numpy.ndarray or\n+    scipy.sparse.csc_matrix, float\n+        row labels, column labels, the DWPC matrix, and the computation time\n     \"\"\"\n-    # returns a newly allocated array if copy is True\n-    matrix = copy_array(matrix, copy)\n+    start_time = time.perf_counter()\n+    category_to_function = {'no_repeats': _dwpc_no_repeats,","path":"hetmech/degree_weight.py","position":68,"original_position":68,"commit_id":"d180e0821587a7665e690a0789d0d991728a885e","original_commit_id":"d180e0821587a7665e690a0789d0d991728a885e","user":{"login":"zietzm","id":7230303,"avatar_url":"https://avatars1.githubusercontent.com/u/7230303?v=4","gravatar_id":"","url":"https://api.github.com/users/zietzm","html_url":"https://github.com/zietzm","followers_url":"https://api.github.com/users/zietzm/followers","following_url":"https://api.github.com/users/zietzm/following{/other_user}","gists_url":"https://api.github.com/users/zietzm/gists{/gist_id}","starred_url":"https://api.github.com/users/zietzm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zietzm/subscriptions","organizations_url":"https://api.github.com/users/zietzm/orgs","repos_url":"https://api.github.com/users/zietzm/repos","events_url":"https://api.github.com/users/zietzm/events{/privacy}","received_events_url":"https://api.github.com/users/zietzm/received_events","type":"User","site_admin":false},"body":"Tried it, and it gives errors because the functions have to all be above the dictionary definition. Since it is small, I think it may be best to leave it inside here.","created_at":"2017-08-28T18:22:57Z","updated_at":"2017-08-28T18:22:57Z","html_url":"https://github.com/greenelab/hetmech/pull/70#discussion_r135596378","pull_request_url":"https://api.github.com/repos/greenelab/hetmech/pulls/70","_links":{"self":{"href":"https://api.github.com/repos/greenelab/hetmech/pulls/comments/135596378"},"html":{"href":"https://github.com/greenelab/hetmech/pull/70#discussion_r135596378"},"pull_request":{"href":"https://api.github.com/repos/greenelab/hetmech/pulls/70"}},"in_reply_to_id":135558826},"pull_request":{"url":"https://api.github.com/repos/greenelab/hetmech/pulls/70","id":137291241,"html_url":"https://github.com/greenelab/hetmech/pull/70","diff_url":"https://github.com/greenelab/hetmech/pull/70.diff","patch_url":"https://github.com/greenelab/hetmech/pull/70.patch","issue_url":"https://api.github.com/repos/greenelab/hetmech/issues/70","number":70,"state":"open","locked":false,"title":"Merge 'Develop' into Master","user":{"login":"zietzm","id":7230303,"avatar_url":"https://avatars1.githubusercontent.com/u/7230303?v=4","gravatar_id":"","url":"https://api.github.com/users/zietzm","html_url":"https://github.com/zietzm","followers_url":"https://api.github.com/users/zietzm/followers","following_url":"https://api.github.com/users/zietzm/following{/other_user}","gists_url":"https://api.github.com/users/zietzm/gists{/gist_id}","starred_url":"https://api.github.com/users/zietzm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zietzm/subscriptions","organizations_url":"https://api.github.com/users/zietzm/orgs","repos_url":"https://api.github.com/users/zietzm/repos","events_url":"https://api.github.com/users/zietzm/events{/privacy}","received_events_url":"https://api.github.com/users/zietzm/received_events","type":"User","site_admin":false},"body":"This PR includes all the DWPC functions necessary to completely replicate the results in Rephetio (see #49). Additions since the last changes to master include additional metapath categorizations which allow several longer metapaths to be classified accurately. \r\n\r\nNote that metapaths of length six (six edges, seven metanodes) are only partially supported by the current work. While in principle all metapaths are supported with the general function, there are not yet any sort of specialized functions analogous to `dwpc_baba` for length six metapaths. That is not to say, however, that no 6-paths are supported. In fact, many which are simply disjoint repeats and repeats around pre-defined groups are entirely supported. Additionally, since length six cannot introduce an extra *pair* of repeats from length five, the only added difficulty for these paths should lie in potentially longer split repeats which would need a form of merged `BABA` and `short_repeat` DWPC functions.\r\n\r\nIn addition to the general case DWPC function (#59 #67), this PR incorporates the work @kkloste did in #52 towards the `BABA` case, as well as functions for `short_repeat`, `disjoint`, and `BAAB`. \r\n\r\nI have included here additional work towards `categorize` and `get_segments` which have been significantly expanded. These functions should hopefully be organized in a logical way which will allow relatively simple expansion to further metapaths (especially those of length 6). \r\n\r\nFinally, a quick note about the test file:\r\nThere are no explicit tests for the `disjoint` case due to the fact that the example graph we use in test files does not have any `DrD`, `CrC`, etc. metaedges. The only repeat in the example is `GiG`. My reason for not including a test for `disjoint` is that the example graph does not have the capability to have disjoint metapaths.\r\n\r\nCloses https://github.com/greenelab/hetmech/pull/52\r\nCloses https://github.com/greenelab/hetmech/issues/20","created_at":"2017-08-23T18:50:21Z","updated_at":"2017-08-28T18:22:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0466262a214dd58e2ee37c63e8a50dd2036d9c91","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/greenelab/hetmech/pulls/70/commits","review_comments_url":"https://api.github.com/repos/greenelab/hetmech/pulls/70/comments","review_comment_url":"https://api.github.com/repos/greenelab/hetmech/pulls/comments{/number}","comments_url":"https://api.github.com/repos/greenelab/hetmech/issues/70/comments","statuses_url":"https://api.github.com/repos/greenelab/hetmech/statuses/d180e0821587a7665e690a0789d0d991728a885e","head":{"label":"greenelab:develop","ref":"develop","sha":"d180e0821587a7665e690a0789d0d991728a885e","user":{"login":"greenelab","id":9607754,"avatar_url":"https://avatars1.githubusercontent.com/u/9607754?v=4","gravatar_id":"","url":"https://api.github.com/users/greenelab","html_url":"https://github.com/greenelab","followers_url":"https://api.github.com/users/greenelab/followers","following_url":"https://api.github.com/users/greenelab/following{/other_user}","gists_url":"https://api.github.com/users/greenelab/gists{/gist_id}","starred_url":"https://api.github.com/users/greenelab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/greenelab/subscriptions","organizations_url":"https://api.github.com/users/greenelab/orgs","repos_url":"https://api.github.com/users/greenelab/repos","events_url":"https://api.github.com/users/greenelab/events{/privacy}","received_events_url":"https://api.github.com/users/greenelab/received_events","type":"Organization","site_admin":false},"repo":{"id":63903430,"name":"hetmech","full_name":"greenelab/hetmech","owner":{"login":"greenelab","id":9607754,"avatar_url":"https://avatars1.githubusercontent.com/u/9607754?v=4","gravatar_id":"","url":"https://api.github.com/users/greenelab","html_url":"https://github.com/greenelab","followers_url":"https://api.github.com/users/greenelab/followers","following_url":"https://api.github.com/users/greenelab/following{/other_user}","gists_url":"https://api.github.com/users/greenelab/gists{/gist_id}","starred_url":"https://api.github.com/users/greenelab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/greenelab/subscriptions","organizations_url":"https://api.github.com/users/greenelab/orgs","repos_url":"https://api.github.com/users/greenelab/repos","events_url":"https://api.github.com/users/greenelab/events{/privacy}","received_events_url":"https://api.github.com/users/greenelab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/greenelab/hetmech","description":"Greene Lab/Theory In Practice collaboration on identifying mechanisms using hetnets","fork":false,"url":"https://api.github.com/repos/greenelab/hetmech","forks_url":"https://api.github.com/repos/greenelab/hetmech/forks","keys_url":"https://api.github.com/repos/greenelab/hetmech/keys{/key_id}","collaborators_url":"https://api.github.com/repos/greenelab/hetmech/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/greenelab/hetmech/teams","hooks_url":"https://api.github.com/repos/greenelab/hetmech/hooks","issue_events_url":"https://api.github.com/repos/greenelab/hetmech/issues/events{/number}","events_url":"https://api.github.com/repos/greenelab/hetmech/events","assignees_url":"https://api.github.com/repos/greenelab/hetmech/assignees{/user}","branches_url":"https://api.github.com/repos/greenelab/hetmech/branches{/branch}","tags_url":"https://api.github.com/repos/greenelab/hetmech/tags","blobs_url":"https://api.github.com/repos/greenelab/hetmech/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/greenelab/hetmech/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/greenelab/hetmech/git/refs{/sha}","trees_url":"https://api.github.com/repos/greenelab/hetmech/git/trees{/sha}","statuses_url":"https://api.github.com/repos/greenelab/hetmech/statuses/{sha}","languages_url":"https://api.github.com/repos/greenelab/hetmech/languages","stargazers_url":"https://api.github.com/repos/greenelab/hetmech/stargazers","contributors_url":"https://api.github.com/repos/greenelab/hetmech/contributors","subscribers_url":"https://api.github.com/repos/greenelab/hetmech/subscribers","subscription_url":"https://api.github.com/repos/greenelab/hetmech/subscription","commits_url":"https://api.github.com/repos/greenelab/hetmech/commits{/sha}","git_commits_url":"https://api.github.com/repos/greenelab/hetmech/git/commits{/sha}","comments_url":"https://api.github.com/repos/greenelab/hetmech/comments{/number}","issue_comment_url":"https://api.github.com/repos/greenelab/hetmech/issues/comments{/number}","contents_url":"https://api.github.com/repos/greenelab/hetmech/contents/{+path}","compare_url":"https://api.github.com/repos/greenelab/hetmech/compare/{base}...{head}","merges_url":"https://api.github.com/repos/greenelab/hetmech/merges","archive_url":"https://api.github.com/repos/greenelab/hetmech/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/greenelab/hetmech/downloads","issues_url":"https://api.github.com/repos/greenelab/hetmech/issues{/number}","pulls_url":"https://api.github.com/repos/greenelab/hetmech/pulls{/number}","milestones_url":"https://api.github.com/repos/greenelab/hetmech/milestones{/number}","notifications_url":"https://api.github.com/repos/greenelab/hetmech/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/greenelab/hetmech/labels{/name}","releases_url":"https://api.github.com/repos/greenelab/hetmech/releases{/id}","deployments_url":"https://api.github.com/repos/greenelab/hetmech/deployments","created_at":"2016-07-21T21:25:53Z","updated_at":"2017-08-20T17:12:57Z","pushed_at":"2017-08-28T17:29:11Z","git_url":"git://github.com/greenelab/hetmech.git","ssh_url":"git@github.com:greenelab/hetmech.git","clone_url":"https://github.com/greenelab/hetmech.git","svn_url":"https://github.com/greenelab/hetmech","homepage":"","size":4787,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":12,"forks":3,"open_issues":12,"watchers":1,"default_branch":"master"}},"base":{"label":"greenelab:master","ref":"master","sha":"775ef9b38f549dfd147104c66a256ae9c7df4605","user":{"login":"greenelab","id":9607754,"avatar_url":"https://avatars1.githubusercontent.com/u/9607754?v=4","gravatar_id":"","url":"https://api.github.com/users/greenelab","html_url":"https://github.com/greenelab","followers_url":"https://api.github.com/users/greenelab/followers","following_url":"https://api.github.com/users/greenelab/following{/other_user}","gists_url":"https://api.github.com/users/greenelab/gists{/gist_id}","starred_url":"https://api.github.com/users/greenelab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/greenelab/subscriptions","organizations_url":"https://api.github.com/users/greenelab/orgs","repos_url":"https://api.github.com/users/greenelab/repos","events_url":"https://api.github.com/users/greenelab/events{/privacy}","received_events_url":"https://api.github.com/users/greenelab/received_events","type":"Organization","site_admin":false},"repo":{"id":63903430,"name":"hetmech","full_name":"greenelab/hetmech","owner":{"login":"greenelab","id":9607754,"avatar_url":"https://avatars1.githubusercontent.com/u/9607754?v=4","gravatar_id":"","url":"https://api.github.com/users/greenelab","html_url":"https://github.com/greenelab","followers_url":"https://api.github.com/users/greenelab/followers","following_url":"https://api.github.com/users/greenelab/following{/other_user}","gists_url":"https://api.github.com/users/greenelab/gists{/gist_id}","starred_url":"https://api.github.com/users/greenelab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/greenelab/subscriptions","organizations_url":"https://api.github.com/users/greenelab/orgs","repos_url":"https://api.github.com/users/greenelab/repos","events_url":"https://api.github.com/users/greenelab/events{/privacy}","received_events_url":"https://api.github.com/users/greenelab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/greenelab/hetmech","description":"Greene Lab/Theory In Practice collaboration on identifying mechanisms using hetnets","fork":false,"url":"https://api.github.com/repos/greenelab/hetmech","forks_url":"https://api.github.com/repos/greenelab/hetmech/forks","keys_url":"https://api.github.com/repos/greenelab/hetmech/keys{/key_id}","collaborators_url":"https://api.github.com/repos/greenelab/hetmech/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/greenelab/hetmech/teams","hooks_url":"https://api.github.com/repos/greenelab/hetmech/hooks","issue_events_url":"https://api.github.com/repos/greenelab/hetmech/issues/events{/number}","events_url":"https://api.github.com/repos/greenelab/hetmech/events","assignees_url":"https://api.github.com/repos/greenelab/hetmech/assignees{/user}","branches_url":"https://api.github.com/repos/greenelab/hetmech/branches{/branch}","tags_url":"https://api.github.com/repos/greenelab/hetmech/tags","blobs_url":"https://api.github.com/repos/greenelab/hetmech/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/greenelab/hetmech/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/greenelab/hetmech/git/refs{/sha}","trees_url":"https://api.github.com/repos/greenelab/hetmech/git/trees{/sha}","statuses_url":"https://api.github.com/repos/greenelab/hetmech/statuses/{sha}","languages_url":"https://api.github.com/repos/greenelab/hetmech/languages","stargazers_url":"https://api.github.com/repos/greenelab/hetmech/stargazers","contributors_url":"https://api.github.com/repos/greenelab/hetmech/contributors","subscribers_url":"https://api.github.com/repos/greenelab/hetmech/subscribers","subscription_url":"https://api.github.com/repos/greenelab/hetmech/subscription","commits_url":"https://api.github.com/repos/greenelab/hetmech/commits{/sha}","git_commits_url":"https://api.github.com/repos/greenelab/hetmech/git/commits{/sha}","comments_url":"https://api.github.com/repos/greenelab/hetmech/comments{/number}","issue_comment_url":"https://api.github.com/repos/greenelab/hetmech/issues/comments{/number}","contents_url":"https://api.github.com/repos/greenelab/hetmech/contents/{+path}","compare_url":"https://api.github.com/repos/greenelab/hetmech/compare/{base}...{head}","merges_url":"https://api.github.com/repos/greenelab/hetmech/merges","archive_url":"https://api.github.com/repos/greenelab/hetmech/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/greenelab/hetmech/downloads","issues_url":"https://api.github.com/repos/greenelab/hetmech/issues{/number}","pulls_url":"https://api.github.com/repos/greenelab/hetmech/pulls{/number}","milestones_url":"https://api.github.com/repos/greenelab/hetmech/milestones{/number}","notifications_url":"https://api.github.com/repos/greenelab/hetmech/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/greenelab/hetmech/labels{/name}","releases_url":"https://api.github.com/repos/greenelab/hetmech/releases{/id}","deployments_url":"https://api.github.com/repos/greenelab/hetmech/deployments","created_at":"2016-07-21T21:25:53Z","updated_at":"2017-08-20T17:12:57Z","pushed_at":"2017-08-28T17:29:11Z","git_url":"git://github.com/greenelab/hetmech.git","ssh_url":"git@github.com:greenelab/hetmech.git","clone_url":"https://github.com/greenelab/hetmech.git","svn_url":"https://github.com/greenelab/hetmech","homepage":"","size":4787,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":12,"forks":3,"open_issues":12,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/greenelab/hetmech/pulls/70"},"html":{"href":"https://github.com/greenelab/hetmech/pull/70"},"issue":{"href":"https://api.github.com/repos/greenelab/hetmech/issues/70"},"comments":{"href":"https://api.github.com/repos/greenelab/hetmech/issues/70/comments"},"review_comments":{"href":"https://api.github.com/repos/greenelab/hetmech/pulls/70/comments"},"review_comment":{"href":"https://api.github.com/repos/greenelab/hetmech/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/greenelab/hetmech/pulls/70/commits"},"statuses":{"href":"https://api.github.com/repos/greenelab/hetmech/statuses/d180e0821587a7665e690a0789d0d991728a885e"}}}}
{"actor":{"display_login":"zietzm"}}