def test_hamming_expansion_collisions(self):

        b = barcodeFileParser.BarcodeParser()
        b.addBarcode(barcodeFileAlias='test', barcode='AAA', index='TEST1')
        b.addBarcode(barcodeFileAlias='test', barcode='AAT', index='TEST2')
        b.addBarcode(barcodeFileAlias='test', barcode='TTT', index='TEST3')

        b.expand(2, 'test')
        index, barcode, hd = b.getIndexCorrectedBarcodeAndHammingDistance(
            'AAG', 'test')
        self.assertIsNone(index)
        index, barcode, hd = b.getIndexCorrectedBarcodeAndHammingDistance(
            'AAG', 'test')
        self.assertIsNone(index)
        index, barcode, hd = b.getIndexCorrectedBarcodeAndHammingDistance(
            'TCA', 'test')
        self.assertIsNone(index)

        index, barcode, hd = b.getIndexCorrectedBarcodeAndHammingDistance(
            'AAA', 'test')
        self.assertEqual(index, 'TEST1')
        self.assertEqual(barcode, 'AAA')
        self.assertEqual(hd, 0)

        index, barcode, hd = b.getIndexCorrectedBarcodeAndHammingDistance(
            'TAA', 'test')
        self.assertEqual(index, 'TEST1')
        self.assertEqual(barcode, 'AAA')
        self.assertEqual(hd, 1)
    def test_insert(self):

        b = barcodeFileParser.BarcodeParser()

        b.addBarcode(barcodeFileAlias='test', barcode='AAA', index='TEST1')

        index, barcode, hd = b.getIndexCorrectedBarcodeAndHammingDistance(
            'AAA', 'test')
        self.assertEqual(index, 'TEST1')
        self.assertEqual(barcode, 'AAA')
        self.assertEqual(hd, 0)
    def test_hamming_expansion(self):

        b = barcodeFileParser.BarcodeParser()
        b.addBarcode(barcodeFileAlias='test', barcode='AAA', index='TEST1')
        b.addBarcode(barcodeFileAlias='test', barcode='AAT', index='TEST2')
        b.addBarcode(barcodeFileAlias='test', barcode='TTT', index='TEST3')

        b.expand(2, 'test')
        index, barcode, hd = b.getIndexCorrectedBarcodeAndHammingDistance(
            'CTC', 'test')
        self.assertEqual(index, 'TEST3')
        self.assertEqual(barcode, 'TTT')
        self.assertEqual(hd, 2)
    def test_hamming_expansion(self):

        b = barcodeFileParser.BarcodeParser()
        b.addBarcode(barcodeFileAlias='test', barcode='AAA', index='TEST1')
        b.expand(1, 'test')
        # Postive examples:
        for positive in ['AAT', 'CAA', 'AGA', 'TAA']:
            index, barcode, hd = b.getIndexCorrectedBarcodeAndHammingDistance(
                positive, 'test')
            self.assertEqual(index, 'TEST1')
            self.assertEqual(barcode, 'AAA')
            self.assertEqual(hd, 1)

        #Negative examples
        for negative in ['TAT', 'CCA', 'GGA', 'TCA']:
            index, barcode, hd = b.getIndexCorrectedBarcodeAndHammingDistance(
                negative, 'test')
            self.assertNotEqual(barcode, 'AAA')
        if not args.fastqfiles[0].endswith(
                '.gz') and not args.fastqfiles[0].endswith(
                    '.fastq') and not args.fastqfiles[0].endswith('.fq'):
            # File list:
            print('Input is interpreted as a list of files..')
            with open(args.fastqfiles[0]) as f:
                fqFiles = []
                for line in f:
                    fqFiles.append(line.strip())
            args.fastqfiles = fqFiles

    # Sort the fastq files..
    args.fastqfiles = sorted(args.fastqfiles)

    # Load barcodes
    barcodeParser = barcodeFileParser.BarcodeParser(
        hammingDistanceExpansion=args.hd, barcodeDirectory=args.barcodeDir)

    # Setup the index parser
    indexFileAlias = args.ifa  # let the multiplex methods decide which index file to use

    if args.si:  # the user defines the sequencing indices
        useSequencingIndices = args.si.split(',')
        print(
            f"{Style.BRIGHT} Only these sequencing indices will be kept: {Style.RESET_ALL}"
        )
        for sequencingIndex in useSequencingIndices:
            print(f"{Fore.GREEN}{sequencingIndex}{Style.RESET_ALL}")

        indexParser = barcodeFileParser.BarcodeParser()
        indexFileAlias = 'user'
        for index, sequencingIndex in enumerate(useSequencingIndices):
示例#6
0
import pkg_resources
import singlecellmultiomics.barcodeFileParser.barcodeFileParser as barcodeFileParser
from singlecellmultiomics.modularDemultiplexer.demultiplexingStrategyLoader import DemultiplexingStrategyLoader
import singlecellmultiomics.libraryDetection.sequencingLibraryListing as sequencingLibraryListing
import glob
import fnmatch
import os
from types import SimpleNamespace

if __name__ == '__main__':
    barcode_dir = pkg_resources.resource_filename(
        'singlecellmultiomics', 'modularDemultiplexer/barcodes/')
    index_dir = pkg_resources.resource_filename(
        'singlecellmultiomics', 'modularDemultiplexer/indices/')

    barcode_parser = barcodeFileParser.BarcodeParser(
        hammingDistanceExpansion=0, barcodeDirectory=barcode_dir)
    index_parser = barcodeFileParser.BarcodeParser(hammingDistanceExpansion=1,
                                                   barcodeDirectory=index_dir)

    dmx = DemultiplexingStrategyLoader(barcodeParser=barcode_parser,
                                       indexParser=index_parser,
                                       indexFileAlias=None)

    argparser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        description="""Check multiplexability of many fastq files""")

    argparser.add_argument('-locations', default='.')

    arguments = argparser.parse_args()
    sequencing_dirs = arguments.locations.split(',')