[][src]Struct twobit::TwoBitFile

pub struct TwoBitFile { /* fields omitted */ }

Read data from a 2bit file

Usage:

extern crate twobit;
use twobit::TwoBitFile;

let enable_softmask=true; //set to false to enforce upper case sequences
let tb = TwoBitFile::open("assets/foo.2bit", enable_softmask).unwrap();
let chromosome_lengths = tb.chroms();
assert_eq!(chromosome_lengths["chr1"], 150);
assert_eq!(chromosome_lengths["chr2"], 100);

2bit files offer two types of masks: N masks (aka hard masks) for unknown or arbitrary nucleotides and soft masks for lower-case nucleotides (e.g. "t" instead of "T").


let expected_seq = "NNNNNNNNNNNNNNNNNNNNNNNNNNACGTACGTACGTagctagctGATC"; // some lower and some upper case
assert_eq!(tb.sequence("chr1",24,74).unwrap(), expected_seq);

It is not possible to disable hard masks but you can disable soft masks:


let enable_softmask=false;
let tb_nosoft = TwoBitFile::open("assets/foo.2bit", enable_softmask).unwrap();
let expected_seq = "NNNNNNNNNNNNNNNNNNNNNNNNNNACGTACGTACGTAGCTAGCTGATC"; // all upper case
assert_eq!(tb_nosoft.sequence("chr1",24,74).unwrap(), expected_seq);

There are 2 variants for every sequence-related method:

  • Those that request information on parts of a chromosome
  • Those that request information on a complete chromosome

The partial requests require you to provide a start (0-based, inclusive) and a stop (0-based, exclusive) position as parameters. The full request methods all start with the prefix full_.

Implementations

impl TwoBitFile[src]

pub fn open<P: AsRef<Path>>(
    path: P,
    softmask_enabled: bool
) -> Result<TwoBitFile, Error>
[src]

Constructor for a 2bit file.

  • path - A path to the 2bit file
  • softmask_enabled - return lower case nucleotides for soft blocks

pub fn chroms(&self) -> HashMap<String, Field>[src]

Get the sizes of chromosomes in a 2bit file as a HashMap

pub fn full_sequence(&self, chr: &str) -> Result<String, Error>[src]

Get the full sequence of a chromosome

  • chr Name of the chromosome from the 2bit file
  • returns the full sequence as a String on success

pub fn sequence(
    &self,
    chr: &str,
    start: usize,
    end: usize
) -> Result<String, Error>
[src]

Get a partial sequence of a chromosome

  • chr Name of the chromosome from the 2bit file
  • start Start position of the sequence
  • end Stop position of the sequence
  • returns the full sequence as a String on success

pub fn full_bases(&self, chr: &str) -> Result<BaseCounts, Error>[src]

Count bases of a chromosome

  • chr Name of the chromosome from the 2bit file

pub fn full_bases_percentages(
    &self,
    chr: &str
) -> Result<BasePercentages, Error>
[src]

Calculates percentages of bases of a chromosome

  • chr Name of the chromosome from the 2bit file

pub fn bases(
    &self,
    chr: &str,
    start: usize,
    end: usize
) -> Result<BaseCounts, Error>
[src]

Count bases of a partial chromosome

  • chr Name of the chromosome from the 2bit file

pub fn bases_percentages(
    &self,
    chr: &str,
    start: usize,
    end: usize
) -> Result<BasePercentages, Error>
[src]

Calculates percentages of bases of a partial chromosome

  • chr Name of the chromosome from the 2bit file

pub fn info(&self) -> Result<TwoBitFileInfo, Error>[src]

Obtain general information on the 2bit file you are dealing with

pub fn full_hard_masked_blocks(&self, chr: &str) -> Result<Vec<Block>, Error>[src]

Get all hard blocks (N-blocks) of a chromosome

  • chr Name of the chromosome from the 2bit file

pub fn hard_masked_blocks(
    &self,
    chr: &str,
    start: usize,
    end: usize
) -> Result<Vec<Block>, Error>
[src]

Get hard blocks (N-blocks) of a region on a chromosome

  • chr Name of the chromosome from the 2bit file

pub fn full_soft_masked_blocks(&self, chr: &str) -> Result<Vec<Block>, Error>[src]

Get all soft blocks (lower case blocks) of a chromosome

  • chr Name of the chromosome from the 2bit file

pub fn soft_masked_blocks(
    &self,
    chr: &str,
    start: usize,
    end: usize
) -> Result<Vec<Block>, Error>
[src]

Get soft blocks (lower case blocks) of a region on a chromosome

  • chr Name of the chromosome from the 2bit file

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.