biohazard-0.6.15: bioinformatics support library

Safe HaskellNone
LanguageHaskell2010

Bio.TwoBit

Synopsis

Documentation

data TwoBitFile Source #

Would you believe it? The 2bit format stores blocks of Ns in a table at the beginning of a sequence, then packs four bases into a byte. So it is neither possible nor necessary to store Ns in the main sequence, and you would think they aren't stored there, right? And they aren't. Instead Ts are stored which the reader has to replace with Ns.

The sensible way to treat these is probably to just say there are two kinds of implied annotation (repeats and large gaps for a typical genome), which can be interpreted in whatever way fits. And that's why we have Mask and getSubseqWith.

TODO: use binary search for the Int->Int mappings on the raw data?

Constructors

TBF 

openTwoBit :: FilePath -> IO TwoBitFile Source #

Brings a 2bit file into memory. The file is mmap'ed, so it will not work on streams that are not actual files. It's also unsafe if the file is modified in any way.

getSubseq :: TwoBitFile -> Range -> [Nucleotide] Source #

Extract a subsequence without masking.

getSubseqWith :: (Nucleotide -> Mask -> a) -> TwoBitFile -> Range -> [a] Source #

Extract a subsequence and apply masking. TwoBit file can represent two kinds of masking (hard and soft), where hard masking is usually realized by replacing everything by Ns and soft masking is done by lowercasing. Here, we take a user supplied function to apply masking.

getSubseqAscii :: TwoBitFile -> Range -> String Source #

Extract a subsequence with masking for biologists: soft masking is done by lowercasing, hard masking by printing an N.

getSubseqMasked :: TwoBitFile -> Range -> [Nucleotides] Source #

Extract a subsequence with typical masking: soft masking is ignored, hard masked regions are replaced with Ns.

getLazySubseq :: TwoBitFile -> Position -> [Nucleotide] Source #

Works only in forward direction.

getFragment :: TwoBitFile -> Seqid -> Int -> Int -> Vector Word8 Source #

Gets a fragment from a 2bit file. The result always has the desired length; if necessary, it is padded with Ns. Be careful about the unconventional encoding: 0..4 == TCAGN

clampPosition :: TwoBitFile -> Range -> Range Source #

limits a range to a position within the actual sequence

getRandomSeq Source #

Arguments

:: RandomGen g 
=> TwoBitFile

2bit file

-> Int

desired length

-> g

RNG

-> ((Range, [Nucleotide]), g)

position, sequence, new RNG

Sample a piece of random sequence uniformly from the genome. Only pieces that are not hard masked are sampled, soft masking is allowed, but not reported. On a 32bit platform, this will fail for genomes larger than 1G bases. However, if you're running this code on a 32bit platform, you have bigger problems to worry about.

mergeBlocks :: [(Int, Int)] -> [(Int, Int)] -> [(Int, Int, Mask)] Source #

Merge blocks of Ns and blocks of Ms into single list of blocks with masking annotation. Gaps remain. Used internally only.

data Mask Source #

Constructors

None 
Soft 
Hard 
Both 

Instances

Enum Mask Source # 

Methods

succ :: Mask -> Mask #

pred :: Mask -> Mask #

toEnum :: Int -> Mask #

fromEnum :: Mask -> Int #

enumFrom :: Mask -> [Mask] #

enumFromThen :: Mask -> Mask -> [Mask] #

enumFromTo :: Mask -> Mask -> [Mask] #

enumFromThenTo :: Mask -> Mask -> Mask -> [Mask] #

Eq Mask Source # 

Methods

(==) :: Mask -> Mask -> Bool #

(/=) :: Mask -> Mask -> Bool #

Ord Mask Source # 

Methods

compare :: Mask -> Mask -> Ordering #

(<) :: Mask -> Mask -> Bool #

(<=) :: Mask -> Mask -> Bool #

(>) :: Mask -> Mask -> Bool #

(>=) :: Mask -> Mask -> Bool #

max :: Mask -> Mask -> Mask #

min :: Mask -> Mask -> Mask #

Show Mask Source # 

Methods

showsPrec :: Int -> Mask -> ShowS #

show :: Mask -> String #

showList :: [Mask] -> ShowS #