Skip to content

Commit

Permalink
Reorganise documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
CiaranOMara committed Jan 16, 2024
1 parent 85841d8 commit f9a908a
Show file tree
Hide file tree
Showing 10 changed files with 319 additions and 388 deletions.
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
XAM = "d759349c-bcba-11e9-07c2-5b90f8f05f7c"

[compat]
Documenter = "0.27"
12 changes: 9 additions & 3 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using Pkg
using Documenter, XAM

makedocs(
strict = true,
checkdocs = :all,
linkcheck = true,
format = Documenter.HTML(
Expand All @@ -10,9 +11,14 @@ makedocs(
modules = [XAM, XAM.SAM, XAM.BAM],
sitename = "XAM.jl",
pages = [
"Home" => "index.md",
"SAM and BAM" => "man/hts-files.md",
"API Reference" => "man/api.md"
"Home" => Any[
"Overview" => "index.md",
"Records" => "man/records.md",
"File I/O" => "man/files.md",
],
"SAM" => "man/sam.md",
"BAM" => "man/bam.md",
"BAI" => "man/bai.md",
],
authors = replace(join(Pkg.TOML.parsefile("Project.toml")["authors"], ", "), r" <.*?>" => "" ) * ", The BioJulia Organisation, and other contributors."
)
Expand Down
43 changes: 1 addition & 42 deletions docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# XAM.jl
# XAM

[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![Latest Release](https://img.shields.io/github/release/BioJulia/XAM.jl.svg)](https://github.com/BioJulia/XAM.jl/releases/latest)
[![MIT license](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/BioJulia/XAM.jl/blob/master/LICENSE)
[![Stable documentation](https://img.shields.io/badge/docs-stable-blue.svg)](https://biojulia.github.io/XAM.jl/stable)
[![Latest documentation](https://img.shields.io/badge/docs-dev-blue.svg)](https://biojulia.github.io/XAM.jl/dev/)

> This project follows the [semver](http://semver.org) pro forma and uses the [git-flow branching model](https://nvie.com/posts/a-successful-git-branching-model/).
## Description
The XAM package provides I/O and utilities for manipulating SAM and BAM formatted alignment map files.

## Installation
Expand All @@ -20,48 +17,10 @@ add XAM

If you are interested in the cutting edge of the development, please check out the [develop branch](https://github.com/BioJulia/XAM.jl/tree/develop) to try new features before release.

## Testing
XAM is tested against Julia `1.X` on Linux, OS X, and Windows.

**Latest build status:**

[![Unit tests](https://github.com/BioJulia/XAM.jl/workflows/Unit%20tests/badge.svg?branch=master)](https://github.com/BioJulia/XAM.jl/actions?query=workflow%3A%22Unit+tests%22+branch%3Amaster)
[![Documentation](https://github.com/BioJulia/XAM.jl/workflows/Documentation/badge.svg?branch=master)](https://github.com/BioJulia/XAM.jl/actions?query=workflow%3ADocumentation+branch%3Amaster)
[![codecov](https://codecov.io/gh/BioJulia/XAM.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/BioJulia/XAM.jl)

## Contributing
We appreciate [contributions](https://github.com/BioJulia/XAM.jl/graphs/contributors) from users including reporting bugs, fixing issues, improving performance and adding new features.

Take a look at the [contributing files](https://github.com/BioJulia/Contributing) detailed contributor and maintainer guidelines, and code of conduct.

### Financial contributions
We also welcome financial contributions in full transparency on our [open collective](https://opencollective.com/biojulia).
Anyone can file an expense.
If the expense makes sense for the development the core contributors and the person who filed the expense will be reimbursed.


## Backers & Sponsors
Thank you to all our backers and sponsors!

Love our work and community? [Become a backer](https://opencollective.com/biojulia#backer).

[![backers](https://opencollective.com/biojulia/backers.svg?width=890)](https://opencollective.com/biojulia#backers)

Does your company use BioJulia?
Help keep BioJulia feature rich and healthy by [sponsoring the project](https://opencollective.com/biojulia#sponsor).
Your logo will show up here with a link to your website.

[![](https://opencollective.com/biojulia/sponsor/0/avatar.svg)](https://opencollective.com/biojulia/sponsor/0/website)
[![](https://opencollective.com/biojulia/sponsor/1/avatar.svg)](https://opencollective.com/biojulia/sponsor/1/website)
[![](https://opencollective.com/biojulia/sponsor/2/avatar.svg)](https://opencollective.com/biojulia/sponsor/2/website)
[![](https://opencollective.com/biojulia/sponsor/3/avatar.svg)](https://opencollective.com/biojulia/sponsor/3/website)
[![](https://opencollective.com/biojulia/sponsor/4/avatar.svg)](https://opencollective.com/biojulia/sponsor/4/website)
[![](https://opencollective.com/biojulia/sponsor/5/avatar.svg)](https://opencollective.com/biojulia/sponsor/5/website)
[![](https://opencollective.com/biojulia/sponsor/6/avatar.svg)](https://opencollective.com/biojulia/sponsor/6/website)
[![](https://opencollective.com/biojulia/sponsor/7/avatar.svg)](https://opencollective.com/biojulia/sponsor/7/website)
[![](https://opencollective.com/biojulia/sponsor/8/avatar.svg)](https://opencollective.com/biojulia/sponsor/8/website)
[![](https://opencollective.com/biojulia/sponsor/9/avatar.svg)](https://opencollective.com/biojulia/sponsor/9/website)


## Questions?
If you have a question about contributing or using BioJulia software, come on over and chat to us on [the Julia Slack workspace](https://julialang.slack.com/channels/biology), or you can try the [Bio category of the Julia discourse site](https://discourse.julialang.org/c/domain/bio).
38 changes: 0 additions & 38 deletions docs/src/man/api.md

This file was deleted.

21 changes: 21 additions & 0 deletions docs/src/man/bai.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# BAI files

The `XAM` package supports the BAI index to fetch records in a specific range from a BAM file.
[Samtools](https://samtools.github.io/) provides `index` subcommand to create an index file (.bai) from a sorted BAM file.

```console
$ samtools index -b SRR1238088.sort.bam
$ ls SRR1238088.sort.bam*
SRR1238088.sort.bam SRR1238088.sort.bam.bai
```

The method `eachoverlap(reader, chrom, range)` returns an iterator of BAM records overlapping the query interval:

```julia
reader = open(BAM.Reader, "SRR1238088.sort.bam", index="SRR1238088.sort.bam.bai")
for record in eachoverlap(reader, "Chr2", 10000:11000)
# `record` is a BAM.Record object
# ...
end
close(reader)
```
25 changes: 25 additions & 0 deletions docs/src/man/bam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
```@meta
CurrentModule = XAM
DocTestSetup = quote
using XAM
end
```

# BAM files


## The `BAM.Record`

The `XAM` package supports the following accessors for `BAM.Record` types.

```@docs
BAM.Record
```

## `BAM.Reader` and `BAM.Writer`

### Reference:
```@docs
BAM.Reader
BAM.Writer
```
126 changes: 126 additions & 0 deletions docs/src/man/files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@

# Readers and writers

## Reading SAM and BAM files

Below is an example of a typical script iterating over all records in a file:

```julia
using XAM

# Open a BAM file.
reader = open(BAM.Reader, "data.bam")

# Iterate over BAM records.
for record in reader
# `record` is a BAM.Record object.
if BAM.ismapped(record)
# Print the mapped position.
println(BAM.refname(record), ':', BAM.position(record))
end
end

# Close the BAM file.
close(reader)
```

The size of a BAM file is often extremely large.
The iterator interface demonstrated above allocates an object for each record and that may be a bottleneck of reading data from a BAM file.
In-place reading reuses a pre-allocated object for every record and less memory allocation happens in reading:

```julia
reader = open(BAM.Reader, "data.bam")
record = BAM.Record()
while !eof(reader)
empty!(record)
read!(reader, record)
# do something
end
```

## Writing SAM and BAM files

In order to write a BAM or SAM file, you must first create a `SAM.Header`.

A `SAM.Header` is constructed from a vector of `SAM.MetaInfo` objects.

For example, to create the following simple header:

```
@HD VN:1.6 SO:coordinate
@SQ SN:ref LN:45
```

```julia
julia> a = SAM.MetaInfo("HD", ["VN" => 1.6, "SO" => "coordinate"])
SAM.MetaInfo:
tag: HD
value: VN=1.6 SO=coordinate

julia> b = SAM.MetaInfo("SQ", ["SN" => "ref", "LN" => 45])
SAM.MetaInfo:
tag: SQ
value: SN=ref LN=45

julia> h = SAM.Header([a, b])
SAM.Header(SAM.MetaInfo[SAM.MetaInfo:
tag: HD
value: VN=1.6 SO=coordinate, SAM.MetaInfo:
tag: SQ
value: SN=ref LN=45])

```

Then to create the writer for a SAM file, construct a `SAM.Writer` using the header and an `IO` type:

```julia
julia> samw = SAM.Writer(open("my-data.sam", "w"), h)
SAM.Writer(IOStream(<file my-data.sam>))

```

To make a BAM Writer is slightly different, as you need to use a specific stream type from the [https://github.com/BioJulia/BGZFStreams.jl](https://github.com/BioJulia/BGZFStreams.jl) package:

```julia
julia> using BGZFStreams

julia> bamw = BAM.Writer(BGZFStream(open("my-data.bam", "w"), "w"))
BAM.Writer(BGZFStreams.BGZFStream{IOStream}(<mode=write>))

```

Once you have a BAM or SAM writer, you can use the `write` method to write `BAM.Record`s or `SAM.Record`s to file:

```julia
julia> write(bamw, rec) # Here rec is a `BAM.Record`
330780
```


## Getting records overlapping genomic features

The `eachoverlap` method also accepts the `Interval` type defined in [GenomicFeatures.jl](https://github.com/BioJulia/GenomicFeatures.jl).

This allows you to do things like first read in the genomic features from a GFF3 file, and then for each feature, iterate over all the BAM records that overlap with that feature.

```julia
using GenomicFeatures
using GFF3
using XAM

# Load genomic features from a GFF3 file.
features = open(collect, GFF3.Reader, "TAIR10_GFF3_genes.gff")

# Keep mRNA features.
filter!(x -> GFF3.featuretype(x) == "mRNA", features)

# Open a BAM file and iterate over records overlapping mRNA transcripts.
reader = open(BAM.Reader, "SRR1238088.sort.bam")
for feature in features
for record in eachoverlap(reader, feature)
# `record` overlaps `feature`.
# ...
end
end
close(reader)
```
Loading

0 comments on commit f9a908a

Please sign in to comment.