-- GENERATED by C->Haskell Compiler, version 0.16.3 Crystal Seed, 24 Jan 2009 (Haskell)
-- Edit the ORIGNAL .chs file instead!


{-# LINE 1 "src/Bio/SamTools/LowLevel.chs" #-}-- -*- haskell -*-
{-# LANGUAGE ForeignFunctionInterface, EmptyDataDecls, GeneralizedNewtypeDeriving #-}

module Bio.SamTools.LowLevel ( TamFilePtr
                             , samOpen, samClose
                             , BamFilePtr, BamFileInt
                             , bamOpen, bamClose
                             
                             , BamHeaderPtr, BamHeaderInt
                             , getNTargets, getTargetName, getTargetLen, bamGetTid
                             , bamHeaderInit, bamHeaderDestroy, bamHeaderDestroyPtr, bamInitHeaderHash
                             , setNTargets, setTargetName, setTargetLen
                             
                             , samHeaderRead, samHeaderRead2                             
                             , samRead1
                             
                             , bamHeaderRead, bamHeaderWrite
                             , bamRead1, bamWrite1
                             , BamCigar(..)                             
                             , cigarMatch, cigarIns, cigarDel, cigarRefSkip, cigarSoftClip, cigarHardClip, cigarPad
                             , cigarOp, cigarLength
                             , BamFlag(..)
                             , flagPaired, flagProperPair, flagUnmap, flagMUnmap, flagReverse, flagMReverse
                             , flagRead1, flagRead2, flagSecondary, flagQCFail, flagDup
                             , Bam1Ptr, Bam1Int
                             , getTID, getPos, getFlag, getNCigar, getLQSeq, getMTID, getMPos, getISize
                             , bam1Strand, bam1MStrand, bam1Cigar, bam1QName, bam1Seq, bam1Qual, bam1Seqi
                                                                                                                             
                             , bamAuxGet, bamAux2Z, bamAux2i --, bamAux2f, bamAux2d, bamAux2A
                                                                                                 
                             , bamInit1, bamDestroy1, bamDestroy1Ptr, bamDup1, bamFormat1
                             
                             , BamIndexInt, BamIndexPtr
                             , bamIndexLoad, bamIndexDestroy
                             , BamIterInt, BamIterPtr
                             , bamIterQuery, bamIterRead, bamIterDestroy
                             , BamFetchFPtr, mkBamFetchFPtr, bamFetch
                             , SamFilePtr, SamFileInt
                             , sbamOpen, sbamClose, getSbamHeader, sbamRead, sbamWrite                             
                             , FaIdxPtr, FaIdxInt
                             , faiLoad, faiDestroy, faiFetchSeq
                             )
where

import Foreign hiding (Word)
import Foreign.C

import Control.Monad
import qualified Data.ByteString.Char8 as BS



data TamFileInt
type TamFilePtr = Ptr (TamFileInt)
{-# LINE 58 "src/Bio/SamTools/LowLevel.chs" #-}

data BamFileInt
type BamFilePtr = Ptr (BamFileInt)
{-# LINE 61 "src/Bio/SamTools/LowLevel.chs" #-}

bamOpen :: String -> String -> IO (BamFilePtr)
bamOpen a1 a2 =
  withCString a1 $ \a1' -> 
  withCString a2 $ \a2' -> 
  bamOpen'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 65 "src/Bio/SamTools/LowLevel.chs" #-}

bamClose :: BamFilePtr -> IO (CInt)
bamClose a1 =
  let {a1' = id a1} in 
  bamClose'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 68 "src/Bio/SamTools/LowLevel.chs" #-}

data BamHeaderInt
type BamHeaderPtr = Ptr (BamHeaderInt)
{-# LINE 71 "src/Bio/SamTools/LowLevel.chs" #-}

getNTargets :: BamHeaderPtr -> IO CInt
getNTargets = (\ptr -> do {peekByteOff ptr 0 ::IO CInt})
{-# LINE 74 "src/Bio/SamTools/LowLevel.chs" #-}

setNTargets :: BamHeaderPtr -> CInt -> IO ()
setNTargets = (\ptr val -> do {pokeByteOff ptr 0 (val::CInt)})
{-# LINE 77 "src/Bio/SamTools/LowLevel.chs" #-}

getTargetName :: BamHeaderPtr -> IO (Ptr CString)
getTargetName = (\ptr -> do {peekByteOff ptr 4 ::IO (Ptr (Ptr CChar))})
{-# LINE 80 "src/Bio/SamTools/LowLevel.chs" #-}

setTargetName :: BamHeaderPtr -> Ptr CString -> IO ()
setTargetName = (\ptr val -> do {pokeByteOff ptr 4 (val::(Ptr (Ptr CChar)))})
{-# LINE 83 "src/Bio/SamTools/LowLevel.chs" #-}

getTargetLen :: BamHeaderPtr -> IO (Ptr CUInt)
getTargetLen = (\ptr -> do {peekByteOff ptr 8 ::IO (Ptr CUInt)})
{-# LINE 86 "src/Bio/SamTools/LowLevel.chs" #-}

setTargetLen :: BamHeaderPtr -> Ptr CUInt -> IO ()
setTargetLen = (\ptr val -> do {pokeByteOff ptr 8 (val::(Ptr CUInt))})
{-# LINE 89 "src/Bio/SamTools/LowLevel.chs" #-}

newtype BamFlag = BamFlag { unBamFlag :: CUInt }
                deriving (Eq, Show, Ord, Num, Bits)

flagPaired :: BamFlag
flagPaired = BamFlag bam_fpaired
{-# LINE 95 "src/Bio/SamTools/LowLevel.chs" #-}

flagProperPair :: BamFlag
flagProperPair = BamFlag bam_fproper_pair
{-# LINE 98 "src/Bio/SamTools/LowLevel.chs" #-}

flagUnmap :: BamFlag
flagUnmap = BamFlag bam_funmap
{-# LINE 101 "src/Bio/SamTools/LowLevel.chs" #-}

flagMUnmap :: BamFlag
flagMUnmap = BamFlag bam_fmunmap
{-# LINE 104 "src/Bio/SamTools/LowLevel.chs" #-}

flagReverse :: BamFlag
flagReverse = BamFlag bam_freverse
{-# LINE 107 "src/Bio/SamTools/LowLevel.chs" #-}

flagMReverse :: BamFlag
flagMReverse = BamFlag bam_fmreverse
{-# LINE 110 "src/Bio/SamTools/LowLevel.chs" #-}

flagRead1 :: BamFlag
flagRead1 = BamFlag bam_fread1
{-# LINE 113 "src/Bio/SamTools/LowLevel.chs" #-}

flagRead2 :: BamFlag
flagRead2 = BamFlag bam_fread2
{-# LINE 116 "src/Bio/SamTools/LowLevel.chs" #-}

flagSecondary :: BamFlag
flagSecondary = BamFlag bam_fsecondary
{-# LINE 119 "src/Bio/SamTools/LowLevel.chs" #-}

flagQCFail :: BamFlag
flagQCFail = BamFlag bam_fqcfail
{-# LINE 122 "src/Bio/SamTools/LowLevel.chs" #-}

flagDup :: BamFlag
flagDup = BamFlag bam_fdup
{-# LINE 125 "src/Bio/SamTools/LowLevel.chs" #-}

newtype BamCigar = BamCigar { unBamCigar :: CUInt }
                   deriving (Eq, Show, Ord)
                            
cigarMatch :: BamCigar
cigarMatch = BamCigar bam_cmatch
{-# LINE 131 "src/Bio/SamTools/LowLevel.chs" #-}

cigarIns :: BamCigar
cigarIns = BamCigar bam_cins
{-# LINE 134 "src/Bio/SamTools/LowLevel.chs" #-}

cigarDel :: BamCigar
cigarDel = BamCigar bam_cdel
{-# LINE 137 "src/Bio/SamTools/LowLevel.chs" #-}

cigarRefSkip :: BamCigar
cigarRefSkip = BamCigar bam_cref_skip
{-# LINE 140 "src/Bio/SamTools/LowLevel.chs" #-}

cigarSoftClip :: BamCigar
cigarSoftClip = BamCigar bam_csoft_clip
{-# LINE 143 "src/Bio/SamTools/LowLevel.chs" #-}

cigarHardClip :: BamCigar
cigarHardClip = BamCigar bam_chard_clip
{-# LINE 146 "src/Bio/SamTools/LowLevel.chs" #-}

cigarPad :: BamCigar
cigarPad = BamCigar bam_cpad
{-# LINE 149 "src/Bio/SamTools/LowLevel.chs" #-}

cigarOp :: CUInt -> BamCigar
cigarOp = BamCigar . bam_cigar_op
{-# LINE 152 "src/Bio/SamTools/LowLevel.chs" #-}

cigarLength :: CUInt -> CUInt
cigarLength = bam_cigar_length
{-# LINE 155 "src/Bio/SamTools/LowLevel.chs" #-}

data Bam1Int
type Bam1Ptr = Ptr (Bam1Int)
{-# LINE 158 "src/Bio/SamTools/LowLevel.chs" #-}

getTID :: Bam1Ptr -> IO CInt
getTID = (\ptr -> do {peekByteOff ptr 0 ::IO CInt})
{-# LINE 161 "src/Bio/SamTools/LowLevel.chs" #-}

getPos :: Bam1Ptr -> IO CInt
getPos = (\ptr -> do {peekByteOff ptr 4 ::IO CInt})
{-# LINE 164 "src/Bio/SamTools/LowLevel.chs" #-}

getFlag :: Bam1Ptr -> IO BamFlag
getFlag = liftM BamFlag . (\ptr -> do {val <- peekByteOff ptr 11 ::IO CUInt{-:16-}; return $ (val `shiftL` (32 - 24)) `shiftR` (32 - 16)})
{-# LINE 167 "src/Bio/SamTools/LowLevel.chs" #-}

getNCigar :: Bam1Ptr -> IO Int
getNCigar = liftM fromIntegral . (\ptr -> do {val <- peekByteOff ptr 14 ::IO CUInt{-:16-}; return $ (val `shiftL` (32 - 16)) `shiftR` (32 - 16)})
{-# LINE 170 "src/Bio/SamTools/LowLevel.chs" #-}

getLQSeq :: Bam1Ptr -> IO CInt
getLQSeq = (\ptr -> do {peekByteOff ptr 16 ::IO CInt})
{-# LINE 173 "src/Bio/SamTools/LowLevel.chs" #-}

getMTID :: Bam1Ptr -> IO CInt
getMTID = (\ptr -> do {peekByteOff ptr 20 ::IO CInt})
{-# LINE 176 "src/Bio/SamTools/LowLevel.chs" #-}

getMPos :: Bam1Ptr -> IO CInt
getMPos =  (\ptr -> do {peekByteOff ptr 24 ::IO CInt})
{-# LINE 179 "src/Bio/SamTools/LowLevel.chs" #-}

getISize :: Bam1Ptr -> IO CInt
getISize = (\ptr -> do {peekByteOff ptr 28 ::IO CInt})
{-# LINE 182 "src/Bio/SamTools/LowLevel.chs" #-}

bam1Strand :: Bam1Ptr -> Bool
bam1Strand a1 =
  let {a1' = id a1} in 
  let {res = bam1Strand'_ a1'} in
  let {res' = toBool res} in
  (res')
{-# LINE 185 "src/Bio/SamTools/LowLevel.chs" #-}

bam1MStrand :: Bam1Ptr -> Bool
bam1MStrand a1 =
  let {a1' = id a1} in 
  let {res = bam1MStrand'_ a1'} in
  let {res' = toBool res} in
  (res')
{-# LINE 188 "src/Bio/SamTools/LowLevel.chs" #-}

bam1Cigar :: Bam1Ptr -> Ptr CUInt
bam1Cigar a1 =
  let {a1' = id a1} in 
  let {res = bam1Cigar'_ a1'} in
  let {res' = id res} in
  (res')
{-# LINE 191 "src/Bio/SamTools/LowLevel.chs" #-}

bam1QName :: Bam1Ptr -> BS.ByteString
bam1QName a1 =
  unsafePerformIO $
  let {a1' = id a1} in 
  let {res = bam1QName'_ a1'} in
  packCString res >>= \res' ->
  return (res')
{-# LINE 194 "src/Bio/SamTools/LowLevel.chs" #-}

bam1Seq :: Bam1Ptr -> Ptr CUChar
bam1Seq a1 =
  let {a1' = id a1} in 
  let {res = bam1Seq'_ a1'} in
  let {res' = id res} in
  (res')
{-# LINE 197 "src/Bio/SamTools/LowLevel.chs" #-}

bam1Qual :: Bam1Ptr -> Ptr CUChar
bam1Qual a1 =
  let {a1' = id a1} in 
  let {res = bam1Qual'_ a1'} in
  let {res' = id res} in
  (res')
{-# LINE 200 "src/Bio/SamTools/LowLevel.chs" #-}

bam1Seqi :: Ptr CUChar -> CInt -> CUChar
bam1Seqi a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  let {res = bam1Seqi'_ a1' a2'} in
  let {res' = id res} in
  (res')
{-# LINE 204 "src/Bio/SamTools/LowLevel.chs" #-}

-- Low-level SAM I/O

samOpen :: String -> IO (TamFilePtr)
samOpen a1 =
  withCString a1 $ \a1' -> 
  samOpen'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 209 "src/Bio/SamTools/LowLevel.chs" #-}

samClose :: TamFilePtr -> IO ()
samClose a1 =
  let {a1' = id a1} in 
  samClose'_ a1' >>= \res ->
  return ()
{-# LINE 212 "src/Bio/SamTools/LowLevel.chs" #-}

samRead1 :: TamFilePtr -> BamHeaderPtr -> Bam1Ptr -> IO (Int)
samRead1 a1 a2 a3 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  let {a3' = id a3} in 
  samRead1'_ a1' a2' a3' >>= \res ->
  let {res' = fromIntegral res} in
  return (res')
{-# LINE 217 "src/Bio/SamTools/LowLevel.chs" #-}

samHeaderRead2 :: String -> IO (BamHeaderPtr)
samHeaderRead2 a1 =
  withCString a1 $ \a1' -> 
  samHeaderRead2'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 220 "src/Bio/SamTools/LowLevel.chs" #-}

samHeaderRead :: TamFilePtr -> IO (BamHeaderPtr)
samHeaderRead a1 =
  let {a1' = id a1} in 
  samHeaderRead'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 223 "src/Bio/SamTools/LowLevel.chs" #-}

bamGetTid :: BamHeaderPtr -> BS.ByteString -> IO (CInt)
bamGetTid a1 a2 =
  let {a1' = id a1} in 
  useAsCString a2 $ \a2' -> 
  bamGetTid'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 227 "src/Bio/SamTools/LowLevel.chs" #-}

-- Low-level BAM I/O
bamHeaderInit :: IO (BamHeaderPtr)
bamHeaderInit =
  bamHeaderInit'_ >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 231 "src/Bio/SamTools/LowLevel.chs" #-}

bamHeaderDestroy :: BamHeaderPtr -> IO ()
bamHeaderDestroy a1 =
  let {a1' = id a1} in 
  bamHeaderDestroy'_ a1' >>= \res ->
  return ()
{-# LINE 234 "src/Bio/SamTools/LowLevel.chs" #-}

foreign import ccall unsafe "bam.h &bam_header_destroy" bamHeaderDestroyPtr :: FunPtr (Ptr BamHeaderInt -> IO ())

bamHeaderRead :: BamFilePtr -> IO (BamHeaderPtr)
bamHeaderRead a1 =
  let {a1' = id a1} in 
  bamHeaderRead'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 239 "src/Bio/SamTools/LowLevel.chs" #-}

bamHeaderWrite :: BamFilePtr -> BamHeaderPtr -> IO (CInt)
bamHeaderWrite a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  bamHeaderWrite'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 243 "src/Bio/SamTools/LowLevel.chs" #-}

bamInitHeaderHash :: BamHeaderPtr -> IO (())
bamInitHeaderHash a1 =
  let {a1' = id a1} in 
  bamInitHeaderHash'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 246 "src/Bio/SamTools/LowLevel.chs" #-}

bamRead1 :: BamFilePtr -> Bam1Ptr -> IO (CInt)
bamRead1 a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  bamRead1'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 250 "src/Bio/SamTools/LowLevel.chs" #-}

bamWrite1 :: BamFilePtr -> Bam1Ptr -> IO (CInt)
bamWrite1 a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  bamWrite1'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 254 "src/Bio/SamTools/LowLevel.chs" #-}

bamAuxGet :: Bam1Ptr -> CString -> IO (Ptr CUChar)
bamAuxGet a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  bamAuxGet'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 258 "src/Bio/SamTools/LowLevel.chs" #-}

bamAux2Z :: Ptr CUChar -> IO (CString)
bamAux2Z a1 =
  let {a1' = id a1} in 
  bamAux2Z'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 261 "src/Bio/SamTools/LowLevel.chs" #-}

bamAux2i :: Ptr CUChar -> IO (CInt)
bamAux2i a1 =
  let {a1' = id a1} in 
  bamAux2i'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 264 "src/Bio/SamTools/LowLevel.chs" #-}

bamInit1 :: IO (Bam1Ptr)
bamInit1 =
  bamInit1'_ >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 267 "src/Bio/SamTools/LowLevel.chs" #-}

bamDestroy1 :: Bam1Ptr -> IO ()
bamDestroy1 a1 =
  let {a1' = id a1} in 
  bamDestroy1'_ a1' >>= \res ->
  return ()
{-# LINE 270 "src/Bio/SamTools/LowLevel.chs" #-}

foreign import ccall unsafe "samtools.h &bam_destroy1_" bamDestroy1Ptr :: FunPtr (Ptr Bam1Int -> IO ())

bamDup1 :: Bam1Ptr -> IO (Bam1Ptr)
bamDup1 a1 =
  let {a1' = id a1} in 
  bamDup1'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 275 "src/Bio/SamTools/LowLevel.chs" #-}

bamFormat1 :: BamHeaderPtr -> Bam1Ptr -> IO (CString)
bamFormat1 a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  bamFormat1'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 278 "src/Bio/SamTools/LowLevel.chs" #-}

-- BAM indexing

data BamIndexInt
type BamIndexPtr = Ptr (BamIndexInt)
{-# LINE 283 "src/Bio/SamTools/LowLevel.chs" #-}

bamIndexLoad :: String -> IO (BamIndexPtr)
bamIndexLoad a1 =
  withCString a1 $ \a1' -> 
  bamIndexLoad'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 286 "src/Bio/SamTools/LowLevel.chs" #-}

bamIndexDestroy :: BamIndexPtr -> IO ()
bamIndexDestroy a1 =
  let {a1' = id a1} in 
  bamIndexDestroy'_ a1' >>= \res ->
  return ()
{-# LINE 289 "src/Bio/SamTools/LowLevel.chs" #-}

type BamFetchFPtr = FunPtr (((Bam1Ptr) -> ((Ptr ()) -> (IO CInt))))
{-# LINE 291 "src/Bio/SamTools/LowLevel.chs" #-}

foreign import ccall "wrapper"
  mkBamFetchFPtr :: (Bam1Ptr -> Ptr () -> IO CInt) -> IO (FunPtr (Bam1Ptr ->Ptr () -> IO CInt))

bamFetch :: BamFilePtr -> BamIndexPtr -> CInt -> CInt -> CInt -> Ptr () -> BamFetchFPtr -> IO (CInt)
bamFetch a1 a2 a3 a4 a5 a6 a7 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  let {a3' = id a3} in 
  let {a4' = id a4} in 
  let {a5' = id a5} in 
  let {a6' = id a6} in 
  let {a7' = id a7} in 
  bamFetch'_ a1' a2' a3' a4' a5' a6' a7' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 299 "src/Bio/SamTools/LowLevel.chs" #-}

data BamIterInt
type BamIterPtr = Ptr (BamIterInt)
{-# LINE 302 "src/Bio/SamTools/LowLevel.chs" #-}

bamIterQuery :: BamIndexPtr -> CInt -> CInt -> CInt -> IO (BamIterPtr)
bamIterQuery a1 a2 a3 a4 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  let {a3' = id a3} in 
  let {a4' = id a4} in 
  bamIterQuery'_ a1' a2' a3' a4' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 305 "src/Bio/SamTools/LowLevel.chs" #-}

bamIterRead :: BamFilePtr -> BamIterPtr -> Bam1Ptr -> IO (CInt)
bamIterRead a1 a2 a3 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  let {a3' = id a3} in 
  bamIterRead'_ a1' a2' a3' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 308 "src/Bio/SamTools/LowLevel.chs" #-}

bamIterDestroy :: BamIterPtr -> IO (())
bamIterDestroy a1 =
  let {a1' = id a1} in 
  bamIterDestroy'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 311 "src/Bio/SamTools/LowLevel.chs" #-}

-- Unified SAM/BAM I/O

data SamFileInt
type SamFilePtr = Ptr (SamFileInt)
{-# LINE 316 "src/Bio/SamTools/LowLevel.chs" #-}

getSbamHeader :: SamFilePtr -> IO BamHeaderPtr
getSbamHeader = (\ptr -> do {peekByteOff ptr 8 ::IO (BamHeaderPtr)})
{-# LINE 319 "src/Bio/SamTools/LowLevel.chs" #-}

sbamOpen :: String -> String -> Ptr () -> IO (SamFilePtr)
sbamOpen a1 a2 a3 =
  withCString a1 $ \a1' -> 
  withCString a2 $ \a2' -> 
  let {a3' = id a3} in 
  sbamOpen'_ a1' a2' a3' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 324 "src/Bio/SamTools/LowLevel.chs" #-}
    
sbamClose :: SamFilePtr -> IO ()
sbamClose a1 =
  let {a1' = id a1} in 
  sbamClose'_ a1' >>= \res ->
  return ()
{-# LINE 327 "src/Bio/SamTools/LowLevel.chs" #-}

sbamRead :: SamFilePtr -> Bam1Ptr -> IO (CInt)
sbamRead a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  sbamRead'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 331 "src/Bio/SamTools/LowLevel.chs" #-}

sbamWrite :: SamFilePtr -> Bam1Ptr -> IO (CInt)
sbamWrite a1 a2 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  sbamWrite'_ a1' a2' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 335 "src/Bio/SamTools/LowLevel.chs" #-}

-- FASTA Indexing

data FaIdxInt
type FaIdxPtr = Ptr (FaIdxInt)
{-# LINE 340 "src/Bio/SamTools/LowLevel.chs" #-}

faiLoad :: String -> IO (FaIdxPtr)
faiLoad a1 =
  withCString a1 $ \a1' -> 
  faiLoad'_ a1' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 343 "src/Bio/SamTools/LowLevel.chs" #-}

faiDestroy :: FaIdxPtr -> IO ()
faiDestroy a1 =
  let {a1' = id a1} in 
  faiDestroy'_ a1' >>= \res ->
  return ()
{-# LINE 346 "src/Bio/SamTools/LowLevel.chs" #-}

faiFetchSeq :: FaIdxPtr -> CString -> CInt -> CInt -> Ptr CInt -> IO (CString)
faiFetchSeq a1 a2 a3 a4 a5 =
  let {a1' = id a1} in 
  let {a2' = id a2} in 
  let {a3' = id a3} in 
  let {a4' = id a4} in 
  let {a5' = id a5} in 
  faiFetchSeq'_ a1' a2' a3' a4' a5' >>= \res ->
  let {res' = id res} in
  return (res')
{-# LINE 351 "src/Bio/SamTools/LowLevel.chs" #-}

-- Helpers

packCString :: CString -> IO BS.ByteString
packCString = BS.packCString

useAsCString :: BS.ByteString -> (CString -> IO a) -> IO a
useAsCString = BS.useAsCString


foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_open_"
  bamOpen'_ :: ((Ptr CChar) -> ((Ptr CChar) -> (IO (BamFilePtr))))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_close_"
  bamClose'_ :: ((BamFilePtr) -> (IO CInt))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_fpaired"
  bam_fpaired :: CUInt

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_fproper_pair"
  bam_fproper_pair :: CUInt

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_funmap"
  bam_funmap :: CUInt

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_fmunmap"
  bam_fmunmap :: CUInt

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_freverse"
  bam_freverse :: CUInt

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_fmreverse"
  bam_fmreverse :: CUInt

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_fread1"
  bam_fread1 :: CUInt

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_fread2"
  bam_fread2 :: CUInt

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_fsecondary"
  bam_fsecondary :: CUInt

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_fqcfail"
  bam_fqcfail :: CUInt

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_fdup"
  bam_fdup :: CUInt

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_cmatch"
  bam_cmatch :: CUInt

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_cins"
  bam_cins :: CUInt

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_cdel"
  bam_cdel :: CUInt

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_cref_skip"
  bam_cref_skip :: CUInt

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_csoft_clip"
  bam_csoft_clip :: CUInt

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_chard_clip"
  bam_chard_clip :: CUInt

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_cpad"
  bam_cpad :: CUInt

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_cigar_op"
  bam_cigar_op :: (CUInt -> CUInt)

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_cigar_length"
  bam_cigar_length :: (CUInt -> CUInt)

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam1_strand_"
  bam1Strand'_ :: ((Bam1Ptr) -> CInt)

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam1_mstrand_"
  bam1MStrand'_ :: ((Bam1Ptr) -> CInt)

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam1_cigar_"
  bam1Cigar'_ :: ((Bam1Ptr) -> (Ptr CUInt))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam1_qname_"
  bam1QName'_ :: ((Bam1Ptr) -> (Ptr CChar))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam1_seq_"
  bam1Seq'_ :: ((Bam1Ptr) -> (Ptr CUChar))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam1_qual_"
  bam1Qual'_ :: ((Bam1Ptr) -> (Ptr CUChar))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam1_seqi_"
  bam1Seqi'_ :: ((Ptr CUChar) -> (CInt -> CUChar))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h sam_open"
  samOpen'_ :: ((Ptr CChar) -> (IO (TamFilePtr)))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h sam_close"
  samClose'_ :: ((TamFilePtr) -> (IO ()))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h sam_read1"
  samRead1'_ :: ((TamFilePtr) -> ((BamHeaderPtr) -> ((Bam1Ptr) -> (IO CInt))))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h sam_header_read2"
  samHeaderRead2'_ :: ((Ptr CChar) -> (IO (BamHeaderPtr)))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h sam_header_read"
  samHeaderRead'_ :: ((TamFilePtr) -> (IO (BamHeaderPtr)))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_get_tid"
  bamGetTid'_ :: ((BamHeaderPtr) -> ((Ptr CChar) -> (IO CInt)))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_header_init"
  bamHeaderInit'_ :: (IO (BamHeaderPtr))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_header_destroy"
  bamHeaderDestroy'_ :: ((BamHeaderPtr) -> (IO ()))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_header_read"
  bamHeaderRead'_ :: ((BamFilePtr) -> (IO (BamHeaderPtr)))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_header_write"
  bamHeaderWrite'_ :: ((BamFilePtr) -> ((BamHeaderPtr) -> (IO CInt)))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_init_header_hash"
  bamInitHeaderHash'_ :: ((BamHeaderPtr) -> (IO ()))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_read1"
  bamRead1'_ :: ((BamFilePtr) -> ((Bam1Ptr) -> (IO CInt)))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_write1"
  bamWrite1'_ :: ((BamFilePtr) -> ((Bam1Ptr) -> (IO CInt)))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_aux_get"
  bamAuxGet'_ :: ((Bam1Ptr) -> ((Ptr CChar) -> (IO (Ptr CUChar))))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_aux2Z"
  bamAux2Z'_ :: ((Ptr CUChar) -> (IO (Ptr CChar)))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_aux2i"
  bamAux2i'_ :: ((Ptr CUChar) -> (IO CInt))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_init1_"
  bamInit1'_ :: (IO (Bam1Ptr))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_destroy1_"
  bamDestroy1'_ :: ((Bam1Ptr) -> (IO ()))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_dup1_"
  bamDup1'_ :: ((Bam1Ptr) -> (IO (Bam1Ptr)))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_format1"
  bamFormat1'_ :: ((BamHeaderPtr) -> ((Bam1Ptr) -> (IO (Ptr CChar))))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_index_load"
  bamIndexLoad'_ :: ((Ptr CChar) -> (IO (BamIndexPtr)))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_index_destroy"
  bamIndexDestroy'_ :: ((BamIndexPtr) -> (IO ()))

foreign import ccall safe "Bio/SamTools/LowLevel.chs.h bam_fetch"
  bamFetch'_ :: ((BamFilePtr) -> ((BamIndexPtr) -> (CInt -> (CInt -> (CInt -> ((Ptr ()) -> ((BamFetchFPtr) -> (IO CInt))))))))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_iter_query"
  bamIterQuery'_ :: ((BamIndexPtr) -> (CInt -> (CInt -> (CInt -> (IO (BamIterPtr))))))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_iter_read"
  bamIterRead'_ :: ((BamFilePtr) -> ((BamIterPtr) -> ((Bam1Ptr) -> (IO CInt))))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h bam_iter_destroy"
  bamIterDestroy'_ :: ((BamIterPtr) -> (IO ()))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h samopen"
  sbamOpen'_ :: ((Ptr CChar) -> ((Ptr CChar) -> ((Ptr ()) -> (IO (SamFilePtr)))))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h samclose"
  sbamClose'_ :: ((SamFilePtr) -> (IO ()))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h samread"
  sbamRead'_ :: ((SamFilePtr) -> ((Bam1Ptr) -> (IO CInt)))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h samwrite"
  sbamWrite'_ :: ((SamFilePtr) -> ((Bam1Ptr) -> (IO CInt)))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h fai_load"
  faiLoad'_ :: ((Ptr CChar) -> (IO (FaIdxPtr)))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h fai_destroy"
  faiDestroy'_ :: ((FaIdxPtr) -> (IO ()))

foreign import ccall unsafe "Bio/SamTools/LowLevel.chs.h faidx_fetch_seq"
  faiFetchSeq'_ :: ((FaIdxPtr) -> ((Ptr CChar) -> (CInt -> (CInt -> ((Ptr CInt) -> (IO (Ptr CChar)))))))