Beispiel #1
0
    def setUp(self):
        super(TestCascades, self).setUp()

        self.n1 = Node(type=PROTEIN, bel='p(HGNC:A)')
        self.n2 = Node(type=PROTEIN, bel='p(HGNC:B)')
        self.n3 = Node(type=PROTEIN, bel='p(HGNC:C)')
        self.e1 = Edge(source=self.n1,
                       target=self.n2,
                       relation=INCREASES,
                       bel='p(HGNC:A) increases p(HGNC:B)')
        self.e2 = Edge(source=self.n2,
                       target=self.n3,
                       relation=INCREASES,
                       bel='p(HGNC:B) increases p(HGNC:C)')
        self.e3 = Edge(source=self.n1,
                       target=self.n3,
                       relation=INCREASES,
                       bel='p(HGNC:A) increases p(HGNC:C)')
        self.g1 = Network(name=n(),
                          version=n(),
                          edges=[self.e1, self.e2, self.e3])
        self.g2 = Network(name=n(), version=n(), edges=[self.e1])

        self.manager.session.add_all([
            self.n1, self.n2, self.n3, self.e1, self.e2, self.e3, self.g1,
            self.g2
        ])
        self.manager.session.commit()

        self.assertEqual(3, self.manager.count_nodes())
        self.assertEqual(3, self.manager.count_edges())
        self.assertEqual(2, self.manager.count_networks())
Beispiel #2
0
    def setUp(self):
        self.name = n()
        self.version = n()
        self.created = datetime.datetime.utcnow()

        self.model = Network(
            name=self.name,
            version=self.version,
            created=self.created,
        )
        self.expected = {
            METADATA_NAME: self.name,
            METADATA_VERSION: self.version,
            'created': str(self.created),
        }
Beispiel #3
0
    def authenticated_render_network_summary(self, user: User,
                                             network: Network,
                                             template: str) -> Response:
        """Render the graph summary page."""
        graph = network.as_bel()
        report: Report = network.report
        context: BELGraphSummary = report.get_calculations()

        overlaps = self.get_top_overlaps(user=user, network=network)
        network_versions = self.get_networks_by_name(network.name)

        return render_template(
            template,
            blueprints=set(current_app.blueprints),
            current_user=user,
            network=network,
            graph=graph,
            network_versions=network_versions,
            overlaps=overlaps,
            chart_1_data=context.prepare_c3_for_function_count(),
            chart_2_data=context.prepare_c3_for_relation_count(),
            chart_3_data=context.prepare_c3_for_error_count(),
            chart_4_data=context.prepare_c3_for_transformations(),
            number_transformations=sum(context.modifications_count.values()),
            chart_5_data=context.prepare_c3_for_variants(),
            number_variants=sum(context.variants_count.values()),
            chart_6_data=context.prepare_c3_for_namespace_count(),
            number_namespaces=len(context.namespaces_count),
            chart_7_data=context.prepare_c3_for_hub_data(),
            chart_9_data=context.prepare_c3_for_pathology_count(),
            chart_10_data=context.prepare_c3_for_citation_years(),
        )
def fill_out_report(*,
                    network: Network,
                    report: Report,
                    graph: Optional[BELGraph] = None) -> None:
    """Fill out the report for the network."""
    if graph is None:
        graph = network.as_bel()

    number_nodes = graph.number_of_nodes()

    try:
        average_degree = graph.number_of_edges() / graph.number_of_nodes()
    except ZeroDivisionError:
        average_degree = 0.0

    report.network = network
    report.number_nodes = number_nodes
    report.number_edges = graph.number_of_edges()
    report.number_warnings = graph.number_of_warnings()
    report.number_citations = graph.number_of_citations()
    report.number_authors = graph.number_of_authors()
    report.number_components = nx.number_weakly_connected_components(graph)
    report.network_density = nx.density(graph)
    report.average_degree = average_degree
    report.dump_calculations(graph)
    report.completed = True
Beispiel #5
0
    def test_find_network(self):
        """Check a network is present."""
        n = Network(name='test network', version='1.0.0')
        self.manager.session.add(n)
        self.manager.session.commit()

        with self.app.app_context():
            response = self.client.get('/network', follow_redirects=True)
            self.assertIn('test network', response.data.decode('utf8'))
class TestNetwork(unittest.TestCase):

    def setUp(self):
        self.name = n()
        self.version = n()
        self.created = datetime.datetime.utcnow()

        self.model = Network(
            name=self.name,
            version=self.version,
            created=self.created,
        )
        self.expected = {
            METADATA_NAME: self.name,
            METADATA_VERSION: self.version,
            'created': str(self.created),
        }

    def test_to_json(self):
        model_json = self.model.to_json()

        self.assertIn(METADATA_NAME, model_json)
        self.assertEqual(self.name, model_json[METADATA_NAME])
        self.assertIn(METADATA_VERSION, model_json)
        self.assertEqual(self.version, model_json[METADATA_VERSION])
        self.assertIn('created', model_json)
        self.assertEqual(str(self.created), model_json['created'])

        self.assertEqual(self.expected, model_json)

    def test_dump(self):
        json.dumps(self.model)

    def test_network(self):
        self.expected[METADATA_AUTHORS] = self.model.authors = n()
        self.assertEqual(self.expected, self.model.to_json())

        self.expected[METADATA_CONTACT] = self.model.contact = n()
        self.assertEqual(self.expected, self.model.to_json())

        self.expected[METADATA_DESCRIPTION] = self.model.description = n()
        self.assertEqual(self.expected, self.model.to_json())

        self.expected[METADATA_COPYRIGHT] = self.model.copyright = n()
        self.assertEqual(self.expected, self.model.to_json())

        self.expected[METADATA_DISCLAIMER] = self.model.disclaimer = n()
        self.assertEqual(self.expected, self.model.to_json())

        self.expected[METADATA_LICENSES] = self.model.licenses = n()
        self.assertEqual(self.expected, self.model.to_json())

        self.expected['id'] = None
        self.assertEqual(self.expected, self.model.to_json(include_id=True))
Beispiel #7
0
    def setUp(self):
        super(TestCascades, self).setUp()

        self.n1 = Node._start_from_base_entity(yfg1)
        self.n2 = Node._start_from_base_entity(yfg2)
        self.n3 = Node._start_from_base_entity(yfg3)
        self.e1 = make_increase_edge(self.n1, self.n2)
        self.e2 = make_increase_edge(self.n2, self.n3)
        self.e3 = make_increase_edge(self.n1, self.n3)
        self.g1 = Network(name=n(),
                          version=n(),
                          edges=[self.e1, self.e2, self.e3])
        self.g2 = Network(name=n(), version=n(), edges=[self.e1])

        self.manager.session.add_all([
            self.n1, self.n2, self.n3, self.e1, self.e2, self.e3, self.g1,
            self.g2
        ])
        self.manager.session.commit()

        self.assertEqual(3, self.manager.count_nodes())
        self.assertEqual(3, self.manager.count_edges())
        self.assertEqual(2, self.manager.count_networks())