tethne.writers package¶
Submodules¶
tethne.writers.collection module¶
Write GraphCollection
to a structured data format.
to_dxgmml (graphcollection, path) |
Writes a GraphCollection to `dynamic XGMML. |
-
tethne.writers.collection.
to_dxgmml
(graphcollection, 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 theGraphCollection
.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 Corpus, and slice it temporally using a >>> # 4-year sliding time-window. >>> from tethne.data import Corpus, GraphCollection >>> D = Corpus(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: graphcollection :
GraphCollection
The
GraphCollection
to be written to XGMML.path : str
Path to file to be written. Will be created/overwritten.
Raises: AttributeError
C must be a tethne.classes.GraphCollection.
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.
tethne.writers.corpus module¶
-
tethne.writers.corpus.
write_documents_dtm
(corpus, target, featureset_name, slice_kwargs={}, metadata_fields=['date', 'title'])[source]¶ Parameters: target : str
Target path for documents; e.g. ‘./mycorpus’ will result in ‘./mycorpus-mult.dat’, ‘./mycorpus-seq.dat’, ‘mycorpus-vocab.dat’, and ‘./mycorpus-meta.dat’.
D :
Corpus
Contains
Paper
objects generated from the same DfR dataset as t_ngrams, indexed by doi and sliced by date.feature : str
(default: ‘unigrams’) Features in
Corpus
to use for modeling.fields : list
(optional) Fields in
Paper
to include in the metadata file.Returns: None : If all goes well.
Raises: IOError
tethne.writers.graph module¶
Write NetworkX graphs to structured and unstructured network file formats.
write_csv (graph, prefix) |
Write graph as tables of nodes (prefix-nodes.csv ) and edges (prefix-edges.csv ). |
write_graphml (graph, path[, encoding, ...]) |
Writes graph to GraphML. |
-
class
tethne.writers.graph.
TethneGraphMLWriter
(graph=None, encoding='utf-8', prettyprint=True)[source]¶ Bases:
networkx.readwrite.graphml.GraphMLWriter
-
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_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.
write_csv
(graph, prefix)[source]¶ Write
graph
as tables of nodes (prefix-nodes.csv
) and edges (prefix-edges.csv
).Parameters: graph : networkx.Graph
prefix : str
-
tethne.writers.graph.
write_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.matrix module¶
Methods for writing matrices to commonly-used file formats, for external visualization and analysis. Not yet implemented.
Module contents¶
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. |