Skip to content

Commit

Permalink
Hotfix for some correct stats and parsing model info from bam heade…
Browse files Browse the repository at this point in the history
…rs (#126)

* Fixing barcode corrected stats in the case of padded barcodes.
* Fixed header parsing for model information.
  • Loading branch information
jonn-smith authored Jun 27, 2022
1 parent 4bba69f commit 022f39a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/longbow/correct/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,14 @@ def _correct_barcode_fn(in_queue, out_queue, bam_header_dict, barcode_tag, corre
if new_bc is not None:
read.set_tag(corrected_tag, new_bc)
read.set_tag(longbow.utils.constants.COULD_CORRECT_BARCODE_TAG, True)
read.set_tag(longbow.utils.constants.BARCODE_CORRECTION_PERFORMED, new_bc != old_bc)

# Need to do some basic math for padded barcode strings:
if len(old_bc) > barcode_length:
end_pad_bases = int((len(old_bc) - barcode_length)/2)
correction_performed = new_bc != old_bc[end_pad_bases:end_pad_bases+barcode_length]
else:
correction_performed = new_bc != old_bc
read.set_tag(longbow.utils.constants.BARCODE_CORRECTION_PERFORMED, correction_performed)

read.set_tag(longbow.utils.constants.READ_ADJUSTED_BARCODE_START, offset)

Expand Down
11 changes: 7 additions & 4 deletions src/longbow/utils/bam_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,13 @@ def get_model_from_bam_header(header):
def get_models_from_bam_header(header):
model_jsons = []
for pg in header.as_dict()['PG']:
if pg['PN'] == 'longbow' and 'annotate' in pg['ID']:
desc, models_str= pg['DS'].split('MODEL(s): ')
model_json = json.loads(models_str)
model_jsons.append(model_json)
try:
if pg['PN'] == 'longbow' and (pg['ID'].startswith('longbow-annotate') or pg['ID'].startswith('longbow-pad')):
desc, models_str = pg['DS'].split('MODEL(s): ')
model_json = json.loads(models_str)
model_jsons.append(model_json)
except KeyError:
continue

return model_jsons

Expand Down

0 comments on commit 022f39a

Please sign in to comment.