writers Package

writers Package

Export networks to structured and unstructured formats, for visualization.

collection Write GraphCollection to a structured data format.
graph Write NetworkX graphs to structured and unstructured network file formats.
corpora
matrix Methods for writing matrices to commonly-used file formats, for external visualization and analysis.

collection Module

Write GraphCollection to a structured data format.

to_dxgmml(C, path) Writes a GraphCollection to
tethne.writers.collection.to_dxgmml(C, path)[source]

Writes a GraphCollection to dynamic XGMML..

Dynamic XGMML is a schema for describing dynamic networks in Cytoscape 3.0. This method assumes that Graph indices are orderable points in time (e.g. years). The “start” and “end” of each node and edge are determined by periods of consecutive appearance in the GraphCollection . Node and edge attributes are defined for each Graph. in the GraphCollection.

For example, to build and visualize an evolving co-citation network:

>>> # Load some data.
>>> import tethne.readers as rd
>>> papers = rd.wos.read(datapath)

>>> # Build a DataCollection, and slice it temporally using a
>>> #  4-year sliding time-window.
>>> from tethne.data import DataCollection, GraphCollection
>>> D = DataCollection(papers)
>>> D.slice('date', 'time_window', window_size=4)

>>> # Generate a GraphCollection of co-citation graphs.
>>> from tethne.builders import paperCollectionBuilder
>>> builder = paperCollectionBuilder(D)
>>> C = builder.build('date', 'cocitation', threshold=2)

>>> # Write the GraphCollection as a dynamic network.
>>> import tethne.writers as wr
>>> wr.collection.to_dxgmml(C, "/path/to/network.xgmml")
Parameters :

C : GraphCollection

The GraphCollection to be written to XGMML.

path : str

Path to file to be written. Will be created/overwritten.

Notes

Period start and end dates in this method are inclusive, whereas XGMML end dates are exclusive. Hence +1 is added to all end dates when writing XGMML.

corpora Module

tethne.writers.corpora.to_documents(target, ngrams)[source]
Parameters :

target : str

Target path for documents; e.g. ‘./mycorpus’ will result in ‘./mycorpus_docs.txt’ and ‘./mycorpus_meta.csv’.

ngrams : dict

Keys are paper DOIs, values are lists of (Ngram, frequency) tuples.

Returns :

None : If all goes well.

Raises :

ValueError :

graph Module

Write NetworkX graphs to structured and unstructured network file formats.

Many methods simply invoke equivalent methods in NetworkX.

to_gexf(graph, output_path) Writes graph to GEXF.
to_graphml(graph, path[, encoding, prettyprint]) Writes graph to GraphML.
to_sif(graph, output_path) Generates Simple Interaction Format output file from provided graph.
class tethne.writers.graph.TethneGraphMLWriter(graph=None, encoding='utf-8', prettyprint=True)

Bases: networkx.readwrite.graphml.GraphMLWriter

Methods

add_attributes(scope, xml_obj, data, default) Appends attributes to edges or nodes.
add_data(name, element_type, value[, scope, ...]) Make a data element for an edge or a node.
add_edges(G, graph_element)
add_graph_element(G) Serialize graph G in GraphML to the stream.
add_graphs(graph_list) Add many graphs to this GraphML document.
add_nodes(G, graph_element)
dump(stream)
get_key(name, attr_type, scope, default)
indent(elem[, level])
get_key(name, attr_type, scope, default)
tethne.writers.graph.to_gexf(graph, output_path)[source]

Writes graph to GEXF.

Uses the NetworkX method write_gexf.

Parameters :

graph : networkx.Graph

The Graph to be exported to GEXF.

output_path : str

Full path, including filename (without suffix). e.g. using ”./graphFolder/graphFile” will result in a GEXF file at ./graphFolder/graphFile.gexf.

tethne.writers.graph.to_graphml(graph, path, encoding='utf-8', prettyprint=True)[source]

Writes graph to GraphML.

Uses the NetworkX method write_graphml.

Parameters :

graph : networkx.Graph

The Graph to be exported to GraphML.

output_path : str

Full path, including filename (without suffix). e.g. using ”./graphFolder/graphFile” will result in a GraphML file at ./graphFolder/graphFile.graphml.

tethne.writers.graph.to_sif(graph, output_path)[source]

Generates Simple Interaction Format output file from provided graph.

The SIF specification is described here.

to_sif() will generate a .sif file describing the network, and a few .eda and .noa files containing edge and node attributes, respectively. These are equivalent to tab-delimited tables, and can be imported as such in Cytoscape 3.0.

Parameters :

graph : networkx.Graph

The Graph to be exported to SIF.

output_path : str

Full path, including filename (without suffix). e.g. using ”./graphFolder/graphFile” will result in a SIF file at ./graphFolder/graphFile.sif, and corresponding .eda and .noa files.

tethne.writers.graph.to_table(graph, path)[source]

matrix Module

Methods for writing matrices to commonly-used file formats, for external visualization and analysis. Not yet implemented.

Table Of Contents

Previous topic

utilities Package

This Page