Tutorials with Jupyter lab#
Jupyter lab#
Metasmith comes with a Jupyter lab environment, which provides a visual interface to browse, edit, and execute files. It is advisable to first create a workspace folder, since additional resources will be downloaded to the current working directory.
$ mkdir -p metasmith_ws
$ cd metasmith_ws
Once Jupyter lab is started, come back to this page and press the connect button below.
$ msm lab --tutorial my_first_agent
The notebook should have been opened automatically, but it can also be found manually using the file browser on the left of Jupyter’s GUI.
Jupyter lab GUI with file browser on the left#
Resources#
msm lab will setup the current directory with everything needed for any tutorial.
If you want more control over this process, the following will achieve the same result.
Each tutorial comes with a Jupyter notebook which can be copied to the current directory like so:
$ msm get tutorials/my_first_agent.ipynb
A git repo provides a standard library of Bioinformatics tools that have been integrated into Metasmith, including those used by the tutorials.
$ git clone https://github.com/hallamlab/MetasmithLibraries.git
Jupyter notebooks#
The first cell of the Jupyter notebook loads the required elements from the Metasmith API for the tutorial.
1from pathlib import Path
2from metasmith.python_api import Agent, ContainerRuntime
3from metasmith.python_api import DataTypeLibrary, DataInstanceLibrary, TransformInstanceLibrary
4from metasmith.python_api import Source, Logistics
5from metasmith.python_api import TargetBuilder, Resources, Size, Duration
6from metasmith.python_api import ipynbButtonLink
We create some variables to reduce ambiguity for important paths.
If using the packaged Jupyter lab environment, the workspace is 2 folders up since we are in example_resources/tutorials.
1WORKSPACE = Path("../../").resolve()
2WORKSPACE
Otherwise, we can just specify the current working directory.
1# or
2WORKSPACE = Path("./")
3WORKSPACE
We also specify the path to the cloned standard library.
1MLIB = WORKSPACE/"MetasmithLibraries"
Autocomplete#
Autocomplete is configured within Jupyter lab with the TAB key.
1agent_home = Source.FromLocal(WORKSPACE/"msm_home")
2smith = Agent(
3 home = agent_home,
4 runtime=ContainerRuntime.DOCKER,
5)
6
7smith.Gen
Finding files#
A convience tool is provided to display buttons that link to files at a given path.
1# create a new file
2hello_world_file = WORKSPACE/"hello_world.txt"
3with open(hello_world_file, "w") as f:
4 f.write("hello world!")
5
6# show button
7ipynbButtonLink(url=hello_world_file, text="go to hello world")
With the file open, we can right click, then select “Show in File Browser” to find file in the file browser panel on the left.
The context menu with “show in file browser”#