Skip to content

Commit

Permalink
update docs (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
bicycle1885 authored Apr 11, 2017
1 parent 9dc6576 commit da0fb8f
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 59 deletions.
120 changes: 67 additions & 53 deletions docs/src/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ as well as a GAP (-) symbol.

| Symbol | Constant | Meaning |
| :----- | :-------------------- | :------------------------- |
| 'A' | `DNA_A` / `RNA_A` | A; Adenine |
| 'C' | `DNA_C` / `RNA_C` | C; Cytosine |
| 'G' | `DNA_G` / `RNA_G` | G; Guanine |
| 'T' | `DNA_T` | T; Thymine (DNA only) |
| 'U' | `RNA_U` | U; Uracil (RNA only) |
| 'M' | `DNA_M` / `RNA_M` | A or C |
| 'R' | `DNA_R` / `RNA_R` | A or G |
| 'W' | `DNA_W` / `RNA_W` | A or T/U |
| 'S' | `DNA_S` / `RNA_S` | C or G |
| 'Y' | `DNA_Y` / `RNA_Y` | C or T/U |
| 'K' | `DNA_K` / `RNA_K` | G or T/U |
| 'V' | `DNA_V` / `RNA_V` | A or C or G; not T/U |
| 'H' | `DNA_H` / `RNA_H` | A or C or T; not G |
| 'D' | `DNA_D` / `RNA_D` | A or G or T/U; not C |
| 'B' | `DNA_B` / `RNA_B` | C or G or T/U; not A |
| 'N' | `DNA_N` / `RNA_N` | A or C or G or T/U |
| '-' | `DNA_Gap` / `RNA_Gap` | Gap (none of the above) |
| `'A'` | `DNA_A` / `RNA_A` | A; Adenine |
| `'C'` | `DNA_C` / `RNA_C` | C; Cytosine |
| `'G'` | `DNA_G` / `RNA_G` | G; Guanine |
| `'T'` | `DNA_T` | T; Thymine (DNA only) |
| `'U'` | `RNA_U` | U; Uracil (RNA only) |
| `'M'` | `DNA_M` / `RNA_M` | A or C |
| `'R'` | `DNA_R` / `RNA_R` | A or G |
| `'W'` | `DNA_W` / `RNA_W` | A or T/U |
| `'S'` | `DNA_S` / `RNA_S` | C or G |
| `'Y'` | `DNA_Y` / `RNA_Y` | C or T/U |
| `'K'` | `DNA_K` / `RNA_K` | G or T/U |
| `'V'` | `DNA_V` / `RNA_V` | A or C or G; not T/U |
| `'H'` | `DNA_H` / `RNA_H` | A or C or T; not G |
| `'D'` | `DNA_D` / `RNA_D` | A or G or T/U; not C |
| `'B'` | `DNA_B` / `RNA_B` | C or G or T/U; not A |
| `'N'` | `DNA_N` / `RNA_N` | A or C or G or T/U |
| `'-'` | `DNA_Gap` / `RNA_Gap` | Gap (none of the above) |

<http://www.insdc.org/documents/feature_table.html#7.4.1>

Expand Down Expand Up @@ -72,6 +72,17 @@ DNA_C
julia> convert(DNA, 'C') === DNA_C
true
julia> convert(DNA, 'c') === convert(DNA, 'C') # convertion is not case-sensitive
true
```

`print` and `show` methods are defined to output the text representation of a symbol:
```jldoctest
julia> print(DNA_A) # un-decorated text
A
julia> show(DNA_A) # informative text
DNA_A
```

### Bit encoding
Expand All @@ -89,36 +100,36 @@ of `0001` (`DNA_A`) and `0100` (`DNA_G`). The gap symbol is always `0000`.
Set of amino acid symbols also covers IUPAC amino acid symbols plus a gap
symbol:

| Symbol | Constant | Meaning |
| :----------- | :-------------- | :-------------------------- |
| 'A' | `AA_A` | Alanine |
| 'R' | `AA_R` | Arginine |
| 'N' | `AA_N` | Asparagine |
| 'D' | `AA_D` | Aspartic acid (Aspartate) |
| 'C' | `AA_C` | Cysteine |
| 'Q' | `AA_Q` | Glutamine |
| 'E' | `AA_E` | Glutamic acid (Glutamate) |
| 'G' | `AA_G` | Glycine |
| 'H' | `AA_H` | Histidine |
| 'I' | `AA_I` | Isoleucine |
| 'L' | `AA_L` | Leucine |
| 'K' | `AA_K` | Lysine |
| 'M' | `AA_M` | Methionine |
| 'F' | `AA_F` | Phenylalanine |
| 'P' | `AA_P` | Proline |
| 'S' | `AA_S` | Serine |
| 'T' | `AA_T` | Threonine |
| 'W' | `AA_W` | Tryptophan |
| 'Y' | `AA_Y` | Tyrosine |
| 'V' | `AA_V` | Valine |
| 'O' | `AA_O` | Pyrrolysine |
| 'U' | `AA_U` | Selenocysteine |
| 'B' | `AA_B` | Aspartic acid or Asparagine |
| 'J' | `AA_J` | Leucine or Isoleucine |
| 'Z' | `AA_Z` | Glutamine or Glutamic acid |
| 'X' | `AA_X` | Any amino acid |
| '*' | `AA_Term` | Termination codon |
| '-' | `AA_Gap` | Gap (none of the above) |
| Symbol | Constant | Meaning |
| :----- | :-------- | :-------------------------- |
| `'A'` | `AA_A` | Alanine |
| `'R'` | `AA_R` | Arginine |
| `'N'` | `AA_N` | Asparagine |
| `'D'` | `AA_D` | Aspartic acid (Aspartate) |
| `'C'` | `AA_C` | Cysteine |
| `'Q'` | `AA_Q` | Glutamine |
| `'E'` | `AA_E` | Glutamic acid (Glutamate) |
| `'G'` | `AA_G` | Glycine |
| `'H'` | `AA_H` | Histidine |
| `'I'` | `AA_I` | Isoleucine |
| `'L'` | `AA_L` | Leucine |
| `'K'` | `AA_K` | Lysine |
| `'M'` | `AA_M` | Methionine |
| `'F'` | `AA_F` | Phenylalanine |
| `'P'` | `AA_P` | Proline |
| `'S'` | `AA_S` | Serine |
| `'T'` | `AA_T` | Threonine |
| `'W'` | `AA_W` | Tryptophan |
| `'Y'` | `AA_Y` | Tyrosine |
| `'V'` | `AA_V` | Valine |
| `'O'` | `AA_O` | Pyrrolysine |
| `'U'` | `AA_U` | Selenocysteine |
| `'B'` | `AA_B` | Aspartic acid or Asparagine |
| `'J'` | `AA_J` | Leucine or Isoleucine |
| `'Z'` | `AA_Z` | Glutamine or Glutamic acid |
| `'X'` | `AA_X` | Any amino acid |
| `'*'` | `AA_Term` | Termination codon |
| `'-'` | `AA_Gap` | Gap (none of the above) |

<http://www.insdc.org/documents/feature_table.html#7.4.3>

Expand Down Expand Up @@ -146,20 +157,23 @@ AA_A
julia> convert(AminoAcid, 'P') === AA_P
true
julia> convert(AminoAcid, 'a') === convert(AminoAcid, 'A')
true
```

# Functions
## Functions

```@docs
alphabet
gap
compatbits
complement
isgap
iscompatible
isGC
ispurine
ispyrimidine
isambiguous
iscertain
isgap
complement
iscompatible
compatbits
alphabet
```
14 changes: 14 additions & 0 deletions src/aminoacid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,20 @@ Base.isvalid(aa::AminoAcid) = aa ≤ AA_Gap
isambiguous(aa::AminoAcid) = AA_B aa AA_X
gap(::Type{AminoAcid}) = AA_Gap

"""
compatbits(aa::AminoAcid)
Return the compatibility bits of `aa` as `UInt32`.
```jldoctest
julia> compatbits(AA_A)
0x00000001
julia> compatbits(AA_J)
0x00000600
```
"""
compatbits(aa::AminoAcid) = compatbits_aa[reinterpret(UInt8, aa)+1]

function iscompatible(x::AminoAcid, y::AminoAcid)
Expand Down
89 changes: 83 additions & 6 deletions src/nucleicacid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,24 @@ for (char, doc, bits) in [
end
end

"""
alphabet(type)
Get all symbols of `type`.
# Examples
```jldoctest
julia> alphabet(DNA)
(DNA_Gap,DNA_A,DNA_C,DNA_M,DNA_G,DNA_R,DNA_S,DNA_V,DNA_T,DNA_W,DNA_Y,DNA_H,DNA_K,DNA_D,DNA_B,DNA_N)
julia> issorted(alphabet(DNA))
true
```
"""
function alphabet end

@eval function alphabet(::Type{DNA})
return $(tuple([reinterpret(DNA, x) for x in 0b0000:0b1111]...))
end
Expand Down Expand Up @@ -221,12 +239,26 @@ function Base.trailing_zeros(nt::NucleicAcid)
return trailing_zeros(reinterpret(UInt8, nt))
end

"""
gap(type)
Return the gap value of `type`.
# Examples
```jldoctest
julia> gap(DNA)
DNA_Gap
```
"""
function gap{N<:NucleicAcid}(::Type{N})
return reinterpret(N, 0b0000)
end

"""
isGC(nt::NucleicAcid)
Test if `nt` is surely either guanine or cytosine.
"""
function isGC(nt::NucleicAcid)
Expand All @@ -236,7 +268,8 @@ end

"""
ispurine(nt::NucleicAcid)
Test if nucleotide is surely a purine.
Test if `nt` is surely a purine.
"""
@inline function ispurine(nt::NucleicAcid)
bits = reinterpret(UInt8, nt)
Expand All @@ -245,7 +278,8 @@ end

"""
ispyrimidine(nt::NucleicAcid)
Test if nucleotide is surely a pyrimidine.
Test if `nt` is surely a pyrimidine.
"""
@inline function ispyrimidine(nt::NucleicAcid)
bits = reinterpret(UInt8, nt)
Expand All @@ -254,6 +288,7 @@ end

"""
isambiguous(nt::NucleicAcid)
Test if `nt` is ambiguous nucleotide.
"""
@inline function isambiguous(nt::NucleicAcid)
Expand All @@ -262,6 +297,7 @@ end

"""
iscertain(nt::NucleicAcid)
Test if `nt` is a non-ambiguous nucleotide e.g. ACGT.
"""
@inline function iscertain(nt::NucleicAcid)
Expand All @@ -270,6 +306,7 @@ end

"""
isgap(nt::NucleicAcid)
Test if `nt` is a gap.
"""
@inline function isgap(nt::NucleicAcid)
Expand All @@ -278,7 +315,24 @@ end

"""
complement(nt::NucleicAcid)
Return the complementary nucleotide of `nt`.
This function returns the union of all possible complementary nucleotides.
# Examples
```jldoctest
julia> complement(DNA_A)
DNA_T
julia> complement(DNA_N)
DNA_N
julia> complement(RNA_U)
RNA_A
```
"""
function complement(nt::NucleicAcid)
bits = compatbits(nt)
Expand All @@ -298,26 +352,49 @@ end

"""
iscompatible(x, y)
Return `true` if and only if `x` and `y` are compatible with each other (i.e.
`x` and `y` can be the same symbol).
Test if `x` and `y` are compatible with each other (i.e. `x` and `y` can be the same symbol).
`x` and `y` must be the same type (`DNA`, `RNA` or `AminoAcid`).
# Examples
```julia
```jldoctest
julia> iscompatible(DNA_A, DNA_A)
true
julia> iscompatible(DNA_C, DNA_N) # DNA_N can be DNA_C
true
julia> iscompatible(DNA_C, DNA_R) # DNA_R (A or G) cannot be DNA_C
false
julia> iscompatible(AA_A, AA_X) # AA_X can be AA_A
true
```
"""
@inline function iscompatible{T<:NucleicAcid}(x::T, y::T)
return compatbits(x) & compatbits(y) != 0
end

# Return the compatibility bits of `nt`.
"""
compatbits(nt::NucleicAcid)
Return the compatibility bits of `nt` as `UInt8`.
```jldoctest
julia> compatbits(DNA_A)
0x01
julia> compatbits(DNA_C)
0x02
julia> compatbits(DNA_N)
0x0f
```
"""
@inline function compatbits(nt::NucleicAcid)
return reinterpret(UInt8, nt)
end

0 comments on commit da0fb8f

Please sign in to comment.