module Bio.Genocall.AvroFile where
import Bio.Base
import Bio.Bam.Pileup
import Data.Aeson
import Data.Avro hiding ((.=))
import Data.Binary.Builder
import Data.Binary.Get
import Data.Monoid
import qualified Data.ByteString as B
import qualified Data.Text as T
import qualified Data.Vector.Unboxed as U
data GenoCallBlock = GenoCallBlock
{ reference_name :: T.Text
, start_position :: Int
, called_sites :: [ GenoCallSite ] }
data GenoCallSite = GenoCallSite
{ snp_stats :: CallStats
, snp_likelihoods :: [ Int ]
, indel_stats :: CallStats
, indel_variants :: [ IndelVariant ]
, indel_likelihoods :: [ Int ]
}
$( deriveAvros [ ''GenoCallBlock, ''GenoCallSite, ''CallStats, ''IndelVariant ] )
instance Avro V_Nuc where
toSchema _ = return $ object [ "type" .= String "bytes", "doc" .= String "A,C,G,T" ]
toBin (V_Nuc v) = encodeIntBase128 (U.length v) <> U.foldr ((<>) . singleton . unN) mempty v
fromBin = decodeIntBase128 >>= fmap (V_Nuc . U.fromList . map N . B.unpack) . getByteString
toAvron (V_Nuc v) = String . T.pack . map w2c . U.toList $ U.map unN v