当前位置: 首页>>代码示例>>Python>>正文


Python ProvDocument.get_provn方法代码示例

本文整理汇总了Python中prov.model.ProvDocument.get_provn方法的典型用法代码示例。如果您正苦于以下问题:Python ProvDocument.get_provn方法的具体用法?Python ProvDocument.get_provn怎么用?Python ProvDocument.get_provn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在prov.model.ProvDocument的用法示例。


在下文中一共展示了ProvDocument.get_provn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: NIDMObjectsUnitTesting

# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import get_provn [as 别名]
class NIDMObjectsUnitTesting(unittest.TestCase):
    """
    Unit testing of NIDM objects (compared to examples provided in 
    nidm-results.owl)
    """

    def setUp(self):
        self.export_dir = os.path.join(TEST_FOLDER, 'nidm')
        if not os.path.isdir(self.export_dir):
            os.mkdir(self.export_dir)

        # Retreive owl file for NIDM-Results
        owl_file = os.path.join(TERM_RESULTS_DIR, 'nidm-results.owl')
        assert owl_file
        self.owl = OwlReader(owl_file)

        self.doc = ProvDocument()
        # self.bundle = ProvBundle(identifier=NIIRI[software_lc+'_results_id'])

        self.provn_file = os.path.join(self.export_dir, 'unit_test.provn')

        namespaces_file = os.path.join(TERM_RESULTS_DIR, "templates", \
            "Namespaces.txt")
        namespaces_fid = open(namespaces_file)
        self.prefixes = namespaces_fid.read()
        namespaces_fid.close()

        self.to_delete_files = [self.provn_file]
        self.gt_ttl_files = list()

    def test_design_matrix(self):
        mat = np.matrix('1 2; 3 4')

        mat_image = os.path.join(os.path.dirname(TEST_FOLDER), "data", \
            "fmri.feat", "design.png")

        design_matrix = DesignMatrix(mat, mat_image, self.export_dir)
        self.doc.update(design_matrix.export())

        # In the FSL export the design matrix contains both the Design Matrix
        # entity and the Image entity representing the design matrix 
        # visualisation.
        self.to_delete_files.append(os.path.join(self.export_dir, \
            "DesignMatrix.csv"))
        self.to_delete_files.append(os.path.join(self.export_dir, \
            "DesignMatrix.png")) 

        gt_file = self.owl.get_example(NIDM['DesignMatrix'])
        self.gt_ttl_files = [os.path.join(TERM_RESULTS_DIR, \
            gt_file.replace("file://./", "")), 
            os.path.join(TERM_RESULTS_DIR, "examples", "Image-DesignMatrix.txt")]

        self._create_gt_and_compare("Design Matrix")

    def test_data(self):
        data = Data(grand_mean_scaling=True, target=100.0)
        self.doc.update(data.export())

        gt_file = self.owl.get_example(NIDM['Data'])
        self.gt_ttl_files.append(os.path.join(TERM_RESULTS_DIR, \
            gt_file.replace("file://./", "")))

        self._create_gt_and_compare("Data")

# INDEPEDENT_CORR = NIDM['IndependentError']
# SERIALLY_CORR = NIDM['SeriallyCorrelatedError']
# COMPOUND_SYMMETRY_CORR = NIDM['CompoundSymmetricError']
# ARBITRARILY_CORR = NIDM['ArbitriralyCorrelatedError']


    # def test_error_model_indepdt_global(self):
    #     error_distribution = GAUSSIAN_DISTRIBUTION
    #     variance_homo = True
    #     variance_spatial = SPATIALLY_GLOBAL
    #     dependance = INDEPEDENT_CORR
    #     dependance_spatial = SPATIALLY_GLOBAL

    #     error_model = ErrorModel(error_distribution, variance_homo, 
    #         variance_spatial, dependance, dependance_spatial)
    #     self.doc.update(error_model.export())

    #     nidm_classes = {
    #         "ErrorModel": dict(
    #             error_model_id="niiri:error_model_id",
    #             noise_distribution="nidm:GaussianDistribution",
    #             variance_homo="true",
    #             variance_spatial="nidm:SpatiallyGlobal",
    #             dependence="nidm:IndependentError",
    #             dependence_spatial="nidm:SpatiallyLocal"
    #         )
    #         }
    #     self._create_gt_and_compare(nidm_classes, "Data")

    def _create_gt_and_compare(self, class_name):
        # Write-out current example in a provn file and convert to turtle
        provn_fid = open(self.provn_file, 'w')
        provn_fid.write(self.doc.get_provn())
        provn_fid.close()

        ttl_file = self.provn_file.replace(".provn", ".ttl")
#.........这里部分代码省略.........
开发者ID:afni-rickr,项目名称:nidm-results_afni,代码行数:103,代码来源:test_objects_unit.py

示例2: example

# 需要导入模块: from prov.model import ProvDocument [as 别名]
# 或者: from prov.model.ProvDocument import get_provn [as 别名]

#.........这里部分代码省略.........
    g.actedOnBehalfOf(walter, utexas)
    g.actedOnBehalfOf(me, utexas)

    # Include the ADAMA platform as an Agent and set attribution
    # dcterms:title and dcterms:description are hardcoded
    # dcterms:language is hard-coded
    # dcterms:source is the URI of the public git source repository for ADAMA
    # "dcterms:updated": "2015-04-17T09:44:56" - this would actually be the date ADAMA was updated
    adama_platform = g.agent(ap['adama_platform'], {'dcterms:title': "ADAMA", 'dcterms:description': "Araport Data and Microservices API", 'dcterms:language':"en-US", 'dcterms:identifier':"https://api.araport.org/community/v0.3/", 'dcterms:updated': "2015-04-17T09:44:56" })
    g.wasGeneratedBy(adama_platform, walter)

    # Include the ADAMA microservice as an Agent and set attribution+delegation
    # dcterms:title and dcterms:description are inherited from the service's metadata
    # dcterms:language is hard-coded
    # dcterms:identifier is the deployment URI for the service
    # dcterms:source is the URI of the public git source repository. The URL in this example is just a dummy
    #
    # The name for each microservice should be unique. We've decided to
    # use the combination of namespace, service name, and version
    microservice_name = 'mwvaughn/bar_annotation_v1.0.0'
    adama_microservice = g.agent(ap[microservice_name], {'dcterms:title': "BAR Annotation Service", 'dcterms:description': "Returns annotation from locus ID", 'dcterms:language':"en-US", 'dcterms:identifier':"https://api.araport.org/community/v0.3/mwvaughn/bar_annotation_v1.0.0", 'dcterms:source':"https://github.com/Arabidopsis-Information-Portal/prov-enabled-api-sample" })

    # the microservice was generated by me on date X (don't use now, use when the service was updated)
    g.wasGeneratedBy(adama_microservice, me, datetime.datetime.now())
    # The microservice used the platform now
    g.used(adama_microservice, adama_platform, datetime.datetime.now())

    # Sources
    #
    # Define BAR
    # Agents
    nick = g.agent(ap['nicholas_provart'], {
        'prov:type': PROV["Person"], 'foaf:givenName': "Nicholas Provart", 'foaf:mbox': "[email protected]"
    })
    utoronto = g.agent(ap['university_of_toronto'], {
        'prov:type': PROV["Organization"], 'foaf:givenName': "University of Toronto", 'dcterms:identifier':"http://www.utoronto.ca/"
    })
    g.actedOnBehalfOf(nick, utoronto)

    # Entity
    # All fields derived from Sources.yml
    # dcterms:title and dcterms:description come straight from the YAML
    # dcterms:identifier - URI pointing to the source's canonical URI representation
    # optional - dcterms:language: Recommended best practice is to use a controlled vocabulary such as RFC 4646
    # optional - dcterms:updated: date the source was published or last updated
    # optional - dcterms:license: Simple string or URI to license. Validate URI if provided?
    datasource1 = g.entity(ap['datasource1'], {'dcterms:title': "BAR Arabidopsis AGI -> Annotation", 'dcterms:description': "Most recent annotation for given AGI", 'dcterms:language':"en-US", 'dcterms:identifier':"http://bar.utoronto.ca/webservices/agiToAnnot.php", 'dcterms:updated':"2015-04-17T09:44:56", 'dcterms:license':"Creative Commons 3.0" })
    # Set up attribution to Nick
    g.wasAttributedTo(datasource1, nick)

    # Define TAIR
    # Agents
    # dcterms:language: Recommended best practice is to use a controlled vocabulary such as RFC 4646
    eva = g.agent(ap['eva_huala'], {
        'prov:type': PROV["Person"], 'foaf:givenName': "Eva Huala"
    })
    phoenix = g.agent(ap['phoenix_bioinformatics'], {
        'prov:type': PROV["Organization"], 'foaf:givenName': "Phoenix Bioinformatics"
    })
    g.actedOnBehalfOf(eva, phoenix)

    # Entity
    # All fields derived from Sources.yml
    # optional - dcterms:citation: Plain text bibliographic citation. If only provided as doi, should we try to validate it?
    datasource2 = g.entity(ap['datasource2'], {'dcterms:title': "TAIR", 'dcterms:description': "The Arabidopsis Information Resource", 'dcterms:language':"en-US", 'dcterms:identifier':"https://www.arabidopsis.org/", 'dcterms:citation':"The Arabidopsis Information Resource (TAIR): improved gene annotation and new tools. Nucleic Acids Research 2011 doi: 10.1093/nar/gkr1090"})
    g.wasAttributedTo(datasource2, eva)

    # In Sources.yml, these two sources are nested. Define that relationship here
    # There are other types of relationships but we will just use derived from for simplicity in this prototype
    g.wasDerivedFrom(ap['datasource1'], ap['datasource2'])

    # Depending on which ADAMA microservice type we are using, define an activity
    # Eventually, break these into more atomic actions in a chain
    action1 = g.activity(ap['do_query'], datetime.datetime.now())
    # action1 = g.activity(ap['do_map'], datetime.datetime.now())
    # action1 = g.activity(ap['do_generic'], datetime.datetime.now())
    # action1 = g.activity(ap['do_passthrough'], datetime.datetime.now())
    # Future... Support for ADAMA-native microservices
    # action1 = g.activity(ap['generate'], datetime.datetime.now())

    # Define current ADAMA response as an Entity
    # This is what's being returned to the user and is thus the subject of the PROV record
    # May be able to add more attributes to it but this is the minimum
    response = g.entity(ap['adama_response'])

    # Response is generated by the process_query action
    # Time-stamp it!
    g.wasGeneratedBy(response, ap['do_query'], datetime.datetime.now())
    # The process_query used the microservice
    g.used(ap['do_query'], adama_microservice, datetime.datetime.now())
    # The microservice used datasource1
    g.used(adama_microservice, datasource1, datetime.datetime.now())

    # Print prov_n
    print(g.get_provn())
    # Print prov-json
    print(g.serialize())
    # Write out as a pretty picture
    graph = prov.dot.prov_to_dot(g)
    graph.write_png('Sources.png')
开发者ID:Arabidopsis-Information-Portal,项目名称:araport-prov,代码行数:104,代码来源:Sources.py


注:本文中的prov.model.ProvDocument.get_provn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。