def diff(old, new, workdir=".gbdiff"): print mkjs({"type": "diff", "source": old.name, "target": new.name}) oldrec = nebgb.parse(old).next() oldrec.load_sequence() newrec = nebgb.parse(new).next() newrec.load_sequence() seq_updated = update_features(oldrec, newrec, workdir) for m in meta.diff(oldrec, newrec): print mkjs(m) (matched, todel, toins) = merge.merge(oldrec, newrec, seq_updated) for td in todel: print mkfeat(oldrec, td, delete=True) for m in matched: h1, h2 = map(mkjshash, m) if h1 != h2: m[0]["location"]["source"] = newrec.locus["source"] print mkfeat(newrec, m[1], prev=m[0]) for ti in toins: print mkfeat(newrec, ti)
def insert(handle): print mkjs({"type": "insert", "source": handle.name}) rec = nebgb.parse(handle).next() rec.load_sequence() seqid = writeseq(rec.sequence) rec.locus["source"] = seqid print mkjs({"type": "keyword", "keyword": "locus", "value": rec.locus}) for kw in rec.keywords: if kw == "reference": for ref in rec.keywords[kw]: print mkjs({ "type": "reference", "refid": mkjshash(ref), "value": ref }) else: print mkjs({ "type": "keyword", "keyword": kw, "value": rec.keywords[kw] }) for f in rec.features: print mkfeat(rec, f)