INNER CODE UNIT · Python
correct_barcodes
timoast/sinto · sinto/addbarcodes.py:12
def correct_barcodes(barcodes, whitelist):
"""
Use a whitelist computed with some external tool (such as UMI-tools)
to correct the barcodes. This could be useful whenever the fastq file with
cell barcodes does not contain corrected barcodes.
"""
if type(whitelist) == dict:
# whitelist is derived from UMI-tools
# create a dict where everything is corrected to itself
u_barcodes = set(barcodes)
corrected = dict(zip(u_barcodes, u_barcodes))
# iterate over whitelist to add actual corrections where possible
for bc in whitelist:
for rbc in whitelist[bc]:
corrected[rbc] = bc
else:
# whitelist is just a list of cell barcodes, hence
# we need to perform corrections