unimod.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:mzidentml_writer 作者: mobiusklein 项目源码 文件源码
def create(doc_path, output_path="sqlite://"):
    '''
    Parse the relational table-like XML file provided by http://www.unimod.org/downloads.html
    and convert each <tag>_row into an equivalent database entry.

    By default the table will be held in memory.
    '''
    tree = preprocess_xml(doc_path)
    engine = create_engine(output_path)
    Base.metadata.create_all(engine)
    session = sessionmaker(bind=engine, autoflush=False)()
    with warnings.catch_warnings():
        warnings.simplefilter("ignore", category=sa_exc.SAWarning)
        for model in Base._decl_class_registry.values():
            if hasattr(model, "_tag_name") and hasattr(model, "from_tag"):
                for tag in tree.iterfind(".//" + model._tag_name):
                    session.add(model.from_tag(tag))
            session.commit()
    return session
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号