<commit_before>#! /usr/bin/env python

__author__ = '<NAME>'
__email__ = '<EMAIL>'

from pbcore.io.BarcodeH5Reader import BarcodeH5Fofn, BarcodeH5Reader
from pbhla.utils import validate_file

def get_barcode_reader( barcode_file ):
    barcode_file = validate_file( barcode_file )
    if barcode_file.endswith('.fofn'):
        return BarcodeH5Fofn( barcode_file )
    elif barcode_file.endswith('.bc.h5'):
        return BarcodeH5Reader( barcode_file )
    else:
        raise ValueError

def barcode_string_to_list( barcode_string ):
    if barcode_string is None:
        return None
    barcodes = barcode_string.split(',')
    return [format_barcode(b) for b in barcodes]

def format_barcode( barcode ):
    if '--' in barcode:
        return barcode
    else:
        return 'F{0}--R{0}'.format( barcode )

def get_barcodes( bc_reader, bc_string ):
    barcodes = barcode_string_to_list( bc_string )
    for label in bc_reader.barcodeLabels:
        print barcodes, label<commit_msg>Finished get_barcodes function<commit_after>#! /usr/bin/env python

__author__ = '<NAME>'
__email__ = '<EMAIL>'

import logging

from pbcore.io.BarcodeH5Reader import BarcodeH5Fofn, BarcodeH5Reader
from pbhla.utils import validate_file

log = logging.getLogger()

def get_barcode_reader( barcode_file ):
    barcode_file = validate_file( barcode_file )
    if barcode_file.endswith('.fofn'):
        return BarcodeH5Fofn( barcode_file )
    elif barcode_file.endswith('.bc.h5'):
        return BarcodeH5Reader( barcode_file )
    else:
        raise ValueError

def barcode_string_to_list( barcode_string ):
    if barcode_string is None:
        return None
    barcodes = barcode_string.split(',')
    return [format_barcode(b) for b in barcodes]

def format_barcode( barcode ):
    if '--' in barcode:
        return barcode
    else:
        return 'F{0}--R{0}'.format( barcode )

def get_barcodes( bc_reader, bc_string ):
    barcodes = barcode_string_to_list( bc_string )

    # If no barcodes specified, return them all
    if barcodes is None:
        return bc_reader.barcodeLabels

    # Otherwise return the intersection and warn if missing
    bc_list = []
    for bc in barcodes:
        if bc in bc_reader.barcodeLabels:
            bc_list.append( bc )
        else:
            log.warn('Barcode "%s" requested but not found, skipping' % bc)
    return bc_list
{'fraction_non_alphanumeric': 0.08964059196617336, 'fraction_numerical': 0.006765327695560253, 'mean_word_length': 3.3018181818181818, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4981126', 'n_tokens_mistral': 791, 'n_tokens_neox': 800, 'n_words': 197}