{"action":"created","comment":{"url":"https://api.github.com/repos/bigdatagenomics/adam/pulls/comments/25547171","id":25547171,"diff_hunk":"@@ -0,0 +1,187 @@\n+/**\n+ * Licensed to Big Data Genomics (BDG) under one\n+ * or more contributor license agreements.  See the NOTICE file\n+ * distributed with this work for additional information\n+ * regarding copyright ownership.  The BDG licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance\n+ * with the License.  You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package org.bdgenomics.adam.rdd\n+\n+import org.apache.spark.SparkContext._\n+import org.apache.spark.rdd.RDD\n+import org.bdgenomics.adam.models.{ SequenceDictionary, ReferenceRegionWithOrientation, ReferenceRegion }\n+import org.bdgenomics.adam.models.ReferenceRegionContext._\n+import org.bdgenomics.adam.rich.ReferenceMappingContext.ReferenceRegionReferenceMapping\n+import scala.reflect.ClassTag\n+import scala.math.max\n+\n+/**\n+ * Functions (joins, filters, groups, counts) that are often invoked on RDD[R] where R is a\n+ * type which extends ReferenceRegion (and is often just ReferenceRegion directly).\n+ *\n+ * @param rdd The argument RDD\n+ * @param kt The type of the argument RDD must be explicit\n+ * @tparam Region The type of the argument RDD\n+ */\n+class RegionRDDFunctions[Region <: ReferenceRegion](rdd: RDD[Region])(implicit kt: ClassTag[Region])\n+    extends Serializable {\n+\n+  import RegionRDDFunctions._\n+\n+  private def regionToReferenceRegion(region: Region): Option[ReferenceRegion] = Option(region)\n+\n+  private def expander(range: Long)(r: Region): ReferenceRegion =\n+    ReferenceRegion(r.referenceName, max(0, r.start - range), r.end + range)\n+\n+  /**\n+   * Performs an 'overlap join' on the input RDD, returning pairs whose first element is a member of the\n+   * input RDD and whose second element is a member of the argument RDD which overlaps the first element\n+   * of the pair.\n+   *\n+   * @param that The argument RDD\n+   * @param kt2 The type of the values in the argument RDD must be explicit.\n+   * @tparam R2 The explicit type of the regions in the argument RDD\n+   * @return The RDD of pairs (f, s) where f comes from the input RDD and s comes from 'that', the argument\n+   *         RDD.\n+   */\n+  def joinByOverlap[R2 <: ReferenceRegion](that: RDD[R2])(implicit kt2: ClassTag[R2]): RDD[(Region, R2)] =\n+    RegionJoin.partitionAndJoin[Region, R2](rdd, that, r => regionToReferenceRegion(r), (r: R2) => Option(r))\n+\n+  /**\n+   * Performs a 'range join' on the input RDD, returning pairs whose first element is a member of the\n+   * input RDD and whose second element is a member of the argument RDD which is within 'range' bases\n+   * of the first element of the pair.\n+   *\n+   * @param that The argument RDD\n+   * @param range A long integer; if two regions are within 'range' of each other (along the same chromosome),\n+   *              then they are present in the returned RDD.\n+   * @param kt2 The type of the values in the argument RDD must be explicit.\n+   * @tparam R2 The explicit type of the regions in the argument RDD\n+   * @return The RDD of pairs (f, s) where f comes from the input RDD and s comes from 'that', the argument\n+   *         RDD.\n+   */\n+  def joinWithinRange[R2 <: ReferenceRegion](that: RDD[R2], range: Long)(implicit kt2: ClassTag[R2]): RDD[(Region, R2)] =","path":"adam-core/src/main/scala/org/bdgenomics/adam/rdd/RegionRDDFunctions.scala","position":73,"original_position":73,"commit_id":"90f16597534b8ba07b1fdd0e6a18578a539cf01b","original_commit_id":"345fa84593f3ac0895f6ef3547e7fabce3798d9d","user":{"login":"laserson","id":118141,"avatar_url":"https://avatars.githubusercontent.com/u/118141?v=3","gravatar_id":"","url":"https://api.github.com/users/laserson","html_url":"https://github.com/laserson","followers_url":"https://api.github.com/users/laserson/followers","following_url":"https://api.github.com/users/laserson/following{/other_user}","gists_url":"https://api.github.com/users/laserson/gists{/gist_id}","starred_url":"https://api.github.com/users/laserson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laserson/subscriptions","organizations_url":"https://api.github.com/users/laserson/orgs","repos_url":"https://api.github.com/users/laserson/repos","events_url":"https://api.github.com/users/laserson/events{/privacy}","received_events_url":"https://api.github.com/users/laserson/received_events","type":"User","site_admin":false},"body":"Another alternative is to move these fns from here to the corresponding join impls.","created_at":"2015-02-27T23:19:42Z","updated_at":"2015-02-27T23:19:42Z","html_url":"https://github.com/bigdatagenomics/adam/pull/517#discussion_r25547171","pull_request_url":"https://api.github.com/repos/bigdatagenomics/adam/pulls/517","_links":{"self":{"href":"https://api.github.com/repos/bigdatagenomics/adam/pulls/comments/25547171"},"html":{"href":"https://github.com/bigdatagenomics/adam/pull/517#discussion_r25547171"},"pull_request":{"href":"https://api.github.com/repos/bigdatagenomics/adam/pulls/517"}}},"pull_request":{"url":"https://api.github.com/repos/bigdatagenomics/adam/pulls/517","id":25371638,"html_url":"https://github.com/bigdatagenomics/adam/pull/517","diff_url":"https://github.com/bigdatagenomics/adam/pull/517.diff","patch_url":"https://github.com/bigdatagenomics/adam/pull/517.patch","issue_url":"https://api.github.com/repos/bigdatagenomics/adam/issues/517","number":517,"state":"open","locked":false,"title":"Adding RegionRDDFunctions","user":{"login":"tdanford","id":395608,"avatar_url":"https://avatars.githubusercontent.com/u/395608?v=3","gravatar_id":"","url":"https://api.github.com/users/tdanford","html_url":"https://github.com/tdanford","followers_url":"https://api.github.com/users/tdanford/followers","following_url":"https://api.github.com/users/tdanford/following{/other_user}","gists_url":"https://api.github.com/users/tdanford/gists{/gist_id}","starred_url":"https://api.github.com/users/tdanford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tdanford/subscriptions","organizations_url":"https://api.github.com/users/tdanford/orgs","repos_url":"https://api.github.com/users/tdanford/repos","events_url":"https://api.github.com/users/tdanford/events{/privacy}","received_events_url":"https://api.github.com/users/tdanford/received_events","type":"User","site_admin":false},"body":"This PR contains two commits fixing #511 and #512.  \r\n\r\nFirst, it updates ReferenceRegion so that the class doesn't extend Ordered -- rather, we providing _an_ Ordering which can be used in the same contexts (and which we can replace by other orderings, if we want to order the regions in a different way).  \r\n\r\nSecond, it provides three new RDD wrapper (*Functions) classes, around RDDs of \r\n1. ReferenceRegions\r\n2. Reference-mappable values\r\n3. Pairs whose first element is a ReferenceRegion\r\n\r\nIn each case, the wrapper class provides a standard set of operations (join, filter, groupBy, windowCounts) which operate on sets of geometric operations (and are implemented under the hood, here, with RegionJoin.partitionAndJoin).  \r\n\r\nThese PRs are necessary pre-cursors to the Mutect work that's going on over in the avocado repository.","created_at":"2014-12-02T20:27:52Z","updated_at":"2015-02-27T23:19:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a78da89496c8b11492272746f3a4a8d7ae3a0867","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bigdatagenomics/adam/pulls/517/commits","review_comments_url":"https://api.github.com/repos/bigdatagenomics/adam/pulls/517/comments","review_comment_url":"https://api.github.com/repos/bigdatagenomics/adam/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bigdatagenomics/adam/issues/517/comments","statuses_url":"https://api.github.com/repos/bigdatagenomics/adam/statuses/90f16597534b8ba07b1fdd0e6a18578a539cf01b","head":{"label":"tdanford:region-rdd-functions","ref":"region-rdd-functions","sha":"90f16597534b8ba07b1fdd0e6a18578a539cf01b","user":{"login":"tdanford","id":395608,"avatar_url":"https://avatars.githubusercontent.com/u/395608?v=3","gravatar_id":"","url":"https://api.github.com/users/tdanford","html_url":"https://github.com/tdanford","followers_url":"https://api.github.com/users/tdanford/followers","following_url":"https://api.github.com/users/tdanford/following{/other_user}","gists_url":"https://api.github.com/users/tdanford/gists{/gist_id}","starred_url":"https://api.github.com/users/tdanford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tdanford/subscriptions","organizations_url":"https://api.github.com/users/tdanford/orgs","repos_url":"https://api.github.com/users/tdanford/repos","events_url":"https://api.github.com/users/tdanford/events{/privacy}","received_events_url":"https://api.github.com/users/tdanford/received_events","type":"User","site_admin":false},"repo":{"id":23480866,"name":"adam","full_name":"tdanford/adam","owner":{"login":"tdanford","id":395608,"avatar_url":"https://avatars.githubusercontent.com/u/395608?v=3","gravatar_id":"","url":"https://api.github.com/users/tdanford","html_url":"https://github.com/tdanford","followers_url":"https://api.github.com/users/tdanford/followers","following_url":"https://api.github.com/users/tdanford/following{/other_user}","gists_url":"https://api.github.com/users/tdanford/gists{/gist_id}","starred_url":"https://api.github.com/users/tdanford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tdanford/subscriptions","organizations_url":"https://api.github.com/users/tdanford/orgs","repos_url":"https://api.github.com/users/tdanford/repos","events_url":"https://api.github.com/users/tdanford/events{/privacy}","received_events_url":"https://api.github.com/users/tdanford/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tdanford/adam","description":"A genomics processing engine and specialized file format built using Apache Avro, Apache Spark and Parquet. Apache 2 licensed.","fork":true,"url":"https://api.github.com/repos/tdanford/adam","forks_url":"https://api.github.com/repos/tdanford/adam/forks","keys_url":"https://api.github.com/repos/tdanford/adam/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tdanford/adam/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tdanford/adam/teams","hooks_url":"https://api.github.com/repos/tdanford/adam/hooks","issue_events_url":"https://api.github.com/repos/tdanford/adam/issues/events{/number}","events_url":"https://api.github.com/repos/tdanford/adam/events","assignees_url":"https://api.github.com/repos/tdanford/adam/assignees{/user}","branches_url":"https://api.github.com/repos/tdanford/adam/branches{/branch}","tags_url":"https://api.github.com/repos/tdanford/adam/tags","blobs_url":"https://api.github.com/repos/tdanford/adam/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tdanford/adam/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tdanford/adam/git/refs{/sha}","trees_url":"https://api.github.com/repos/tdanford/adam/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tdanford/adam/statuses/{sha}","languages_url":"https://api.github.com/repos/tdanford/adam/languages","stargazers_url":"https://api.github.com/repos/tdanford/adam/stargazers","contributors_url":"https://api.github.com/repos/tdanford/adam/contributors","subscribers_url":"https://api.github.com/repos/tdanford/adam/subscribers","subscription_url":"https://api.github.com/repos/tdanford/adam/subscription","commits_url":"https://api.github.com/repos/tdanford/adam/commits{/sha}","git_commits_url":"https://api.github.com/repos/tdanford/adam/git/commits{/sha}","comments_url":"https://api.github.com/repos/tdanford/adam/comments{/number}","issue_comment_url":"https://api.github.com/repos/tdanford/adam/issues/comments{/number}","contents_url":"https://api.github.com/repos/tdanford/adam/contents/{+path}","compare_url":"https://api.github.com/repos/tdanford/adam/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tdanford/adam/merges","archive_url":"https://api.github.com/repos/tdanford/adam/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tdanford/adam/downloads","issues_url":"https://api.github.com/repos/tdanford/adam/issues{/number}","pulls_url":"https://api.github.com/repos/tdanford/adam/pulls{/number}","milestones_url":"https://api.github.com/repos/tdanford/adam/milestones{/number}","notifications_url":"https://api.github.com/repos/tdanford/adam/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tdanford/adam/labels{/name}","releases_url":"https://api.github.com/repos/tdanford/adam/releases{/id}","created_at":"2014-08-29T23:51:21Z","updated_at":"2015-02-26T18:30:27Z","pushed_at":"2015-02-26T18:36:28Z","git_url":"git://github.com/tdanford/adam.git","ssh_url":"git@github.com:tdanford/adam.git","clone_url":"https://github.com/tdanford/adam.git","svn_url":"https://github.com/tdanford/adam","homepage":"http://bdgenomics.org/","size":51367,"stargazers_count":0,"watchers_count":0,"language":"Scala","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":"bigdatagenomics:master","ref":"master","sha":"cd10066547285becc70aded4e074277aedfa6fc8","user":{"login":"bigdatagenomics","id":5839438,"avatar_url":"https://avatars.githubusercontent.com/u/5839438?v=3","gravatar_id":"","url":"https://api.github.com/users/bigdatagenomics","html_url":"https://github.com/bigdatagenomics","followers_url":"https://api.github.com/users/bigdatagenomics/followers","following_url":"https://api.github.com/users/bigdatagenomics/following{/other_user}","gists_url":"https://api.github.com/users/bigdatagenomics/gists{/gist_id}","starred_url":"https://api.github.com/users/bigdatagenomics/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bigdatagenomics/subscriptions","organizations_url":"https://api.github.com/users/bigdatagenomics/orgs","repos_url":"https://api.github.com/users/bigdatagenomics/repos","events_url":"https://api.github.com/users/bigdatagenomics/events{/privacy}","received_events_url":"https://api.github.com/users/bigdatagenomics/received_events","type":"Organization","site_admin":false},"repo":{"id":14541530,"name":"adam","full_name":"bigdatagenomics/adam","owner":{"login":"bigdatagenomics","id":5839438,"avatar_url":"https://avatars.githubusercontent.com/u/5839438?v=3","gravatar_id":"","url":"https://api.github.com/users/bigdatagenomics","html_url":"https://github.com/bigdatagenomics","followers_url":"https://api.github.com/users/bigdatagenomics/followers","following_url":"https://api.github.com/users/bigdatagenomics/following{/other_user}","gists_url":"https://api.github.com/users/bigdatagenomics/gists{/gist_id}","starred_url":"https://api.github.com/users/bigdatagenomics/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bigdatagenomics/subscriptions","organizations_url":"https://api.github.com/users/bigdatagenomics/orgs","repos_url":"https://api.github.com/users/bigdatagenomics/repos","events_url":"https://api.github.com/users/bigdatagenomics/events{/privacy}","received_events_url":"https://api.github.com/users/bigdatagenomics/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bigdatagenomics/adam","description":"A genomics processing engine and specialized file format built using Apache Avro, Apache Spark and Parquet. Apache 2 licensed.","fork":false,"url":"https://api.github.com/repos/bigdatagenomics/adam","forks_url":"https://api.github.com/repos/bigdatagenomics/adam/forks","keys_url":"https://api.github.com/repos/bigdatagenomics/adam/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bigdatagenomics/adam/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bigdatagenomics/adam/teams","hooks_url":"https://api.github.com/repos/bigdatagenomics/adam/hooks","issue_events_url":"https://api.github.com/repos/bigdatagenomics/adam/issues/events{/number}","events_url":"https://api.github.com/repos/bigdatagenomics/adam/events","assignees_url":"https://api.github.com/repos/bigdatagenomics/adam/assignees{/user}","branches_url":"https://api.github.com/repos/bigdatagenomics/adam/branches{/branch}","tags_url":"https://api.github.com/repos/bigdatagenomics/adam/tags","blobs_url":"https://api.github.com/repos/bigdatagenomics/adam/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bigdatagenomics/adam/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bigdatagenomics/adam/git/refs{/sha}","trees_url":"https://api.github.com/repos/bigdatagenomics/adam/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bigdatagenomics/adam/statuses/{sha}","languages_url":"https://api.github.com/repos/bigdatagenomics/adam/languages","stargazers_url":"https://api.github.com/repos/bigdatagenomics/adam/stargazers","contributors_url":"https://api.github.com/repos/bigdatagenomics/adam/contributors","subscribers_url":"https://api.github.com/repos/bigdatagenomics/adam/subscribers","subscription_url":"https://api.github.com/repos/bigdatagenomics/adam/subscription","commits_url":"https://api.github.com/repos/bigdatagenomics/adam/commits{/sha}","git_commits_url":"https://api.github.com/repos/bigdatagenomics/adam/git/commits{/sha}","comments_url":"https://api.github.com/repos/bigdatagenomics/adam/comments{/number}","issue_comment_url":"https://api.github.com/repos/bigdatagenomics/adam/issues/comments{/number}","contents_url":"https://api.github.com/repos/bigdatagenomics/adam/contents/{+path}","compare_url":"https://api.github.com/repos/bigdatagenomics/adam/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bigdatagenomics/adam/merges","archive_url":"https://api.github.com/repos/bigdatagenomics/adam/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bigdatagenomics/adam/downloads","issues_url":"https://api.github.com/repos/bigdatagenomics/adam/issues{/number}","pulls_url":"https://api.github.com/repos/bigdatagenomics/adam/pulls{/number}","milestones_url":"https://api.github.com/repos/bigdatagenomics/adam/milestones{/number}","notifications_url":"https://api.github.com/repos/bigdatagenomics/adam/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bigdatagenomics/adam/labels{/name}","releases_url":"https://api.github.com/repos/bigdatagenomics/adam/releases{/id}","created_at":"2013-11-19T23:47:57Z","updated_at":"2015-02-27T20:18:46Z","pushed_at":"2015-02-26T18:29:30Z","git_url":"git://github.com/bigdatagenomics/adam.git","ssh_url":"git@github.com:bigdatagenomics/adam.git","clone_url":"https://github.com/bigdatagenomics/adam.git","svn_url":"https://github.com/bigdatagenomics/adam","homepage":"http://bdgenomics.org/","size":56346,"stargazers_count":221,"watchers_count":221,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":80,"mirror_url":null,"open_issues_count":80,"forks":80,"open_issues":80,"watchers":221,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bigdatagenomics/adam/pulls/517"},"html":{"href":"https://github.com/bigdatagenomics/adam/pull/517"},"issue":{"href":"https://api.github.com/repos/bigdatagenomics/adam/issues/517"},"comments":{"href":"https://api.github.com/repos/bigdatagenomics/adam/issues/517/comments"},"review_comments":{"href":"https://api.github.com/repos/bigdatagenomics/adam/pulls/517/comments"},"review_comment":{"href":"https://api.github.com/repos/bigdatagenomics/adam/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bigdatagenomics/adam/pulls/517/commits"},"statuses":{"href":"https://api.github.com/repos/bigdatagenomics/adam/statuses/90f16597534b8ba07b1fdd0e6a18578a539cf01b"}}}}