AlignmentTagger
An object to facilitate adding tags to alignments in a bam file
AlignmentTagger
¶
Bases: BarcodeParser
Given an indexed fasta file (genome), id length and insertion length, this object can returned a read tagged with the RG, XS and XZ tags
Source code in callingcardstools/Alignment/AlignmentTagger.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
fasta: str
property
writable
¶
path to the fasta file. The index .fai file MUST BE in the same directory
genome
deletable
property
writable
¶
pysam FastaFile object
__del__()
¶
ensure that the genome file is closed when deleted
Source code in callingcardstools/Alignment/AlignmentTagger.py
42 43 44 |
|
__init__(barcode_details_json, fasta_path)
¶
Initializes the AlignmentTagger object with given barcode details and a fasta file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
barcode_details_json |
str
|
The path to a JSON file containing barcode details. |
required |
fasta_path |
str
|
The path to the genome fasta file. A .fai index file created by samtools faidx must exist at the same location. |
required |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
Raised if the path to the fasta file or its index file doesn’t exist. |
Source code in callingcardstools/Alignment/AlignmentTagger.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
close()
¶
close the genome file
Source code in callingcardstools/Alignment/AlignmentTagger.py
88 89 90 |
|
extract_tag_dict(id)
¶
given an id string created by ReadParser, parse into a dictionary of tags
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id |
str
|
id line from a given read in a bam produced from a fastq processed by (a script that uses) the ReadParser |
required |
Raises:
Type | Description |
---|---|
IndexError
|
Raised if parsing of the id doesn’t work as expected |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
For example, the id line MN00200:647:000H533KW:1:11102:20080:1075_RT-AATTCACTACGTCAACA;RS-TaqAI;TF-ERT1 would be returned as {‘RT’: ‘AATTCACTACGTCAACA’, ‘RS’: ‘TaqAI’, ‘TF’: ‘ERT1’} |
Source code in callingcardstools/Alignment/AlignmentTagger.py
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 |
|
is_open()
¶
check if genome file is open
Source code in callingcardstools/Alignment/AlignmentTagger.py
84 85 86 |
|
open()
¶
open the genome file and set the self.genome attribute
Source code in callingcardstools/Alignment/AlignmentTagger.py
80 81 82 |
|
tag_read(read, decompose_barcode=True)
¶
given a AlignedSegment object, add RG, XS and XZ tags
Parameters:
Name | Type | Description | Default |
---|---|---|---|
read |
AlignedSegment
|
An aligned segment object – eg returned in a for loop by interating over bam.fetch() object from pysam |
required |
decompose_barcode |
bool
|
if the barcode is appended as a read identifer on the bam id line, rather than an already decomposed tag string, then extract the barcode and evaluate it against expectations in the barcode_details json. Default to True. |
True
|
Raises:
Type | Description |
---|---|
IndexError
|
Raised if no read ID is present. |
TypeError
|
Raised with the cigarstring is not parse-able in a given read |
ValueError
|
Raised when the insertion sequence indicies are out of bounds |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary with key:value pairs {‘read’: tagged_read, ‘barcode_details’: dictionary of barcode detals} |
Source code in callingcardstools/Alignment/AlignmentTagger.py
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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|