Sequence operations
Importing polars_bio registers a seq namespace on every Polars expression.
See Sequence operations for usage and the reference
tools each function matches.
Sequence operations, available as pl.col(...).seq.
Source code in polars_bio/seq.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
revcomp(alphabet='dna', strict=False)
Reverse complement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alphabet
|
str
|
|
'dna'
|
strict
|
bool
|
Raise |
False
|
Example
Source code in polars_bio/seq.py
reverse()
Reverse a string, for example a FASTQ quality alongside :meth:revcomp.
Equivalent to str.reverse() for sequence and quality data, but
much faster: it reverses ASCII bytes directly instead of Unicode
grapheme clusters. A multi-byte character is kept whole.
Example
Source code in polars_bio/seq.py
complement(alphabet='dna', strict=False)
Complement, without reversing. Same rules as :meth:revcomp.
Source code in polars_bio/seq.py
gc_content(denominator='length')
GC fraction between 0 and 1, as Float64.
Counts G and C in either case (not S, like every reference tool).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
denominator
|
str
|
|
'length'
|
Source code in polars_bio/seq.py
translate(frame=1, table=1, to_stop=False)
Translate nucleotides to amino acids.
A trailing partial codon is dropped and stops are *. An ambiguous
codon gives an amino acid only when every base it can stand for
agrees, otherwise X. Three gap characters give -; any other
unreadable codon gives X.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame
|
int
|
1, 2 or 3, or -1, -2, -3 to read the reverse complement. |
1
|
table
|
int
|
NCBI translation table id. |
1
|
to_stop
|
bool
|
End the protein before the first stop codon. |
False
|
Source code in polars_bio/seq.py
mean_quality(offset=33, method='error_prob')
Mean Phred quality of a quality string, as Float64.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
offset
|
int
|
Phred offset, 33 (Sanger/Illumina 1.8+) or 64. A byte
below it raises |
33
|
method
|
str
|
|
'error_prob'
|
Source code in polars_bio/seq.py
SQL functions
The same kernels are available in pb.sql as scalar functions.
Optional arguments are positional constants.
| Function | Optional arguments | Returns |
|---|---|---|
seq_revcomp(seq) |
alphabet = 'dna', strict = false |
the input's string type |
seq_reverse(seq) |
โ | the input's string type |
seq_complement(seq) |
alphabet = 'dna', strict = false |
the input's string type |
seq_gc_content(seq) |
denominator = 'length' |
DOUBLE |
seq_translate(seq) |
frame = 1, table = 1, to_stop = false |
the input's string type |
seq_mean_quality(qual) |
offset = 33, method = 'error_prob' |
DOUBLE |