File: test_samtools_python.py

package info (click to toggle)
python-pysam 0.15.2%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 17,604 kB
  • sloc: ansic: 125,787; python: 7,782; sh: 284; makefile: 222; perl: 41
file content (46 lines) | stat: -rw-r--r-- 1,875 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import pysam
import os
from TestUtils import BAM_DATADIR


def test_idxstats_parse_split_lines():
    bam_filename = os.path.join(BAM_DATADIR, "ex2.bam")
    # Test pysam 0.8.X style output, which returns a list of lines
    lines = pysam.idxstats(bam_filename, split_lines=True)
    for line in lines:
        _seqname, _seqlen, nmapped, _nunmapped = line.split()


def test_bedcov_split_lines():
    bam_filename = os.path.join(BAM_DATADIR, "ex1.bam")
    bed_filename = os.path.join(BAM_DATADIR, "ex1.bed")
    # Test pysam 0.8.X style output, which returns a list of lines
    lines = pysam.bedcov(bed_filename, bam_filename, split_lines=True)
    for line in lines:
        fields = line.split('\t')
        assert len(fields) in [4, 5], \
            ("bedcov should give tab delimited output with 4 or 5 fields. "
             "Split line (%s) gives %d fields." % (fields, len(fields)))


def test_idxstats_parse():
    bam_filename = os.path.join(BAM_DATADIR, "ex2.bam")
    # Test pysam 0.9.X style output, which returns a string that needs to be split by \n
    idxstats_string = pysam.idxstats(bam_filename, split_lines=False)
    lines = idxstats_string.splitlines()
    for line in lines:
        splt = line.split("\t")
        _seqname, _seqlen, nmapped, _nunmapped = splt


def test_bedcov():
    bam_filename = os.path.join(BAM_DATADIR, "ex1.bam")
    bed_filename = os.path.join(BAM_DATADIR, "ex1.bed")
    # Test pysam 0.9.X style output, which returns a string that needs to be split by \n
    bedcov_string = pysam.bedcov(bed_filename, bam_filename, split_lines=False)
    lines = bedcov_string.splitlines()
    for line in lines:
        fields = line.split('\t')
        assert len(fields) in [4, 5], \
            ("bedcov should give tab delimited output with 4 or 5 fields. "
             "Split line (%s) gives %d fields." % (fields, len(fields)))