bio-0.5.2: A bioinformatics library

Safe Haskell | Safe-Inferred

Bio.Location.ContigLocation

Contents

- Sequence locations
- Locations and positions
- Extracting subsequences
- Transforming locations
- Displaying locations

Description

Data type for a sequence location consiting of a contiguous range of positions on the sequence.

Throughout, sequence position refers to a `Pos` which includes a strand. An index into a sequence is referred to as an offset, and is generally of type `Offset`.

Synopsis

- data ContigLoc = ContigLoc {
  - offset5 :: !Offset
  - length :: !Offset
  - strand :: !Strand
  }
- fromStartEnd :: Offset -> Offset -> ContigLoc
- fromPosLen :: Pos -> Offset -> ContigLoc
- bounds :: ContigLoc -> (Offset, Offset)
- startPos :: ContigLoc -> Pos
- endPos :: ContigLoc -> Pos
- posInto :: Pos -> ContigLoc -> Maybe Pos
- posOutof :: Pos -> ContigLoc -> Maybe Pos
- isWithin :: Pos -> ContigLoc -> Bool
- overlaps :: ContigLoc -> ContigLoc -> Bool
- seqData :: (Error e, MonadError e m) => SeqData -> ContigLoc -> m SeqData
- seqDataPadded :: SeqData -> ContigLoc -> SeqData
- slide :: Offset -> ContigLoc -> ContigLoc
- extend :: (Offset, Offset) -> ContigLoc -> ContigLoc
- display :: ContigLoc -> String

# Sequence locations

data ContigLoc

Contiguous sequence location defined by a span of sequence positions, lying on a specific strand of the sequence.

Constructors

ContigLoc |

Fields

offset5 :: !Offset

  The offset of the 5' end of the location, as a 0-based index

length :: !Offset

  The length of the location

strand :: !Strand

  The strand of the location

Instances

Eq ContigLoc |
Ord ContigLoc |
Show ContigLoc |
Stranded ContigLoc |

fromStartEnd :: Offset -> Offset -> ContigLoc

Create a sequence location lying between 0-based starting and ending offsets. When `start < end`, the location be on the forward strand, otherwise it will be on the reverse complement strand.

fromPosLen :: Pos -> Offset -> ContigLoc

Create a sequence location from the sequence position of the start of the location and the length of the position. The strand of the location, and the direction it extends from the starting position, are determined by the strand of the starting position.

# Locations and positions

bounds :: ContigLoc -> (Offset, Offset)

The bounds of a sequence location. This is a pair consisting of the lowest and highest sequence offsets covered by the region. The bounds ignore the strand of the sequence location, and the first element of the pair will always be lower than the second.

startPos :: ContigLoc -> Pos

Sequence position of the start of the location. This is the 5' end on the location strand, which will have a higher offset than `endPos` if the location is on the `RevCompl` strand.

endPos :: ContigLoc -> Pos

Sequence position of the end of the location, as described in `startPos`.

posInto :: Pos -> ContigLoc -> Maybe Pos

Given a sequence position and a sequence location relative to the same sequence, compute a new position representing the original position relative to the subsequence defined by the location. If the sequence position lies outside of the sequence location, `Nothing` is returned; thus, the offset of the new position will always be in the range `[0, length cloc - 1]`.

posOutof :: Pos -> ContigLoc -> Maybe Pos

Given a sequence location and a sequence position within that location, compute a new position representing the original position relative to the outer sequence. If the sequence position lies outside the location, `Nothing` is returned.

This function inverts `posInto` when the sequence position lies within the position is actually within the location.

isWithin :: Pos -> ContigLoc -> Bool

Returns `True` when a sequence position lies within a sequence location on the same sequence, and occupies the same strand.

overlaps :: ContigLoc -> ContigLoc -> Bool

Returns `True` when two sequence locations overlap at any position.

# Extracting subsequences

seqData :: (Error e, MonadError e m) => SeqData -> ContigLoc -> m SeqData

Extract the nucleotide `SeqData` for the sequence location. If any part of the location lies outside the bounds of the sequence, an error results.

seqDataPadded :: SeqData -> ContigLoc -> SeqData

As `seqData`, extract the nucleotide subsequence for the location. Any positions in the location lying outside the bounds of the sequence are returned as `N` rather than producing an error.

# Transforming locations

slide :: Offset -> ContigLoc -> ContigLoc

Returns a location resulting from sliding the original location along the sequence by a specified offset. A positive offset will move the location away from the 5' end of the forward stand of the sequence regardless of the strand of the location itself. Thus,

     slide (revCompl cloc) off == revCompl (slide cloc off)

extend :: (Offset, Offset) -> ContigLoc -> ContigLoc

Returns a sequence location produced by extending the original location on each end, based on a pair of (5\' extension, /3' extension/). The 5' extension is applied to the 5' end of the location on the location strand; if the location is on the `RevCompl` strand, the 5' end will have a higher offset than the 3' end and this offset will increase by the amount of the 5' extension. Similarly, the 3' extension is applied to the 3' end of the location.

# Displaying locations

display :: ContigLoc -> String

Display a human-friendly, zero-based representation of a sequence location.