{"action":"created","comment":{"url":"https://api.github.com/repos/biocore/deblur/pulls/comments/39879629","id":39879629,"diff_hunk":"@@ -185,9 +194,114 @@ def remove_chimeras_denovo_from_seqs(seqs_fp, output_fp):\n     rename(output_non_chimera_filepath, output_fp)\n \n \n-def generate_biom_table(seqs_fp):\n-    \"\"\"Generate BIOM table and representative FASTA set\"\"\"\n-    pass\n+def parse_deblur_output(seqs_fp, derep_clusters):\n+    \"\"\" Parse deblur output file into an OTU map\n+\n+    For each deblurred sequence in seqs_fp, use the sequence label to\n+    obtain all dereplicated sequence labels belonging to it\n+    (from derep_clusters) to create entries in a new dictionary where the keys\n+    are actual sequences (not the labels). Note not all sequences\n+    in derep_clusters will be in seqs_fp since they could have been removed in\n+    the artifact filtering step.\n+\n+    Parameters\n+    ----------\n+    seqs_fp: string\n+        file path to deblurred sequences\n+    derep_clusters: dictionary\n+        dictionary of dereplicated sequences map\n+\n+    Returns\n+    -------\n+    clusters: dictionary\n+        dictionary of clusters including dereplicated sequence labels\n+    \"\"\"\n+    clusters = {}\n+    # Replace representative sequence name with actual sequence in cluster\n+    msa_fa = Alignment.read(seqs_fp, format='fasta')\n+    for label, seq in Alignment.iteritems(msa_fa):\n+        cluster_id = label.split(';')[0]\n+        seq2 = str(seq.degap())\n+        if seq2 not in clusters:\n+            clusters[seq2] = []\n+        if cluster_id not in derep_clusters:\n+            raise ValueError(\n+                'Seed ID %s does not exist in .uc file' % cluster_id)\n+        else:\n+            clusters[seq2].extend(derep_clusters[cluster_id])\n+    return clusters\n+\n+\n+def generate_biom_data(clusters, delim='_'):\n+    \"\"\" Parse OTU map dictionary into a sparse dictionary\n+    {(cluster_idx,sample_idx):count}\n+\n+    Parameters\n+    ----------\n+    clusters: dictionary\n+        OTU map as dictionary\n+    delim: string, optional\n+        delimiter for splitting sample and sequence IDs in sequence label\n+\n+    Returns\n+    -------\n+    data: dictionary\n+        sprase dictionary {(otu_idx,sample_idx):count}\n+    cluster_ids: list\n+        list of cluster IDs\n+    sample_ids: list\n+        list of sample IDs\n+    \"\"\"\n+    sample_ids = []\n+    sample_id_idx = {}\n+    data = defaultdict(int)\n+    sample_count = 0\n+    for cluster_idx, otu in enumerate(clusters):\n+        for seq_id in clusters[otu]:\n+            seq_id_sample = seq_id.split(delim)[0]\n+            try:\n+                sample_idx = sample_id_idx[seq_id_sample]\n+            except KeyError:\n+                sample_idx = sample_count\n+                sample_id_idx[seq_id_sample] = sample_idx\n+                sample_ids.append(seq_id_sample)\n+                sample_count += 1\n+            data[(cluster_idx, sample_idx)] += 1\n+    cluster_ids = clusters.keys()\n+\n+    return data, cluster_ids, sample_ids\n+\n+\n+def generate_biom_table(seqs_fp,\n+                        uc_fp,\n+                        output_biom_fp,\n+                        delim='_'):\n+    \"\"\"Generate BIOM table and representative FASTA set\n+\n+    Parameters\n+    ----------\n+    seqs_fp: string\n+        file path to deblurred sequences\n+    uc_fp: string\n+        file path to dereplicated sequences map (.uc format)\n+    output_biom_fp: string\n+        file path to output BIOM table\n+    delim: string, optional\n+        delimiter for splitting sample and sequence IDs in sequence label","path":"deblur/workflow.py","position":151,"original_position":151,"commit_id":"3bff903f1a1f60c879c31ce7231342b28ee20544","original_commit_id":"3bff903f1a1f60c879c31ce7231342b28ee20544","user":{"login":"josenavas","id":2501478,"avatar_url":"https://avatars.githubusercontent.com/u/2501478?v=3","gravatar_id":"","url":"https://api.github.com/users/josenavas","html_url":"https://github.com/josenavas","followers_url":"https://api.github.com/users/josenavas/followers","following_url":"https://api.github.com/users/josenavas/following{/other_user}","gists_url":"https://api.github.com/users/josenavas/gists{/gist_id}","starred_url":"https://api.github.com/users/josenavas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josenavas/subscriptions","organizations_url":"https://api.github.com/users/josenavas/orgs","repos_url":"https://api.github.com/users/josenavas/repos","events_url":"https://api.github.com/users/josenavas/events{/privacy}","received_events_url":"https://api.github.com/users/josenavas/received_events","type":"User","site_admin":false},"body":"Same here","created_at":"2015-09-18T17:27:10Z","updated_at":"2015-09-18T17:27:10Z","html_url":"https://github.com/biocore/deblur/pull/22#discussion_r39879629","pull_request_url":"https://api.github.com/repos/biocore/deblur/pulls/22","_links":{"self":{"href":"https://api.github.com/repos/biocore/deblur/pulls/comments/39879629"},"html":{"href":"https://github.com/biocore/deblur/pull/22#discussion_r39879629"},"pull_request":{"href":"https://api.github.com/repos/biocore/deblur/pulls/22"}}},"pull_request":{"url":"https://api.github.com/repos/biocore/deblur/pulls/22","id":44042327,"html_url":"https://github.com/biocore/deblur/pull/22","diff_url":"https://github.com/biocore/deblur/pull/22.diff","patch_url":"https://github.com/biocore/deblur/pull/22.patch","issue_url":"https://api.github.com/repos/biocore/deblur/issues/22","number":22,"state":"open","locked":false,"title":"Issue 15","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":"","created_at":"2015-09-02T21:04:44Z","updated_at":"2015-09-18T17:27:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0624b8fb8a6081eb44f5a8095a0d2966fbf428e4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/biocore/deblur/pulls/22/commits","review_comments_url":"https://api.github.com/repos/biocore/deblur/pulls/22/comments","review_comment_url":"https://api.github.com/repos/biocore/deblur/pulls/comments{/number}","comments_url":"https://api.github.com/repos/biocore/deblur/issues/22/comments","statuses_url":"https://api.github.com/repos/biocore/deblur/statuses/3bff903f1a1f60c879c31ce7231342b28ee20544","head":{"label":"ekopylova:issue_15","ref":"issue_15","sha":"3bff903f1a1f60c879c31ce7231342b28ee20544","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":31328080,"name":"deblur","full_name":"ekopylova/deblur","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/deblur","description":"","fork":true,"url":"https://api.github.com/repos/ekopylova/deblur","forks_url":"https://api.github.com/repos/ekopylova/deblur/forks","keys_url":"https://api.github.com/repos/ekopylova/deblur/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ekopylova/deblur/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ekopylova/deblur/teams","hooks_url":"https://api.github.com/repos/ekopylova/deblur/hooks","issue_events_url":"https://api.github.com/repos/ekopylova/deblur/issues/events{/number}","events_url":"https://api.github.com/repos/ekopylova/deblur/events","assignees_url":"https://api.github.com/repos/ekopylova/deblur/assignees{/user}","branches_url":"https://api.github.com/repos/ekopylova/deblur/branches{/branch}","tags_url":"https://api.github.com/repos/ekopylova/deblur/tags","blobs_url":"https://api.github.com/repos/ekopylova/deblur/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ekopylova/deblur/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ekopylova/deblur/git/refs{/sha}","trees_url":"https://api.github.com/repos/ekopylova/deblur/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ekopylova/deblur/statuses/{sha}","languages_url":"https://api.github.com/repos/ekopylova/deblur/languages","stargazers_url":"https://api.github.com/repos/ekopylova/deblur/stargazers","contributors_url":"https://api.github.com/repos/ekopylova/deblur/contributors","subscribers_url":"https://api.github.com/repos/ekopylova/deblur/subscribers","subscription_url":"https://api.github.com/repos/ekopylova/deblur/subscription","commits_url":"https://api.github.com/repos/ekopylova/deblur/commits{/sha}","git_commits_url":"https://api.github.com/repos/ekopylova/deblur/git/commits{/sha}","comments_url":"https://api.github.com/repos/ekopylova/deblur/comments{/number}","issue_comment_url":"https://api.github.com/repos/ekopylova/deblur/issues/comments{/number}","contents_url":"https://api.github.com/repos/ekopylova/deblur/contents/{+path}","compare_url":"https://api.github.com/repos/ekopylova/deblur/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ekopylova/deblur/merges","archive_url":"https://api.github.com/repos/ekopylova/deblur/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ekopylova/deblur/downloads","issues_url":"https://api.github.com/repos/ekopylova/deblur/issues{/number}","pulls_url":"https://api.github.com/repos/ekopylova/deblur/pulls{/number}","milestones_url":"https://api.github.com/repos/ekopylova/deblur/milestones{/number}","notifications_url":"https://api.github.com/repos/ekopylova/deblur/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ekopylova/deblur/labels{/name}","releases_url":"https://api.github.com/repos/ekopylova/deblur/releases{/id}","created_at":"2015-02-25T18:07:35Z","updated_at":"2015-04-14T16:24:52Z","pushed_at":"2015-09-16T12:11:55Z","git_url":"git://github.com/ekopylova/deblur.git","ssh_url":"git@github.com:ekopylova/deblur.git","clone_url":"https://github.com/ekopylova/deblur.git","svn_url":"https://github.com/ekopylova/deblur","homepage":"","size":273,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"c30f3b42a75201af27555a858743b37a1fad45eb","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":29548011,"name":"deblur","full_name":"biocore/deblur","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/deblur","description":"","fork":false,"url":"https://api.github.com/repos/biocore/deblur","forks_url":"https://api.github.com/repos/biocore/deblur/forks","keys_url":"https://api.github.com/repos/biocore/deblur/keys{/key_id}","collaborators_url":"https://api.github.com/repos/biocore/deblur/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/biocore/deblur/teams","hooks_url":"https://api.github.com/repos/biocore/deblur/hooks","issue_events_url":"https://api.github.com/repos/biocore/deblur/issues/events{/number}","events_url":"https://api.github.com/repos/biocore/deblur/events","assignees_url":"https://api.github.com/repos/biocore/deblur/assignees{/user}","branches_url":"https://api.github.com/repos/biocore/deblur/branches{/branch}","tags_url":"https://api.github.com/repos/biocore/deblur/tags","blobs_url":"https://api.github.com/repos/biocore/deblur/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/biocore/deblur/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/biocore/deblur/git/refs{/sha}","trees_url":"https://api.github.com/repos/biocore/deblur/git/trees{/sha}","statuses_url":"https://api.github.com/repos/biocore/deblur/statuses/{sha}","languages_url":"https://api.github.com/repos/biocore/deblur/languages","stargazers_url":"https://api.github.com/repos/biocore/deblur/stargazers","contributors_url":"https://api.github.com/repos/biocore/deblur/contributors","subscribers_url":"https://api.github.com/repos/biocore/deblur/subscribers","subscription_url":"https://api.github.com/repos/biocore/deblur/subscription","commits_url":"https://api.github.com/repos/biocore/deblur/commits{/sha}","git_commits_url":"https://api.github.com/repos/biocore/deblur/git/commits{/sha}","comments_url":"https://api.github.com/repos/biocore/deblur/comments{/number}","issue_comment_url":"https://api.github.com/repos/biocore/deblur/issues/comments{/number}","contents_url":"https://api.github.com/repos/biocore/deblur/contents/{+path}","compare_url":"https://api.github.com/repos/biocore/deblur/compare/{base}...{head}","merges_url":"https://api.github.com/repos/biocore/deblur/merges","archive_url":"https://api.github.com/repos/biocore/deblur/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/biocore/deblur/downloads","issues_url":"https://api.github.com/repos/biocore/deblur/issues{/number}","pulls_url":"https://api.github.com/repos/biocore/deblur/pulls{/number}","milestones_url":"https://api.github.com/repos/biocore/deblur/milestones{/number}","notifications_url":"https://api.github.com/repos/biocore/deblur/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/biocore/deblur/labels{/name}","releases_url":"https://api.github.com/repos/biocore/deblur/releases{/id}","created_at":"2015-01-20T19:34:02Z","updated_at":"2015-04-14T15:54:30Z","pushed_at":"2015-09-16T12:11:57Z","git_url":"git://github.com/biocore/deblur.git","ssh_url":"git@github.com:biocore/deblur.git","clone_url":"https://github.com/biocore/deblur.git","svn_url":"https://github.com/biocore/deblur","homepage":"","size":342,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":9,"forks":5,"open_issues":9,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/biocore/deblur/pulls/22"},"html":{"href":"https://github.com/biocore/deblur/pull/22"},"issue":{"href":"https://api.github.com/repos/biocore/deblur/issues/22"},"comments":{"href":"https://api.github.com/repos/biocore/deblur/issues/22/comments"},"review_comments":{"href":"https://api.github.com/repos/biocore/deblur/pulls/22/comments"},"review_comment":{"href":"https://api.github.com/repos/biocore/deblur/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/biocore/deblur/pulls/22/commits"},"statuses":{"href":"https://api.github.com/repos/biocore/deblur/statuses/3bff903f1a1f60c879c31ce7231342b28ee20544"}}}}