# Class FileIndexChrPos

java.lang.Object
org.snpeff.vcf.FileIndexChrPos

public class FileIndexChrPos extends Object
Index a file that has "chr \t pos" as the beginning of a line (e.g. VCF) WARNING: It is assumed that the file is ordered by position (chromosome order does not matter)

Author:
  pcingola

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`class`
`FileIndexChrPos.FileRegion`
A part of a file
`class`
`FileIndexChrPos.LineAndPos`
A line and the position on the file where it begins

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`POS_OFFSET`

## Constructor Summary

Constructors
Constructor
Description
`FileIndexChrPos(String fileName)`

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Close file
`String`
`dump(String chr, int posStart, int posEnd, boolean toString)`
Dump all lines in the interval chr:posStart-posEnd
`long`
`find(String chr, int pos, boolean lessEq)`
Find the position in the file for the first character of the first line equal or less than a specific chr:pos
`byte`
`get(long bytePosition)`
Get a byte from a file
`byte[]`
`get(long bytePosition, int len)`
Read 'len' bytes after 'bytePosition' or until a '\n' is reached.
`Set<String>`
`getChromos()`
Available chromosomes
`long`
`getEnd(String chr)`
Get position where 'chr' ends
`FileIndexChrPos.LineAndPos`
`getLine(long pos)`
Get the line where 'pos' hits
`FileIndexChrPos.LineAndPos`
`getLineSlow(long pos)`
A slow method for getLine
`long`
`getStart(String chr)`
Get position where 'chr' starts
`void`
`index()`
Index chromosomes in the whole file
`void`
`open()`
Open file and initiate mappings
`int`
`pos(String line)`
The position argument of a line (second column in tab-separated format).
`void`
`setDebug(boolean debug)`
`void`
`setVerbose(boolean verbose)`
`long`
`size()`
File size
`String`
`toString()`

### Methods inherited from class Object

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

## Field Details

### POS_OFFSET

public static final int POS_OFFSET

See Also:
  - Constant Field Values

## Constructor Details

### FileIndexChrPos

public FileIndexChrPos(String fileName)

## Method Details

### close

public void close()
Close file

### dump

public String dump(String chr, int posStart, int posEnd, boolean toString)
Dump all lines in the interval chr:posStart-posEnd

Parameters:
  `chr` - : Chromosome
  `posStart` - : Start coordinate in chromosome (zero-based)
  `posEnd` - : End coordinate in chromosome (zero-based)
  `toString` - : Return a sting with file contents?
Returns:
  If toString is 'true', return a string with file's content between those coordinates (this is used only for test cases and debugging)

### find

public long find(String chr, int pos, boolean lessEq)
Find the position in the file for the first character of the first line equal or less than a specific chr:pos

### get

public byte get(long bytePosition)
Get a byte from a file

### get

public byte[] get(long bytePosition, int len)
Read 'len' bytes after 'bytePosition' or until a '\n' is reached. If len is negative, read 'abs(len)' bytes before bytePosition or until '\n' is reached

Parameters:
  `bytePosition` -
  `len` -
Returns:
  An array of 'len' bytes. null if either end of file (len > 0) or beginning of file (len invalid input: '<' 0)

### getChromos

public Set<String> getChromos()
Available chromosomes

Returns:

### getEnd

public long getEnd(String chr)
Get position where 'chr' ends

Parameters:
  `chr` -
Returns:
  -1 if 'chr' is not in the index

### getLine

public FileIndexChrPos.LineAndPos getLine(long pos)
Get the line where 'pos' hits

Returns:
  A string with the line that 'pos' hits, null if it's out of boundaries

### getLineSlow

public FileIndexChrPos.LineAndPos getLineSlow(long pos)
A slow method for getLine

### getStart

public long getStart(String chr)
Get position where 'chr' starts

Parameters:
  `chr` -
Returns:
  -1 if 'chr' is not in the index

### index

public void index()
Index chromosomes in the whole file

### open

public void open()
Open file and initiate mappings

### pos

public int pos(String line)
The position argument of a line (second column in tab-separated format). Negative if not found

Returns:
  The position argument of a line. Negative if not found

### setDebug

public void setDebug(boolean debug)

### setVerbose

public void setVerbose(boolean verbose)

### size

public long size()
File size

### toString

public String toString()

Overrides:
  `toString` in class `Object`