GitHub PullRequestReviewCommentEvent at 2014-12-24 07:39:22
Repository: afra
Actor: yeban
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/yeban/afra/pulls/comments/22248073","id":22248073,"diff_hunk":"@@ -0,0 +1,137 @@\n+# This file creates a GFF3 file for all the annotation submissions\n+# corresponding to GFF file specified by the user. The GFF3 specification can\n+# be found on The Sequence Ontology Project's website [1]. To verify the\n+# generated GFF3 file use the online tool provided by genometools [2].\n+class Exporter\n+\n+  BLACKLISTED_TYPES = %w(non_canonical_splice_site\n+                          non_canonical_translation_start_site\n+                          non_canonical_translation_stop_site)\n+  def initialize(annotations_file)\n+    @annotations_file = annotations_file\n+    species, asm_id = annotations_file.split('/')[-2..-1]\n+    asm_id.sub!(/(\\.gff)$/, '')\n+    @genome = Genome.first species: species, asm_id: asm_id\n+\n+    @subfeature_count = Hash.new(0)\n+  end\n+\n+  attr_reader :genome\n+\n+  # Returns all the submissions objects for a given GFF3 file.\n+  def submissions\n+    ref_seqs = @genome.ref_seqs.map(&:seq_id)\n+    task_ids  = Task.where(ref_seq_id: ref_seqs).map(&:id)\n+    Submission.where task_id: task_ids\n+  end\n+\n+  def run\n+    gff_data = []\n+    submissions.each do |submission|\n+      submission.data['value'].each do |transcript|\n+        gff_data << transcript_to_gff(transcript)\n+      end\n+    end\n+    puts create_gff_file_from_data(gff_data)\n+  end\n+\n+  def transcript_to_gff(transcript)\n+    data = []\n+    data << feature_to_gff(transcript)\n+\n+    phase = 0\n+    transcript['subfeatures'].each do |subfeature|\n+      unless BLACKLISTED_TYPES.include? subfeature['type']\n+        data << feature_to_gff(subfeature, phase, true)\n+      end\n+\n+      if subfeature['type'] == 'CDS'\n+        start = subfeature['start']\n+        stop = subfeature['end']\n+        phase = (3 - (((stop + 1) - start - phase) % 3)) % 3\n+      end\n+    end\n+\n+    data\n+  end\n+\n+  def feature_to_gff(subfeature, phase = nil, parent = false)\n+    gff_strand = {\n+      1  => '+',\n+      -1 => '-',\n+      nil => '.'\n+    }\n+    type = subfeature['type'] == 'transcript' ? 'gene' : subfeature['type']\n+    @subfeature_count[type] += 1\n+\n+    data = []\n+\n+    data << \"#{subfeature['seq_id']}\"\n+    data << 'afra' # source\n+    data << \"#{type}\"\n+    data << \"#{subfeature['start']}\"\n+    data << \"#{subfeature['end']}\"\n+    data << '.' # score\n+    data << \"#{gff_strand[subfeature['strand']]}\"\n+\n+    # phase\n+    if type == 'CDS'\n+      data << \"#{phase}\"\n+    else\n+      data << '.'\n+    end\n+\n+    # attributes\n+    id = \"#{type}#{@subfeature_count[type]}\"\n+    if parent\n+      data << \"ID=#{id};\\\n+               Name=#{subfeature['name']}:#{id};\\\n+               Parent=gene#{@subfeature_count['gene']}\"\n+    else\n+      data << \"ID=gene#{@subfeature_count['gene']};Name=#{subfeature['name']}\"\n+    end\n+\n+    data\n+  end\n+\n+  def create_gff_file_from_data(gff_data)\n+    sr_data = []  # sr: sequence-region\n+    seq_id_index = {}\n+\n+    # Seperate the transcript data on the basis of their seq_id\n+    gff_data.each do |transcript_data|\n+      seq_id = transcript_data[0][0]\n+      unless seq_id_index.keys.include? seq_id\n+        seq_id_index[seq_id] = sr_data.length\n+        sr_data << []\n+      end\n+\n+      sr_data[seq_id_index[seq_id]] << transcript_data\n+    end\n+\n+    sr_str = []\n+    sr_data.each_with_index do |file, i|\n+      sr_str << []\n+      seq_id = seq_id_index.invert[i]\n+      start = 1\n+      stop = (RefSeq.where seq_id: seq_id).first[:length]","path":"services/exporter.rb","position":117,"original_position":117,"commit_id":"350ae26beb141f40ea183a15391a155d887c7ad7","original_commit_id":"350ae26beb141f40ea183a15391a155d887c7ad7","user":{"login":"yeban","id":90373,"avatar_url":"https://avatars.githubusercontent.com/u/90373?v=3","gravatar_id":"","url":"https://api.github.com/users/yeban","html_url":"https://github.com/yeban","followers_url":"https://api.github.com/users/yeban/followers","following_url":"https://api.github.com/users/yeban/following{/other_user}","gists_url":"https://api.github.com/users/yeban/gists{/gist_id}","starred_url":"https://api.github.com/users/yeban/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yeban/subscriptions","organizations_url":"https://api.github.com/users/yeban/orgs","repos_url":"https://api.github.com/users/yeban/repos","events_url":"https://api.github.com/users/yeban/events{/privacy}","received_events_url":"https://api.github.com/users/yeban/received_events","type":"User","site_admin":false},"body":"Use parens around the params, instead of around the statement.","created_at":"2014-12-24T07:39:22Z","updated_at":"2014-12-24T07:39:22Z","html_url":"https://github.com/yeban/afra/pull/67#discussion_r22248073","pull_request_url":"https://api.github.com/repos/yeban/afra/pulls/67","_links":{"self":{"href":"https://api.github.com/repos/yeban/afra/pulls/comments/22248073"},"html":{"href":"https://github.com/yeban/afra/pull/67#discussion_r22248073"},"pull_request":{"href":"https://api.github.com/repos/yeban/afra/pulls/67"}}},"pull_request":{"url":"https://api.github.com/repos/yeban/afra/pulls/67","id":26298189,"html_url":"https://github.com/yeban/afra/pull/67","diff_url":"https://github.com/yeban/afra/pull/67.diff","patch_url":"https://github.com/yeban/afra/pull/67.patch","issue_url":"https://api.github.com/repos/yeban/afra/issues/67","number":67,"state":"open","locked":false,"title":"[WIP] export submissions to GFF3 format","user":{"login":"hargup","id":2477788,"avatar_url":"https://avatars.githubusercontent.com/u/2477788?v=3","gravatar_id":"","url":"https://api.github.com/users/hargup","html_url":"https://github.com/hargup","followers_url":"https://api.github.com/users/hargup/followers","following_url":"https://api.github.com/users/hargup/following{/other_user}","gists_url":"https://api.github.com/users/hargup/gists{/gist_id}","starred_url":"https://api.github.com/users/hargup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hargup/subscriptions","organizations_url":"https://api.github.com/users/hargup/orgs","repos_url":"https://api.github.com/users/hargup/repos","events_url":"https://api.github.com/users/hargup/events{/privacy}","received_events_url":"https://api.github.com/users/hargup/received_events","type":"User","site_admin":false},"body":"This is a Work in Progress[WIP].\r\n\r\n- [x] Change indentation to 2 spaces.\r\n- [x] Verify the generated GFF3 file using http://genometools.org/cgi-bin/gff3validator.cgi\r\n- [x] Handle more than one submission\r\n- [x] Handle more than one transcript in a single submission\r\n- [x] Create a black list of non standard subfeature type to ignore while exporting them.\r\n- [x] Fix the phase calculation\r\n- [x] Query `Task` and `Submission` to find out all the submission corresponding to a `GFF` given by the user from the database.\r\n- [x] Re-factor code to reduce redundancy.\r\n- [x] Calculate the `end` part for the `##sequence-region` meta-data\r\n- [ ] Rebase and clean up the history.","created_at":"2014-12-18T12:56:55Z","updated_at":"2014-12-24T07:39:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"30e64316d99f58479efbc02206547a93dd420c12","assignee":{"login":"hargup","id":2477788,"avatar_url":"https://avatars.githubusercontent.com/u/2477788?v=3","gravatar_id":"","url":"https://api.github.com/users/hargup","html_url":"https://github.com/hargup","followers_url":"https://api.github.com/users/hargup/followers","following_url":"https://api.github.com/users/hargup/following{/other_user}","gists_url":"https://api.github.com/users/hargup/gists{/gist_id}","starred_url":"https://api.github.com/users/hargup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hargup/subscriptions","organizations_url":"https://api.github.com/users/hargup/orgs","repos_url":"https://api.github.com/users/hargup/repos","events_url":"https://api.github.com/users/hargup/events{/privacy}","received_events_url":"https://api.github.com/users/hargup/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/yeban/afra/pulls/67/commits","review_comments_url":"https://api.github.com/repos/yeban/afra/pulls/67/comments","review_comment_url":"https://api.github.com/repos/yeban/afra/pulls/comments/{number}","comments_url":"https://api.github.com/repos/yeban/afra/issues/67/comments","statuses_url":"https://api.github.com/repos/yeban/afra/statuses/350ae26beb141f40ea183a15391a155d887c7ad7","head":{"label":"hargup:exporter","ref":"exporter","sha":"350ae26beb141f40ea183a15391a155d887c7ad7","user":{"login":"hargup","id":2477788,"avatar_url":"https://avatars.githubusercontent.com/u/2477788?v=3","gravatar_id":"","url":"https://api.github.com/users/hargup","html_url":"https://github.com/hargup","followers_url":"https://api.github.com/users/hargup/followers","following_url":"https://api.github.com/users/hargup/following{/other_user}","gists_url":"https://api.github.com/users/hargup/gists{/gist_id}","starred_url":"https://api.github.com/users/hargup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hargup/subscriptions","organizations_url":"https://api.github.com/users/hargup/orgs","repos_url":"https://api.github.com/users/hargup/repos","events_url":"https://api.github.com/users/hargup/events{/privacy}","received_events_url":"https://api.github.com/users/hargup/received_events","type":"User","site_admin":false},"repo":{"id":23881274,"name":"afra","full_name":"hargup/afra","owner":{"login":"hargup","id":2477788,"avatar_url":"https://avatars.githubusercontent.com/u/2477788?v=3","gravatar_id":"","url":"https://api.github.com/users/hargup","html_url":"https://github.com/hargup","followers_url":"https://api.github.com/users/hargup/followers","following_url":"https://api.github.com/users/hargup/following{/other_user}","gists_url":"https://api.github.com/users/hargup/gists{/gist_id}","starred_url":"https://api.github.com/users/hargup/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hargup/subscriptions","organizations_url":"https://api.github.com/users/hargup/orgs","repos_url":"https://api.github.com/users/hargup/repos","events_url":"https://api.github.com/users/hargup/events{/privacy}","received_events_url":"https://api.github.com/users/hargup/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/hargup/afra","description":"Genome Annotation for the Masses","fork":true,"url":"https://api.github.com/repos/hargup/afra","forks_url":"https://api.github.com/repos/hargup/afra/forks","keys_url":"https://api.github.com/repos/hargup/afra/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hargup/afra/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hargup/afra/teams","hooks_url":"https://api.github.com/repos/hargup/afra/hooks","issue_events_url":"https://api.github.com/repos/hargup/afra/issues/events{/number}","events_url":"https://api.github.com/repos/hargup/afra/events","assignees_url":"https://api.github.com/repos/hargup/afra/assignees{/user}","branches_url":"https://api.github.com/repos/hargup/afra/branches{/branch}","tags_url":"https://api.github.com/repos/hargup/afra/tags","blobs_url":"https://api.github.com/repos/hargup/afra/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hargup/afra/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hargup/afra/git/refs{/sha}","trees_url":"https://api.github.com/repos/hargup/afra/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hargup/afra/statuses/{sha}","languages_url":"https://api.github.com/repos/hargup/afra/languages","stargazers_url":"https://api.github.com/repos/hargup/afra/stargazers","contributors_url":"https://api.github.com/repos/hargup/afra/contributors","subscribers_url":"https://api.github.com/repos/hargup/afra/subscribers","subscription_url":"https://api.github.com/repos/hargup/afra/subscription","commits_url":"https://api.github.com/repos/hargup/afra/commits{/sha}","git_commits_url":"https://api.github.com/repos/hargup/afra/git/commits{/sha}","comments_url":"https://api.github.com/repos/hargup/afra/comments{/number}","issue_comment_url":"https://api.github.com/repos/hargup/afra/issues/comments/{number}","contents_url":"https://api.github.com/repos/hargup/afra/contents/{+path}","compare_url":"https://api.github.com/repos/hargup/afra/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hargup/afra/merges","archive_url":"https://api.github.com/repos/hargup/afra/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hargup/afra/downloads","issues_url":"https://api.github.com/repos/hargup/afra/issues{/number}","pulls_url":"https://api.github.com/repos/hargup/afra/pulls{/number}","milestones_url":"https://api.github.com/repos/hargup/afra/milestones{/number}","notifications_url":"https://api.github.com/repos/hargup/afra/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hargup/afra/labels{/name}","releases_url":"https://api.github.com/repos/hargup/afra/releases{/id}","created_at":"2014-09-10T16:03:52Z","updated_at":"2014-11-11T15:01:55Z","pushed_at":"2014-12-23T16:10:26Z","git_url":"git://github.com/hargup/afra.git","ssh_url":"git@github.com:hargup/afra.git","clone_url":"https://github.com/hargup/afra.git","svn_url":"https://github.com/hargup/afra","homepage":"http://afra.sbcs.qmul.ac.uk","size":14185,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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":"yeban:master","ref":"master","sha":"d75a8ba47148131130d37321892cbfcd466e0923","user":{"login":"yeban","id":90373,"avatar_url":"https://avatars.githubusercontent.com/u/90373?v=3","gravatar_id":"","url":"https://api.github.com/users/yeban","html_url":"https://github.com/yeban","followers_url":"https://api.github.com/users/yeban/followers","following_url":"https://api.github.com/users/yeban/following{/other_user}","gists_url":"https://api.github.com/users/yeban/gists{/gist_id}","starred_url":"https://api.github.com/users/yeban/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yeban/subscriptions","organizations_url":"https://api.github.com/users/yeban/orgs","repos_url":"https://api.github.com/users/yeban/repos","events_url":"https://api.github.com/users/yeban/events{/privacy}","received_events_url":"https://api.github.com/users/yeban/received_events","type":"User","site_admin":false},"repo":{"id":6967038,"name":"afra","full_name":"yeban/afra","owner":{"login":"yeban","id":90373,"avatar_url":"https://avatars.githubusercontent.com/u/90373?v=3","gravatar_id":"","url":"https://api.github.com/users/yeban","html_url":"https://github.com/yeban","followers_url":"https://api.github.com/users/yeban/followers","following_url":"https://api.github.com/users/yeban/following{/other_user}","gists_url":"https://api.github.com/users/yeban/gists{/gist_id}","starred_url":"https://api.github.com/users/yeban/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yeban/subscriptions","organizations_url":"https://api.github.com/users/yeban/orgs","repos_url":"https://api.github.com/users/yeban/repos","events_url":"https://api.github.com/users/yeban/events{/privacy}","received_events_url":"https://api.github.com/users/yeban/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yeban/afra","description":"Genome Annotation for the Masses","fork":false,"url":"https://api.github.com/repos/yeban/afra","forks_url":"https://api.github.com/repos/yeban/afra/forks","keys_url":"https://api.github.com/repos/yeban/afra/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yeban/afra/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yeban/afra/teams","hooks_url":"https://api.github.com/repos/yeban/afra/hooks","issue_events_url":"https://api.github.com/repos/yeban/afra/issues/events{/number}","events_url":"https://api.github.com/repos/yeban/afra/events","assignees_url":"https://api.github.com/repos/yeban/afra/assignees{/user}","branches_url":"https://api.github.com/repos/yeban/afra/branches{/branch}","tags_url":"https://api.github.com/repos/yeban/afra/tags","blobs_url":"https://api.github.com/repos/yeban/afra/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yeban/afra/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yeban/afra/git/refs{/sha}","trees_url":"https://api.github.com/repos/yeban/afra/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yeban/afra/statuses/{sha}","languages_url":"https://api.github.com/repos/yeban/afra/languages","stargazers_url":"https://api.github.com/repos/yeban/afra/stargazers","contributors_url":"https://api.github.com/repos/yeban/afra/contributors","subscribers_url":"https://api.github.com/repos/yeban/afra/subscribers","subscription_url":"https://api.github.com/repos/yeban/afra/subscription","commits_url":"https://api.github.com/repos/yeban/afra/commits{/sha}","git_commits_url":"https://api.github.com/repos/yeban/afra/git/commits{/sha}","comments_url":"https://api.github.com/repos/yeban/afra/comments{/number}","issue_comment_url":"https://api.github.com/repos/yeban/afra/issues/comments/{number}","contents_url":"https://api.github.com/repos/yeban/afra/contents/{+path}","compare_url":"https://api.github.com/repos/yeban/afra/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yeban/afra/merges","archive_url":"https://api.github.com/repos/yeban/afra/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yeban/afra/downloads","issues_url":"https://api.github.com/repos/yeban/afra/issues{/number}","pulls_url":"https://api.github.com/repos/yeban/afra/pulls{/number}","milestones_url":"https://api.github.com/repos/yeban/afra/milestones{/number}","notifications_url":"https://api.github.com/repos/yeban/afra/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yeban/afra/labels{/name}","releases_url":"https://api.github.com/repos/yeban/afra/releases{/id}","created_at":"2012-12-02T12:41:46Z","updated_at":"2014-12-20T04:41:48Z","pushed_at":"2014-12-20T04:41:45Z","git_url":"git://github.com/yeban/afra.git","ssh_url":"git@github.com:yeban/afra.git","clone_url":"https://github.com/yeban/afra.git","svn_url":"https://github.com/yeban/afra","homepage":"http://afra.sbcs.qmul.ac.uk","size":17480,"stargazers_count":21,"watchers_count":21,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"open_issues_count":14,"forks":10,"open_issues":14,"watchers":21,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/yeban/afra/pulls/67"},"html":{"href":"https://github.com/yeban/afra/pull/67"},"issue":{"href":"https://api.github.com/repos/yeban/afra/issues/67"},"comments":{"href":"https://api.github.com/repos/yeban/afra/issues/67/comments"},"review_comments":{"href":"https://api.github.com/repos/yeban/afra/pulls/67/comments"},"review_comment":{"href":"https://api.github.com/repos/yeban/afra/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/yeban/afra/pulls/67/commits"},"statuses":{"href":"https://api.github.com/repos/yeban/afra/statuses/350ae26beb141f40ea183a15391a155d887c7ad7"}}}}