from sequana.bamtools import BAM

import os
from . import data
pathdata = data.__path__[0]


def test_bam():
    s = BAM(pathdata + os.sep + "test.bam")
    assert len(s) == 432

    assert len(list(s.iter_unmapped_reads())) == 432
    s.reset()
    assert len(list(s.iter_mapped_reads())) == 0
    s.reset()

    assert s.get_read_names()[0] == 'HISEQ:426:C5T65ACXX:5:2302:1943:2127'

    s.get_stats()

@@ -29,34 +29,61 @@
  BAM
-%0A%0Aim
+, Alignment, SAMFlags, BAMRe
 port
- os
 %0Afrom 
-.
+sequana
  import 
 data
@@ -82,40 +82,50 @@
 ort 
-data%0Apathdata = data.__path__%5B0%5D
+sequana_data%0Afrom easydev import TempFile%0A
 %0A%0A%0Ad
@@ -155,28 +155,21 @@
 BAM(
-pathdata + os.sep + 
+sequana_data(
 %22tes
@@ -175,16 +175,17 @@
 st.bam%22)
+)
 %0A    ass
@@ -198,19 +198,20 @@
 n(s) == 
-432
+1000
 %0A%0A    as
@@ -253,18 +253,16 @@
 ())) == 
-43
 2%0A    s.
@@ -316,17 +316,19 @@
 ())) == 
-0
+998
 %0A    s.r
@@ -368,69 +368,582 @@
 es()
-%5B0%5D == 'HISEQ:426:C5T65ACXX:5:2302:1943:2127'%0A
+%0A%0A    s.get_stats()%0A%0A    with TempFile(suffix='.png') as fh:%0A        s.plot_bar_flags(filename=fh.name, logy=True)%0A        s.plot_bar_flags(filename=fh.name)%0A    %0A%0A    with TempFile(suffix='.png') as fh:%0A        s.plot_bar_mapq(filename=fh.name)%0A  %0A%0Adef test_alignment(): %0A    s = BAM(sequana_data(%22test.bam%22))%0A    a = Alignment(next(s))%0A    a.as_dict()%0A%0A%0Adef test_samflags():%0A%0A    sf = SAMFlags(4095)%0A    print(sf)
 %0A    s
+f
 .get_
-stats
+meaning()%0A    sf.get_flags()%0A%0A%0Adef test_bamreport():%0A    b = BAM(sequana_data(%22test.bam%22))%0A    r = BAMReport()%0A    r.set_data(b)%0A    r.create_report
 ()%0A

add more test related to BAM files