{"action":"created","comment":{"url":"https://api.github.com/repos/samtools/htsjdk/pulls/comments/75124568","id":75124568,"diff_hunk":"@@ -1096,4 +1097,79 @@ public static SAMRecord clipOverlappingAlignedBases(final SAMRecord record, fina\n     public static boolean isValidUnsignedIntegerAttribute(long value) {\n         return value >= 0 && value <= BinaryCodec.MAX_UINT;\n     }\n+    \n+    /**\n+     * Extract a List of 'other canonical alignments' from a SAM record. Those alignments are stored as a string in the 'SA' tag as defined\n+     * in the SAM specification.\n+     * Each record in the List is a non-paired read.\n+     * The name, sequence and qualities are copied from the original record.\n+     * The SAM flag is set to <code>SUPPLEMENTARY_ALIGNMENT (+ READ_REVERSE_STRAND )</code>\n+     * @param record must be non null and must have a non-null associated header.\n+     * @return a list of 'other canonical alignments' SAMRecords. The list is empty if the 'SA' attribute is missing.\n+     */\n+    public static List<SAMRecord> getOtherCanonicalAlignments(final SAMRecord record) {\n+        final Pattern semiColonPattern = Pattern.compile(\"[;]\");\n+        final Pattern commaPattern = Pattern.compile(\"[,]\");\n+        if( record == null ) throw new IllegalArgumentException(\"record is null\");\n+        if( record.getHeader() == null ) throw new IllegalArgumentException(\"record.getHeader() is null\");\n+        /* extract value of SA tag */\n+        final Object saValue = record.getAttribute( SAMTagUtil.getSingleton().SA );\n+        if( saValue == null ) return Collections.emptyList();\n+        if( ! (saValue instanceof String) ) throw new SAMException(\n+                \"Expected a String for attribute 'SA' but got \" + saValue.getClass() );\n+        \n+        final SAMRecordFactory samReaderFactory = new DefaultSAMRecordFactory();\n+        \n+        /* the spec says: \"Other canonical alignments in a chimeric alignment, formatted as a \n+         * semicolon-delimited list: (rname,pos,strand,CIGAR,mapQ,NM;)+. \n+         * Each element in the list represents a part of the chimeric alignment.\n+         * Conventionally, at a supplementary line, the  1rst element points to the primary line.\n+         */\n+        \n+        /* break string using semicolon */\n+        final String semiColonStrs[] = semiColonPattern.split((String)saValue);\n+        \n+        /* the result list */\n+        final List<SAMRecord> alignments = new ArrayList<>( semiColonStrs.length );\n+        \n+        for( final String semiColonStr : semiColonStrs ) {\n+            /* ignore empty string */\n+            if( semiColonStr.isEmpty() ) continue;\n+            \n+            /* break string using comma */\n+            final String commaStrs[] = commaPattern.split(semiColonStr);\n+            if( commaStrs.length != 6 )  throw new SAMException(\"Bad 'SA' attribute in \" + semiColonStr);\n+            \n+            /* create the new record */\n+            final SAMRecord otherRec = samReaderFactory.createSAMRecord( record.getHeader() );\n+            \n+            /* copy fields from the original record */\n+            otherRec.setReadName( record.getReadName() );\n+            otherRec.setReadBases( record.getReadBases() );\n+            otherRec.setBaseQualities( record.getBaseQualities() );","path":"src/main/java/htsjdk/samtools/SAMUtils.java","position":61,"original_position":61,"commit_id":"de3873f108394db43a231fda412fb93c78b98e83","original_commit_id":"de3873f108394db43a231fda412fb93c78b98e83","user":{"login":"jamesemery","id":16102845,"avatar_url":"https://avatars.githubusercontent.com/u/16102845?v=3","gravatar_id":"","url":"https://api.github.com/users/jamesemery","html_url":"https://github.com/jamesemery","followers_url":"https://api.github.com/users/jamesemery/followers","following_url":"https://api.github.com/users/jamesemery/following{/other_user}","gists_url":"https://api.github.com/users/jamesemery/gists{/gist_id}","starred_url":"https://api.github.com/users/jamesemery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jamesemery/subscriptions","organizations_url":"https://api.github.com/users/jamesemery/orgs","repos_url":"https://api.github.com/users/jamesemery/repos","events_url":"https://api.github.com/users/jamesemery/events{/privacy}","received_events_url":"https://api.github.com/users/jamesemery/received_events","type":"User","site_admin":false},"body":"Furthermore, what about the mate information?\r\n","created_at":"2016-08-17T13:43:26Z","updated_at":"2016-08-17T13:43:26Z","html_url":"https://github.com/samtools/htsjdk/pull/685#discussion_r75124568","pull_request_url":"https://api.github.com/repos/samtools/htsjdk/pulls/685","_links":{"self":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/comments/75124568"},"html":{"href":"https://github.com/samtools/htsjdk/pull/685#discussion_r75124568"},"pull_request":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/685"}}},"pull_request":{"url":"https://api.github.com/repos/samtools/htsjdk/pulls/685","id":81485189,"html_url":"https://github.com/samtools/htsjdk/pull/685","diff_url":"https://github.com/samtools/htsjdk/pull/685.diff","patch_url":"https://github.com/samtools/htsjdk/pull/685.patch","issue_url":"https://api.github.com/repos/samtools/htsjdk/issues/685","number":685,"state":"open","locked":false,"title":"SAMUtils:getOtherCanonicalAlignments extract 'SA' tag  and return a list of supplementary alignments","user":{"login":"lindenb","id":33838,"avatar_url":"https://avatars.githubusercontent.com/u/33838?v=3","gravatar_id":"","url":"https://api.github.com/users/lindenb","html_url":"https://github.com/lindenb","followers_url":"https://api.github.com/users/lindenb/followers","following_url":"https://api.github.com/users/lindenb/following{/other_user}","gists_url":"https://api.github.com/users/lindenb/gists{/gist_id}","starred_url":"https://api.github.com/users/lindenb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lindenb/subscriptions","organizations_url":"https://api.github.com/users/lindenb/orgs","repos_url":"https://api.github.com/users/lindenb/repos","events_url":"https://api.github.com/users/lindenb/events{/privacy}","received_events_url":"https://api.github.com/users/lindenb/received_events","type":"User","site_admin":false},"body":"### Description\r\n\r\nI've added a new function `getOtherCanonicalAlignments` in SAMUtils. This function is used to extract the 'SA' tag of a SAMRecord as a `List<SAMRecord>`of supplementary alignements. \r\n\r\n* \r\n```   \r\n    /**\r\n     * Extract a List of 'other canonical alignments' from a SAM record. Those alignments are stored as a string in the 'SA' tag as defined\r\n     * in the SAM specification.\r\n     * Each record in the List is a non-paired read.\r\n     * The name, sequence and qualities are copied from the original record\r\n     * The SAM flag is set to <code>SUPPLEMENTARY_ALIGNMENT (+ READ_REVERSE_STRAND )</code>\r\n     * @param record must be non null and must have a non-null associated header.\r\n     * @return a list of 'other canonical alignments' SAMRecords. The list is empty if the 'SA' attribute is missing.\r\n     */\r\npublic static List<SAMRecord> getOtherCanonicalAlignments(final SAMRecord record)\r\n```\r\n* `testOtherCanonicalAlignments` was added to SAMUtilsTest ( create one read with SA flag, check the values of the supplementary alignments)\r\n\r\nPS: The SA tag is defined in the spec as \r\n\r\n> Other canonical alignments in a chimeric alignment, formatted as a   semicolon-delimited list: (rname,pos,strand,CIGAR,mapQ,NM;)+.  Each element in the list represents a part of the chimeric alignment.\r\n\r\n### Checklist\r\n\r\n- [x] Code compiles correctly\r\n- [x] New tests covering changes and new functionality\r\n- [x] All tests passing\r\n- [x] Extended the README / documentation, if necessary\r\n- [ ] Is not backward compatible (breaks binary or source compatibility)\r\n\r\n\r\n","created_at":"2016-08-16T14:49:24Z","updated_at":"2016-08-17T13:43:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6c86d1a51c72234e59e8bef26224e9e339ea3736","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/samtools/htsjdk/pulls/685/commits","review_comments_url":"https://api.github.com/repos/samtools/htsjdk/pulls/685/comments","review_comment_url":"https://api.github.com/repos/samtools/htsjdk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/samtools/htsjdk/issues/685/comments","statuses_url":"https://api.github.com/repos/samtools/htsjdk/statuses/de3873f108394db43a231fda412fb93c78b98e83","head":{"label":"lindenb:sam_xa","ref":"sam_xa","sha":"de3873f108394db43a231fda412fb93c78b98e83","user":{"login":"lindenb","id":33838,"avatar_url":"https://avatars.githubusercontent.com/u/33838?v=3","gravatar_id":"","url":"https://api.github.com/users/lindenb","html_url":"https://github.com/lindenb","followers_url":"https://api.github.com/users/lindenb/followers","following_url":"https://api.github.com/users/lindenb/following{/other_user}","gists_url":"https://api.github.com/users/lindenb/gists{/gist_id}","starred_url":"https://api.github.com/users/lindenb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lindenb/subscriptions","organizations_url":"https://api.github.com/users/lindenb/orgs","repos_url":"https://api.github.com/users/lindenb/repos","events_url":"https://api.github.com/users/lindenb/events{/privacy}","received_events_url":"https://api.github.com/users/lindenb/received_events","type":"User","site_admin":false},"repo":{"id":19689035,"name":"htsjdk","full_name":"lindenb/htsjdk","owner":{"login":"lindenb","id":33838,"avatar_url":"https://avatars.githubusercontent.com/u/33838?v=3","gravatar_id":"","url":"https://api.github.com/users/lindenb","html_url":"https://github.com/lindenb","followers_url":"https://api.github.com/users/lindenb/followers","following_url":"https://api.github.com/users/lindenb/following{/other_user}","gists_url":"https://api.github.com/users/lindenb/gists{/gist_id}","starred_url":"https://api.github.com/users/lindenb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lindenb/subscriptions","organizations_url":"https://api.github.com/users/lindenb/orgs","repos_url":"https://api.github.com/users/lindenb/repos","events_url":"https://api.github.com/users/lindenb/events{/privacy}","received_events_url":"https://api.github.com/users/lindenb/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lindenb/htsjdk","description":"A Java API for high-throughput sequencing data (HTS) formats.","fork":true,"url":"https://api.github.com/repos/lindenb/htsjdk","forks_url":"https://api.github.com/repos/lindenb/htsjdk/forks","keys_url":"https://api.github.com/repos/lindenb/htsjdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lindenb/htsjdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lindenb/htsjdk/teams","hooks_url":"https://api.github.com/repos/lindenb/htsjdk/hooks","issue_events_url":"https://api.github.com/repos/lindenb/htsjdk/issues/events{/number}","events_url":"https://api.github.com/repos/lindenb/htsjdk/events","assignees_url":"https://api.github.com/repos/lindenb/htsjdk/assignees{/user}","branches_url":"https://api.github.com/repos/lindenb/htsjdk/branches{/branch}","tags_url":"https://api.github.com/repos/lindenb/htsjdk/tags","blobs_url":"https://api.github.com/repos/lindenb/htsjdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lindenb/htsjdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lindenb/htsjdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/lindenb/htsjdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lindenb/htsjdk/statuses/{sha}","languages_url":"https://api.github.com/repos/lindenb/htsjdk/languages","stargazers_url":"https://api.github.com/repos/lindenb/htsjdk/stargazers","contributors_url":"https://api.github.com/repos/lindenb/htsjdk/contributors","subscribers_url":"https://api.github.com/repos/lindenb/htsjdk/subscribers","subscription_url":"https://api.github.com/repos/lindenb/htsjdk/subscription","commits_url":"https://api.github.com/repos/lindenb/htsjdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/lindenb/htsjdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/lindenb/htsjdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/lindenb/htsjdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/lindenb/htsjdk/contents/{+path}","compare_url":"https://api.github.com/repos/lindenb/htsjdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lindenb/htsjdk/merges","archive_url":"https://api.github.com/repos/lindenb/htsjdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lindenb/htsjdk/downloads","issues_url":"https://api.github.com/repos/lindenb/htsjdk/issues{/number}","pulls_url":"https://api.github.com/repos/lindenb/htsjdk/pulls{/number}","milestones_url":"https://api.github.com/repos/lindenb/htsjdk/milestones{/number}","notifications_url":"https://api.github.com/repos/lindenb/htsjdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lindenb/htsjdk/labels{/name}","releases_url":"https://api.github.com/repos/lindenb/htsjdk/releases{/id}","deployments_url":"https://api.github.com/repos/lindenb/htsjdk/deployments","created_at":"2014-05-12T07:04:28Z","updated_at":"2016-01-22T19:47:00Z","pushed_at":"2016-08-17T08:58:10Z","git_url":"git://github.com/lindenb/htsjdk.git","ssh_url":"git@github.com:lindenb/htsjdk.git","clone_url":"https://github.com/lindenb/htsjdk.git","svn_url":"https://github.com/lindenb/htsjdk","homepage":"http://picard.sourceforge.net/index.shtml","size":37216,"stargazers_count":0,"watchers_count":0,"language":"Java","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":"samtools:master","ref":"master","sha":"c8202f23627bf6bc56cf28bb8f1ff8f6c0dd7a27","user":{"login":"samtools","id":1518450,"avatar_url":"https://avatars.githubusercontent.com/u/1518450?v=3","gravatar_id":"","url":"https://api.github.com/users/samtools","html_url":"https://github.com/samtools","followers_url":"https://api.github.com/users/samtools/followers","following_url":"https://api.github.com/users/samtools/following{/other_user}","gists_url":"https://api.github.com/users/samtools/gists{/gist_id}","starred_url":"https://api.github.com/users/samtools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samtools/subscriptions","organizations_url":"https://api.github.com/users/samtools/orgs","repos_url":"https://api.github.com/users/samtools/repos","events_url":"https://api.github.com/users/samtools/events{/privacy}","received_events_url":"https://api.github.com/users/samtools/received_events","type":"Organization","site_admin":false},"repo":{"id":19272315,"name":"htsjdk","full_name":"samtools/htsjdk","owner":{"login":"samtools","id":1518450,"avatar_url":"https://avatars.githubusercontent.com/u/1518450?v=3","gravatar_id":"","url":"https://api.github.com/users/samtools","html_url":"https://github.com/samtools","followers_url":"https://api.github.com/users/samtools/followers","following_url":"https://api.github.com/users/samtools/following{/other_user}","gists_url":"https://api.github.com/users/samtools/gists{/gist_id}","starred_url":"https://api.github.com/users/samtools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samtools/subscriptions","organizations_url":"https://api.github.com/users/samtools/orgs","repos_url":"https://api.github.com/users/samtools/repos","events_url":"https://api.github.com/users/samtools/events{/privacy}","received_events_url":"https://api.github.com/users/samtools/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/samtools/htsjdk","description":"A Java API for high-throughput sequencing data (HTS) formats.","fork":false,"url":"https://api.github.com/repos/samtools/htsjdk","forks_url":"https://api.github.com/repos/samtools/htsjdk/forks","keys_url":"https://api.github.com/repos/samtools/htsjdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/samtools/htsjdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/samtools/htsjdk/teams","hooks_url":"https://api.github.com/repos/samtools/htsjdk/hooks","issue_events_url":"https://api.github.com/repos/samtools/htsjdk/issues/events{/number}","events_url":"https://api.github.com/repos/samtools/htsjdk/events","assignees_url":"https://api.github.com/repos/samtools/htsjdk/assignees{/user}","branches_url":"https://api.github.com/repos/samtools/htsjdk/branches{/branch}","tags_url":"https://api.github.com/repos/samtools/htsjdk/tags","blobs_url":"https://api.github.com/repos/samtools/htsjdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/samtools/htsjdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/samtools/htsjdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/samtools/htsjdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/samtools/htsjdk/statuses/{sha}","languages_url":"https://api.github.com/repos/samtools/htsjdk/languages","stargazers_url":"https://api.github.com/repos/samtools/htsjdk/stargazers","contributors_url":"https://api.github.com/repos/samtools/htsjdk/contributors","subscribers_url":"https://api.github.com/repos/samtools/htsjdk/subscribers","subscription_url":"https://api.github.com/repos/samtools/htsjdk/subscription","commits_url":"https://api.github.com/repos/samtools/htsjdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/samtools/htsjdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/samtools/htsjdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/samtools/htsjdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/samtools/htsjdk/contents/{+path}","compare_url":"https://api.github.com/repos/samtools/htsjdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/samtools/htsjdk/merges","archive_url":"https://api.github.com/repos/samtools/htsjdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/samtools/htsjdk/downloads","issues_url":"https://api.github.com/repos/samtools/htsjdk/issues{/number}","pulls_url":"https://api.github.com/repos/samtools/htsjdk/pulls{/number}","milestones_url":"https://api.github.com/repos/samtools/htsjdk/milestones{/number}","notifications_url":"https://api.github.com/repos/samtools/htsjdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/samtools/htsjdk/labels{/name}","releases_url":"https://api.github.com/repos/samtools/htsjdk/releases{/id}","deployments_url":"https://api.github.com/repos/samtools/htsjdk/deployments","created_at":"2014-04-29T10:11:28Z","updated_at":"2016-08-10T02:06:44Z","pushed_at":"2016-08-17T08:58:10Z","git_url":"git://github.com/samtools/htsjdk.git","ssh_url":"git@github.com:samtools/htsjdk.git","clone_url":"https://github.com/samtools/htsjdk.git","svn_url":"https://github.com/samtools/htsjdk","homepage":"http://samtools.github.io/htsjdk/","size":69628,"stargazers_count":89,"watchers_count":89,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":128,"mirror_url":null,"open_issues_count":137,"forks":128,"open_issues":137,"watchers":89,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/685"},"html":{"href":"https://github.com/samtools/htsjdk/pull/685"},"issue":{"href":"https://api.github.com/repos/samtools/htsjdk/issues/685"},"comments":{"href":"https://api.github.com/repos/samtools/htsjdk/issues/685/comments"},"review_comments":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/685/comments"},"review_comment":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/685/commits"},"statuses":{"href":"https://api.github.com/repos/samtools/htsjdk/statuses/de3873f108394db43a231fda412fb93c78b98e83"}}}}
{"actor":{"display_login":"jamesemery"}}