コード例 #1
0
def test_bam_coverage_filter_blacklist():
    """
    Test --samFlagInclude --samFlagExclude --minMappingQuality --ignoreDuplicates and --blackListFileName
    """
    outfile = '/tmp/test_file_filter.bg'
    for fname in [BAMFILE_FILTER1, CRAMFILE_FILTER1]:
        args = "--bam {} --normalizeUsing RPGC --effectiveGenomeSize 1400 -p 1 -o {} -of bedgraph --samFlagInclude 512 " \
               "--samFlagExclude 256 --minMappingQuality 5 --ignoreDuplicates " \
               "--blackListFileName {}".format(fname, outfile, BEDFILE_FILTER)
        args = args.split()
        bam_cov.main(args)

        _foo = open(outfile, 'r')
        resp = _foo.readlines()
        _foo.close()

        expected = ['3R\t0\t100\t0\n', '3R\t100\t150\t1.42338\n',
                    '3R\t150\t250\t4.88017\n', '3R\t250\t300\t3.05011\n',
                    '3R\t300\t400\t2.23675\n', '3R\t400\t450\t3.86347\n',
                    '3R\t450\t500\t4.06681\n', '3R\t500\t550\t2.03341\n',
                    '3R\t550\t600\t2.44009\n', '3R\t600\t650\t4.47349\n',
                    '3R\t650\t700\t3.45679\n', '3R\t700\t750\t3.66013\n',
                    '3R\t750\t800\t4.06681\n', '3R\t900\t950\t2.44009\n',
                    '3R\t950\t1000\t1.62672\n', '3R\t1000\t1050\t0.813362\n',
                    '3R\t1050\t1500\t0\n']

        assert_equal(resp, expected)
        unlink(outfile)
コード例 #2
0
def test_bam_coverage_filter_blacklist():
    """
    Test --samFlagInclude --samFlagExclude --minMappingQuality --ignoreDuplicates and --blackListFileName
    """
    outfile = '/tmp/test_file_filter.bg'
    args = "--bam {} --normalizeTo1x 1400 -p 1 -o {} -of bedgraph --samFlagInclude 512 " \
           "--samFlagExclude 256 --minMappingQuality 5 --ignoreDuplicates " \
           "--blackListFileName {}".format(BAMFILE_FILTER1, outfile, BEDFILE_FILTER)
    args = args.split()
    bam_cov.main(args)

    _foo = open(outfile, 'r')
    resp = _foo.readlines()
    _foo.close()
    expected = [
        '3R\t0\t100\t0\n', '3R\t100\t150\t1.42338\n',
        '3R\t150\t250\t4.88017\n', '3R\t250\t300\t3.05011\n',
        '3R\t300\t400\t2.23675\n', '3R\t400\t450\t3.86347\n',
        '3R\t450\t500\t4.06681\n', '3R\t500\t550\t2.03341\n',
        '3R\t550\t600\t2.44009\n', '3R\t600\t650\t4.47349\n',
        '3R\t650\t700\t3.45679\n', '3R\t700\t750\t3.66013\n',
        '3R\t750\t800\t4.06681\n', '3R\t900\t950\t2.44009\n',
        '3R\t950\t1000\t1.62672\n', '3R\t1000\t1050\t0.813362\n',
        '3R\t1050\t1500\t0\n'
    ]

    assert_equal(resp, expected)
    unlink(outfile)
コード例 #3
0
def test_bam_coverage_extend():
    outfile = '/tmp/test_file.bg'
    args = "-b {} -o {} --extendReads 100 --outFileFormat bedgraph".format(BAMFILE_B, outfile).split()
    bam_cov.main(args)
    resp = open(outfile, 'r').readlines()

    assert resp == ['3R\t0\t150\t1.00\n', '3R\t150\t200\t3.0\n']
    unlink(outfile)
コード例 #4
0
def produce_bamCoverage(Type, bamFile, basenameNoExtension, NumberCpus,
                        binSize, blackListFileName, effectiveGenomeSize,
                        normalizeUsing):
    outFileBW = basenameNoExtension + "_" + Type + "_.bw"
    args_bamCoverage="-b {} -o {} --numberOfProcessors {} --binSize  {} --blackListFileName {} --effectiveGenomeSize {} --normalizeUsing {} " \
         "--outFileFormat bigwig".format(bamFile, outFileBW, NumberCpus, binSize, blackListFileName,effectiveGenomeSize,normalizeUsing).split()
    bamCoverage.main(args_bamCoverage)
    return outFileBW
コード例 #5
0
def test_bam_coverage_skipnas():
    outfile = '/tmp/test_file.bg'
    args = "--bam {} -o {} --outFileFormat bedgraph --skipNAs".format(BAMFILE_B, outfile).split()
    bam_cov.main(args)

    resp = open(outfile, 'r').readlines()
    expected = ['3R\t50\t150\t1.00\n', '3R\t150\t200\t2.0\n']
    assert resp == expected, "{} != {}".format(resp, expected)
    unlink(outfile)
コード例 #6
0
ファイル: bedgraph_handling.py プロジェクト: rluis/BamInsight
def createBedGraphFile(bamFileSorted, cpus):
    basenameNoExtension = os.path.splitext(os.path.basename(bamFileSorted))[0]
    inputNameBAM = os.path.abspath(bamFileSorted)
    outNameBW = basenameNoExtension + ".bedgraph"

    args_bamCoverage = "-b {} -o {} --numberOfProcessors {} --binSize 1 " \
                       "--outFileFormat bedgraph".format(inputNameBAM, outNameBW, cpus).split()

    bamCoverage.main(args_bamCoverage)
    return basenameNoExtension + ".bedgraph"
コード例 #7
0
def test_bam_coverage_extend():
    outfile = '/tmp/test_file.bg'
    args = "-b {} -o {} --extendReads 100 --outFileFormat bedgraph".format(BAMFILE_B, outfile).split()
    bam_cov.main(args)
    _foo = open(outfile, 'r')
    resp = _foo.readlines()
    _foo.close()
    expected = ['3R\t0\t150\t1\n', '3R\t150\t200\t3\n']
    assert_equal(resp, expected)
    unlink(outfile)
コード例 #8
0
def test_bam_coverage_filtering():
    outfile = '/tmp/test_file.bg'
    args = "--bam {} -o {} --outFileFormat bedgraph --ignoreDuplicates --verbose".format(BAMFILE_B, outfile).split()
    bam_cov.main(args)

    _foo = open(outfile, 'r')
    resp = _foo.readlines()
    _foo.close()
    expected = ['3R\t0\t50\t0\n', '3R\t50\t200\t1\n']
    assert_equal(resp, expected)
    unlink(outfile)
コード例 #9
0
def test_bam_coverage_extend():
    outfile = '/tmp/test_file.bg'
    args = "-b {} -o {} --extendReads 100 --outFileFormat bedgraph".format(
        BAMFILE_B, outfile).split()
    bam_cov.main(args)
    _foo = open(outfile, 'r')
    resp = _foo.readlines()
    _foo.close()
    expected = ['3R\t0\t150\t1\n', '3R\t150\t200\t3\n']
    assert_equal(resp, expected)
    unlink(outfile)
コード例 #10
0
def test_bam_coverage_extend_and_normalizeto1x():

    outfile = '/tmp/test_file.bg'
    args = "-b {} -o {} --normalizeTo1x 200 --extendReads 100 " \
           "--outFileFormat bedgraph".format(BAMFILE_B, outfile).split()
    bam_cov.main(args)
    resp = open(outfile, 'r').readlines()
    # the scale factor should be 0.5, thus the result is similar to
    # that of the previous test divided by 0.5
    expected = ['3R\t0\t150\t0.50\n', '3R\t150\t200\t1.5\n']
    assert resp == expected, "{} != {}".format(resp, expected)
    unlink(outfile)
コード例 #11
0
def test_bam_coverage_arguments():
    """
    Test minimal command line args for bamCoverage
    """
    outfile = '/tmp/test_file.bg'
    args = "--bam {} -o {} --outFileFormat bedgraph".format(BAMFILE_B, outfile).split()
    bam_cov.main(args)

    resp = open(outfile, 'r').readlines()
    expected = ['3R\t0\t50\t0.00\n', '3R\t50\t150\t1.00\n', '3R\t150\t200\t2.0\n']
    assert resp == expected, "{} != {}".format(resp, expected)
    unlink(outfile)
コード例 #12
0
def test_bam_coverage_skipnas():
    outfile = '/tmp/test_file.bg'
    for fname in [BAMFILE_B, CRAMFILE_B]:
        args = "--bam {} -o {} --outFileFormat bedgraph --skipNAs".format(fname, outfile).split()
        bam_cov.main(args)

        _foo = open(outfile, 'r')
        resp = _foo.readlines()
        _foo.close()
        expected = ['3R\t50\t150\t1\n', '3R\t150\t200\t2\n']
        assert_equal(resp, expected)
        unlink(outfile)
コード例 #13
0
def test_bam_coverage_skipnas():
    outfile = '/tmp/test_file.bg'
    args = "--bam {} -o {} --outFileFormat bedgraph --skipNAs".format(
        BAMFILE_B, outfile).split()
    bam_cov.main(args)

    _foo = open(outfile, 'r')
    resp = _foo.readlines()
    _foo.close()
    expected = ['3R\t50\t150\t1\n', '3R\t150\t200\t2\n']
    assert_equal(resp, expected)
    unlink(outfile)
コード例 #14
0
def test_bam_coverage_filtering():
    outfile = '/tmp/test_file.bg'
    for fname in [BAMFILE_B, CRAMFILE_B]:
        args = "--bam {} -o {} --outFileFormat bedgraph --ignoreDuplicates --verbose".format(
            fname, outfile).split()
        bam_cov.main(args)

        _foo = open(outfile, 'r')
        resp = _foo.readlines()
        _foo.close()
        expected = ['3R\t0\t50\t0\n', '3R\t50\t200\t1\n']
        assert_equal(resp, expected)
        unlink(outfile)
コード例 #15
0
def test_bam_coverage_arguments():
    """
    Test minimal command line args for bamCoverage
    """
    outfile = '/tmp/test_file.bg'
    args = "--bam {} -o {} --outFileFormat bedgraph".format(BAMFILE_B, outfile).split()
    bam_cov.main(args)

    _foo = open(outfile, 'r')
    resp = _foo.readlines()
    _foo.close()
    expected = ['3R\t0\t50\t0\n', '3R\t50\t150\t1\n', '3R\t150\t200\t2\n']
    assert_equal(resp, expected)
    unlink(outfile)
コード例 #16
0
def test_bam_coverage_offset20_minus4():
    """
    Test -bs 1 --Offset 20 -4
    """
    outfile = '/tmp/test_offset.bw'
    args = "--Offset 20 -4 -b {} -p 1 -bs 1 -o {}".format(BAMFILE_A, outfile)
    args = args.split()
    bam_cov.main(args)
    try:
        # python 3 only
        filecmp.clear_cache()
    except:
        pass
    assert(filecmp.cmp(outfile, "{}testA_offset20_-4.bw".format(ROOT)) is True)
    unlink(outfile)
コード例 #17
0
def test_bam_coverage_extend_and_normalizeUsingRPGC():

    outfile = '/tmp/test_file.bg'
    for fname in [BAMFILE_B, CRAMFILE_B]:
        args = "-b {} -o {} --normalizeUsing RPGC --effectiveGenomeSize 200 --extendReads 100 " \
               "--outFileFormat bedgraph".format(fname, outfile).split()
        bam_cov.main(args)
        _foo = open(outfile, 'r')
        resp = _foo.readlines()
        _foo.close()
        # the scale factor should be 0.5, thus the result is similar to
        # that of the previous test divided by 0.5
        expected = ['3R\t0\t150\t0.5\n', '3R\t150\t200\t1.5\n']
        assert_equal(resp, expected)
        unlink(outfile)
コード例 #18
0
def test_bam_coverage_offset_minus1():
    """
    Test -bs 1 --Offset -1
    """
    outfile = '/tmp/test_offset.bw'
    args = "--Offset -1 -b {} -p 1 -bs 1 -o {}".format(BAMFILE_A, outfile)
    args = args.split()
    bam_cov.main(args)
    try:
        # python 3 only
        filecmp.clear_cache()
    except:
        pass
    assert (filecmp.cmp(outfile, "{}testA_offset-1.bw".format(ROOT)) is True)
    unlink(outfile)
コード例 #19
0
def test_bam_coverage_arguments():
    """
    Test minimal command line args for bamCoverage
    """
    outfile = '/tmp/test_file.bg'
    args = "--bam {} -o {} --outFileFormat bedgraph".format(
        BAMFILE_B, outfile).split()
    bam_cov.main(args)

    _foo = open(outfile, 'r')
    resp = _foo.readlines()
    _foo.close()
    expected = ['3R\t0\t50\t0\n', '3R\t50\t150\t1\n', '3R\t150\t200\t2\n']
    assert_equal(resp, expected)
    unlink(outfile)
コード例 #20
0
def test_bam_coverage_extend_and_normalizeUsingRPGC():

    outfile = '/tmp/test_file.bg'
    for fname in [BAMFILE_B, CRAMFILE_B]:
        args = "-b {} -o {} --normalizeUsing RPGC --effectiveGenomeSize 200 --extendReads 100 " \
               "--outFileFormat bedgraph".format(fname, outfile).split()
        bam_cov.main(args)
        _foo = open(outfile, 'r')
        resp = _foo.readlines()
        _foo.close()
        # the scale factor should be 0.5, thus the result is similar to
        # that of the previous test divided by 0.5
        expected = ['3R\t0\t150\t0.5\n', '3R\t150\t200\t1.5\n']
        assert_equal(resp, expected)
        unlink(outfile)
コード例 #21
0
def test_bam_coverage_offset_minus1():
    """
    Test -bs 1 --Offset -1
    """
    outfile = '/tmp/test_offset.bw'
    for fname in [BAMFILE_A, CRAMFILE_A]:
        args = "--Offset -1 -b {} -p 1 -bs 1 -o {}".format(fname, outfile)
        args = args.split()
        bam_cov.main(args)
        try:
            # python 3 only
            filecmp.clear_cache()
        except:
            pass
        assert(filecmp.cmp(outfile, "{}testA_offset-1.bw".format(ROOT)) is True)
        unlink(outfile)
コード例 #22
0
def test_bam_coverage_offset20_minus4():
    """
    Test -bs 1 --Offset 20 -4
    """
    outfile = '/tmp/test_offset.bw'
    for fname in [BAMFILE_A, CRAMFILE_A]:
        args = "--Offset 20 -4 -b {} -p 1 -bs 1 -o {}".format(fname, outfile)
        args = args.split()
        bam_cov.main(args)
        try:
            # python 3 only
            filecmp.clear_cache()
        except:
            pass
        assert (filecmp.cmp(outfile, "{}testA_offset20_-4.bw".format(ROOT)) is
                True)
        unlink(outfile)