io

snafu.io.load_fluency_data(filepath, category=None, removePerseverations=False, removeIntrusions=False, spell=None, scheme=None, group=None, subject=None, removeNonAlphaChars=False, hierarchical=False, targetletter=None)[source]

Load verbal fluency data from a CSV file and preprocess it according to options.

Parameters:
  • filepath (str) – Path to the CSV file containing fluency data.

  • category (str or list of str, optional) – Restrict to specific semantic categories.

  • removePerseverations (bool, optional) – If True, remove repeated responses in the same list.

  • removeIntrusions (bool, optional) – If True, remove responses not in the scheme or target letter.

  • spell (str, optional) – Path to a spelling correction file.

  • scheme (str, optional) – Path to a valid item list for the given category.

  • group (str or list of str, optional) – Filter data by group.

  • subject (str or list of str, optional) – Filter data by subject ID.

  • removeNonAlphaChars (bool, optional) – If True, remove non-alphabetic characters from item names.

  • hierarchical (bool, optional) – If True, marks the returned structure as hierarchical.

  • targetletter (str, optional) – Restrict responses to those starting with this letter (used for letter fluency tasks).

Returns:

A Data object containing structured fluency data including: - ‘Xs’: response index lists, - ‘items’: subject-specific item index mappings, - ‘irts’: inter-response times (if present), - ‘categories’: category info, - ‘spell_corrected’: spelling corrections, - ‘perseverations’: repeated items, - ‘intrusions’: invalid responses.

Return type:

Data

snafu.io.load_graph(*args, **kwargs)[source]

Alias for load_network for backwards compatibility.

snafu.io.load_network(fh, cols=(0, 1), header=False, filters={}, undirected=True, sparse=False)[source]

Load a network from a CSV file and return its adjacency matrix and node labels.

Parameters:
  • fh (str) – Filepath to a CSV file containing the network edges.

  • cols (tuple of int or str, optional) – Column indices or names indicating source and target node columns. Default is (0, 1).

  • header (bool, optional) – Whether the CSV file has a header row. Default is False.

  • filters (dict, optional) – Dictionary to filter rows based on additional column values. Only used if header=True.

  • undirected (bool, optional) – If True, adds symmetric edges to make the graph undirected. Default is True.

  • sparse (bool, optional) – If True, returns a sparse adjacency matrix. Otherwise, returns a dense NumPy array. Default is False.

Returns:

  • graph (ndarray or csr_matrix) – The adjacency matrix representing the network.

  • items (dict) – Mapping from node indices to node labels.

snafu.io.readX(*args, **kwargs)[source]

Alias for load_fluency_data for backwards compatibility.

snafu.io.read_graph(*args, **kwargs)[source]

Alias for load_network for backwards compatibility.

snafu.io.write_graph(*args, **kwargs)[source]

Alias for write_network for backwards compatibility.

snafu.io.write_network(gs, fh, subj='NA', directed=False, extra_data={}, header=True, labels=None, sparse=False)[source]

Write one or more graphs to a CSV file in edge-list format.

Parameters:
  • gs (list or networkx.Graph) – A graph or list of graphs to be written.

  • fh (str) – Path to the output file.

  • subj (str, optional) – Subject identifier to include in the output. Default is “NA”.

  • directed (bool, optional) – If True, treat the graphs as directed. Default is False.

  • extra_data (dict, optional) – Optional nested dictionary of additional edge-level data.

  • header (bool or str, optional) – If True, write a default header. If str, use as custom header. Default is True.

  • labels (dict or list of dict, optional) – Optional relabeling of graph node indices to string labels.

  • sparse (bool, optional) – If True, only write edges that are present. If False, write all pair combinations. Default is False.

Returns:

Writes data to file and returns nothing.

Return type:

None