{"action":"created","comment":{"url":"https://api.github.com/repos/samtools/htsjdk/pulls/comments/47797057","id":47797057,"diff_hunk":"@@ -0,0 +1,173 @@\n+/*\n+ * The MIT License\n+ *\n+ * Copyright (c) 2015 Pierre Lindenbaum @yokofakun Institut du Thorax - Nantes - France\n+ *\n+ * Permission is hereby granted, free of charge, to any person obtaining a copy\n+ * of this software and associated documentation files (the \"Software\"), to deal\n+ * in the Software without restriction, including without limitation the rights\n+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+ * copies of the Software, and to permit persons to whom the Software is\n+ * furnished to do so, subject to the following conditions:\n+ *\n+ * The above copyright notice and this permission notice shall be included in\n+ * all copies or substantial portions of the Software.\n+ *\n+ * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n+ * THE SOFTWARE.\n+ */\n+package htsjdk.samtools.filter;\n+\n+import java.io.File;\n+import java.io.FileReader;\n+import java.io.IOException;\n+import java.io.Reader;\n+\n+import javax.script.Bindings;\n+import javax.script.Compilable;\n+import javax.script.CompiledScript;\n+import javax.script.ScriptEngine;\n+import javax.script.ScriptEngineManager;\n+import javax.script.ScriptException;\n+import javax.script.SimpleBindings;\n+\n+import htsjdk.samtools.util.CloserUtil;\n+import htsjdk.samtools.util.IOUtil;\n+import htsjdk.samtools.util.RuntimeIOException;\n+\n+/**\n+ * Javascript filter with HEADER type containing TYPE records. contains two\n+ * static method to get a SAM Read filter or a VariantFilter.\n+ * \n+ * warning: tools, like galaxy, using this class are not safe because a script\n+ * can access the filesystem.\n+ * \n+ * @author Pierre Lindenbaum PhD\n+ */\n+public abstract class AbstractJavascriptFilter<HEADER, TYPE> {\n+    public static final String DEFAULT_HEADER_KEY = \"header\";\n+    /** compiled user script */\n+    private CompiledScript script = null;\n+\n+    /** javascript bindings */\n+    protected Bindings bindings;\n+\n+    /**\n+     * constructor using a java.io.File script, compiles the script, puts\n+     * 'header' in the bindings\n+     */\n+    protected AbstractJavascriptFilter(final File scriptFile, final HEADER header) {\n+        this(header, scriptFile);\n+    }\n+\n+    /**\n+     * constructor using a java.lang.String script, compiles the script, puts\n+     * 'header' in the bindings\n+     */\n+    protected AbstractJavascriptFilter(final String scriptExpression, final HEADER header) {\n+        this(header, scriptExpression);\n+    }\n+\n+    /**\n+     * Constructor, compiles script, put header in the bindings\n+     * \n+     * @param scriptFileOrObject\n+     *            javascript source should be either a File or a String\n+     * @param header\n+     *            the header to be injected in the javascript context\n+     */\n+    private AbstractJavascriptFilter(final HEADER header, final Object scriptFileOrString) {\n+        final ScriptEngineManager manager = new ScriptEngineManager();\n+        /* get javascript engine */\n+        final ScriptEngine engine = manager.getEngineByName(\"js\");\n+        if (engine == null) {\n+            throw new RuntimeException(\"The embedded 'javascript' engine is not available in java. \"","path":"src/java/htsjdk/samtools/filter/AbstractJavascriptFilter.java","position":89,"original_position":89,"commit_id":"bc139cea3917b945c2f9c72d6ce45b559705ef85","original_commit_id":"bc139cea3917b945c2f9c72d6ce45b559705ef85","user":{"login":"lbergelson","id":4700332,"avatar_url":"https://avatars.githubusercontent.com/u/4700332?v=3","gravatar_id":"","url":"https://api.github.com/users/lbergelson","html_url":"https://github.com/lbergelson","followers_url":"https://api.github.com/users/lbergelson/followers","following_url":"https://api.github.com/users/lbergelson/following{/other_user}","gists_url":"https://api.github.com/users/lbergelson/gists{/gist_id}","starred_url":"https://api.github.com/users/lbergelson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lbergelson/subscriptions","organizations_url":"https://api.github.com/users/lbergelson/orgs","repos_url":"https://api.github.com/users/lbergelson/repos","events_url":"https://api.github.com/users/lbergelson/events{/privacy}","received_events_url":"https://api.github.com/users/lbergelson/received_events","type":"User","site_admin":false},"body":"Could you add a new exception type `RuntimeScriptException` and use that in all the places you're throwing runtime exception so that someone downstream can catch if it they want?","created_at":"2015-12-16T16:22:12Z","updated_at":"2015-12-16T16:22:12Z","html_url":"https://github.com/samtools/htsjdk/pull/385#discussion_r47797057","pull_request_url":"https://api.github.com/repos/samtools/htsjdk/pulls/385","_links":{"self":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/comments/47797057"},"html":{"href":"https://github.com/samtools/htsjdk/pull/385#discussion_r47797057"},"pull_request":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/385"}}},"pull_request":{"url":"https://api.github.com/repos/samtools/htsjdk/pulls/385","id":50750507,"html_url":"https://github.com/samtools/htsjdk/pull/385","diff_url":"https://github.com/samtools/htsjdk/pull/385.diff","patch_url":"https://github.com/samtools/htsjdk/pull/385.patch","issue_url":"https://api.github.com/repos/samtools/htsjdk/issues/385","number":385,"state":"open","locked":false,"title":"javascript filters from SAM and VCF","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":"from picard :  https://github.com/broadinstitute/picard/pull/335\r\n\r\n> Could you move the filters into htsjdk?\r\n\r\nhere are the new sources:\r\n* wrote an abstract javascript filter and two implementations for SAM and VCF\r\n* wrote two Tests for both format as well as some javascript files used by the test.\r\n","created_at":"2015-11-15T16:53:49Z","updated_at":"2015-12-16T16:22:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"615e15525ee022e8982eeaaa15ed63cd8222759c","assignee":{"login":"lbergelson","id":4700332,"avatar_url":"https://avatars.githubusercontent.com/u/4700332?v=3","gravatar_id":"","url":"https://api.github.com/users/lbergelson","html_url":"https://github.com/lbergelson","followers_url":"https://api.github.com/users/lbergelson/followers","following_url":"https://api.github.com/users/lbergelson/following{/other_user}","gists_url":"https://api.github.com/users/lbergelson/gists{/gist_id}","starred_url":"https://api.github.com/users/lbergelson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lbergelson/subscriptions","organizations_url":"https://api.github.com/users/lbergelson/orgs","repos_url":"https://api.github.com/users/lbergelson/repos","events_url":"https://api.github.com/users/lbergelson/events{/privacy}","received_events_url":"https://api.github.com/users/lbergelson/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/samtools/htsjdk/pulls/385/commits","review_comments_url":"https://api.github.com/repos/samtools/htsjdk/pulls/385/comments","review_comment_url":"https://api.github.com/repos/samtools/htsjdk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/samtools/htsjdk/issues/385/comments","statuses_url":"https://api.github.com/repos/samtools/htsjdk/statuses/bc139cea3917b945c2f9c72d6ce45b559705ef85","head":{"label":"lindenb:javascriptfilters","ref":"javascriptfilters","sha":"bc139cea3917b945c2f9c72d6ce45b559705ef85","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}","created_at":"2014-05-12T07:04:28Z","updated_at":"2015-03-02T11:20:03Z","pushed_at":"2015-11-30T14:24:32Z","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":33142,"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":"f18740b15378e31af23e0f8765c63e0de31ace44","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}","created_at":"2014-04-29T10:11:28Z","updated_at":"2015-12-12T19:06:19Z","pushed_at":"2015-12-15T14:14:36Z","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":63427,"stargazers_count":67,"watchers_count":67,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":91,"mirror_url":null,"open_issues_count":74,"forks":91,"open_issues":74,"watchers":67,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/385"},"html":{"href":"https://github.com/samtools/htsjdk/pull/385"},"issue":{"href":"https://api.github.com/repos/samtools/htsjdk/issues/385"},"comments":{"href":"https://api.github.com/repos/samtools/htsjdk/issues/385/comments"},"review_comments":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/385/comments"},"review_comment":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/samtools/htsjdk/pulls/385/commits"},"statuses":{"href":"https://api.github.com/repos/samtools/htsjdk/statuses/bc139cea3917b945c2f9c72d6ce45b559705ef85"}}}}