@@ -0,0 +1,2192 @@
+%22%22%22%0ACompare multiple GFF files to a reference%0A%22%22%22%0A%0Aimport os%0Aimport pandas as pd%0A%0Afrom mirtop.gff import header%0Aimport mirtop.libs.logger as mylog%0Alogger = mylog.getLogger(__name__)%0A%0A# Add check first %0A%0Adef compare(args):%0A    %22%22%22%0A    From a list of files produce stats%0A    %22%22%22%0A    out = list()%0A    reference = read_reference(args.files%5B0%5D)%0A    for fn in args.files%5B1:%5D:%0A        if not os.path.exists(fn):%0A            raise IOError(%22%25s doesn't exist%22 %25s)%0A        _compare_to_reference(fn, reference)%0A%0Adef read_reference(fn):%0A    %22%22%22Read GFF into UID:Variant key:value dict%22%22%22%0A    srna = dict()%0A    with open(fn) as inh:%0A        for line in inh:%0A            if line.startswith(%22#%22):%0A                continue%0A            cols = line.strip().split(%22%5Ct%22)%0A            attr_v = %5Bv.strip().split(%22 %22)%5B1%5D for v in cols%5B8%5D.strip().split(%22;%22)%5B:-1%5D%5D%0A            attr_k = %5Bv.strip().split(%22 %22)%5B0%5D for v in cols%5B8%5D.strip().split(%22;%22)%5B:-1%5D%5D%0A            attr = dict(zip(attr_k, attr_v))%0A            srna%5Battr%5B'UID'%5D%5D = attr%5B'Variant'%5D%0A    return srna%0A%0Adef _compare_to_reference(fn, reference):%0A    same = 0%0A    diff = 0%0A    new = 0%0A    with open(fn) as inh:%0A        for line in inh:%0A            if line.startswith(%22#%22):%0A                continue%0A            cols = line.strip().split(%22%5Ct%22)%0A            cols = line.strip().split(%22%5Ct%22)%0A            attr_v = %5Bv.strip().split(%22 %22)%5B1%5D for v in cols%5B8%5D.strip().split(%22;%22)%5B:-1%5D%5D%0A            attr_k = %5Bv.strip().split(%22 %22)%5B0%5D for v in cols%5B8%5D.strip().split(%22;%22)%5B:-1%5D%5D%0A            attr = dict(zip(attr_k, attr_v))%0A            if attr%5B'UID'%5D in reference:%0A                if attr%5B'Variant'%5D == reference%5Battr%5B'UID'%5D%5D:%0A                    same += 1%0A                else:%0A                    diff +=1%0A                new += 1%0A    print %22Number of sequences found in reference: %25s%22 %25 new%0A    print %22Number of sequences matches reference: %25s%22 %25 same%0A    print %22Number of sequences different than reference: %25s%22 %25 diff%0A%0Adef _get_samples(fn):%0A    with open(fn) as inh:%0A        for line in inh:%0A            if line.startswith(%22## COLDATA%22):%0A                return line.strip().split(%22: %22)%5B1%5D.strip().split(%22,%22)%0A    raise ValueError(%22%25s doesn't contain COLDATA header.%22 %25 fn)%0A%0A

Add compare missing file