We welcome contributions or suggestions from other developers. Please contact us if you have questions or would like to discuss an addition or major modifications to the Giotto main code. The source code for Giotto Suite may be found on our GitHub repository.
Following a particular programming style will help programmers read and understand source code conforming to the style, and help to avoid introducing errors. Here we present a small list of guidelines on what is considered a good practice when writing R codes in Giotto package. Most of them are adapted from Bioconductor - coding style or Google’s R Style Guide. These guidelines are preferences and strongly encouraged!
functionName()
)function_name()
).function_name()
)a, b, c
.somefunc(a = 1, b = 2)
.'\u00F6'
for ö
Beyond these guidelines, styler should be used in order to maintain code uniformity.
Most Giotto commands can accept several matrix classes (DelayedMatrix, SparseM, Matrix or base matrix). To facilitate this we provide flexible wrappers that work on any type of matrix class.
Giotto has a number of auxiliary or convenience functions that might help you to adapt your code or write new code for Giotto. We encourage you to use these small functions to maintain uniformity throughout the code.
all_plots_save_function
and includes handling for return_plot and show_plot and Giotto instructions checkingThe last function should be used within your contribution code. It has the additional benefit that it will suggest the user how to download the package if it is not available. To keep the size of Giotto within limits we prefer not to add too many new dependencies.
Giotto tracks packages and functions to import in a centralized manner. When adding code that requires functions from another package, add the roxygen tags to the package_imports.R
file for that Giotto module.
Giotto stores information in different slots, which can be accessed through these getters and setters functions. They can be found in the accessors.R file.
getCellMetadata(): Gets cell metadata
setCellMetadata(): Sets cell metadata
getFeatureMetadata(): Gets feature metadata
getFeatureMetadata(): Sets feature metadata
getExpression(): To select the expression matrix to use
setExpression(): Sets a new expression matrix to the expression slot
getSpatialLocations(): Get spatial locations to use
setSpatialLocations(): Sets new spatial locations
getDimReduction(): To select the dimension reduction values to use
setDimReduction(): Sets new dimension reduction object
getNearestNetwork(): To select the nearest neighbor network (kNN or sNN) to use
setNearestNetwork(): Sets a new nearest neighbor network (kNN or sNN)
getSpatialNetwork(): To select the spatial network to use
setSpatialNetwork(): Sets a new spatial network
getPolygonInfo(): Gets spatial polygon information
setPolygonInfo(): Set new spatial polygon information
getFeatureInfo(): Gets spatial feature information
setFeatureInfo(): Sets new spatial feature information
getSpatialEnrichment(): Gets spatial enrichment information
setSpatialEnrichment(): Sets new spatial enrichment information
getMultiomics(): Gets multiomics information
setMultiomics(): Sets multiomics information
To use Python code we prefer to create a python wrapper/functions around the python code, which can then be sourced by reticulate. As an example we show the basic principles of how we implemented the Leiden clustering algorithm.
import igraph as ig
import leidenalg as la
import pandas as pd
import networkx as nx
def python_leiden(df, partition_type, initial_membership=None, weights=None, n_iterations=2, seed=None, resolution_parameter = 1):
# create networkx object
Gx = nx.from_pandas_edgelist(df = df, source = 'from', target = 'to', edge_attr = 'weight')
# get weight attribute
myweights = nx.get_edge_attributes(Gx, 'weight')
....
return(leiden_dfr)
python_leiden_function = system.file("python", "python_leiden.py", package = 'Giotto')
reticulate::source_python(file = python_leiden_function)
pyth_leid_result = python_leiden(df = network_edge_dt,
partition_type = partition_type,
initial_membership = init_membership,
weights = 'weight',
n_iterations = n_iterations,
seed = seed_number,
resolution_parameter = resolution)