| 1 |
# pyabpoa: abPOA Python interface |
| 2 |
## Introduction |
| 3 |
pyabpoa provides an easy-to-use interface to [abPOA](https://github.com/yangao07/abPOA), it contains all the APIs that can be used to perform MSA for a set of sequences and consensus calling from the final alignment graph. |
| 4 |
|
| 5 |
## Installation |
| 6 |
|
| 7 |
### Install pyabpoa with pip |
| 8 |
|
| 9 |
pyabpoa can be installed with pip: |
| 10 |
|
| 11 |
``` |
| 12 |
pip install pyabpoa |
| 13 |
``` |
| 14 |
|
| 15 |
### Install pyabpoa from source |
| 16 |
Alternatively, you can install pyabpoa from source (cython is required): |
| 17 |
``` |
| 18 |
git clone --recursive https://github.com/yangao07/abPOA.git |
| 19 |
cd abPOA |
| 20 |
make install_py |
| 21 |
``` |
| 22 |
|
| 23 |
## Examples |
| 24 |
The following code illustrates how to use pyabpoa. |
| 25 |
``` |
| 26 |
import pyabpoa as pa |
| 27 |
a = pa.msa_aligner() |
| 28 |
seqs=[ |
| 29 |
'CCGAAGA', |
| 30 |
'CCGAACTCGA', |
| 31 |
'CCCGGAAGA', |
| 32 |
'CCGAAGA' |
| 33 |
] |
| 34 |
a_res=a.msa(seqs, out_cons=True, out_msa=True) # perform multiple sequence alignment |
| 35 |
|
| 36 |
for seq in a_res.cons_seq: |
| 37 |
print(seq) # print consensus sequence |
| 38 |
|
| 39 |
a_res.print_msa() # print row-column multiple sequence alignment in PIR format |
| 40 |
|
| 41 |
# incrementally add new seqs |
| 42 |
new_seqs=[ |
| 43 |
'CCAGA', |
| 44 |
'CCGAAAGA' |
| 45 |
] |
| 46 |
b = pa.msa_aligner() |
| 47 |
b.msa_align(seqs, out_cons=True, out_msa=True) |
| 48 |
b.msa_add(new_seqs) |
| 49 |
b_res = b.msa_output() |
| 50 |
b_res.print_msa() |
| 51 |
``` |
| 52 |
You can also try the example script provided in the source folder: |
| 53 |
``` |
| 54 |
python ./python/example.py |
| 55 |
``` |
| 56 |
|
| 57 |
|
| 58 |
## APIs |
| 59 |
|
| 60 |
### Class pyabpoa.msa_aligner |
| 61 |
``` |
| 62 |
pyabpoa.msa_aligner(aln_mode='g', ...) |
| 63 |
``` |
| 64 |
This constructs a multiple sequence alignment handler of pyabpoa, it accepts the following arguments: |
| 65 |
|
| 66 |
* **aln_mode**: alignment mode. 'g': global, 'l': local, 'e': extension; default: **'g'** |
| 67 |
* **is_aa**: input is amino acid sequence; default: **False** |
| 68 |
* **match**: match score; default: **2** |
| 69 |
* **mismatch**: match penaty; default: **4** |
| 70 |
* **score_matrix**: scoring matrix file, **match** and **mismatch** are not used when **score_matrix** is used; default: **''** |
| 71 |
* **gap_open1**: first gap opening penalty; default: **4** |
| 72 |
* **gap_ext1**: first gap extension penalty; default: **2** |
| 73 |
* **gap_open2**: second gap opening penalty; default: **24** |
| 74 |
* **gap_ext2**: second gap extension penalty; default: **1** |
| 75 |
* **extra_b**: first adaptive banding paremeter; set as < 0 to disable adaptive banded DP; default: **10** |
| 76 |
* **extra_f**: second adaptive banding paremete; the number of extra bases added on both sites of the band is *b+f\*L*, where *L* is the length of the aligned sequence; default : **0.01** |
| 77 |
* **cons_algrm**: consensus calling algorithm. 'HB': heaviest bunlding, 'MF': most frequent bases; default: **'HB'** |
| 78 |
|
| 79 |
The `msa_aligner` handler provides one method `msa` which performs multiple sequence alignment and accepts the following arguments: |
| 80 |
``` |
| 81 |
pyabpoa.msa_aligner.msa(seqs, out_cons, out_msa, out_pog='', incr_fn='', qscores=None) |
| 82 |
``` |
| 83 |
|
| 84 |
* **seqs**: a list variable containing a set of input sequences; **positional** |
| 85 |
* **out_cons**: a bool variable to ask pyabpoa to generate consensus sequence; **positional** |
| 86 |
* **out_msa**: a bool variable to ask pyabpoa to generate RC-MSA; **positional** |
| 87 |
* **max_n_cons**: maximum number of consensus sequence to generate; default: **1** |
| 88 |
* **min_freq**: minimum frequency of each consensus to output (effective when **max_n_cons** > 1); default: **0.3** |
| 89 |
* **out_pog**: name of a file (`.png` or `.pdf`) to store the plot of the final alignment graph; default: **''** |
| 90 |
* **incr_fn**: name of an existing graph (GFA) or MSA (FASTA) file, incrementally align sequence to this graph/MSA; default: **''** |
| 91 |
* **qscores**: optional per-sequence quality information used to weight the consensus graph. Each entry must match the corresponding sequence length and should be a list of integer Phred scores, e.g. `record.letter_annotations["phred_quality"]` from Biopython; default: **None** |
| 92 |
|
| 93 |
When `qscores` is provided, pyabpoa enables quality-weighted consensus (`use_qv`) for that run. This is effective for heaviest-bundling consensus (`cons_algrm='HB'`), matching the CLI `-Q/--use-qual-weight` behavior. |
| 94 |
|
| 95 |
`msa_aligner` also provides three methods for incrementally adding sequences to graph/MSA: |
| 96 |
|
| 97 |
``` |
| 98 |
pyabpoa.msa_aligner.msa_align(seqs, out_cons, out_msa, max_n_cons=1, min_freq=0.25, incr_fn=b'', qscores=None) |
| 99 |
pyabpoa.msa_aligner.msa_add(new_seqs, qscores=None) |
| 100 |
pyabpoa.msa_aligner.msa_output() |
| 101 |
``` |
| 102 |
|
| 103 |
Intuitively, `msa()` = `msa_align()`+`msa_add()`+`msa_output()`. |
| 104 |
|
| 105 |
To collect consenus sequence and RC-MSA result, `msa_output()` needs to be called after `msa_align()` and `msa_add()`, which returns an object of `pyabpoa.msa_result`. |
| 106 |
|
| 107 |
### Class pyabpoa.msa_result |
| 108 |
``` |
| 109 |
pyabpoa.msa_result(seq_n, cons_n, cons_len, ...) |
| 110 |
``` |
| 111 |
This class describes the information of the generated consensus sequence and the RC-MSA. The returned result of `pyabpoa.msa_aligner.msa()` is an object of this class that has the following properties: |
| 112 |
|
| 113 |
* **n_seq**: number of input aligned sequences |
| 114 |
* **n_cons**: number of generated consensus sequences (generally 1, could be 2 or more if **max_n_cons** is set as > 1) |
| 115 |
* **clu_n_seq**: an array of sequence cluster size |
| 116 |
* **cons_len**: an array of consensus sequence length(s) |
| 117 |
* **cons_seq**: an array of consensus sequence(s) |
| 118 |
* **cons_cov**: an array of consensus sequence coverage for each base |
| 119 |
* **cons_qv**: an array of consensus quality strings in FASTQ encoding |
| 120 |
* **msa_len**: size of each row in the RC-MSA |
| 121 |
* **msa_seq**: an array containing `n_seq`+`n_cons` strings that demonstrates the RC-MSA, each consisting of one input sequence and several `-` indicating the alignment gaps. |
| 122 |
|
| 123 |
`pyabpoa.msa_result()` has a function of `print_msa` which prints the RC-MSA to screen. |
| 124 |
|
| 125 |
``` |
| 126 |
pyabpoa.msa_result().print_msa() |
| 127 |
``` |