{"action":"created","comment":{"url":"https://api.github.com/repos/biocore/tcga/pulls/comments/75514945","id":75514945,"diff_hunk":"@@ -0,0 +1,200 @@\n+#!/usr/bin/env python\n+\n+#-----------------------------------------------------------------------------\n+# Copyright (c) 2016--, Evguenia Kopylova.\n+#\n+# Distributed under the terms of the Modified BSD License.\n+#\n+# The full license is in the file COPYING.txt, distributed with this software.\n+#-----------------------------------------------------------------------------\n+\n+\"\"\"\n+Parse output of kraken-mpa-report and generate single BIOM table.\n+\"\"\"\n+\n+import sys\n+import os\n+from os.path import isfile, join\n+import random\n+import numpy as np\n+import matplotlib as mpl\n+mpl.use('Agg')\n+# requires matplot version 1.2.1 (or one that supports fontsize in the legend)\n+import matplotlib.pyplot as plt\n+import matplotlib.cm as cm\n+import brewer2mpl\n+\n+\n+def compute_abundances_biom(reports_dp,\n+                            metadata_fp,\n+                            taxonomy_report_dp,\n+                            taxa_level,\n+                            taxa_levels,\n+                            taxa_levels_idx):\n+    \"\"\"Absolute abundance of number of reads matching a defined taxa level.\n+\n+    Parameters\n+    ----------\n+    reports_dp: string\n+        output directory path\n+    metadata_fp: string\n+        path to TCGA tsv metadata file\n+    taxonomy_report_dp: string\n+        path to directory with output(s) of kraken-mpa-report\n+    taxa_level: string\n+        taxonomy level (e.g., genus or species)\n+    taxa_levels: dictionary\n+        \"domain\": \"d__\",\n+        \"phylum\": \"|p__\",\n+        \"class\": \"|c__\",\n+        \"order\": \"|o__\",\n+        \"family\": \"|f__\",\n+        \"genus\": \"|g__\",\n+        \"species\": \"|s__\"\n+    taxa_levels_idx: dictionary\n+        \"d__\": 0, \"|p__\": 1, \"|c__\": 2,\n+        \"|o__\": 3, \"|f__\": 4, \"|g__\": 5,\n+        \"|s__\": 6, \"6\": \"|s__\", \"5\": \"|g__\",\n+        \"4\": \"|f__\", \"3\": \"|o__\", \"2\": \"|c__\",\n+        \"1\": \"|p__\", \"0\": \"d__\"\n+\n+    Returns\n+    -------\n+    \n+    \"\"\"\n+    total_levels = len(taxa_levels)\n+\n+    # keys are file names\n+    metadata = {}\n+    num_samples = 1\n+    with open(metadata_fp, 'U') as metadata_f:\n+        for line in metadata_f:\n+            # skip the header\n+            if line.startswith('#'):\n+                continue\n+            line = line.strip().split(\"\\t\")\n+            file_n = line[6].split(\".bam\")[0]\n+            if file_n not in metadata:\n+                metadata[file_n] = [line[7], line[5], line[9], line[0]]\n+                num_samples += 1\n+\n+    organs_list = sorted({metadata[file_n][1] for file_n in metadata if isfile(join(taxonomy_report_dp, \"%s_kraken.report_mpa\" % file_n))})\n+    print organs_list\n+\n+    # species abundance\n+    abundances = {}\n+    labels = []\n+    total_organs = len(organs_list)\n+    taxa_l = taxa_levels[taxa_level]\n+    sample_id = 0\n+    for file_n in metadata:\n+        kraken_report_fp = join(taxonomy_report_dp, \"%s_kraken.report_mpa\" % file_n) \n+        if isfile(kraken_report_fp):\n+            # record abundances\n+            with open(kraken_report_fp, 'U') as kraken_report_f:\n+                for line in kraken_report_f:\n+                    stop_search = False\n+                    #print \"%s\\t%s\" % (taxa_l, line)\n+                    # get statistics only for specified taxa level\n+                    if taxa_l in line:\n+                        # cannot have deeper levels after specified level\n+                        for i in range(taxa_levels_idx[taxa_l]+1, total_levels):\n+                            if taxa_levels_idx[str(i)] in line:\n+                                stop_search = True\n+                                break\n+                    else:\n+                        stop_search = True\n+                    if stop_search:\n+                        continue\n+                    line = line.strip().split()\n+                    taxa = line[0]\n+                    abundance = np.float128(line[1])\n+                    # check if taxa exists\n+                    if taxa not in abundances:\n+                        abundances[taxa] = []\n+                        # new taxa not found previously in any organ,\n+                        # add to dictionary and set all abundances for\n+                        # other organs to 0.0\n+                        for j in range(0, num_samples):\n+                            abundances[taxa].append(0.0)\n+                    abundances[taxa][sample_id] += abundance\n+            sample_id += 1\n+\n+    return (abundances, organs_list, total_organs, metadata)\n+\n+\n+def output_biom_table(abundances,\n+                      organs_list,\n+                      reports_dp,\n+                      taxa_level,\n+                      taxonomy_report_dp,\n+                      metadata):\n+    \"\"\"\n+    \"\"\"\n+    output_biom_fp = join(reports_dp, \"tcga_output_%s.biom\" % (taxa_level))\n+    with open(output_biom_fp, 'w') as output_f:\n+        # output BIOM tsv file","path":"python_scripts/parse_kraken_to_biom.py","position":136,"original_position":136,"commit_id":"05f1a65db02132c09c802ec93304460a703a5f4c","original_commit_id":"05f1a65db02132c09c802ec93304460a703a5f4c","user":{"login":"ElDeveloper","id":375307,"avatar_url":"https://avatars.githubusercontent.com/u/375307?v=3","gravatar_id":"","url":"https://api.github.com/users/ElDeveloper","html_url":"https://github.com/ElDeveloper","followers_url":"https://api.github.com/users/ElDeveloper/followers","following_url":"https://api.github.com/users/ElDeveloper/following{/other_user}","gists_url":"https://api.github.com/users/ElDeveloper/gists{/gist_id}","starred_url":"https://api.github.com/users/ElDeveloper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ElDeveloper/subscriptions","organizations_url":"https://api.github.com/users/ElDeveloper/orgs","repos_url":"https://api.github.com/users/ElDeveloper/repos","events_url":"https://api.github.com/users/ElDeveloper/events{/privacy}","received_events_url":"https://api.github.com/users/ElDeveloper/received_events","type":"User","site_admin":false},"body":"👍","created_at":"2016-08-19T16:51:28Z","updated_at":"2016-08-19T16:51:28Z","html_url":"https://github.com/biocore/tcga/pull/2#discussion_r75514945","pull_request_url":"https://api.github.com/repos/biocore/tcga/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/biocore/tcga/pulls/comments/75514945"},"html":{"href":"https://github.com/biocore/tcga/pull/2#discussion_r75514945"},"pull_request":{"href":"https://api.github.com/repos/biocore/tcga/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/biocore/tcga/pulls/2","id":82009085,"html_url":"https://github.com/biocore/tcga/pull/2","diff_url":"https://github.com/biocore/tcga/pull/2.diff","patch_url":"https://github.com/biocore/tcga/pull/2.patch","issue_url":"https://api.github.com/repos/biocore/tcga/issues/2","number":2,"state":"open","locked":false,"title":"Biom t","user":{"login":"ekopylova","id":6933444,"avatar_url":"https://avatars.githubusercontent.com/u/6933444?v=3","gravatar_id":"","url":"https://api.github.com/users/ekopylova","html_url":"https://github.com/ekopylova","followers_url":"https://api.github.com/users/ekopylova/followers","following_url":"https://api.github.com/users/ekopylova/following{/other_user}","gists_url":"https://api.github.com/users/ekopylova/gists{/gist_id}","starred_url":"https://api.github.com/users/ekopylova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ekopylova/subscriptions","organizations_url":"https://api.github.com/users/ekopylova/orgs","repos_url":"https://api.github.com/users/ekopylova/repos","events_url":"https://api.github.com/users/ekopylova/events{/privacy}","received_events_url":"https://api.github.com/users/ekopylova/received_events","type":"User","site_admin":false},"body":"Script to convert Kraken output to BIOM Table.\r\n\r\n*** Not ready to merge ***","created_at":"2016-08-19T16:32:36Z","updated_at":"2016-08-19T16:51:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"337b36afa3e20adc3446ddc06cd543ffbaf1282f","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/biocore/tcga/pulls/2/commits","review_comments_url":"https://api.github.com/repos/biocore/tcga/pulls/2/comments","review_comment_url":"https://api.github.com/repos/biocore/tcga/pulls/comments{/number}","comments_url":"https://api.github.com/repos/biocore/tcga/issues/2/comments","statuses_url":"https://api.github.com/repos/biocore/tcga/statuses/05f1a65db02132c09c802ec93304460a703a5f4c","head":{"label":"ekopylova:biom_t","ref":"biom_t","sha":"05f1a65db02132c09c802ec93304460a703a5f4c","user":{"login":"ekopylova","id":6933444,"avatar_url":"https://avatars.githubusercontent.com/u/6933444?v=3","gravatar_id":"","url":"https://api.github.com/users/ekopylova","html_url":"https://github.com/ekopylova","followers_url":"https://api.github.com/users/ekopylova/followers","following_url":"https://api.github.com/users/ekopylova/following{/other_user}","gists_url":"https://api.github.com/users/ekopylova/gists{/gist_id}","starred_url":"https://api.github.com/users/ekopylova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ekopylova/subscriptions","organizations_url":"https://api.github.com/users/ekopylova/orgs","repos_url":"https://api.github.com/users/ekopylova/repos","events_url":"https://api.github.com/users/ekopylova/events{/privacy}","received_events_url":"https://api.github.com/users/ekopylova/received_events","type":"User","site_admin":false},"repo":{"id":65315118,"name":"tcga-1","full_name":"ekopylova/tcga-1","owner":{"login":"ekopylova","id":6933444,"avatar_url":"https://avatars.githubusercontent.com/u/6933444?v=3","gravatar_id":"","url":"https://api.github.com/users/ekopylova","html_url":"https://github.com/ekopylova","followers_url":"https://api.github.com/users/ekopylova/followers","following_url":"https://api.github.com/users/ekopylova/following{/other_user}","gists_url":"https://api.github.com/users/ekopylova/gists{/gist_id}","starred_url":"https://api.github.com/users/ekopylova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ekopylova/subscriptions","organizations_url":"https://api.github.com/users/ekopylova/orgs","repos_url":"https://api.github.com/users/ekopylova/repos","events_url":"https://api.github.com/users/ekopylova/events{/privacy}","received_events_url":"https://api.github.com/users/ekopylova/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ekopylova/tcga-1","description":"Microbial analysis in TCGA data","fork":true,"url":"https://api.github.com/repos/ekopylova/tcga-1","forks_url":"https://api.github.com/repos/ekopylova/tcga-1/forks","keys_url":"https://api.github.com/repos/ekopylova/tcga-1/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ekopylova/tcga-1/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ekopylova/tcga-1/teams","hooks_url":"https://api.github.com/repos/ekopylova/tcga-1/hooks","issue_events_url":"https://api.github.com/repos/ekopylova/tcga-1/issues/events{/number}","events_url":"https://api.github.com/repos/ekopylova/tcga-1/events","assignees_url":"https://api.github.com/repos/ekopylova/tcga-1/assignees{/user}","branches_url":"https://api.github.com/repos/ekopylova/tcga-1/branches{/branch}","tags_url":"https://api.github.com/repos/ekopylova/tcga-1/tags","blobs_url":"https://api.github.com/repos/ekopylova/tcga-1/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ekopylova/tcga-1/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ekopylova/tcga-1/git/refs{/sha}","trees_url":"https://api.github.com/repos/ekopylova/tcga-1/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ekopylova/tcga-1/statuses/{sha}","languages_url":"https://api.github.com/repos/ekopylova/tcga-1/languages","stargazers_url":"https://api.github.com/repos/ekopylova/tcga-1/stargazers","contributors_url":"https://api.github.com/repos/ekopylova/tcga-1/contributors","subscribers_url":"https://api.github.com/repos/ekopylova/tcga-1/subscribers","subscription_url":"https://api.github.com/repos/ekopylova/tcga-1/subscription","commits_url":"https://api.github.com/repos/ekopylova/tcga-1/commits{/sha}","git_commits_url":"https://api.github.com/repos/ekopylova/tcga-1/git/commits{/sha}","comments_url":"https://api.github.com/repos/ekopylova/tcga-1/comments{/number}","issue_comment_url":"https://api.github.com/repos/ekopylova/tcga-1/issues/comments{/number}","contents_url":"https://api.github.com/repos/ekopylova/tcga-1/contents/{+path}","compare_url":"https://api.github.com/repos/ekopylova/tcga-1/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ekopylova/tcga-1/merges","archive_url":"https://api.github.com/repos/ekopylova/tcga-1/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ekopylova/tcga-1/downloads","issues_url":"https://api.github.com/repos/ekopylova/tcga-1/issues{/number}","pulls_url":"https://api.github.com/repos/ekopylova/tcga-1/pulls{/number}","milestones_url":"https://api.github.com/repos/ekopylova/tcga-1/milestones{/number}","notifications_url":"https://api.github.com/repos/ekopylova/tcga-1/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ekopylova/tcga-1/labels{/name}","releases_url":"https://api.github.com/repos/ekopylova/tcga-1/releases{/id}","deployments_url":"https://api.github.com/repos/ekopylova/tcga-1/deployments","created_at":"2016-08-09T17:34:32Z","updated_at":"2016-08-09T17:33:06Z","pushed_at":"2016-08-19T16:31:38Z","git_url":"git://github.com/ekopylova/tcga-1.git","ssh_url":"git@github.com:ekopylova/tcga-1.git","clone_url":"https://github.com/ekopylova/tcga-1.git","svn_url":"https://github.com/ekopylova/tcga-1","homepage":null,"size":1,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"biocore:master","ref":"master","sha":"69fa3a47465656ae6c0cb4f8cd684a0785cfd3cc","user":{"login":"biocore","id":6241857,"avatar_url":"https://avatars.githubusercontent.com/u/6241857?v=3","gravatar_id":"","url":"https://api.github.com/users/biocore","html_url":"https://github.com/biocore","followers_url":"https://api.github.com/users/biocore/followers","following_url":"https://api.github.com/users/biocore/following{/other_user}","gists_url":"https://api.github.com/users/biocore/gists{/gist_id}","starred_url":"https://api.github.com/users/biocore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biocore/subscriptions","organizations_url":"https://api.github.com/users/biocore/orgs","repos_url":"https://api.github.com/users/biocore/repos","events_url":"https://api.github.com/users/biocore/events{/privacy}","received_events_url":"https://api.github.com/users/biocore/received_events","type":"Organization","site_admin":false},"repo":{"id":65315023,"name":"tcga","full_name":"biocore/tcga","owner":{"login":"biocore","id":6241857,"avatar_url":"https://avatars.githubusercontent.com/u/6241857?v=3","gravatar_id":"","url":"https://api.github.com/users/biocore","html_url":"https://github.com/biocore","followers_url":"https://api.github.com/users/biocore/followers","following_url":"https://api.github.com/users/biocore/following{/other_user}","gists_url":"https://api.github.com/users/biocore/gists{/gist_id}","starred_url":"https://api.github.com/users/biocore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biocore/subscriptions","organizations_url":"https://api.github.com/users/biocore/orgs","repos_url":"https://api.github.com/users/biocore/repos","events_url":"https://api.github.com/users/biocore/events{/privacy}","received_events_url":"https://api.github.com/users/biocore/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/biocore/tcga","description":"Microbial analysis in TCGA data","fork":false,"url":"https://api.github.com/repos/biocore/tcga","forks_url":"https://api.github.com/repos/biocore/tcga/forks","keys_url":"https://api.github.com/repos/biocore/tcga/keys{/key_id}","collaborators_url":"https://api.github.com/repos/biocore/tcga/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/biocore/tcga/teams","hooks_url":"https://api.github.com/repos/biocore/tcga/hooks","issue_events_url":"https://api.github.com/repos/biocore/tcga/issues/events{/number}","events_url":"https://api.github.com/repos/biocore/tcga/events","assignees_url":"https://api.github.com/repos/biocore/tcga/assignees{/user}","branches_url":"https://api.github.com/repos/biocore/tcga/branches{/branch}","tags_url":"https://api.github.com/repos/biocore/tcga/tags","blobs_url":"https://api.github.com/repos/biocore/tcga/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/biocore/tcga/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/biocore/tcga/git/refs{/sha}","trees_url":"https://api.github.com/repos/biocore/tcga/git/trees{/sha}","statuses_url":"https://api.github.com/repos/biocore/tcga/statuses/{sha}","languages_url":"https://api.github.com/repos/biocore/tcga/languages","stargazers_url":"https://api.github.com/repos/biocore/tcga/stargazers","contributors_url":"https://api.github.com/repos/biocore/tcga/contributors","subscribers_url":"https://api.github.com/repos/biocore/tcga/subscribers","subscription_url":"https://api.github.com/repos/biocore/tcga/subscription","commits_url":"https://api.github.com/repos/biocore/tcga/commits{/sha}","git_commits_url":"https://api.github.com/repos/biocore/tcga/git/commits{/sha}","comments_url":"https://api.github.com/repos/biocore/tcga/comments{/number}","issue_comment_url":"https://api.github.com/repos/biocore/tcga/issues/comments{/number}","contents_url":"https://api.github.com/repos/biocore/tcga/contents/{+path}","compare_url":"https://api.github.com/repos/biocore/tcga/compare/{base}...{head}","merges_url":"https://api.github.com/repos/biocore/tcga/merges","archive_url":"https://api.github.com/repos/biocore/tcga/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/biocore/tcga/downloads","issues_url":"https://api.github.com/repos/biocore/tcga/issues{/number}","pulls_url":"https://api.github.com/repos/biocore/tcga/pulls{/number}","milestones_url":"https://api.github.com/repos/biocore/tcga/milestones{/number}","notifications_url":"https://api.github.com/repos/biocore/tcga/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/biocore/tcga/labels{/name}","releases_url":"https://api.github.com/repos/biocore/tcga/releases{/id}","deployments_url":"https://api.github.com/repos/biocore/tcga/deployments","created_at":"2016-08-09T17:33:06Z","updated_at":"2016-08-09T17:33:06Z","pushed_at":"2016-08-19T16:32:36Z","git_url":"git://github.com/biocore/tcga.git","ssh_url":"git@github.com:biocore/tcga.git","clone_url":"https://github.com/biocore/tcga.git","svn_url":"https://github.com/biocore/tcga","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":2,"forks":2,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/biocore/tcga/pulls/2"},"html":{"href":"https://github.com/biocore/tcga/pull/2"},"issue":{"href":"https://api.github.com/repos/biocore/tcga/issues/2"},"comments":{"href":"https://api.github.com/repos/biocore/tcga/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/biocore/tcga/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/biocore/tcga/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/biocore/tcga/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/biocore/tcga/statuses/05f1a65db02132c09c802ec93304460a703a5f4c"}}}}
{"actor":{"display_login":"ElDeveloper"}}