# Class JavascriptSamRecordFilter

java.lang.Object
htsjdk.samtools.filter.AbstractJavascriptFilter<SAMFileHeader, SAMRecord>
htsjdk.samtools.filter.JavascriptSamRecordFilter

All Implemented Interfaces:
  `SamRecordFilter`

public class JavascriptSamRecordFilter extends AbstractJavascriptFilter<SAMFileHeader, SAMRecord> implements SamRecordFilter
JavaScript-based `SamRecordFilter`.

The user-supplied script is evaluated against each `SAMRecord` with the following variables in scope:

- `record` - the `SAMRecord` being evaluated
- `header` - the `SAMFileHeader` associated with the reader

Example: keep only records with mapping quality >= 30:

        new JavascriptSamRecordFilter("record.getMappingQuality() >= 30;", header)

Runtime requirement: as of htsjdk 5.0.0, htsjdk does not ship a JavaScript engine as a runtime dependency. To use this class, add a JSR-223-compatible JavaScript engine (e.g. `org.openjdk.nashorn:nashorn-core`) to your runtime classpath. If no engine is available, the constructor throws a `RuntimeScriptException` whose message lists the dependency coordinates.

## Field Summary

### Fields inherited from class AbstractJavascriptFilter

`bindings, DEFAULT_HEADER_KEY`

## Constructor Summary

Constructors
Constructor
Description
`JavascriptSamRecordFilter(File scriptFile, SAMFileHeader header)`
constructor using a javascript File
`JavascriptSamRecordFilter(Reader scriptReader, SAMFileHeader header)`
constructor using a java.io.Reader
`JavascriptSamRecordFilter(String scriptExpression, SAMFileHeader header)`
constructor using a javascript expression

## Method Summary

Modifier and Type
Method
Description
`boolean`
`filterOut(SAMRecord record)`
read is filtered out if the javascript program returns false
`boolean`
`filterOut(SAMRecord first, SAMRecord second)`
return true of both records are filteredOut (AND)
`String`
`getRecordKey()`
returns key used for record binding

### Methods inherited from class AbstractJavascriptFilter

`accept, getHeaderKey`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### JavascriptSamRecordFilter

public JavascriptSamRecordFilter(File scriptFile, SAMFileHeader header) throws IOException
constructor using a javascript File

Parameters:
  `scriptFile` - the javascript file to be compiled
  `header` - the SAMHeader
Throws:
  `IOException`

### JavascriptSamRecordFilter

public JavascriptSamRecordFilter(String scriptExpression, SAMFileHeader header)
constructor using a javascript expression

Parameters:
  `scriptExpression` - the javascript expression to be compiled
  `header` - the SAMHeader

### JavascriptSamRecordFilter

public JavascriptSamRecordFilter(Reader scriptReader, SAMFileHeader header)
constructor using a java.io.Reader

Parameters:
  `scriptReader` - the javascript reader to be compiled. will be closed
  `header` - the SAMHeader

## Method Details

### filterOut

public boolean filterOut(SAMRecord first, SAMRecord second)
return true of both records are filteredOut (AND)

Specified by:
  `filterOut` in interface `SamRecordFilter`
Parameters:
  `first` - the first SAMRecord to evaluate
  `second` - the second SAMRecord to evaluate
Returns:
  true if the pair of records matches filter, otherwise false

### filterOut

public boolean filterOut(SAMRecord record)
read is filtered out if the javascript program returns false

Specified by:
  `filterOut` in interface `SamRecordFilter`
Parameters:
  `record` - the SAMRecord to evaluate
Returns:
  true if the SAMRecord matches the filter, otherwise false

### getRecordKey

public String getRecordKey()
Description copied from class: `AbstractJavascriptFilter`
returns key used for record binding

Specified by:
  `getRecordKey` in class `AbstractJavascriptFilter<SAMFileHeader, SAMRecord>`