-- | Annotate the genomic @Location@ of features or elements. A @Location@ is
-- always contiguous, using strand, 0-based position, and length.
-- Transformation to different systems of annotation is made possible.

module Biobase.Types.Location where

import Control.DeepSeq
import Control.Lens hiding (Index, index)
import Data.Coerce
import Data.Data
import Data.Data.Lens
import GHC.Generics (Generic)
import GHC.TypeNats
import Prelude hiding (length)
import qualified Data.ByteString as BS
import qualified Streaming.Internal as SI
import qualified Streaming.Prelude as SP
import Text.Printf

import Biobase.Types.BioSequence
import Biobase.Types.Index
import Biobase.Types.Position
import Biobase.Types.Strand
import Data.Info




-- | Operations on locations.

class ModifyLocation posTy seqTy where
  -- | Append to the left.
  locAppendLeft  :: seqTy -> Location i posTy seqTy -> Location i posTy seqTy
  -- | Append to the right.
  locAppendRight :: seqTy -> Location i posTy seqTy -> Location i posTy seqTy
  -- | Split a location.
  locSplitAt  :: Int -> Location i posTy seqTy -> (Location i posTy seqTy, Location i posTy seqTy)
  -- | Length of location
  locLength :: Location i posTy seqTy -> Int

locTake :: Int -> Location i posTy seqTy -> Location i posTy seqTy
locTake Int
k = (Location i posTy seqTy, Location i posTy seqTy)
-> Location i posTy seqTy
forall a b. (a, b) -> a
fst ((Location i posTy seqTy, Location i posTy seqTy)
 -> Location i posTy seqTy)
-> (Location i posTy seqTy
    -> (Location i posTy seqTy, Location i posTy seqTy))
-> Location i posTy seqTy
-> Location i posTy seqTy
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> Location i posTy seqTy
-> (Location i posTy seqTy, Location i posTy seqTy)
forall posTy seqTy k (i :: k).
ModifyLocation posTy seqTy =>
Int
-> Location i posTy seqTy
-> (Location i posTy seqTy, Location i posTy seqTy)
locSplitAt Int
k

locTakeEnd :: Int -> Location i posTy seqTy -> Location i posTy seqTy
locTakeEnd Int
k Location i posTy seqTy
loc = let l :: Int
l = Location i posTy seqTy -> Int
forall posTy seqTy k (i :: k).
ModifyLocation posTy seqTy =>
Location i posTy seqTy -> Int
locLength Location i posTy seqTy
loc in (Location i posTy seqTy, Location i posTy seqTy)
-> Location i posTy seqTy
forall a b. (a, b) -> b
snd ((Location i posTy seqTy, Location i posTy seqTy)
 -> Location i posTy seqTy)
-> (Location i posTy seqTy, Location i posTy seqTy)
-> Location i posTy seqTy
forall a b. (a -> b) -> a -> b
$ Int
-> Location i posTy seqTy
-> (Location i posTy seqTy, Location i posTy seqTy)
forall posTy seqTy k (i :: k).
ModifyLocation posTy seqTy =>
Int
-> Location i posTy seqTy
-> (Location i posTy seqTy, Location i posTy seqTy)
locSplitAt (Int
lInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
k) Location i posTy seqTy
loc

locDrop :: Int -> Location i posTy seqTy -> Location i posTy seqTy
locDrop Int
k = (Location i posTy seqTy, Location i posTy seqTy)
-> Location i posTy seqTy
forall a b. (a, b) -> b
snd ((Location i posTy seqTy, Location i posTy seqTy)
 -> Location i posTy seqTy)
-> (Location i posTy seqTy
    -> (Location i posTy seqTy, Location i posTy seqTy))
-> Location i posTy seqTy
-> Location i posTy seqTy
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> Location i posTy seqTy
-> (Location i posTy seqTy, Location i posTy seqTy)
forall posTy seqTy k (i :: k).
ModifyLocation posTy seqTy =>
Int
-> Location i posTy seqTy
-> (Location i posTy seqTy, Location i posTy seqTy)
locSplitAt Int
k

locDropEnd :: Int -> Location i posTy seqTy -> Location i posTy seqTy
locDropEnd Int
k Location i posTy seqTy
loc = let l :: Int
l = Location i posTy seqTy -> Int
forall posTy seqTy k (i :: k).
ModifyLocation posTy seqTy =>
Location i posTy seqTy -> Int
locLength Location i posTy seqTy
loc in (Location i posTy seqTy, Location i posTy seqTy)
-> Location i posTy seqTy
forall a b. (a, b) -> a
fst ((Location i posTy seqTy, Location i posTy seqTy)
 -> Location i posTy seqTy)
-> (Location i posTy seqTy, Location i posTy seqTy)
-> Location i posTy seqTy
forall a b. (a -> b) -> a -> b
$ Int
-> Location i posTy seqTy
-> (Location i posTy seqTy, Location i posTy seqTy)
forall posTy seqTy k (i :: k).
ModifyLocation posTy seqTy =>
Int
-> Location i posTy seqTy
-> (Location i posTy seqTy, Location i posTy seqTy)
locSplitAt (Int
lInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
k) Location i posTy seqTy
loc

locSplitEndAt :: Int
-> Location i posTy seqTy
-> (Location i posTy seqTy, Location i posTy seqTy)
locSplitEndAt Int
k Location i posTy seqTy
loc = let l :: Int
l = Location i posTy seqTy -> Int
forall posTy seqTy k (i :: k).
ModifyLocation posTy seqTy =>
Location i posTy seqTy -> Int
locLength Location i posTy seqTy
loc in Int
-> Location i posTy seqTy
-> (Location i posTy seqTy, Location i posTy seqTy)
forall posTy seqTy k (i :: k).
ModifyLocation posTy seqTy =>
Int
-> Location i posTy seqTy
-> (Location i posTy seqTy, Location i posTy seqTy)
locSplitAt (Int
lInt -> Int -> Int
forall a. Num a => a -> a -> a
-Int
k) Location i posTy seqTy
loc



data Location ident posTy seqTy = Location
  { Location ident posTy seqTy -> SequenceIdentifier ident
_locIdentifier  :: !(SequenceIdentifier ident)
  , Location ident posTy seqTy -> posTy
_locPosition    :: !posTy
  , Location ident posTy seqTy -> seqTy
_locSequence    :: !seqTy
  }
  deriving stock (Int -> Location ident posTy seqTy -> ShowS
[Location ident posTy seqTy] -> ShowS
Location ident posTy seqTy -> String
(Int -> Location ident posTy seqTy -> ShowS)
-> (Location ident posTy seqTy -> String)
-> ([Location ident posTy seqTy] -> ShowS)
-> Show (Location ident posTy seqTy)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (ident :: k) posTy seqTy.
(Show posTy, Show seqTy) =>
Int -> Location ident posTy seqTy -> ShowS
forall k (ident :: k) posTy seqTy.
(Show posTy, Show seqTy) =>
[Location ident posTy seqTy] -> ShowS
forall k (ident :: k) posTy seqTy.
(Show posTy, Show seqTy) =>
Location ident posTy seqTy -> String
showList :: [Location ident posTy seqTy] -> ShowS
$cshowList :: forall k (ident :: k) posTy seqTy.
(Show posTy, Show seqTy) =>
[Location ident posTy seqTy] -> ShowS
show :: Location ident posTy seqTy -> String
$cshow :: forall k (ident :: k) posTy seqTy.
(Show posTy, Show seqTy) =>
Location ident posTy seqTy -> String
showsPrec :: Int -> Location ident posTy seqTy -> ShowS
$cshowsPrec :: forall k (ident :: k) posTy seqTy.
(Show posTy, Show seqTy) =>
Int -> Location ident posTy seqTy -> ShowS
Show,Typeable (Location ident posTy seqTy)
DataType
Constr
Typeable (Location ident posTy seqTy)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g)
    -> Location ident posTy seqTy
    -> c (Location ident posTy seqTy))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r)
    -> Constr
    -> c (Location ident posTy seqTy))
-> (Location ident posTy seqTy -> Constr)
-> (Location ident posTy seqTy -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d))
    -> Maybe (c (Location ident posTy seqTy)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (Location ident posTy seqTy)))
-> ((forall b. Data b => b -> b)
    -> Location ident posTy seqTy -> Location ident posTy seqTy)
-> (forall r r'.
    (r -> r' -> r)
    -> r
    -> (forall d. Data d => d -> r')
    -> Location ident posTy seqTy
    -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r
    -> (forall d. Data d => d -> r')
    -> Location ident posTy seqTy
    -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> Location ident posTy seqTy -> [u])
-> (forall u.
    Int
    -> (forall d. Data d => d -> u) -> Location ident posTy seqTy -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> Location ident posTy seqTy -> m (Location ident posTy seqTy))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> Location ident posTy seqTy -> m (Location ident posTy seqTy))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> Location ident posTy seqTy -> m (Location ident posTy seqTy))
-> Data (Location ident posTy seqTy)
Location ident posTy seqTy -> DataType
Location ident posTy seqTy -> Constr
(forall b. Data b => b -> b)
-> Location ident posTy seqTy -> Location ident posTy seqTy
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> Location ident posTy seqTy
-> c (Location ident posTy seqTy)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Location ident posTy seqTy)
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int
-> (forall d. Data d => d -> u) -> Location ident posTy seqTy -> u
forall u.
(forall d. Data d => d -> u) -> Location ident posTy seqTy -> [u]
forall k (ident :: k) posTy seqTy.
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
Typeable (Location ident posTy seqTy)
forall k (ident :: k) posTy seqTy.
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
Location ident posTy seqTy -> DataType
forall k (ident :: k) posTy seqTy.
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
Location ident posTy seqTy -> Constr
forall k (ident :: k) posTy seqTy.
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
(forall b. Data b => b -> b)
-> Location ident posTy seqTy -> Location ident posTy seqTy
forall k (ident :: k) posTy seqTy u.
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
Int
-> (forall d. Data d => d -> u) -> Location ident posTy seqTy -> u
forall k (ident :: k) posTy seqTy u.
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
(forall d. Data d => d -> u) -> Location ident posTy seqTy -> [u]
forall k (ident :: k) posTy seqTy r r'.
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> Location ident posTy seqTy
-> r
forall k (ident :: k) posTy seqTy r r'.
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> Location ident posTy seqTy
-> r
forall k (ident :: k) posTy seqTy (m :: * -> *).
(Typeable ident, Typeable k, Data posTy, Data seqTy, Monad m) =>
(forall d. Data d => d -> m d)
-> Location ident posTy seqTy -> m (Location ident posTy seqTy)
forall k (ident :: k) posTy seqTy (m :: * -> *).
(Typeable ident, Typeable k, Data posTy, Data seqTy,
 MonadPlus m) =>
(forall d. Data d => d -> m d)
-> Location ident posTy seqTy -> m (Location ident posTy seqTy)
forall k (ident :: k) posTy seqTy (c :: * -> *).
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Location ident posTy seqTy)
forall k (ident :: k) posTy seqTy (c :: * -> *).
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> Location ident posTy seqTy
-> c (Location ident posTy seqTy)
forall k (ident :: k) posTy seqTy (t :: * -> *) (c :: * -> *).
(Typeable ident, Typeable k, Data posTy, Data seqTy, Typeable t) =>
(forall d. Data d => c (t d))
-> Maybe (c (Location ident posTy seqTy))
forall k (ident :: k) posTy seqTy (t :: * -> * -> *) (c :: * -> *).
(Typeable ident, Typeable k, Data posTy, Data seqTy, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Location ident posTy seqTy))
forall r r'.
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> Location ident posTy seqTy
-> r
forall r r'.
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> Location ident posTy seqTy
-> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> Location ident posTy seqTy -> m (Location ident posTy seqTy)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> Location ident posTy seqTy -> m (Location ident posTy seqTy)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Location ident posTy seqTy)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> Location ident posTy seqTy
-> c (Location ident posTy seqTy)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d))
-> Maybe (c (Location ident posTy seqTy))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Location ident posTy seqTy))
$cLocation :: Constr
$tLocation :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> Location ident posTy seqTy -> m (Location ident posTy seqTy)
$cgmapMo :: forall k (ident :: k) posTy seqTy (m :: * -> *).
(Typeable ident, Typeable k, Data posTy, Data seqTy,
 MonadPlus m) =>
(forall d. Data d => d -> m d)
-> Location ident posTy seqTy -> m (Location ident posTy seqTy)
gmapMp :: (forall d. Data d => d -> m d)
-> Location ident posTy seqTy -> m (Location ident posTy seqTy)
$cgmapMp :: forall k (ident :: k) posTy seqTy (m :: * -> *).
(Typeable ident, Typeable k, Data posTy, Data seqTy,
 MonadPlus m) =>
(forall d. Data d => d -> m d)
-> Location ident posTy seqTy -> m (Location ident posTy seqTy)
gmapM :: (forall d. Data d => d -> m d)
-> Location ident posTy seqTy -> m (Location ident posTy seqTy)
$cgmapM :: forall k (ident :: k) posTy seqTy (m :: * -> *).
(Typeable ident, Typeable k, Data posTy, Data seqTy, Monad m) =>
(forall d. Data d => d -> m d)
-> Location ident posTy seqTy -> m (Location ident posTy seqTy)
gmapQi :: Int
-> (forall d. Data d => d -> u) -> Location ident posTy seqTy -> u
$cgmapQi :: forall k (ident :: k) posTy seqTy u.
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
Int
-> (forall d. Data d => d -> u) -> Location ident posTy seqTy -> u
gmapQ :: (forall d. Data d => d -> u) -> Location ident posTy seqTy -> [u]
$cgmapQ :: forall k (ident :: k) posTy seqTy u.
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
(forall d. Data d => d -> u) -> Location ident posTy seqTy -> [u]
gmapQr :: (r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> Location ident posTy seqTy
-> r
$cgmapQr :: forall k (ident :: k) posTy seqTy r r'.
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
(r' -> r -> r)
-> r
-> (forall d. Data d => d -> r')
-> Location ident posTy seqTy
-> r
gmapQl :: (r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> Location ident posTy seqTy
-> r
$cgmapQl :: forall k (ident :: k) posTy seqTy r r'.
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
(r -> r' -> r)
-> r
-> (forall d. Data d => d -> r')
-> Location ident posTy seqTy
-> r
gmapT :: (forall b. Data b => b -> b)
-> Location ident posTy seqTy -> Location ident posTy seqTy
$cgmapT :: forall k (ident :: k) posTy seqTy.
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
(forall b. Data b => b -> b)
-> Location ident posTy seqTy -> Location ident posTy seqTy
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Location ident posTy seqTy))
$cdataCast2 :: forall k (ident :: k) posTy seqTy (t :: * -> * -> *) (c :: * -> *).
(Typeable ident, Typeable k, Data posTy, Data seqTy, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (Location ident posTy seqTy))
dataCast1 :: (forall d. Data d => c (t d))
-> Maybe (c (Location ident posTy seqTy))
$cdataCast1 :: forall k (ident :: k) posTy seqTy (t :: * -> *) (c :: * -> *).
(Typeable ident, Typeable k, Data posTy, Data seqTy, Typeable t) =>
(forall d. Data d => c (t d))
-> Maybe (c (Location ident posTy seqTy))
dataTypeOf :: Location ident posTy seqTy -> DataType
$cdataTypeOf :: forall k (ident :: k) posTy seqTy.
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
Location ident posTy seqTy -> DataType
toConstr :: Location ident posTy seqTy -> Constr
$ctoConstr :: forall k (ident :: k) posTy seqTy.
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
Location ident posTy seqTy -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Location ident posTy seqTy)
$cgunfold :: forall k (ident :: k) posTy seqTy (c :: * -> *).
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (Location ident posTy seqTy)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> Location ident posTy seqTy
-> c (Location ident posTy seqTy)
$cgfoldl :: forall k (ident :: k) posTy seqTy (c :: * -> *).
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> Location ident posTy seqTy
-> c (Location ident posTy seqTy)
$cp1Data :: forall k (ident :: k) posTy seqTy.
(Typeable ident, Typeable k, Data posTy, Data seqTy) =>
Typeable (Location ident posTy seqTy)
Data,Typeable,(forall x.
 Location ident posTy seqTy -> Rep (Location ident posTy seqTy) x)
-> (forall x.
    Rep (Location ident posTy seqTy) x -> Location ident posTy seqTy)
-> Generic (Location ident posTy seqTy)
forall x.
Rep (Location ident posTy seqTy) x -> Location ident posTy seqTy
forall x.
Location ident posTy seqTy -> Rep (Location ident posTy seqTy) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall k (ident :: k) posTy seqTy x.
Rep (Location ident posTy seqTy) x -> Location ident posTy seqTy
forall k (ident :: k) posTy seqTy x.
Location ident posTy seqTy -> Rep (Location ident posTy seqTy) x
$cto :: forall k (ident :: k) posTy seqTy x.
Rep (Location ident posTy seqTy) x -> Location ident posTy seqTy
$cfrom :: forall k (ident :: k) posTy seqTy x.
Location ident posTy seqTy -> Rep (Location ident posTy seqTy) x
Generic)
makeLenses ''Location

instance (NFData p, NFData s) => NFData (Location i p s)

retagLocation :: Location i posTy seqTy -> Location j posTy seqTy
{-# Inline retagLocation #-}
retagLocation :: Location i posTy seqTy -> Location j posTy seqTy
retagLocation = ASetter
  (Location i posTy seqTy)
  (Location j posTy seqTy)
  (SequenceIdentifier i)
  (SequenceIdentifier j)
-> (SequenceIdentifier i -> SequenceIdentifier j)
-> Location i posTy seqTy
-> Location j posTy seqTy
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter
  (Location i posTy seqTy)
  (Location j posTy seqTy)
  (SequenceIdentifier i)
  (SequenceIdentifier j)
forall k (ident :: k) posTy seqTy k (ident :: k).
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  (SequenceIdentifier ident)
  (SequenceIdentifier ident)
locIdentifier SequenceIdentifier i -> SequenceIdentifier j
coerce

instance ModifyLocation FwdPosition (BioSequence w) where
  {-# Inline locAppendLeft #-}
  locAppendLeft :: BioSequence w
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
locAppendLeft BioSequence w
s Location i FwdPosition (BioSequence w)
loc = let l :: Int
l = BioSequence w
sBioSequence w -> Getting Int (BioSequence w) Int -> Int
forall s a. s -> Getting a s a -> a
^.(ByteString -> Const Int ByteString)
-> BioSequence w -> Const Int (BioSequence w)
forall k1 (which1 :: k1) k (which :: k).
Iso (BioSequence which1) (BioSequence which) ByteString ByteString
_BioSequence((ByteString -> Const Int ByteString)
 -> BioSequence w -> Const Int (BioSequence w))
-> ((Int -> Const Int Int) -> ByteString -> Const Int ByteString)
-> Getting Int (BioSequence w) Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ByteString -> Int)
-> (Int -> Const Int Int) -> ByteString -> Const Int ByteString
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to ByteString -> Int
BS.length
    in Location i FwdPosition (BioSequence w)
loc Location i FwdPosition (BioSequence w)
-> (Location i FwdPosition (BioSequence w)
    -> Location i FwdPosition (BioSequence w))
-> Location i FwdPosition (BioSequence w)
forall a b. a -> (a -> b) -> b
& (BioSequence w -> Identity (BioSequence w))
-> Location i FwdPosition (BioSequence w)
-> Identity (Location i FwdPosition (BioSequence w))
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence ((BioSequence w -> Identity (BioSequence w))
 -> Location i FwdPosition (BioSequence w)
 -> Identity (Location i FwdPosition (BioSequence w)))
-> (BioSequence w -> BioSequence w)
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (BioSequence w
s BioSequence w -> BioSequence w -> BioSequence w
forall a. Semigroup a => a -> a -> a
<>) Location i FwdPosition (BioSequence w)
-> (Location i FwdPosition (BioSequence w)
    -> Location i FwdPosition (BioSequence w))
-> Location i FwdPosition (BioSequence w)
forall a b. a -> (a -> b) -> b
& (FwdPosition -> Identity FwdPosition)
-> Location i FwdPosition (BioSequence w)
-> Identity (Location i FwdPosition (BioSequence w))
forall k (ident :: k) posTy seqTy posTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  posTy
  posTy
locPosition ((FwdPosition -> Identity FwdPosition)
 -> Location i FwdPosition (BioSequence w)
 -> Identity (Location i FwdPosition (BioSequence w)))
-> (FwdPosition -> FwdPosition)
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (\FwdPosition
p -> if FwdPosition
pFwdPosition -> Getting Strand FwdPosition Strand -> Strand
forall s a. s -> Getting a s a -> a
^.Getting Strand FwdPosition Strand
Lens' FwdPosition Strand
fwdStrand Strand -> Strand -> Bool
forall a. Eq a => a -> a -> Bool
== Strand
PlusStrand then FwdPosition
p FwdPosition -> (FwdPosition -> FwdPosition) -> FwdPosition
forall a b. a -> (a -> b) -> b
& (Index 0 -> Identity (Index 0))
-> FwdPosition -> Identity FwdPosition
Lens' FwdPosition (Index 0)
fwdStart ((Index 0 -> Identity (Index 0))
 -> FwdPosition -> Identity FwdPosition)
-> (Index 0 -> Index 0) -> FwdPosition -> FwdPosition
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Index 0 -> Int -> Index 0
forall (t :: Nat). KnownNat t => Index t -> Int -> Index t
-. Int
l) else FwdPosition
p)
  {-# Inline locAppendRight #-}
  locAppendRight :: BioSequence w
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
locAppendRight BioSequence w
s Location i FwdPosition (BioSequence w)
loc = let l :: Int
l = BioSequence w
sBioSequence w -> Getting Int (BioSequence w) Int -> Int
forall s a. s -> Getting a s a -> a
^.(ByteString -> Const Int ByteString)
-> BioSequence w -> Const Int (BioSequence w)
forall k1 (which1 :: k1) k (which :: k).
Iso (BioSequence which1) (BioSequence which) ByteString ByteString
_BioSequence((ByteString -> Const Int ByteString)
 -> BioSequence w -> Const Int (BioSequence w))
-> ((Int -> Const Int Int) -> ByteString -> Const Int ByteString)
-> Getting Int (BioSequence w) Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ByteString -> Int)
-> (Int -> Const Int Int) -> ByteString -> Const Int ByteString
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to ByteString -> Int
BS.length
    in Location i FwdPosition (BioSequence w)
loc Location i FwdPosition (BioSequence w)
-> (Location i FwdPosition (BioSequence w)
    -> Location i FwdPosition (BioSequence w))
-> Location i FwdPosition (BioSequence w)
forall a b. a -> (a -> b) -> b
& (BioSequence w -> Identity (BioSequence w))
-> Location i FwdPosition (BioSequence w)
-> Identity (Location i FwdPosition (BioSequence w))
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence ((BioSequence w -> Identity (BioSequence w))
 -> Location i FwdPosition (BioSequence w)
 -> Identity (Location i FwdPosition (BioSequence w)))
-> (BioSequence w -> BioSequence w)
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (BioSequence w -> BioSequence w -> BioSequence w
forall a. Semigroup a => a -> a -> a
<> BioSequence w
s) Location i FwdPosition (BioSequence w)
-> (Location i FwdPosition (BioSequence w)
    -> Location i FwdPosition (BioSequence w))
-> Location i FwdPosition (BioSequence w)
forall a b. a -> (a -> b) -> b
& (FwdPosition -> Identity FwdPosition)
-> Location i FwdPosition (BioSequence w)
-> Identity (Location i FwdPosition (BioSequence w))
forall k (ident :: k) posTy seqTy posTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  posTy
  posTy
locPosition ((FwdPosition -> Identity FwdPosition)
 -> Location i FwdPosition (BioSequence w)
 -> Identity (Location i FwdPosition (BioSequence w)))
-> (FwdPosition -> FwdPosition)
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (\FwdPosition
p -> if FwdPosition
pFwdPosition -> Getting Strand FwdPosition Strand -> Strand
forall s a. s -> Getting a s a -> a
^.Getting Strand FwdPosition Strand
Lens' FwdPosition Strand
fwdStrand Strand -> Strand -> Bool
forall a. Eq a => a -> a -> Bool
== Strand
MinusStrand then FwdPosition
p FwdPosition -> (FwdPosition -> FwdPosition) -> FwdPosition
forall a b. a -> (a -> b) -> b
& (Index 0 -> Identity (Index 0))
-> FwdPosition -> Identity FwdPosition
Lens' FwdPosition (Index 0)
fwdStart ((Index 0 -> Identity (Index 0))
 -> FwdPosition -> Identity FwdPosition)
-> (Index 0 -> Index 0) -> FwdPosition -> FwdPosition
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Index 0 -> Int -> Index 0
forall (t :: Nat). KnownNat t => Index t -> Int -> Index t
-. Int
l) else FwdPosition
p)
  {-# Inline locSplitAt #-}
  locSplitAt :: Int
-> Location i FwdPosition (BioSequence w)
-> (Location i FwdPosition (BioSequence w),
    Location i FwdPosition (BioSequence w))
locSplitAt Int
k Location i FwdPosition (BioSequence w)
loc =
    let (ByteString
h',ByteString
t') = Location i FwdPosition (BioSequence w)
locLocation i FwdPosition (BioSequence w)
-> Getting
     (ByteString, ByteString)
     (Location i FwdPosition (BioSequence w))
     (ByteString, ByteString)
-> (ByteString, ByteString)
forall s a. s -> Getting a s a -> a
^.(BioSequence w -> Const (ByteString, ByteString) (BioSequence w))
-> Location i FwdPosition (BioSequence w)
-> Const
     (ByteString, ByteString) (Location i FwdPosition (BioSequence w))
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence((BioSequence w -> Const (ByteString, ByteString) (BioSequence w))
 -> Location i FwdPosition (BioSequence w)
 -> Const
      (ByteString, ByteString) (Location i FwdPosition (BioSequence w)))
-> (((ByteString, ByteString)
     -> Const (ByteString, ByteString) (ByteString, ByteString))
    -> BioSequence w -> Const (ByteString, ByteString) (BioSequence w))
-> Getting
     (ByteString, ByteString)
     (Location i FwdPosition (BioSequence w))
     (ByteString, ByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ByteString -> Const (ByteString, ByteString) ByteString)
-> BioSequence w -> Const (ByteString, ByteString) (BioSequence w)
forall k1 (which1 :: k1) k (which :: k).
Iso (BioSequence which1) (BioSequence which) ByteString ByteString
_BioSequence((ByteString -> Const (ByteString, ByteString) ByteString)
 -> BioSequence w -> Const (ByteString, ByteString) (BioSequence w))
-> (((ByteString, ByteString)
     -> Const (ByteString, ByteString) (ByteString, ByteString))
    -> ByteString -> Const (ByteString, ByteString) ByteString)
-> ((ByteString, ByteString)
    -> Const (ByteString, ByteString) (ByteString, ByteString))
-> BioSequence w
-> Const (ByteString, ByteString) (BioSequence w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ByteString -> (ByteString, ByteString))
-> ((ByteString, ByteString)
    -> Const (ByteString, ByteString) (ByteString, ByteString))
-> ByteString
-> Const (ByteString, ByteString) ByteString
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to (Int -> ByteString -> (ByteString, ByteString)
BS.splitAt Int
k)
        hl :: Int
hl = ByteString -> Int
BS.length ByteString
h' ; tl :: Int
tl = ByteString -> Int
BS.length ByteString
t'
        h :: Location i FwdPosition (BioSequence w)
h = Location i FwdPosition (BioSequence w)
loc Location i FwdPosition (BioSequence w)
-> (Location i FwdPosition (BioSequence w)
    -> Location i FwdPosition (BioSequence w))
-> Location i FwdPosition (BioSequence w)
forall a b. a -> (a -> b) -> b
& (BioSequence w -> Identity (BioSequence w))
-> Location i FwdPosition (BioSequence w)
-> Identity (Location i FwdPosition (BioSequence w))
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence((BioSequence w -> Identity (BioSequence w))
 -> Location i FwdPosition (BioSequence w)
 -> Identity (Location i FwdPosition (BioSequence w)))
-> ((ByteString -> Identity ByteString)
    -> BioSequence w -> Identity (BioSequence w))
-> (ByteString -> Identity ByteString)
-> Location i FwdPosition (BioSequence w)
-> Identity (Location i FwdPosition (BioSequence w))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ByteString -> Identity ByteString)
-> BioSequence w -> Identity (BioSequence w)
forall k1 (which1 :: k1) k (which :: k).
Iso (BioSequence which1) (BioSequence which) ByteString ByteString
_BioSequence ((ByteString -> Identity ByteString)
 -> Location i FwdPosition (BioSequence w)
 -> Identity (Location i FwdPosition (BioSequence w)))
-> ByteString
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ByteString
h' Location i FwdPosition (BioSequence w)
-> (Location i FwdPosition (BioSequence w)
    -> Location i FwdPosition (BioSequence w))
-> Location i FwdPosition (BioSequence w)
forall a b. a -> (a -> b) -> b
& (FwdPosition -> Identity FwdPosition)
-> Location i FwdPosition (BioSequence w)
-> Identity (Location i FwdPosition (BioSequence w))
forall k (ident :: k) posTy seqTy posTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  posTy
  posTy
locPosition ((FwdPosition -> Identity FwdPosition)
 -> Location i FwdPosition (BioSequence w)
 -> Identity (Location i FwdPosition (BioSequence w)))
-> (FwdPosition -> FwdPosition)
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (\FwdPosition
p -> if FwdPosition
pFwdPosition -> Getting Strand FwdPosition Strand -> Strand
forall s a. s -> Getting a s a -> a
^.Getting Strand FwdPosition Strand
Lens' FwdPosition Strand
fwdStrand Strand -> Strand -> Bool
forall a. Eq a => a -> a -> Bool
== Strand
MinusStrand then FwdPosition
p FwdPosition -> (FwdPosition -> FwdPosition) -> FwdPosition
forall a b. a -> (a -> b) -> b
& (Index 0 -> Identity (Index 0))
-> FwdPosition -> Identity FwdPosition
Lens' FwdPosition (Index 0)
fwdStart ((Index 0 -> Identity (Index 0))
 -> FwdPosition -> Identity FwdPosition)
-> (Index 0 -> Index 0) -> FwdPosition -> FwdPosition
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Index 0 -> Int -> Index 0
forall (t :: Nat). KnownNat t => Index t -> Int -> Index t
+. Int
tl) else FwdPosition
p)
        t :: Location i FwdPosition (BioSequence w)
t = Location i FwdPosition (BioSequence w)
loc Location i FwdPosition (BioSequence w)
-> (Location i FwdPosition (BioSequence w)
    -> Location i FwdPosition (BioSequence w))
-> Location i FwdPosition (BioSequence w)
forall a b. a -> (a -> b) -> b
& (BioSequence w -> Identity (BioSequence w))
-> Location i FwdPosition (BioSequence w)
-> Identity (Location i FwdPosition (BioSequence w))
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence((BioSequence w -> Identity (BioSequence w))
 -> Location i FwdPosition (BioSequence w)
 -> Identity (Location i FwdPosition (BioSequence w)))
-> ((ByteString -> Identity ByteString)
    -> BioSequence w -> Identity (BioSequence w))
-> (ByteString -> Identity ByteString)
-> Location i FwdPosition (BioSequence w)
-> Identity (Location i FwdPosition (BioSequence w))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ByteString -> Identity ByteString)
-> BioSequence w -> Identity (BioSequence w)
forall k1 (which1 :: k1) k (which :: k).
Iso (BioSequence which1) (BioSequence which) ByteString ByteString
_BioSequence ((ByteString -> Identity ByteString)
 -> Location i FwdPosition (BioSequence w)
 -> Identity (Location i FwdPosition (BioSequence w)))
-> ByteString
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ByteString
t' Location i FwdPosition (BioSequence w)
-> (Location i FwdPosition (BioSequence w)
    -> Location i FwdPosition (BioSequence w))
-> Location i FwdPosition (BioSequence w)
forall a b. a -> (a -> b) -> b
& (FwdPosition -> Identity FwdPosition)
-> Location i FwdPosition (BioSequence w)
-> Identity (Location i FwdPosition (BioSequence w))
forall k (ident :: k) posTy seqTy posTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  posTy
  posTy
locPosition ((FwdPosition -> Identity FwdPosition)
 -> Location i FwdPosition (BioSequence w)
 -> Identity (Location i FwdPosition (BioSequence w)))
-> (FwdPosition -> FwdPosition)
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (\FwdPosition
p -> if FwdPosition
pFwdPosition -> Getting Strand FwdPosition Strand -> Strand
forall s a. s -> Getting a s a -> a
^.Getting Strand FwdPosition Strand
Lens' FwdPosition Strand
fwdStrand Strand -> Strand -> Bool
forall a. Eq a => a -> a -> Bool
== Strand
PlusStrand then FwdPosition
p FwdPosition -> (FwdPosition -> FwdPosition) -> FwdPosition
forall a b. a -> (a -> b) -> b
& (Index 0 -> Identity (Index 0))
-> FwdPosition -> Identity FwdPosition
Lens' FwdPosition (Index 0)
fwdStart ((Index 0 -> Identity (Index 0))
 -> FwdPosition -> Identity FwdPosition)
-> (Index 0 -> Index 0) -> FwdPosition -> FwdPosition
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Index 0 -> Int -> Index 0
forall (t :: Nat). KnownNat t => Index t -> Int -> Index t
+. Int
hl) else FwdPosition
p)
    in  (Location i FwdPosition (BioSequence w)
h,Location i FwdPosition (BioSequence w)
t)
  {-# Inline locLength #-}
  locLength :: Location i FwdPosition (BioSequence w) -> Int
locLength = Getting Int (Location i FwdPosition (BioSequence w)) Int
-> Location i FwdPosition (BioSequence w) -> Int
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view ((BioSequence w -> Const Int (BioSequence w))
-> Location i FwdPosition (BioSequence w)
-> Const Int (Location i FwdPosition (BioSequence w))
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence((BioSequence w -> Const Int (BioSequence w))
 -> Location i FwdPosition (BioSequence w)
 -> Const Int (Location i FwdPosition (BioSequence w)))
-> Getting Int (BioSequence w) Int
-> Getting Int (Location i FwdPosition (BioSequence w)) Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ByteString -> Const Int ByteString)
-> BioSequence w -> Const Int (BioSequence w)
forall k1 (which1 :: k1) k (which :: k).
Iso (BioSequence which1) (BioSequence which) ByteString ByteString
_BioSequence((ByteString -> Const Int ByteString)
 -> BioSequence w -> Const Int (BioSequence w))
-> ((Int -> Const Int Int) -> ByteString -> Const Int ByteString)
-> Getting Int (BioSequence w) Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ByteString -> Int)
-> (Int -> Const Int Int) -> ByteString -> Const Int ByteString
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to ByteString -> Int
BS.length)

instance ModifyLocation FwdPosition Int where
  {-# Inline locAppendLeft #-}
  locAppendLeft :: Int -> Location i FwdPosition Int -> Location i FwdPosition Int
locAppendLeft Int
k' Location i FwdPosition Int
loc = let k :: Int
k = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int
forall a. Ord a => a -> a -> a
min (Location i FwdPosition Int
locLocation i FwdPosition Int
-> Getting Int (Location i FwdPosition Int) Int -> Int
forall s a. s -> Getting a s a -> a
^.(FwdPosition -> Const Int FwdPosition)
-> Location i FwdPosition Int
-> Const Int (Location i FwdPosition Int)
forall k (ident :: k) posTy seqTy posTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  posTy
  posTy
locPosition((FwdPosition -> Const Int FwdPosition)
 -> Location i FwdPosition Int
 -> Const Int (Location i FwdPosition Int))
-> ((Int -> Const Int Int) -> FwdPosition -> Const Int FwdPosition)
-> Getting Int (Location i FwdPosition Int) Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Index 0 -> Const Int (Index 0))
-> FwdPosition -> Const Int FwdPosition
Lens' FwdPosition (Index 0)
fwdStart((Index 0 -> Const Int (Index 0))
 -> FwdPosition -> Const Int FwdPosition)
-> ((Int -> Const Int Int) -> Index 0 -> Const Int (Index 0))
-> (Int -> Const Int Int)
-> FwdPosition
-> Const Int FwdPosition
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Index 0 -> Int)
-> (Int -> Const Int Int) -> Index 0 -> Const Int (Index 0)
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to Index 0 -> Int
forall (t :: Nat). KnownNat t => Index t -> Int
toInt0) Int
k' in
    Location i FwdPosition Int
loc Location i FwdPosition Int
-> (Location i FwdPosition Int -> Location i FwdPosition Int)
-> Location i FwdPosition Int
forall a b. a -> (a -> b) -> b
& (Int -> Identity Int)
-> Location i FwdPosition Int
-> Identity (Location i FwdPosition Int)
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence ((Int -> Identity Int)
 -> Location i FwdPosition Int
 -> Identity (Location i FwdPosition Int))
-> (Int -> Int)
-> Location i FwdPosition Int
-> Location i FwdPosition Int
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
k) Location i FwdPosition Int
-> (Location i FwdPosition Int -> Location i FwdPosition Int)
-> Location i FwdPosition Int
forall a b. a -> (a -> b) -> b
& (FwdPosition -> Identity FwdPosition)
-> Location i FwdPosition Int
-> Identity (Location i FwdPosition Int)
forall k (ident :: k) posTy seqTy posTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  posTy
  posTy
locPosition ((FwdPosition -> Identity FwdPosition)
 -> Location i FwdPosition Int
 -> Identity (Location i FwdPosition Int))
-> (FwdPosition -> FwdPosition)
-> Location i FwdPosition Int
-> Location i FwdPosition Int
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (\FwdPosition
p -> if FwdPosition
pFwdPosition -> Getting Strand FwdPosition Strand -> Strand
forall s a. s -> Getting a s a -> a
^.Getting Strand FwdPosition Strand
Lens' FwdPosition Strand
fwdStrand Strand -> Strand -> Bool
forall a. Eq a => a -> a -> Bool
== Strand
PlusStrand then FwdPosition
p FwdPosition -> (FwdPosition -> FwdPosition) -> FwdPosition
forall a b. a -> (a -> b) -> b
& (Index 0 -> Identity (Index 0))
-> FwdPosition -> Identity FwdPosition
Lens' FwdPosition (Index 0)
fwdStart ((Index 0 -> Identity (Index 0))
 -> FwdPosition -> Identity FwdPosition)
-> (Index 0 -> Index 0) -> FwdPosition -> FwdPosition
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Index 0 -> Int -> Index 0
forall (t :: Nat). KnownNat t => Index t -> Int -> Index t
-. Int
k) else FwdPosition
p)
  {-# Inline locAppendRight #-}
  locAppendRight :: Int -> Location i FwdPosition Int -> Location i FwdPosition Int
locAppendRight Int
k' Location i FwdPosition Int
loc = let k :: Int
k = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int
forall a. Ord a => a -> a -> a
min (Location i FwdPosition Int
locLocation i FwdPosition Int
-> Getting Int (Location i FwdPosition Int) Int -> Int
forall s a. s -> Getting a s a -> a
^.(FwdPosition -> Const Int FwdPosition)
-> Location i FwdPosition Int
-> Const Int (Location i FwdPosition Int)
forall k (ident :: k) posTy seqTy posTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  posTy
  posTy
locPosition((FwdPosition -> Const Int FwdPosition)
 -> Location i FwdPosition Int
 -> Const Int (Location i FwdPosition Int))
-> ((Int -> Const Int Int) -> FwdPosition -> Const Int FwdPosition)
-> Getting Int (Location i FwdPosition Int) Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Index 0 -> Const Int (Index 0))
-> FwdPosition -> Const Int FwdPosition
Lens' FwdPosition (Index 0)
fwdStart((Index 0 -> Const Int (Index 0))
 -> FwdPosition -> Const Int FwdPosition)
-> ((Int -> Const Int Int) -> Index 0 -> Const Int (Index 0))
-> (Int -> Const Int Int)
-> FwdPosition
-> Const Int FwdPosition
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Index 0 -> Int)
-> (Int -> Const Int Int) -> Index 0 -> Const Int (Index 0)
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to Index 0 -> Int
forall (t :: Nat). KnownNat t => Index t -> Int
toInt0) Int
k' in
    Location i FwdPosition Int
loc Location i FwdPosition Int
-> (Location i FwdPosition Int -> Location i FwdPosition Int)
-> Location i FwdPosition Int
forall a b. a -> (a -> b) -> b
& (Int -> Identity Int)
-> Location i FwdPosition Int
-> Identity (Location i FwdPosition Int)
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence ((Int -> Identity Int)
 -> Location i FwdPosition Int
 -> Identity (Location i FwdPosition Int))
-> (Int -> Int)
-> Location i FwdPosition Int
-> Location i FwdPosition Int
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
k) Location i FwdPosition Int
-> (Location i FwdPosition Int -> Location i FwdPosition Int)
-> Location i FwdPosition Int
forall a b. a -> (a -> b) -> b
& (FwdPosition -> Identity FwdPosition)
-> Location i FwdPosition Int
-> Identity (Location i FwdPosition Int)
forall k (ident :: k) posTy seqTy posTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  posTy
  posTy
locPosition ((FwdPosition -> Identity FwdPosition)
 -> Location i FwdPosition Int
 -> Identity (Location i FwdPosition Int))
-> (FwdPosition -> FwdPosition)
-> Location i FwdPosition Int
-> Location i FwdPosition Int
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (\FwdPosition
p -> if FwdPosition
pFwdPosition -> Getting Strand FwdPosition Strand -> Strand
forall s a. s -> Getting a s a -> a
^.Getting Strand FwdPosition Strand
Lens' FwdPosition Strand
fwdStrand Strand -> Strand -> Bool
forall a. Eq a => a -> a -> Bool
== Strand
MinusStrand then FwdPosition
p FwdPosition -> (FwdPosition -> FwdPosition) -> FwdPosition
forall a b. a -> (a -> b) -> b
& (Index 0 -> Identity (Index 0))
-> FwdPosition -> Identity FwdPosition
Lens' FwdPosition (Index 0)
fwdStart ((Index 0 -> Identity (Index 0))
 -> FwdPosition -> Identity FwdPosition)
-> (Index 0 -> Index 0) -> FwdPosition -> FwdPosition
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Index 0 -> Int -> Index 0
forall (t :: Nat). KnownNat t => Index t -> Int -> Index t
-. Int
k) else FwdPosition
p)
  {-# Inline locSplitAt #-}
  locSplitAt :: Int
-> Location i FwdPosition Int
-> (Location i FwdPosition Int, Location i FwdPosition Int)
locSplitAt Int
k Location i FwdPosition Int
loc =
    let h' :: Int
h' = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> (Int -> Int) -> Int -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int -> Int
forall a. Ord a => a -> a -> a
min Int
k (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Location i FwdPosition Int -> Int
forall posTy seqTy k (i :: k).
ModifyLocation posTy seqTy =>
Location i posTy seqTy -> Int
locLength Location i FwdPosition Int
loc
        t' :: Int
t' = Location i FwdPosition Int -> Int
forall posTy seqTy k (i :: k).
ModifyLocation posTy seqTy =>
Location i posTy seqTy -> Int
locLength Location i FwdPosition Int
loc Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
h'
        h :: Location i FwdPosition Int
h = Location i FwdPosition Int
loc Location i FwdPosition Int
-> (Location i FwdPosition Int -> Location i FwdPosition Int)
-> Location i FwdPosition Int
forall a b. a -> (a -> b) -> b
& (Int -> Identity Int)
-> Location i FwdPosition Int
-> Identity (Location i FwdPosition Int)
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence ((Int -> Identity Int)
 -> Location i FwdPosition Int
 -> Identity (Location i FwdPosition Int))
-> Int -> Location i FwdPosition Int -> Location i FwdPosition Int
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Int
h' Location i FwdPosition Int
-> (Location i FwdPosition Int -> Location i FwdPosition Int)
-> Location i FwdPosition Int
forall a b. a -> (a -> b) -> b
& (FwdPosition -> Identity FwdPosition)
-> Location i FwdPosition Int
-> Identity (Location i FwdPosition Int)
forall k (ident :: k) posTy seqTy posTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  posTy
  posTy
locPosition ((FwdPosition -> Identity FwdPosition)
 -> Location i FwdPosition Int
 -> Identity (Location i FwdPosition Int))
-> (FwdPosition -> FwdPosition)
-> Location i FwdPosition Int
-> Location i FwdPosition Int
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (\FwdPosition
p -> if FwdPosition
pFwdPosition -> Getting Strand FwdPosition Strand -> Strand
forall s a. s -> Getting a s a -> a
^.Getting Strand FwdPosition Strand
Lens' FwdPosition Strand
fwdStrand Strand -> Strand -> Bool
forall a. Eq a => a -> a -> Bool
== Strand
MinusStrand then FwdPosition
p FwdPosition -> (FwdPosition -> FwdPosition) -> FwdPosition
forall a b. a -> (a -> b) -> b
& (Index 0 -> Identity (Index 0))
-> FwdPosition -> Identity FwdPosition
Lens' FwdPosition (Index 0)
fwdStart ((Index 0 -> Identity (Index 0))
 -> FwdPosition -> Identity FwdPosition)
-> (Index 0 -> Index 0) -> FwdPosition -> FwdPosition
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~(Index 0 -> Int -> Index 0
forall (t :: Nat). KnownNat t => Index t -> Int -> Index t
+. Int
t') else FwdPosition
p)
        t :: Location i FwdPosition Int
t = Location i FwdPosition Int
loc Location i FwdPosition Int
-> (Location i FwdPosition Int -> Location i FwdPosition Int)
-> Location i FwdPosition Int
forall a b. a -> (a -> b) -> b
& (Int -> Identity Int)
-> Location i FwdPosition Int
-> Identity (Location i FwdPosition Int)
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence ((Int -> Identity Int)
 -> Location i FwdPosition Int
 -> Identity (Location i FwdPosition Int))
-> Int -> Location i FwdPosition Int -> Location i FwdPosition Int
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Int
t' Location i FwdPosition Int
-> (Location i FwdPosition Int -> Location i FwdPosition Int)
-> Location i FwdPosition Int
forall a b. a -> (a -> b) -> b
& (FwdPosition -> Identity FwdPosition)
-> Location i FwdPosition Int
-> Identity (Location i FwdPosition Int)
forall k (ident :: k) posTy seqTy posTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  posTy
  posTy
locPosition ((FwdPosition -> Identity FwdPosition)
 -> Location i FwdPosition Int
 -> Identity (Location i FwdPosition Int))
-> (FwdPosition -> FwdPosition)
-> Location i FwdPosition Int
-> Location i FwdPosition Int
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (\FwdPosition
p -> if FwdPosition
pFwdPosition -> Getting Strand FwdPosition Strand -> Strand
forall s a. s -> Getting a s a -> a
^.Getting Strand FwdPosition Strand
Lens' FwdPosition Strand
fwdStrand Strand -> Strand -> Bool
forall a. Eq a => a -> a -> Bool
== Strand
PlusStrand then FwdPosition
p FwdPosition -> (FwdPosition -> FwdPosition) -> FwdPosition
forall a b. a -> (a -> b) -> b
& (Index 0 -> Identity (Index 0))
-> FwdPosition -> Identity FwdPosition
Lens' FwdPosition (Index 0)
fwdStart ((Index 0 -> Identity (Index 0))
 -> FwdPosition -> Identity FwdPosition)
-> (Index 0 -> Index 0) -> FwdPosition -> FwdPosition
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Index 0 -> Int -> Index 0
forall (t :: Nat). KnownNat t => Index t -> Int -> Index t
+. Int
h') else FwdPosition
p)
    in  (Location i FwdPosition Int
h,Location i FwdPosition Int
t)
  {-# Inline locLength #-}
  locLength :: Location i FwdPosition Int -> Int
locLength = Getting Int (Location i FwdPosition Int) Int
-> Location i FwdPosition Int -> Int
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting Int (Location i FwdPosition Int) Int
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence

instance Reversing (Location i FwdPosition (BioSequence w)) where
  {-# Inline reversing #-}
  reversing :: Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
reversing = ASetter
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  ByteString
  ByteString
-> (ByteString -> ByteString)
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ((BioSequence w -> Identity (BioSequence w))
-> Location i FwdPosition (BioSequence w)
-> Identity (Location i FwdPosition (BioSequence w))
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence((BioSequence w -> Identity (BioSequence w))
 -> Location i FwdPosition (BioSequence w)
 -> Identity (Location i FwdPosition (BioSequence w)))
-> ((ByteString -> Identity ByteString)
    -> BioSequence w -> Identity (BioSequence w))
-> ASetter
     (Location i FwdPosition (BioSequence w))
     (Location i FwdPosition (BioSequence w))
     ByteString
     ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ByteString -> Identity ByteString)
-> BioSequence w -> Identity (BioSequence w)
forall k1 (which1 :: k1) k (which :: k).
Iso (BioSequence which1) (BioSequence which) ByteString ByteString
_BioSequence) ByteString -> ByteString
BS.reverse (Location i FwdPosition (BioSequence w)
 -> Location i FwdPosition (BioSequence w))
-> (Location i FwdPosition (BioSequence w)
    -> Location i FwdPosition (BioSequence w))
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ASetter
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  FwdPosition
  FwdPosition
-> (FwdPosition -> FwdPosition)
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over (ASetter
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  FwdPosition
  FwdPosition
forall k (ident :: k) posTy seqTy posTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  posTy
  posTy
locPosition) FwdPosition -> FwdPosition
forall t. Reversing t => t -> t
reversing

instance Complement (BioSequence w) => Complement (Location i FwdPosition (BioSequence w)) where
  {-# Inline complement #-}
  complement :: p (Location i FwdPosition (BioSequence w))
  (f (Location i FwdPosition (BioSequence w)))
-> p (Location i FwdPosition (BioSequence w))
     (f (Location i FwdPosition (BioSequence w)))
complement = (Location i FwdPosition (BioSequence w)
 -> Location i FwdPosition (BioSequence w))
-> (Location i FwdPosition (BioSequence w)
    -> Location i FwdPosition (BioSequence w))
-> Iso'
     (Location i FwdPosition (BioSequence w))
     (Location i FwdPosition (BioSequence w))
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall k (ident :: k) posTy.
Location ident posTy (BioSequence w)
-> Location ident posTy (BioSequence w)
f Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall k (ident :: k) posTy.
Location ident posTy (BioSequence w)
-> Location ident posTy (BioSequence w)
f
    where f :: Location ident posTy (BioSequence w)
-> Location ident posTy (BioSequence w)
f = ASetter
  (Location ident posTy (BioSequence w))
  (Location ident posTy (BioSequence w))
  (BioSequence w)
  (BioSequence w)
-> (BioSequence w -> BioSequence w)
-> Location ident posTy (BioSequence w)
-> Location ident posTy (BioSequence w)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter
  (Location ident posTy (BioSequence w))
  (Location ident posTy (BioSequence w))
  (BioSequence w)
  (BioSequence w)
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence (Getting (BioSequence w) (BioSequence w) (BioSequence w)
-> BioSequence w -> BioSequence w
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (BioSequence w) (BioSequence w) (BioSequence w)
forall f. Complement f => Iso' f f
complement)

instance (Info (BioSequence w)) => Info (Location i FwdPosition (BioSequence w)) where
  info :: Location i FwdPosition (BioSequence w) -> String
info Location i FwdPosition (BioSequence w)
loc = String -> String -> String -> ShowS
forall r. PrintfType r => String -> r
printf String
"%s %s %s" (Location i FwdPosition (BioSequence w)
locLocation i FwdPosition (BioSequence w)
-> Getting
     (SequenceIdentifier i)
     (Location i FwdPosition (BioSequence w))
     (SequenceIdentifier i)
-> SequenceIdentifier i
forall s a. s -> Getting a s a -> a
^.Getting
  (SequenceIdentifier i)
  (Location i FwdPosition (BioSequence w))
  (SequenceIdentifier i)
forall k (ident :: k) posTy seqTy k (ident :: k).
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  (SequenceIdentifier ident)
  (SequenceIdentifier ident)
locIdentifierSequenceIdentifier i
-> Getting String (SequenceIdentifier i) String -> String
forall s a. s -> Getting a s a -> a
^.(SequenceIdentifier i -> String)
-> Getting String (SequenceIdentifier i) String
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to SequenceIdentifier i -> String
forall a. Show a => a -> String
show) (FwdPosition -> String
forall a. Show a => a -> String
show (FwdPosition -> String) -> FwdPosition -> String
forall a b. (a -> b) -> a -> b
$ Location i FwdPosition (BioSequence w)
locLocation i FwdPosition (BioSequence w)
-> Getting
     FwdPosition (Location i FwdPosition (BioSequence w)) FwdPosition
-> FwdPosition
forall s a. s -> Getting a s a -> a
^.Getting
  FwdPosition (Location i FwdPosition (BioSequence w)) FwdPosition
forall k (ident :: k) posTy seqTy posTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  posTy
  posTy
locPosition) (Location i FwdPosition (BioSequence w)
locLocation i FwdPosition (BioSequence w)
-> Getting String (Location i FwdPosition (BioSequence w)) String
-> String
forall s a. s -> Getting a s a -> a
^.(BioSequence w -> Const String (BioSequence w))
-> Location i FwdPosition (BioSequence w)
-> Const String (Location i FwdPosition (BioSequence w))
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence((BioSequence w -> Const String (BioSequence w))
 -> Location i FwdPosition (BioSequence w)
 -> Const String (Location i FwdPosition (BioSequence w)))
-> ((String -> Const String String)
    -> BioSequence w -> Const String (BioSequence w))
-> Getting String (Location i FwdPosition (BioSequence w)) String
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(BioSequence w -> String)
-> (String -> Const String String)
-> BioSequence w
-> Const String (BioSequence w)
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to BioSequence w -> String
forall c. Info c => c -> String
info)

-- | Will extract a substring for a given biosequence. It is allowed to hand in partially or not at
-- all overlapping locational information. This will yield empty resulting locations.
--
-- This will convert the @FwdPosition@ strand, which in turn allows dealing with reverse-complement
-- searches.
--
-- @
-- 0123456789
--    3.3
-- @

subLocation :: Location i FwdPosition (BioSequence w) -> (FwdPosition, Int) -> Location i FwdPosition (BioSequence w)
{-# Inline subLocation #-}
subLocation :: Location i FwdPosition (BioSequence w)
-> (FwdPosition, Int) -> Location i FwdPosition (BioSequence w)
subLocation Location i FwdPosition (BioSequence w)
s (FwdPosition
p',Int
l)
  | Strand
ssStrand -> Strand -> Bool
forall a. Eq a => a -> a -> Bool
==Strand
PlusStrand = Int
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall k posTy seqTy (i :: k).
ModifyLocation posTy seqTy =>
Int -> Location i posTy seqTy -> Location i posTy seqTy
locTake Int
l (Location i FwdPosition (BioSequence w)
 -> Location i FwdPosition (BioSequence w))
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall a b. (a -> b) -> a -> b
$ Int
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall k posTy seqTy (i :: k).
ModifyLocation posTy seqTy =>
Int -> Location i posTy seqTy -> Location i posTy seqTy
locDrop Int
d Location i FwdPosition (BioSequence w)
s
  | Strand
ssStrand -> Strand -> Bool
forall a. Eq a => a -> a -> Bool
==Strand
MinusStrand = Int
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall k posTy seqTy (i :: k).
ModifyLocation posTy seqTy =>
Int -> Location i posTy seqTy -> Location i posTy seqTy
locTakeEnd Int
l (Location i FwdPosition (BioSequence w)
 -> Location i FwdPosition (BioSequence w))
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall a b. (a -> b) -> a -> b
$ Int
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall k posTy seqTy (i :: k).
ModifyLocation posTy seqTy =>
Int -> Location i posTy seqTy -> Location i posTy seqTy
locDropEnd Int
d Location i FwdPosition (BioSequence w)
s
  where ss :: Strand
ss = Location i FwdPosition (BioSequence w)
sLocation i FwdPosition (BioSequence w)
-> Getting Strand (Location i FwdPosition (BioSequence w)) Strand
-> Strand
forall s a. s -> Getting a s a -> a
^.(FwdPosition -> Const Strand FwdPosition)
-> Location i FwdPosition (BioSequence w)
-> Const Strand (Location i FwdPosition (BioSequence w))
forall k (ident :: k) posTy seqTy posTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  posTy
  posTy
locPosition((FwdPosition -> Const Strand FwdPosition)
 -> Location i FwdPosition (BioSequence w)
 -> Const Strand (Location i FwdPosition (BioSequence w)))
-> Getting Strand FwdPosition Strand
-> Getting Strand (Location i FwdPosition (BioSequence w)) Strand
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Getting Strand FwdPosition Strand
Lens' FwdPosition Strand
fwdStrand
        p :: FwdPosition
p = if Strand
ss Strand -> Strand -> Bool
forall a. Eq a => a -> a -> Bool
== FwdPosition
p'FwdPosition -> Getting Strand FwdPosition Strand -> Strand
forall s a. s -> Getting a s a -> a
^.Getting Strand FwdPosition Strand
Lens' FwdPosition Strand
fwdStrand then FwdPosition
p' else FwdPosition -> FwdPosition
forall t. Reversing t => t -> t
reversing FwdPosition
p'
        d :: Int
d = Index 0 -> Index 0 -> Int
forall (t :: Nat). KnownNat t => Index t -> Index t -> Int
delta (Location i FwdPosition (BioSequence w)
sLocation i FwdPosition (BioSequence w)
-> Getting
     (Index 0) (Location i FwdPosition (BioSequence w)) (Index 0)
-> Index 0
forall s a. s -> Getting a s a -> a
^.(FwdPosition -> Const (Index 0) FwdPosition)
-> Location i FwdPosition (BioSequence w)
-> Const (Index 0) (Location i FwdPosition (BioSequence w))
forall k (ident :: k) posTy seqTy posTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  posTy
  posTy
locPosition((FwdPosition -> Const (Index 0) FwdPosition)
 -> Location i FwdPosition (BioSequence w)
 -> Const (Index 0) (Location i FwdPosition (BioSequence w)))
-> ((Index 0 -> Const (Index 0) (Index 0))
    -> FwdPosition -> Const (Index 0) FwdPosition)
-> Getting
     (Index 0) (Location i FwdPosition (BioSequence w)) (Index 0)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Index 0 -> Const (Index 0) (Index 0))
-> FwdPosition -> Const (Index 0) FwdPosition
Lens' FwdPosition (Index 0)
fwdStart) (FwdPosition
pFwdPosition
-> ((Index 0 -> Const (Index 0) (Index 0))
    -> FwdPosition -> Const (Index 0) FwdPosition)
-> Index 0
forall s a. s -> Getting a s a -> a
^.(Index 0 -> Const (Index 0) (Index 0))
-> FwdPosition -> Const (Index 0) FwdPosition
Lens' FwdPosition (Index 0)
fwdStart)

data PIS i p s = PIS
  { PIS i p s -> Maybe (Location i p s)
_pisPrefix  :: Maybe (Location i p s)
  , PIS i p s -> Location i p s
_pisInfix   :: !(Location i p s)
  , PIS i p s -> Maybe (Location i p s)
_pisSuffix  :: Maybe (Location i p s)
  }
  deriving stock (Int -> PIS i p s -> ShowS
[PIS i p s] -> ShowS
PIS i p s -> String
(Int -> PIS i p s -> ShowS)
-> (PIS i p s -> String)
-> ([PIS i p s] -> ShowS)
-> Show (PIS i p s)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (i :: k) p s.
(Show p, Show s) =>
Int -> PIS i p s -> ShowS
forall k (i :: k) p s. (Show p, Show s) => [PIS i p s] -> ShowS
forall k (i :: k) p s. (Show p, Show s) => PIS i p s -> String
showList :: [PIS i p s] -> ShowS
$cshowList :: forall k (i :: k) p s. (Show p, Show s) => [PIS i p s] -> ShowS
show :: PIS i p s -> String
$cshow :: forall k (i :: k) p s. (Show p, Show s) => PIS i p s -> String
showsPrec :: Int -> PIS i p s -> ShowS
$cshowsPrec :: forall k (i :: k) p s.
(Show p, Show s) =>
Int -> PIS i p s -> ShowS
Show, Typeable (PIS i p s)
DataType
Constr
Typeable (PIS i p s)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> PIS i p s -> c (PIS i p s))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (PIS i p s))
-> (PIS i p s -> Constr)
-> (PIS i p s -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (PIS i p s)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (PIS i p s)))
-> ((forall b. Data b => b -> b) -> PIS i p s -> PIS i p s)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> PIS i p s -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> PIS i p s -> r)
-> (forall u. (forall d. Data d => d -> u) -> PIS i p s -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> PIS i p s -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> PIS i p s -> m (PIS i p s))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PIS i p s -> m (PIS i p s))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> PIS i p s -> m (PIS i p s))
-> Data (PIS i p s)
PIS i p s -> DataType
PIS i p s -> Constr
(forall b. Data b => b -> b) -> PIS i p s -> PIS i p s
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PIS i p s -> c (PIS i p s)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PIS i p s)
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> PIS i p s -> u
forall u. (forall d. Data d => d -> u) -> PIS i p s -> [u]
forall k (i :: k) p s.
(Typeable i, Typeable k, Data p, Data s) =>
Typeable (PIS i p s)
forall k (i :: k) p s.
(Typeable i, Typeable k, Data p, Data s) =>
PIS i p s -> DataType
forall k (i :: k) p s.
(Typeable i, Typeable k, Data p, Data s) =>
PIS i p s -> Constr
forall k (i :: k) p s.
(Typeable i, Typeable k, Data p, Data s) =>
(forall b. Data b => b -> b) -> PIS i p s -> PIS i p s
forall k (i :: k) p s u.
(Typeable i, Typeable k, Data p, Data s) =>
Int -> (forall d. Data d => d -> u) -> PIS i p s -> u
forall k (i :: k) p s u.
(Typeable i, Typeable k, Data p, Data s) =>
(forall d. Data d => d -> u) -> PIS i p s -> [u]
forall k (i :: k) p s r r'.
(Typeable i, Typeable k, Data p, Data s) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PIS i p s -> r
forall k (i :: k) p s r r'.
(Typeable i, Typeable k, Data p, Data s) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PIS i p s -> r
forall k (i :: k) p s (m :: * -> *).
(Typeable i, Typeable k, Data p, Data s, Monad m) =>
(forall d. Data d => d -> m d) -> PIS i p s -> m (PIS i p s)
forall k (i :: k) p s (m :: * -> *).
(Typeable i, Typeable k, Data p, Data s, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PIS i p s -> m (PIS i p s)
forall k (i :: k) p s (c :: * -> *).
(Typeable i, Typeable k, Data p, Data s) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PIS i p s)
forall k (i :: k) p s (c :: * -> *).
(Typeable i, Typeable k, Data p, Data s) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PIS i p s -> c (PIS i p s)
forall k (i :: k) p s (t :: * -> *) (c :: * -> *).
(Typeable i, Typeable k, Data p, Data s, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PIS i p s))
forall k (i :: k) p s (t :: * -> * -> *) (c :: * -> *).
(Typeable i, Typeable k, Data p, Data s, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PIS i p s))
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PIS i p s -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PIS i p s -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> PIS i p s -> m (PIS i p s)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> PIS i p s -> m (PIS i p s)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PIS i p s)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PIS i p s -> c (PIS i p s)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (PIS i p s))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PIS i p s))
$cPIS :: Constr
$tPIS :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> PIS i p s -> m (PIS i p s)
$cgmapMo :: forall k (i :: k) p s (m :: * -> *).
(Typeable i, Typeable k, Data p, Data s, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PIS i p s -> m (PIS i p s)
gmapMp :: (forall d. Data d => d -> m d) -> PIS i p s -> m (PIS i p s)
$cgmapMp :: forall k (i :: k) p s (m :: * -> *).
(Typeable i, Typeable k, Data p, Data s, MonadPlus m) =>
(forall d. Data d => d -> m d) -> PIS i p s -> m (PIS i p s)
gmapM :: (forall d. Data d => d -> m d) -> PIS i p s -> m (PIS i p s)
$cgmapM :: forall k (i :: k) p s (m :: * -> *).
(Typeable i, Typeable k, Data p, Data s, Monad m) =>
(forall d. Data d => d -> m d) -> PIS i p s -> m (PIS i p s)
gmapQi :: Int -> (forall d. Data d => d -> u) -> PIS i p s -> u
$cgmapQi :: forall k (i :: k) p s u.
(Typeable i, Typeable k, Data p, Data s) =>
Int -> (forall d. Data d => d -> u) -> PIS i p s -> u
gmapQ :: (forall d. Data d => d -> u) -> PIS i p s -> [u]
$cgmapQ :: forall k (i :: k) p s u.
(Typeable i, Typeable k, Data p, Data s) =>
(forall d. Data d => d -> u) -> PIS i p s -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PIS i p s -> r
$cgmapQr :: forall k (i :: k) p s r r'.
(Typeable i, Typeable k, Data p, Data s) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> PIS i p s -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PIS i p s -> r
$cgmapQl :: forall k (i :: k) p s r r'.
(Typeable i, Typeable k, Data p, Data s) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> PIS i p s -> r
gmapT :: (forall b. Data b => b -> b) -> PIS i p s -> PIS i p s
$cgmapT :: forall k (i :: k) p s.
(Typeable i, Typeable k, Data p, Data s) =>
(forall b. Data b => b -> b) -> PIS i p s -> PIS i p s
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PIS i p s))
$cdataCast2 :: forall k (i :: k) p s (t :: * -> * -> *) (c :: * -> *).
(Typeable i, Typeable k, Data p, Data s, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (PIS i p s))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (PIS i p s))
$cdataCast1 :: forall k (i :: k) p s (t :: * -> *) (c :: * -> *).
(Typeable i, Typeable k, Data p, Data s, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (PIS i p s))
dataTypeOf :: PIS i p s -> DataType
$cdataTypeOf :: forall k (i :: k) p s.
(Typeable i, Typeable k, Data p, Data s) =>
PIS i p s -> DataType
toConstr :: PIS i p s -> Constr
$ctoConstr :: forall k (i :: k) p s.
(Typeable i, Typeable k, Data p, Data s) =>
PIS i p s -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PIS i p s)
$cgunfold :: forall k (i :: k) p s (c :: * -> *).
(Typeable i, Typeable k, Data p, Data s) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (PIS i p s)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PIS i p s -> c (PIS i p s)
$cgfoldl :: forall k (i :: k) p s (c :: * -> *).
(Typeable i, Typeable k, Data p, Data s) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> PIS i p s -> c (PIS i p s)
$cp1Data :: forall k (i :: k) p s.
(Typeable i, Typeable k, Data p, Data s) =>
Typeable (PIS i p s)
Data)
makeLenses ''PIS

pis :: Location i p s -> PIS i p s
pis Location i p s
ifx = Maybe (Location i p s)
-> Location i p s -> Maybe (Location i p s) -> PIS i p s
forall k (i :: k) p s.
Maybe (Location i p s)
-> Location i p s -> Maybe (Location i p s) -> PIS i p s
PIS Maybe (Location i p s)
forall a. Maybe a
Nothing Location i p s
ifx Maybe (Location i p s)
forall a. Maybe a
Nothing

retagPis :: PIS i p s -> PIS j p s
retagPis :: PIS i p s -> PIS j p s
retagPis (PIS Maybe (Location i p s)
p Location i p s
i Maybe (Location i p s)
s) = Maybe (Location j p s)
-> Location j p s -> Maybe (Location j p s) -> PIS j p s
forall k (i :: k) p s.
Maybe (Location i p s)
-> Location i p s -> Maybe (Location i p s) -> PIS i p s
PIS ((Location i p s -> Location j p s)
-> Maybe (Location i p s) -> Maybe (Location j p s)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Location i p s -> Location j p s
forall k k (i :: k) posTy seqTy (j :: k).
Location i posTy seqTy -> Location j posTy seqTy
retagLocation Maybe (Location i p s)
p) (Location i p s -> Location j p s
forall k k (i :: k) posTy seqTy (j :: k).
Location i posTy seqTy -> Location j posTy seqTy
retagLocation Location i p s
i) ((Location i p s -> Location j p s)
-> Maybe (Location i p s) -> Maybe (Location j p s)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Location i p s -> Location j p s
forall k k (i :: k) posTy seqTy (j :: k).
Location i posTy seqTy -> Location j posTy seqTy
retagLocation Maybe (Location i p s)
s)

-- | Given a @PIS@, this will return the @substring@ indicated by the location in the 2nd argument.
-- Allows for easy substring extraction, and retains the system of prefix/infix/suffix.
--
-- It is allowed to hand locations that only partially (or not at all) correspond to the @PIS@, but
-- then the resulting @PIS@ will be empty!

subPisLocation :: PIS i FwdPosition (BioSequence w) -> (FwdPosition, Int) -> PIS i FwdPosition (BioSequence w)
{-# Inline subPisLocation #-}
subPisLocation :: PIS i FwdPosition (BioSequence w)
-> (FwdPosition, Int) -> PIS i FwdPosition (BioSequence w)
subPisLocation PIS i FwdPosition (BioSequence w)
pis (FwdPosition, Int)
loc =
  let f :: Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
f Location i FwdPosition (BioSequence w)
z = Location i FwdPosition (BioSequence w)
-> (FwdPosition, Int) -> Location i FwdPosition (BioSequence w)
forall k k (i :: k) (w :: k).
Location i FwdPosition (BioSequence w)
-> (FwdPosition, Int) -> Location i FwdPosition (BioSequence w)
subLocation Location i FwdPosition (BioSequence w)
z (FwdPosition, Int)
loc
  in  ASetter
  (PIS i FwdPosition (BioSequence w))
  (PIS i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
-> (Location i FwdPosition (BioSequence w)
    -> Location i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ((Maybe (Location i FwdPosition (BioSequence w))
 -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
-> PIS i FwdPosition (BioSequence w)
-> Identity (PIS i FwdPosition (BioSequence w))
forall k (i :: k) p s. Lens' (PIS i p s) (Maybe (Location i p s))
pisPrefix((Maybe (Location i FwdPosition (BioSequence w))
  -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
 -> PIS i FwdPosition (BioSequence w)
 -> Identity (PIS i FwdPosition (BioSequence w)))
-> ((Location i FwdPosition (BioSequence w)
     -> Identity (Location i FwdPosition (BioSequence w)))
    -> Maybe (Location i FwdPosition (BioSequence w))
    -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
-> ASetter
     (PIS i FwdPosition (BioSequence w))
     (PIS i FwdPosition (BioSequence w))
     (Location i FwdPosition (BioSequence w))
     (Location i FwdPosition (BioSequence w))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Location i FwdPosition (BioSequence w)
 -> Identity (Location i FwdPosition (BioSequence w)))
-> Maybe (Location i FwdPosition (BioSequence w))
-> Identity (Maybe (Location i FwdPosition (BioSequence w)))
forall a b. Prism (Maybe a) (Maybe b) a b
_Just) Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
f (PIS i FwdPosition (BioSequence w)
 -> PIS i FwdPosition (BioSequence w))
-> (PIS i FwdPosition (BioSequence w)
    -> PIS i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ASetter
  (PIS i FwdPosition (BioSequence w))
  (PIS i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
-> (Location i FwdPosition (BioSequence w)
    -> Location i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter
  (PIS i FwdPosition (BioSequence w))
  (PIS i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
forall k (i :: k) p s. Lens' (PIS i p s) (Location i p s)
pisInfix Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
f (PIS i FwdPosition (BioSequence w)
 -> PIS i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall a b. (a -> b) -> a -> b
$ ASetter
  (PIS i FwdPosition (BioSequence w))
  (PIS i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
-> (Location i FwdPosition (BioSequence w)
    -> Location i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ((Maybe (Location i FwdPosition (BioSequence w))
 -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
-> PIS i FwdPosition (BioSequence w)
-> Identity (PIS i FwdPosition (BioSequence w))
forall k (i :: k) p s. Lens' (PIS i p s) (Maybe (Location i p s))
pisSuffix((Maybe (Location i FwdPosition (BioSequence w))
  -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
 -> PIS i FwdPosition (BioSequence w)
 -> Identity (PIS i FwdPosition (BioSequence w)))
-> ((Location i FwdPosition (BioSequence w)
     -> Identity (Location i FwdPosition (BioSequence w)))
    -> Maybe (Location i FwdPosition (BioSequence w))
    -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
-> ASetter
     (PIS i FwdPosition (BioSequence w))
     (PIS i FwdPosition (BioSequence w))
     (Location i FwdPosition (BioSequence w))
     (Location i FwdPosition (BioSequence w))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Location i FwdPosition (BioSequence w)
 -> Identity (Location i FwdPosition (BioSequence w)))
-> Maybe (Location i FwdPosition (BioSequence w))
-> Identity (Maybe (Location i FwdPosition (BioSequence w)))
forall a b. Prism (Maybe a) (Maybe b) a b
_Just) Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
f PIS i FwdPosition (BioSequence w)
pis

instance (Reversing (Location i FwdPosition (BioSequence w))) => Reversing (PIS i FwdPosition (BioSequence w)) where
  {-# Inline reversing #-}
  reversing :: PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
reversing PIS i FwdPosition (BioSequence w)
pis
    = ASetter
  (PIS i FwdPosition (BioSequence w))
  (PIS i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
-> (Location i FwdPosition (BioSequence w)
    -> Location i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ((Maybe (Location i FwdPosition (BioSequence w))
 -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
-> PIS i FwdPosition (BioSequence w)
-> Identity (PIS i FwdPosition (BioSequence w))
forall k (i :: k) p s. Lens' (PIS i p s) (Maybe (Location i p s))
pisPrefix((Maybe (Location i FwdPosition (BioSequence w))
  -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
 -> PIS i FwdPosition (BioSequence w)
 -> Identity (PIS i FwdPosition (BioSequence w)))
-> ((Location i FwdPosition (BioSequence w)
     -> Identity (Location i FwdPosition (BioSequence w)))
    -> Maybe (Location i FwdPosition (BioSequence w))
    -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
-> ASetter
     (PIS i FwdPosition (BioSequence w))
     (PIS i FwdPosition (BioSequence w))
     (Location i FwdPosition (BioSequence w))
     (Location i FwdPosition (BioSequence w))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Location i FwdPosition (BioSequence w)
 -> Identity (Location i FwdPosition (BioSequence w)))
-> Maybe (Location i FwdPosition (BioSequence w))
-> Identity (Maybe (Location i FwdPosition (BioSequence w)))
forall a b. Prism (Maybe a) (Maybe b) a b
_Just) Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall t. Reversing t => t -> t
reversing (PIS i FwdPosition (BioSequence w)
 -> PIS i FwdPosition (BioSequence w))
-> (PIS i FwdPosition (BioSequence w)
    -> PIS i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ASetter
  (PIS i FwdPosition (BioSequence w))
  (PIS i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
-> (Location i FwdPosition (BioSequence w)
    -> Location i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter
  (PIS i FwdPosition (BioSequence w))
  (PIS i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
forall k (i :: k) p s. Lens' (PIS i p s) (Location i p s)
pisInfix Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall t. Reversing t => t -> t
reversing (PIS i FwdPosition (BioSequence w)
 -> PIS i FwdPosition (BioSequence w))
-> (PIS i FwdPosition (BioSequence w)
    -> PIS i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ASetter
  (PIS i FwdPosition (BioSequence w))
  (PIS i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
-> (Location i FwdPosition (BioSequence w)
    -> Location i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ((Maybe (Location i FwdPosition (BioSequence w))
 -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
-> PIS i FwdPosition (BioSequence w)
-> Identity (PIS i FwdPosition (BioSequence w))
forall k (i :: k) p s. Lens' (PIS i p s) (Maybe (Location i p s))
pisSuffix((Maybe (Location i FwdPosition (BioSequence w))
  -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
 -> PIS i FwdPosition (BioSequence w)
 -> Identity (PIS i FwdPosition (BioSequence w)))
-> ((Location i FwdPosition (BioSequence w)
     -> Identity (Location i FwdPosition (BioSequence w)))
    -> Maybe (Location i FwdPosition (BioSequence w))
    -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
-> ASetter
     (PIS i FwdPosition (BioSequence w))
     (PIS i FwdPosition (BioSequence w))
     (Location i FwdPosition (BioSequence w))
     (Location i FwdPosition (BioSequence w))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Location i FwdPosition (BioSequence w)
 -> Identity (Location i FwdPosition (BioSequence w)))
-> Maybe (Location i FwdPosition (BioSequence w))
-> Identity (Maybe (Location i FwdPosition (BioSequence w)))
forall a b. Prism (Maybe a) (Maybe b) a b
_Just) Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall t. Reversing t => t -> t
reversing
    (PIS i FwdPosition (BioSequence w)
 -> PIS i FwdPosition (BioSequence w))
-> (PIS i FwdPosition (BioSequence w)
    -> PIS i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Maybe (Location i FwdPosition (BioSequence w))
  -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
 -> PIS i FwdPosition (BioSequence w)
 -> Identity (PIS i FwdPosition (BioSequence w)))
-> Maybe (Location i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> b -> s -> t
set (Maybe (Location i FwdPosition (BioSequence w))
 -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
-> PIS i FwdPosition (BioSequence w)
-> Identity (PIS i FwdPosition (BioSequence w))
forall k (i :: k) p s. Lens' (PIS i p s) (Maybe (Location i p s))
pisPrefix (PIS i FwdPosition (BioSequence w)
pisPIS i FwdPosition (BioSequence w)
-> Getting
     (Maybe (Location i FwdPosition (BioSequence w)))
     (PIS i FwdPosition (BioSequence w))
     (Maybe (Location i FwdPosition (BioSequence w)))
-> Maybe (Location i FwdPosition (BioSequence w))
forall s a. s -> Getting a s a -> a
^.Getting
  (Maybe (Location i FwdPosition (BioSequence w)))
  (PIS i FwdPosition (BioSequence w))
  (Maybe (Location i FwdPosition (BioSequence w)))
forall k (i :: k) p s. Lens' (PIS i p s) (Maybe (Location i p s))
pisSuffix) (PIS i FwdPosition (BioSequence w)
 -> PIS i FwdPosition (BioSequence w))
-> (PIS i FwdPosition (BioSequence w)
    -> PIS i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Maybe (Location i FwdPosition (BioSequence w))
  -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
 -> PIS i FwdPosition (BioSequence w)
 -> Identity (PIS i FwdPosition (BioSequence w)))
-> Maybe (Location i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> b -> s -> t
set (Maybe (Location i FwdPosition (BioSequence w))
 -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
-> PIS i FwdPosition (BioSequence w)
-> Identity (PIS i FwdPosition (BioSequence w))
forall k (i :: k) p s. Lens' (PIS i p s) (Maybe (Location i p s))
pisSuffix (PIS i FwdPosition (BioSequence w)
pisPIS i FwdPosition (BioSequence w)
-> Getting
     (Maybe (Location i FwdPosition (BioSequence w)))
     (PIS i FwdPosition (BioSequence w))
     (Maybe (Location i FwdPosition (BioSequence w)))
-> Maybe (Location i FwdPosition (BioSequence w))
forall s a. s -> Getting a s a -> a
^.Getting
  (Maybe (Location i FwdPosition (BioSequence w)))
  (PIS i FwdPosition (BioSequence w))
  (Maybe (Location i FwdPosition (BioSequence w)))
forall k (i :: k) p s. Lens' (PIS i p s) (Maybe (Location i p s))
pisPrefix) (PIS i FwdPosition (BioSequence w)
 -> PIS i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall a b. (a -> b) -> a -> b
$ PIS i FwdPosition (BioSequence w)
pis

instance Complement (BioSequence w) => Complement (PIS i FwdPosition (BioSequence w)) where
  {-# Inline complement #-}
  complement :: p (PIS i FwdPosition (BioSequence w))
  (f (PIS i FwdPosition (BioSequence w)))
-> p (PIS i FwdPosition (BioSequence w))
     (f (PIS i FwdPosition (BioSequence w)))
complement =
    let f :: PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
f = ASetter
  (PIS i FwdPosition (BioSequence w))
  (PIS i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
-> (Location i FwdPosition (BioSequence w)
    -> Location i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter
  (PIS i FwdPosition (BioSequence w))
  (PIS i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
forall k (i :: k) p s. Lens' (PIS i p s) (Location i p s)
pisInfix (Getting
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
forall f. Complement f => Iso' f f
complement) (PIS i FwdPosition (BioSequence w)
 -> PIS i FwdPosition (BioSequence w))
-> (PIS i FwdPosition (BioSequence w)
    -> PIS i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ASetter
  (PIS i FwdPosition (BioSequence w))
  (PIS i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
-> (Location i FwdPosition (BioSequence w)
    -> Location i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ((Maybe (Location i FwdPosition (BioSequence w))
 -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
-> PIS i FwdPosition (BioSequence w)
-> Identity (PIS i FwdPosition (BioSequence w))
forall k (i :: k) p s. Lens' (PIS i p s) (Maybe (Location i p s))
pisPrefix((Maybe (Location i FwdPosition (BioSequence w))
  -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
 -> PIS i FwdPosition (BioSequence w)
 -> Identity (PIS i FwdPosition (BioSequence w)))
-> ((Location i FwdPosition (BioSequence w)
     -> Identity (Location i FwdPosition (BioSequence w)))
    -> Maybe (Location i FwdPosition (BioSequence w))
    -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
-> ASetter
     (PIS i FwdPosition (BioSequence w))
     (PIS i FwdPosition (BioSequence w))
     (Location i FwdPosition (BioSequence w))
     (Location i FwdPosition (BioSequence w))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Location i FwdPosition (BioSequence w)
 -> Identity (Location i FwdPosition (BioSequence w)))
-> Maybe (Location i FwdPosition (BioSequence w))
-> Identity (Maybe (Location i FwdPosition (BioSequence w)))
forall a b. Prism (Maybe a) (Maybe b) a b
_Just) (Getting
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
forall f. Complement f => Iso' f f
complement) (PIS i FwdPosition (BioSequence w)
 -> PIS i FwdPosition (BioSequence w))
-> (PIS i FwdPosition (BioSequence w)
    -> PIS i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ASetter
  (PIS i FwdPosition (BioSequence w))
  (PIS i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
-> (Location i FwdPosition (BioSequence w)
    -> Location i FwdPosition (BioSequence w))
-> PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ((Maybe (Location i FwdPosition (BioSequence w))
 -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
-> PIS i FwdPosition (BioSequence w)
-> Identity (PIS i FwdPosition (BioSequence w))
forall k (i :: k) p s. Lens' (PIS i p s) (Maybe (Location i p s))
pisSuffix((Maybe (Location i FwdPosition (BioSequence w))
  -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
 -> PIS i FwdPosition (BioSequence w)
 -> Identity (PIS i FwdPosition (BioSequence w)))
-> ((Location i FwdPosition (BioSequence w)
     -> Identity (Location i FwdPosition (BioSequence w)))
    -> Maybe (Location i FwdPosition (BioSequence w))
    -> Identity (Maybe (Location i FwdPosition (BioSequence w))))
-> ASetter
     (PIS i FwdPosition (BioSequence w))
     (PIS i FwdPosition (BioSequence w))
     (Location i FwdPosition (BioSequence w))
     (Location i FwdPosition (BioSequence w))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Location i FwdPosition (BioSequence w)
 -> Identity (Location i FwdPosition (BioSequence w)))
-> Maybe (Location i FwdPosition (BioSequence w))
-> Identity (Maybe (Location i FwdPosition (BioSequence w)))
forall a b. Prism (Maybe a) (Maybe b) a b
_Just) (Getting
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition (BioSequence w)
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition (BioSequence w))
forall f. Complement f => Iso' f f
complement)
    in  (PIS i FwdPosition (BioSequence w)
 -> PIS i FwdPosition (BioSequence w))
-> (PIS i FwdPosition (BioSequence w)
    -> PIS i FwdPosition (BioSequence w))
-> Iso'
     (PIS i FwdPosition (BioSequence w))
     (PIS i FwdPosition (BioSequence w))
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
f PIS i FwdPosition (BioSequence w)
-> PIS i FwdPosition (BioSequence w)
f

pisSequence :: Lens (PIS i p (BioSequence s)) (PIS i p (BioSequence t)) (BioSequence s) (BioSequence t)
{-# Inline pisSequence #-}
pisSequence :: (BioSequence s -> f (BioSequence t))
-> PIS i p (BioSequence s) -> f (PIS i p (BioSequence t))
pisSequence = (PIS i p (BioSequence s) -> BioSequence s)
-> (PIS i p (BioSequence s)
    -> BioSequence t -> PIS i p (BioSequence t))
-> Lens
     (PIS i p (BioSequence s))
     (PIS i p (BioSequence t))
     (BioSequence s)
     (BioSequence t)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens PIS i p (BioSequence s) -> BioSequence s
f PIS i p (BioSequence s) -> BioSequence t -> PIS i p (BioSequence t)
t where
  v :: Location i p (BioSequence s) -> ByteString
v = Getting ByteString (Location i p (BioSequence s)) ByteString
-> Location i p (BioSequence s) -> ByteString
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view ((BioSequence s -> Const ByteString (BioSequence s))
-> Location i p (BioSequence s)
-> Const ByteString (Location i p (BioSequence s))
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence((BioSequence s -> Const ByteString (BioSequence s))
 -> Location i p (BioSequence s)
 -> Const ByteString (Location i p (BioSequence s)))
-> ((ByteString -> Const ByteString ByteString)
    -> BioSequence s -> Const ByteString (BioSequence s))
-> Getting ByteString (Location i p (BioSequence s)) ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ByteString -> Const ByteString ByteString)
-> BioSequence s -> Const ByteString (BioSequence s)
forall k1 (which1 :: k1) k (which :: k).
Iso (BioSequence which1) (BioSequence which) ByteString ByteString
bioSequence)
  f :: PIS i p (BioSequence s) -> BioSequence s
f (PIS Maybe (Location i p (BioSequence s))
p Location i p (BioSequence s)
i Maybe (Location i p (BioSequence s))
s) = ByteString -> BioSequence s
forall k (which :: k). ByteString -> BioSequence which
BioSequence (ByteString -> BioSequence s) -> ByteString -> BioSequence s
forall a b. (a -> b) -> a -> b
$ ByteString
-> (Location i p (BioSequence s) -> ByteString)
-> Maybe (Location i p (BioSequence s))
-> ByteString
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ByteString
BS.empty Location i p (BioSequence s) -> ByteString
v Maybe (Location i p (BioSequence s))
p ByteString -> ByteString -> ByteString
`BS.append` Location i p (BioSequence s) -> ByteString
v Location i p (BioSequence s)
i ByteString -> ByteString -> ByteString
`BS.append` ByteString
-> (Location i p (BioSequence s) -> ByteString)
-> Maybe (Location i p (BioSequence s))
-> ByteString
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ByteString
BS.empty Location i p (BioSequence s) -> ByteString
v Maybe (Location i p (BioSequence s))
s
  t :: PIS i p (BioSequence s) -> BioSequence t -> PIS i p (BioSequence t)
t (PIS Maybe (Location i p (BioSequence s))
p Location i p (BioSequence s)
i Maybe (Location i p (BioSequence s))
s) (BioSequence ByteString
str) =
    let (BioSequence t
pfx,ByteString
ifxsfx) = ASetter
  (ByteString, ByteString)
  (BioSequence t, ByteString)
  ByteString
  (BioSequence t)
-> (ByteString -> BioSequence t)
-> (ByteString, ByteString)
-> (BioSequence t, ByteString)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter
  (ByteString, ByteString)
  (BioSequence t, ByteString)
  ByteString
  (BioSequence t)
forall s t a b. Field1 s t a b => Lens s t a b
_1 ByteString -> BioSequence t
forall k (which :: k). ByteString -> BioSequence which
BioSequence   ((ByteString, ByteString) -> (BioSequence t, ByteString))
-> (ByteString, ByteString) -> (BioSequence t, ByteString)
forall a b. (a -> b) -> a -> b
$ Int -> ByteString -> (ByteString, ByteString)
BS.splitAt (Int
-> (Location i p (BioSequence s) -> Int)
-> Maybe (Location i p (BioSequence s))
-> Int
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
0 (ByteString -> Int
BS.length (ByteString -> Int)
-> (Location i p (BioSequence s) -> ByteString)
-> Location i p (BioSequence s)
-> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Location i p (BioSequence s) -> ByteString
v) Maybe (Location i p (BioSequence s))
p) ByteString
str
        (BioSequence t
ifx,BioSequence t
sfx   ) = ASetter
  (ByteString, ByteString)
  (BioSequence t, BioSequence t)
  ByteString
  (BioSequence t)
-> (ByteString -> BioSequence t)
-> (ByteString, ByteString)
-> (BioSequence t, BioSequence t)
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter
  (ByteString, ByteString)
  (BioSequence t, BioSequence t)
  ByteString
  (BioSequence t)
forall (r :: * -> * -> *) a b.
Bitraversable r =>
Traversal (r a a) (r b b) a b
both ByteString -> BioSequence t
forall k (which :: k). ByteString -> BioSequence which
BioSequence ((ByteString, ByteString) -> (BioSequence t, BioSequence t))
-> (ByteString, ByteString) -> (BioSequence t, BioSequence t)
forall a b. (a -> b) -> a -> b
$ Int -> ByteString -> (ByteString, ByteString)
BS.splitAt (ByteString -> Int
BS.length (ByteString -> Int) -> ByteString -> Int
forall a b. (a -> b) -> a -> b
$ Location i p (BioSequence s) -> ByteString
v Location i p (BioSequence s)
i) ByteString
ifxsfx
    in  Maybe (Location i p (BioSequence t))
-> Location i p (BioSequence t)
-> Maybe (Location i p (BioSequence t))
-> PIS i p (BioSequence t)
forall k (i :: k) p s.
Maybe (Location i p s)
-> Location i p s -> Maybe (Location i p s) -> PIS i p s
PIS (ASetter
  (Maybe (Location i p (BioSequence s)))
  (Maybe (Location i p (BioSequence t)))
  (BioSequence s)
  (BioSequence t)
-> BioSequence t
-> Maybe (Location i p (BioSequence s))
-> Maybe (Location i p (BioSequence t))
forall s t a b. ASetter s t a b -> b -> s -> t
set ((Location i p (BioSequence s)
 -> Identity (Location i p (BioSequence t)))
-> Maybe (Location i p (BioSequence s))
-> Identity (Maybe (Location i p (BioSequence t)))
forall a b. Prism (Maybe a) (Maybe b) a b
_Just ((Location i p (BioSequence s)
  -> Identity (Location i p (BioSequence t)))
 -> Maybe (Location i p (BioSequence s))
 -> Identity (Maybe (Location i p (BioSequence t))))
-> ((BioSequence s -> Identity (BioSequence t))
    -> Location i p (BioSequence s)
    -> Identity (Location i p (BioSequence t)))
-> ASetter
     (Maybe (Location i p (BioSequence s)))
     (Maybe (Location i p (BioSequence t)))
     (BioSequence s)
     (BioSequence t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BioSequence s -> Identity (BioSequence t))
-> Location i p (BioSequence s)
-> Identity (Location i p (BioSequence t))
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence) BioSequence t
pfx Maybe (Location i p (BioSequence s))
p) (((BioSequence s -> Identity (BioSequence t))
 -> Location i p (BioSequence s)
 -> Identity (Location i p (BioSequence t)))
-> BioSequence t
-> Location i p (BioSequence s)
-> Location i p (BioSequence t)
forall s t a b. ASetter s t a b -> b -> s -> t
set (BioSequence s -> Identity (BioSequence t))
-> Location i p (BioSequence s)
-> Identity (Location i p (BioSequence t))
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence BioSequence t
ifx Location i p (BioSequence s)
i) (ASetter
  (Maybe (Location i p (BioSequence s)))
  (Maybe (Location i p (BioSequence t)))
  (BioSequence s)
  (BioSequence t)
-> BioSequence t
-> Maybe (Location i p (BioSequence s))
-> Maybe (Location i p (BioSequence t))
forall s t a b. ASetter s t a b -> b -> s -> t
set ((Location i p (BioSequence s)
 -> Identity (Location i p (BioSequence t)))
-> Maybe (Location i p (BioSequence s))
-> Identity (Maybe (Location i p (BioSequence t)))
forall a b. Prism (Maybe a) (Maybe b) a b
_Just ((Location i p (BioSequence s)
  -> Identity (Location i p (BioSequence t)))
 -> Maybe (Location i p (BioSequence s))
 -> Identity (Maybe (Location i p (BioSequence t))))
-> ((BioSequence s -> Identity (BioSequence t))
    -> Location i p (BioSequence s)
    -> Identity (Location i p (BioSequence t)))
-> ASetter
     (Maybe (Location i p (BioSequence s)))
     (Maybe (Location i p (BioSequence t)))
     (BioSequence s)
     (BioSequence t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BioSequence s -> Identity (BioSequence t))
-> Location i p (BioSequence s)
-> Identity (Location i p (BioSequence t))
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence) BioSequence t
sfx Maybe (Location i p (BioSequence s))
s)



-- | Given a @Location@ with a @BioSequence@, replace the sequence with its length.

locAsLength :: Location i FwdPosition (BioSequence w) -> Location i FwdPosition Int
{-# Inline locAsLength #-}
locAsLength :: Location i FwdPosition (BioSequence w)
-> Location i FwdPosition Int
locAsLength = ASetter
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition Int)
  (BioSequence w)
  Int
-> (BioSequence w -> Int)
-> Location i FwdPosition (BioSequence w)
-> Location i FwdPosition Int
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over ASetter
  (Location i FwdPosition (BioSequence w))
  (Location i FwdPosition Int)
  (BioSequence w)
  Int
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence (Getting Int (BioSequence w) Int -> BioSequence w -> Int
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view ((ByteString -> Const Int ByteString)
-> BioSequence w -> Const Int (BioSequence w)
forall k1 (which1 :: k1) k (which :: k).
Iso (BioSequence which1) (BioSequence which) ByteString ByteString
_BioSequence((ByteString -> Const Int ByteString)
 -> BioSequence w -> Const Int (BioSequence w))
-> ((Int -> Const Int Int) -> ByteString -> Const Int ByteString)
-> Getting Int (BioSequence w) Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ByteString -> Int)
-> (Int -> Const Int Int) -> ByteString -> Const Int ByteString
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to ByteString -> Int
BS.length))



-- | Provides a range in a notation as used by blast, for example. This
-- isomorphism can translate back as well. @FwdLocation - 8 4 ^. blastRange1 ==
-- 9 6 MinusStrand@, since these ranges are 1-based and start and end included.

blastRange1 :: (Location i FwdPosition Int) -> (Int,Int,Strand)
{-# Inline blastRange1 #-}
blastRange1 :: Location i FwdPosition Int -> (Int, Int, Strand)
blastRange1 = Location i FwdPosition Int -> (Int, Int, Strand)
forall k (ident :: k).
Location ident FwdPosition Int -> (Int, Int, Strand)
f -- iso f t
  where
    f :: Location ident FwdPosition Int -> (Int, Int, Strand)
f Location ident FwdPosition Int
loc =
      let s :: Int
s = Location ident FwdPosition Int
locLocation ident FwdPosition Int
-> Getting Int (Location ident FwdPosition Int) Int -> Int
forall s a. s -> Getting a s a -> a
^.(FwdPosition -> Const Int FwdPosition)
-> Location ident FwdPosition Int
-> Const Int (Location ident FwdPosition Int)
forall k (ident :: k) posTy seqTy posTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  posTy
  posTy
locPosition((FwdPosition -> Const Int FwdPosition)
 -> Location ident FwdPosition Int
 -> Const Int (Location ident FwdPosition Int))
-> ((Int -> Const Int Int) -> FwdPosition -> Const Int FwdPosition)
-> Getting Int (Location ident FwdPosition Int) Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Index 0 -> Const Int (Index 0))
-> FwdPosition -> Const Int FwdPosition
Lens' FwdPosition (Index 0)
fwdStart((Index 0 -> Const Int (Index 0))
 -> FwdPosition -> Const Int FwdPosition)
-> ((Int -> Const Int Int) -> Index 0 -> Const Int (Index 0))
-> (Int -> Const Int Int)
-> FwdPosition
-> Const Int FwdPosition
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Index 0 -> Int)
-> (Int -> Const Int Int) -> Index 0 -> Const Int (Index 0)
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to Index 0 -> Int
forall (t :: Nat). KnownNat t => Index t -> Int
toInt1
          l :: Int
l = Location ident FwdPosition Int
locLocation ident FwdPosition Int
-> Getting Int (Location ident FwdPosition Int) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (Location ident FwdPosition Int) Int
forall k (ident :: k) posTy seqTy seqTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  seqTy
  seqTy
locSequence
          pm :: Strand
pm = Location ident FwdPosition Int
locLocation ident FwdPosition Int
-> Getting Strand (Location ident FwdPosition Int) Strand -> Strand
forall s a. s -> Getting a s a -> a
^.(FwdPosition -> Const Strand FwdPosition)
-> Location ident FwdPosition Int
-> Const Strand (Location ident FwdPosition Int)
forall k (ident :: k) posTy seqTy posTy.
Lens
  (Location ident posTy seqTy)
  (Location ident posTy seqTy)
  posTy
  posTy
locPosition((FwdPosition -> Const Strand FwdPosition)
 -> Location ident FwdPosition Int
 -> Const Strand (Location ident FwdPosition Int))
-> Getting Strand FwdPosition Strand
-> Getting Strand (Location ident FwdPosition Int) Strand
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Getting Strand FwdPosition Strand
Lens' FwdPosition Strand
fwdStrand
      in  case Strand
pm of Strand
PlusStrand -> (Int
s,Int
sInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
l,Strand
pm) ; Strand
MinusStrand -> (Int
sInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
l,Int
s,Strand
pm)
--    t (x,y,pm) =
--      let s = fromInt1 x
--          l = 1 + abs (x-y)
--      in  Location (FwdPosition pm s) l



-- | For each element, attach the prefix as well. The @Int@ indicates the maximal prefix length to
-- attach.
--
-- @1 2 3 4@ -> @01 12 23 34@
--
-- TODO are we sure this is correct for @MinusStrand@?

attachPrefixes
  :: ( Monad m, ModifyLocation p s )
  => Int
  -> SP.Stream (SP.Of (PIS i p s)) m r
  -> SP.Stream (SP.Of (PIS i p s)) m r
{-# Inlinable attachPrefixes #-}
attachPrefixes :: Int -> Stream (Of (PIS i p s)) m r -> Stream (Of (PIS i p s)) m r
attachPrefixes Int
k = (Maybe (PIS i p s) -> PIS i p s)
-> Stream (Of (Maybe (PIS i p s))) m r
-> Stream (Of (PIS i p s)) m r
forall (m :: * -> *) a b r.
Monad m =>
(a -> b) -> Stream (Of a) m r -> Stream (Of b) m r
SP.map (\(Just PIS i p s
w) -> PIS i p s
w) (Stream (Of (Maybe (PIS i p s))) m r
 -> Stream (Of (PIS i p s)) m r)
-> (Stream (Of (PIS i p s)) m r
    -> Stream (Of (Maybe (PIS i p s))) m r)
-> Stream (Of (PIS i p s)) m r
-> Stream (Of (PIS i p s)) m r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int
-> Stream (Of (Maybe (PIS i p s))) m r
-> Stream (Of (Maybe (PIS i p s))) m r
forall (m :: * -> *) a r.
Monad m =>
Int -> Stream (Of a) m r -> Stream (Of a) m r
SP.drop Int
1 (Stream (Of (Maybe (PIS i p s))) m r
 -> Stream (Of (Maybe (PIS i p s))) m r)
-> (Stream (Of (PIS i p s)) m r
    -> Stream (Of (Maybe (PIS i p s))) m r)
-> Stream (Of (PIS i p s)) m r
-> Stream (Of (Maybe (PIS i p s))) m r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (PIS i p s) -> PIS i p s -> Maybe (PIS i p s))
-> Maybe (PIS i p s)
-> (Maybe (PIS i p s) -> Maybe (PIS i p s))
-> Stream (Of (PIS i p s)) m r
-> Stream (Of (Maybe (PIS i p s))) m r
forall (m :: * -> *) x a b r.
Monad m =>
(x -> a -> x)
-> x -> (x -> b) -> Stream (Of a) m r -> Stream (Of b) m r
SP.scan Maybe (PIS i p s) -> PIS i p s -> Maybe (PIS i p s)
go Maybe (PIS i p s)
forall a. Maybe a
Nothing Maybe (PIS i p s) -> Maybe (PIS i p s)
forall a. a -> a
id
  where
    go :: Maybe (PIS i p s) -> PIS i p s -> Maybe (PIS i p s)
go Maybe (PIS i p s)
Nothing = PIS i p s -> Maybe (PIS i p s)
forall a. a -> Maybe a
Just
    go (Just PIS i p s
p) = PIS i p s -> Maybe (PIS i p s)
forall a. a -> Maybe a
Just (PIS i p s -> Maybe (PIS i p s))
-> (PIS i p s -> PIS i p s) -> PIS i p s -> Maybe (PIS i p s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ASetter
  (PIS i p s)
  (PIS i p s)
  (Maybe (Location i p s))
  (Maybe (Location i p s))
-> Maybe (Location i p s) -> PIS i p s -> PIS i p s
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter
  (PIS i p s)
  (PIS i p s)
  (Maybe (Location i p s))
  (Maybe (Location i p s))
forall k (i :: k) p s. Lens' (PIS i p s) (Maybe (Location i p s))
pisPrefix (Location i p s -> Maybe (Location i p s)
forall a. a -> Maybe a
Just (Location i p s -> Maybe (Location i p s))
-> (Location i p s -> Location i p s)
-> Location i p s
-> Maybe (Location i p s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Location i p s -> Location i p s
forall k posTy seqTy (i :: k).
ModifyLocation posTy seqTy =>
Int -> Location i posTy seqTy -> Location i posTy seqTy
locTakeEnd Int
k (Location i p s -> Maybe (Location i p s))
-> Location i p s -> Maybe (Location i p s)
forall a b. (a -> b) -> a -> b
$ Getting (Location i p s) (PIS i p s) (Location i p s)
-> PIS i p s -> Location i p s
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (Location i p s) (PIS i p s) (Location i p s)
forall k (i :: k) p s. Lens' (PIS i p s) (Location i p s)
pisInfix PIS i p s
p)



-- | For each element, attach the suffix as well.
--
-- @1 2 3 4@ -> @12 23 34 40@

attachSuffixes
  :: ( Monad m, ModifyLocation p s )
  => Int
  -> SP.Stream (SP.Of (PIS i p s)) m r
  -> SP.Stream (SP.Of (PIS i p s)) m r
{-# Inlinable attachSuffixes #-}
attachSuffixes :: Int -> Stream (Of (PIS i p s)) m r -> Stream (Of (PIS i p s)) m r
attachSuffixes Int
k = Maybe (PIS i p s)
-> Stream (Of (PIS i p s)) m r -> Stream (Of (PIS i p s)) m r
loop Maybe (PIS i p s)
forall a. Maybe a
Nothing
  where
    loop :: Maybe (PIS i p s)
-> Stream (Of (PIS i p s)) m r -> Stream (Of (PIS i p s)) m r
loop Maybe (PIS i p s)
Nothing = \case
      SI.Return r
r -> r -> Stream (Of (PIS i p s)) m r
forall (f :: * -> *) (m :: * -> *) r. r -> Stream f m r
SI.Return r
r
      SI.Effect m (Stream (Of (PIS i p s)) m r)
m -> m (Stream (Of (PIS i p s)) m r) -> Stream (Of (PIS i p s)) m r
forall (f :: * -> *) (m :: * -> *) r.
m (Stream f m r) -> Stream f m r
SI.Effect (m (Stream (Of (PIS i p s)) m r) -> Stream (Of (PIS i p s)) m r)
-> m (Stream (Of (PIS i p s)) m r) -> Stream (Of (PIS i p s)) m r
forall a b. (a -> b) -> a -> b
$ (Stream (Of (PIS i p s)) m r -> Stream (Of (PIS i p s)) m r)
-> m (Stream (Of (PIS i p s)) m r)
-> m (Stream (Of (PIS i p s)) m r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Maybe (PIS i p s)
-> Stream (Of (PIS i p s)) m r -> Stream (Of (PIS i p s)) m r
loop Maybe (PIS i p s)
forall a. Maybe a
Nothing) m (Stream (Of (PIS i p s)) m r)
m
      SI.Step (PIS i p s
a SP.:> Stream (Of (PIS i p s)) m r
rest) -> Maybe (PIS i p s)
-> Stream (Of (PIS i p s)) m r -> Stream (Of (PIS i p s)) m r
loop (PIS i p s -> Maybe (PIS i p s)
forall a. a -> Maybe a
Just PIS i p s
a) Stream (Of (PIS i p s)) m r
rest
    loop (Just PIS i p s
p) = \case
      SI.Return r
r -> Of (PIS i p s) (Stream (Of (PIS i p s)) m r)
-> Stream (Of (PIS i p s)) m r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
SI.Step (PIS i p s
p PIS i p s
-> Stream (Of (PIS i p s)) m r
-> Of (PIS i p s) (Stream (Of (PIS i p s)) m r)
forall a b. a -> b -> Of a b
SP.:> r -> Stream (Of (PIS i p s)) m r
forall (f :: * -> *) (m :: * -> *) r. r -> Stream f m r
SI.Return r
r)
      SI.Effect m (Stream (Of (PIS i p s)) m r)
m -> m (Stream (Of (PIS i p s)) m r) -> Stream (Of (PIS i p s)) m r
forall (f :: * -> *) (m :: * -> *) r.
m (Stream f m r) -> Stream f m r
SI.Effect (m (Stream (Of (PIS i p s)) m r) -> Stream (Of (PIS i p s)) m r)
-> m (Stream (Of (PIS i p s)) m r) -> Stream (Of (PIS i p s)) m r
forall a b. (a -> b) -> a -> b
$ (Stream (Of (PIS i p s)) m r -> Stream (Of (PIS i p s)) m r)
-> m (Stream (Of (PIS i p s)) m r)
-> m (Stream (Of (PIS i p s)) m r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Maybe (PIS i p s)
-> Stream (Of (PIS i p s)) m r -> Stream (Of (PIS i p s)) m r
loop (PIS i p s -> Maybe (PIS i p s)
forall a. a -> Maybe a
Just PIS i p s
p)) m (Stream (Of (PIS i p s)) m r)
m
      SI.Step (PIS i p s
a SP.:> Stream (Of (PIS i p s)) m r
rest) ->
        let p' :: PIS i p s
p' = PIS i p s
p PIS i p s -> (PIS i p s -> PIS i p s) -> PIS i p s
forall a b. a -> (a -> b) -> b
& ASetter
  (PIS i p s)
  (PIS i p s)
  (Maybe (Location i p s))
  (Maybe (Location i p s))
-> Maybe (Location i p s) -> PIS i p s -> PIS i p s
forall s t a b. ASetter s t a b -> b -> s -> t
set ASetter
  (PIS i p s)
  (PIS i p s)
  (Maybe (Location i p s))
  (Maybe (Location i p s))
forall k (i :: k) p s. Lens' (PIS i p s) (Maybe (Location i p s))
pisSuffix (Location i p s -> Maybe (Location i p s)
forall a. a -> Maybe a
Just (Location i p s -> Maybe (Location i p s))
-> (Location i p s -> Location i p s)
-> Location i p s
-> Maybe (Location i p s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Location i p s -> Location i p s
forall k posTy seqTy (i :: k).
ModifyLocation posTy seqTy =>
Int -> Location i posTy seqTy -> Location i posTy seqTy
locTake Int
k (Location i p s -> Maybe (Location i p s))
-> Location i p s -> Maybe (Location i p s)
forall a b. (a -> b) -> a -> b
$ Getting (Location i p s) (PIS i p s) (Location i p s)
-> PIS i p s -> Location i p s
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting (Location i p s) (PIS i p s) (Location i p s)
forall k (i :: k) p s. Lens' (PIS i p s) (Location i p s)
pisInfix PIS i p s
a)
        in  Of (PIS i p s) (Stream (Of (PIS i p s)) m r)
-> Stream (Of (PIS i p s)) m r
forall (f :: * -> *) (m :: * -> *) r.
f (Stream f m r) -> Stream f m r
SI.Step (PIS i p s
p' PIS i p s
-> Stream (Of (PIS i p s)) m r
-> Of (PIS i p s) (Stream (Of (PIS i p s)) m r)
forall a b. a -> b -> Of a b
SP.:> Maybe (PIS i p s)
-> Stream (Of (PIS i p s)) m r -> Stream (Of (PIS i p s)) m r
loop (PIS i p s -> Maybe (PIS i p s)
forall a. a -> Maybe a
Just PIS i p s
a) Stream (Of (PIS i p s)) m r
rest)