GitHub PullRequestReviewCommentEvent at 2014-09-10 09:40:30
Repository: visualizations
Actor: remiolsen
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/SciLifeLab/visualizations/pulls/comments/17351530","id":17351530,"diff_hunk":"@@ -0,0 +1,298 @@\n+#!/usr/bin/python\n+\"\"\"\n+plot_observed_genes.py\n+\n+Takes results from cufflinks for a range of subsampled BAM files\n+and plots the number of genes with FPKM > 1 at increasing sampling\n+rates.\n+\n+Input must be a space separated list of directories. They must be\n+named with the structure:\n+  */<original_bam_filename>_<subsample_fraction>/\n+eg:\n+  path/to/data/inputFile1.bam_0.1/\n+  path/to/data/inputFile1.bam_0.2/\n+  ..\n+  path/to/data/inputFile1.bam_1.0/\n+\"\"\"\n+\n+from __future__ import print_function\n+\n+import argparse\n+from collections import defaultdict\n+import logging\n+import numpy\n+import os\n+import re\n+\n+# Import matplot lib but avoid default X environment\n+import matplotlib\n+matplotlib.use('Agg')\n+import matplotlib.pyplot as plt\n+\n+def plot_observed_genes (input_dirs, fpkm_cutoff=0, output_fn='gene_counts', read_counts_fn=None):\n+    \"\"\"\n+    Main function. Takes input files and makes a plot.\n+    \"\"\"\n+    # Parse the directory names\n+    samples = parse_input_dirnames(input_dirs)\n+    \n+    # Find the gene counts\n+    gene_counts = count_cufflinks_observed_genes(samples, fpkm_cutoff)\n+    \n+    # Try to find read counts if we have the cufflinks logs\n+    if read_counts_fn is not None:\n+        read_counts = get_read_counts(read_counts_fn, samples)\n+    else:\n+        read_counts = None\n+    \n+    # Plot the proportions\n+    filenames = plot_gene_counts(gene_counts, fpkm_cutoff, None, \"{}_proportions\".format(output_fn))\n+    \n+    # Plot the counts if we have them\n+    if read_counts is not None:\n+        proportion_filenames = plot_gene_counts(gene_counts, fpkm_cutoff, read_counts, output_fn)\n+    \n+\n+def parse_filename (fn):\n+    \"\"\"\n+    Helper function - takes a file name as input and returns a dict with \n+    the sample name and proportion.\n+    \"\"\"\n+    re_pattern = re.compile('^(.*)_([\\d\\.]+)$')\n+    m = re_pattern.match(fn)\n+    if m is None:\n+        return None\n+    else:\n+        sample = m.group(1)\n+        proportion = m.group(2)\n+        match = {\"sample\":sample, \"proportion\":proportion}\n+        return match\n+    \n+def parse_input_dirnames (input_dirs):\n+    \"\"\"\n+    Take a list of input directories and sort them into sample and proportion.\n+    Returns a dict with keys = sample names. Each var is a dict with keys\n+    equal to the proportion number and value the path to the genes.fpkm_tracking\n+    If we find a parsing error then we die.\n+    \"\"\"\n+    # Check that we have enough directories\n+    if len(input_dirs) < 2:\n+        raise IOError(\"Fatal error - we need at least two input directories!\")\n+    \n+    # Go through directories\n+    samples = defaultdict(lambda: defaultdict(str))\n+    for dirname in sorted(input_dirs):\n+        # check that we're a dir and that we exists\n+        if not os.path.isdir(dirname):\n+            if os.path.exists(dirname):\n+                raise IOError(\"Fatal error - not a directory: {}\".format(dirname))\n+            else:\n+                raise IOError(\"Fatal error - can't find input directory: {}\".format(dirname))\n+        # Strip the basename from the path\n+        dirbase = os.path.basename(dirname)\n+        # Parse the names and assign to the array\n+        match = parse_filename(dirbase)\n+        if match is None:\n+            raise Exception(\"Fatal error - couldn't match the directory name {}\".format(dirbase))","path":"subsampled_gene_observations/plot_observed_genes.py","position":97,"original_position":97,"commit_id":"4a3103177f32316ccf6138f3214ca8155d97cd4b","original_commit_id":"4a3103177f32316ccf6138f3214ca8155d97cd4b","user":{"login":"remiolsen","id":6576325,"avatar_url":"https://avatars.githubusercontent.com/u/6576325?v=2","gravatar_id":"2a3d3e1043495eb2e72e4349b06cdae6","url":"https://api.github.com/users/remiolsen","html_url":"https://github.com/remiolsen","followers_url":"https://api.github.com/users/remiolsen/followers","following_url":"https://api.github.com/users/remiolsen/following{/other_user}","gists_url":"https://api.github.com/users/remiolsen/gists{/gist_id}","starred_url":"https://api.github.com/users/remiolsen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/remiolsen/subscriptions","organizations_url":"https://api.github.com/users/remiolsen/orgs","repos_url":"https://api.github.com/users/remiolsen/repos","events_url":"https://api.github.com/users/remiolsen/events{/privacy}","received_events_url":"https://api.github.com/users/remiolsen/received_events","type":"User","site_admin":false},"body":"Sounds like an IOError to me? Not that it matters that much.","created_at":"2014-09-10T09:40:30Z","updated_at":"2014-09-10T09:40:30Z","html_url":"https://github.com/SciLifeLab/visualizations/pull/8#discussion_r17351530","pull_request_url":"https://api.github.com/repos/SciLifeLab/visualizations/pulls/8","_links":{"self":{"href":"https://api.github.com/repos/SciLifeLab/visualizations/pulls/comments/17351530"},"html":{"href":"https://github.com/SciLifeLab/visualizations/pull/8#discussion_r17351530"},"pull_request":{"href":"https://api.github.com/repos/SciLifeLab/visualizations/pulls/8"}}},"pull_request":{"url":"https://api.github.com/repos/SciLifeLab/visualizations/pulls/8","id":20875326,"html_url":"https://github.com/SciLifeLab/visualizations/pull/8","diff_url":"https://github.com/SciLifeLab/visualizations/pull/8.diff","patch_url":"https://github.com/SciLifeLab/visualizations/pull/8.patch","issue_url":"https://api.github.com/repos/SciLifeLab/visualizations/issues/8","number":8,"state":"open","locked":false,"title":"New plot tool: subsampled gene counts","user":{"login":"ewels","id":465550,"avatar_url":"https://avatars.githubusercontent.com/u/465550?v=2","gravatar_id":"2a87afa4696e7f2d7a37b5f1684b6567","url":"https://api.github.com/users/ewels","html_url":"https://github.com/ewels","followers_url":"https://api.github.com/users/ewels/followers","following_url":"https://api.github.com/users/ewels/following{/other_user}","gists_url":"https://api.github.com/users/ewels/gists{/gist_id}","starred_url":"https://api.github.com/users/ewels/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ewels/subscriptions","organizations_url":"https://api.github.com/users/ewels/orgs","repos_url":"https://api.github.com/users/ewels/repos","events_url":"https://api.github.com/users/ewels/events{/privacy}","received_events_url":"https://api.github.com/users/ewels/received_events","type":"User","site_admin":false},"body":"Added a new tool - take a group of BAM files (typically RNA-Seq), subsample them, run cufflinks on all of the subsampled files and plot the number of genes observed versus the subsampled read counts.\r\n\r\nDesigned to give a more intuitive / biological angle on the preseq complexity plot.","created_at":"2014-09-08T08:12:37Z","updated_at":"2014-09-10T09:40:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"df04da55acd194d5687aa75f6762add39adefa7f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/SciLifeLab/visualizations/pulls/8/commits","review_comments_url":"https://api.github.com/repos/SciLifeLab/visualizations/pulls/8/comments","review_comment_url":"https://api.github.com/repos/SciLifeLab/visualizations/pulls/comments/{number}","comments_url":"https://api.github.com/repos/SciLifeLab/visualizations/issues/8/comments","statuses_url":"https://api.github.com/repos/SciLifeLab/visualizations/statuses/4a3103177f32316ccf6138f3214ca8155d97cd4b","head":{"label":"ewels:master","ref":"master","sha":"4a3103177f32316ccf6138f3214ca8155d97cd4b","user":{"login":"ewels","id":465550,"avatar_url":"https://avatars.githubusercontent.com/u/465550?v=2","gravatar_id":"2a87afa4696e7f2d7a37b5f1684b6567","url":"https://api.github.com/users/ewels","html_url":"https://github.com/ewels","followers_url":"https://api.github.com/users/ewels/followers","following_url":"https://api.github.com/users/ewels/following{/other_user}","gists_url":"https://api.github.com/users/ewels/gists{/gist_id}","starred_url":"https://api.github.com/users/ewels/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ewels/subscriptions","organizations_url":"https://api.github.com/users/ewels/orgs","repos_url":"https://api.github.com/users/ewels/repos","events_url":"https://api.github.com/users/ewels/events{/privacy}","received_events_url":"https://api.github.com/users/ewels/received_events","type":"User","site_admin":false},"repo":{"id":21644809,"name":"visualizations","full_name":"ewels/visualizations","owner":{"login":"ewels","id":465550,"avatar_url":"https://avatars.githubusercontent.com/u/465550?v=2","gravatar_id":"2a87afa4696e7f2d7a37b5f1684b6567","url":"https://api.github.com/users/ewels","html_url":"https://github.com/ewels","followers_url":"https://api.github.com/users/ewels/followers","following_url":"https://api.github.com/users/ewels/following{/other_user}","gists_url":"https://api.github.com/users/ewels/gists{/gist_id}","starred_url":"https://api.github.com/users/ewels/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ewels/subscriptions","organizations_url":"https://api.github.com/users/ewels/orgs","repos_url":"https://api.github.com/users/ewels/repos","events_url":"https://api.github.com/users/ewels/events{/privacy}","received_events_url":"https://api.github.com/users/ewels/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ewels/visualizations","description":"Next-Gen Sequencing Visualisation Scripts.","fork":false,"url":"https://api.github.com/repos/ewels/visualizations","forks_url":"https://api.github.com/repos/ewels/visualizations/forks","keys_url":"https://api.github.com/repos/ewels/visualizations/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ewels/visualizations/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ewels/visualizations/teams","hooks_url":"https://api.github.com/repos/ewels/visualizations/hooks","issue_events_url":"https://api.github.com/repos/ewels/visualizations/issues/events{/number}","events_url":"https://api.github.com/repos/ewels/visualizations/events","assignees_url":"https://api.github.com/repos/ewels/visualizations/assignees{/user}","branches_url":"https://api.github.com/repos/ewels/visualizations/branches{/branch}","tags_url":"https://api.github.com/repos/ewels/visualizations/tags","blobs_url":"https://api.github.com/repos/ewels/visualizations/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ewels/visualizations/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ewels/visualizations/git/refs{/sha}","trees_url":"https://api.github.com/repos/ewels/visualizations/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ewels/visualizations/statuses/{sha}","languages_url":"https://api.github.com/repos/ewels/visualizations/languages","stargazers_url":"https://api.github.com/repos/ewels/visualizations/stargazers","contributors_url":"https://api.github.com/repos/ewels/visualizations/contributors","subscribers_url":"https://api.github.com/repos/ewels/visualizations/subscribers","subscription_url":"https://api.github.com/repos/ewels/visualizations/subscription","commits_url":"https://api.github.com/repos/ewels/visualizations/commits{/sha}","git_commits_url":"https://api.github.com/repos/ewels/visualizations/git/commits{/sha}","comments_url":"https://api.github.com/repos/ewels/visualizations/comments{/number}","issue_comment_url":"https://api.github.com/repos/ewels/visualizations/issues/comments/{number}","contents_url":"https://api.github.com/repos/ewels/visualizations/contents/{+path}","compare_url":"https://api.github.com/repos/ewels/visualizations/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ewels/visualizations/merges","archive_url":"https://api.github.com/repos/ewels/visualizations/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ewels/visualizations/downloads","issues_url":"https://api.github.com/repos/ewels/visualizations/issues{/number}","pulls_url":"https://api.github.com/repos/ewels/visualizations/pulls{/number}","milestones_url":"https://api.github.com/repos/ewels/visualizations/milestones{/number}","notifications_url":"https://api.github.com/repos/ewels/visualizations/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ewels/visualizations/labels{/name}","releases_url":"https://api.github.com/repos/ewels/visualizations/releases{/id}","created_at":"2014-07-09T08:25:16Z","updated_at":"2014-09-02T14:38:46Z","pushed_at":"2014-09-08T08:10:11Z","git_url":"git://github.com/ewels/visualizations.git","ssh_url":"git@github.com:ewels/visualizations.git","clone_url":"https://github.com/ewels/visualizations.git","svn_url":"https://github.com/ewels/visualizations","homepage":null,"size":1623,"stargazers_count":0,"watchers_count":0,"language":"Perl","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"SciLifeLab:master","ref":"master","sha":"eb23d051360c5dca66440b46045d2fa2389f82da","user":{"login":"SciLifeLab","id":713611,"avatar_url":"https://avatars.githubusercontent.com/u/713611?v=2","gravatar_id":"0ea188b063e94686a1dbb485e590e9f3","url":"https://api.github.com/users/SciLifeLab","html_url":"https://github.com/SciLifeLab","followers_url":"https://api.github.com/users/SciLifeLab/followers","following_url":"https://api.github.com/users/SciLifeLab/following{/other_user}","gists_url":"https://api.github.com/users/SciLifeLab/gists{/gist_id}","starred_url":"https://api.github.com/users/SciLifeLab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SciLifeLab/subscriptions","organizations_url":"https://api.github.com/users/SciLifeLab/orgs","repos_url":"https://api.github.com/users/SciLifeLab/repos","events_url":"https://api.github.com/users/SciLifeLab/events{/privacy}","received_events_url":"https://api.github.com/users/SciLifeLab/received_events","type":"Organization","site_admin":false},"repo":{"id":21646224,"name":"visualizations","full_name":"SciLifeLab/visualizations","owner":{"login":"SciLifeLab","id":713611,"avatar_url":"https://avatars.githubusercontent.com/u/713611?v=2","gravatar_id":"0ea188b063e94686a1dbb485e590e9f3","url":"https://api.github.com/users/SciLifeLab","html_url":"https://github.com/SciLifeLab","followers_url":"https://api.github.com/users/SciLifeLab/followers","following_url":"https://api.github.com/users/SciLifeLab/following{/other_user}","gists_url":"https://api.github.com/users/SciLifeLab/gists{/gist_id}","starred_url":"https://api.github.com/users/SciLifeLab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SciLifeLab/subscriptions","organizations_url":"https://api.github.com/users/SciLifeLab/orgs","repos_url":"https://api.github.com/users/SciLifeLab/repos","events_url":"https://api.github.com/users/SciLifeLab/events{/privacy}","received_events_url":"https://api.github.com/users/SciLifeLab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SciLifeLab/visualizations","description":"Next-Gen Sequencing Visualisation Scripts.","fork":true,"url":"https://api.github.com/repos/SciLifeLab/visualizations","forks_url":"https://api.github.com/repos/SciLifeLab/visualizations/forks","keys_url":"https://api.github.com/repos/SciLifeLab/visualizations/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SciLifeLab/visualizations/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SciLifeLab/visualizations/teams","hooks_url":"https://api.github.com/repos/SciLifeLab/visualizations/hooks","issue_events_url":"https://api.github.com/repos/SciLifeLab/visualizations/issues/events{/number}","events_url":"https://api.github.com/repos/SciLifeLab/visualizations/events","assignees_url":"https://api.github.com/repos/SciLifeLab/visualizations/assignees{/user}","branches_url":"https://api.github.com/repos/SciLifeLab/visualizations/branches{/branch}","tags_url":"https://api.github.com/repos/SciLifeLab/visualizations/tags","blobs_url":"https://api.github.com/repos/SciLifeLab/visualizations/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SciLifeLab/visualizations/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SciLifeLab/visualizations/git/refs{/sha}","trees_url":"https://api.github.com/repos/SciLifeLab/visualizations/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SciLifeLab/visualizations/statuses/{sha}","languages_url":"https://api.github.com/repos/SciLifeLab/visualizations/languages","stargazers_url":"https://api.github.com/repos/SciLifeLab/visualizations/stargazers","contributors_url":"https://api.github.com/repos/SciLifeLab/visualizations/contributors","subscribers_url":"https://api.github.com/repos/SciLifeLab/visualizations/subscribers","subscription_url":"https://api.github.com/repos/SciLifeLab/visualizations/subscription","commits_url":"https://api.github.com/repos/SciLifeLab/visualizations/commits{/sha}","git_commits_url":"https://api.github.com/repos/SciLifeLab/visualizations/git/commits{/sha}","comments_url":"https://api.github.com/repos/SciLifeLab/visualizations/comments{/number}","issue_comment_url":"https://api.github.com/repos/SciLifeLab/visualizations/issues/comments/{number}","contents_url":"https://api.github.com/repos/SciLifeLab/visualizations/contents/{+path}","compare_url":"https://api.github.com/repos/SciLifeLab/visualizations/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SciLifeLab/visualizations/merges","archive_url":"https://api.github.com/repos/SciLifeLab/visualizations/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SciLifeLab/visualizations/downloads","issues_url":"https://api.github.com/repos/SciLifeLab/visualizations/issues{/number}","pulls_url":"https://api.github.com/repos/SciLifeLab/visualizations/pulls{/number}","milestones_url":"https://api.github.com/repos/SciLifeLab/visualizations/milestones{/number}","notifications_url":"https://api.github.com/repos/SciLifeLab/visualizations/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SciLifeLab/visualizations/labels{/name}","releases_url":"https://api.github.com/repos/SciLifeLab/visualizations/releases{/id}","created_at":"2014-07-09T09:11:16Z","updated_at":"2014-07-10T11:34:21Z","pushed_at":"2014-08-13T15:14:49Z","git_url":"git://github.com/SciLifeLab/visualizations.git","ssh_url":"git@github.com:SciLifeLab/visualizations.git","clone_url":"https://github.com/SciLifeLab/visualizations.git","svn_url":"https://github.com/SciLifeLab/visualizations","homepage":null,"size":1182,"stargazers_count":3,"watchers_count":3,"language":"Perl","has_issues":true,"has_downloads":true,"has_wiki":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SciLifeLab/visualizations/pulls/8"},"html":{"href":"https://github.com/SciLifeLab/visualizations/pull/8"},"issue":{"href":"https://api.github.com/repos/SciLifeLab/visualizations/issues/8"},"comments":{"href":"https://api.github.com/repos/SciLifeLab/visualizations/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/SciLifeLab/visualizations/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/SciLifeLab/visualizations/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/SciLifeLab/visualizations/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/SciLifeLab/visualizations/statuses/4a3103177f32316ccf6138f3214ca8155d97cd4b"}}}}