SCanchi
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # A Hands-On Introduction to Conda **When:** Wednesday, April 7th, from 10:00 am-12:00 pm PST **Instructors:** Marisa Lim and Saranya Canchi **Moderator:** Abhijna Parigi **Helpers:** Jose Sanchez, Jeremy Walter **Zoom:** ==link== **Description:** This free 2 hour hands-on tutorial will introduce you to the package and environment manager, Conda. You'll learn how to set up conda environments and manage software installations. We'll discuss other applications, such as packaging software, running workflows, or creating binders all with conda! [toc] :::success While we wait to get started -- 1. :heavy_check_mark: Have you checked the [pre-workshop resources page](https://github.com/nih-cfde/training-and-engagement/wiki/Resources-for-Workshop-Attendees)? 2. :pencil: Please fill out our pre-workshop survey if you have not already done so! Link here: ==link== 3. :computer: Open a web browser - e.g., Firefox, Chrome, or Safari. Open the binder by clicking this button: [![Binder](https://binder.pangeo.io/badge_logo.svg)](https://binder.pangeo.io/v2/gh/nih-cfde/training-rstudio-binder/conda-workshop-march2021?urlpath=rstudio). It may take a few minutes to load. ::: ## Introductions We are both postdocs at UC Davis and part of the training and engagement team for the [NIH Common Fund Data Ecosystem](https://nih-cfde.org/), a project supported by the NIH to increase data reuse and cloud computing for biomedical research. You can contact us at mcwlim@ucdavis.edu and srcanchi@ucdavis.edu. ::: info Goals for today: - learn about conda and how to use it - learn the basics of software installation, software dependencies, and isolation environments - learn about managing virtual environments ::: ### Why Conda? ![](https://i.imgur.com/2R6UDu3.jpg) - OS-agnostic tool for package and environment management (meaning it works for Windows, Mac, and Linux!) - clean software installation along with dependencies - searches for compatible software versions - many packages available - python, R, etc. - user has admin permissions, good for use on HPC where you'd otherwise need to request software installations ### What is an Environment? Think of software environments like school classrooms, where the school is your laptop OS. Schools have many classrooms and while they are independent rooms they are still connected by hallways. Students can walk into any room and each room will have its own set of supplies (i.e., desks, chairs, whiteboard, decorations, etc.). For conda, the equivalent of a classroom and its supplies is a conda environment on your computer and its set of specifically downloaded software/tools. Input/output files, like students, can easily move between environments and just like a school can have multiple classrooms, conda can manage multiple conda environments. This is what makes it a great tool for maintaining different versions of the same software all on 1 computer! ### Why do we need isolated software environments? - **versioning**: your research/project requires specific versions of software packages - **reproducibility**: you want to experiment with new packages or features of existing packages without compromising your current workflow - **repeatability**: you want to replicate results from a publication - **compatibility**: your collaborators require you to use certain software/tools that are incompatibile with your current system :question: Questions? --- ## Let's get started! If not done already: - :computer: Open a web browser - e.g., Firefox, Chrome, or Safari. - Open the binder by clicking this button: [![Binder](https://binder.pangeo.io/badge_logo.svg)](https://binder.pangeo.io/v2/gh/nih-cfde/training-rstudio-binder/conda-workshop-march2021?urlpath=rstudio) :::success :heavy_check_mark: Did the binder load? Put up a :hand: on Zoom if you see Rstudio in your web browser. ::: Set up Rstudio panels! ### Initialize conda :keyboard: Copy/paste commands into the terminal OR run the commands from the `workshop_commands.sh` file in the binder. Installer sets up two things: Conda and the root environment. The root environment contains the selected python version and some basic packages. ![](https://i.imgur.com/NM4wtre.png) Image credit: [Gergely Szerovay](https://www.freecodecamp.org/news/why-you-need-python-environments-and-how-to-manage-them-with-conda-85f155f4353c/) Setup the conda installer and initialize the settings: ```bash=1 conda init ``` We will shorten command prompt to `$`: ```bash=2 echo "PS1='\w $ '" >> .bashrc ``` Re-start terminal for the changes to take effect (type `exit` and then open a new terminal). :::success :heavy_check_mark: Put up a :hand: on Zoom when you've got a new terminal window and see this at the prompt: `~ $` ::: --- ### Conda channels: Searching for software The channels are places that conda looks for packages. The default channels after conda installation is set to Anaconda Inc's channels (Conda's Developer). ```bash=3 conda config --show channels conda list # get list of packages in base environment ``` Channels exist in a hierarchial order. By default: :::info Channel priority > package version > package build number ::: ![](https://i.imgur.com/GE8nY0a.png) Image credit: [Gergely Szerovay](https://www.freecodecamp.org/news/why-you-need-python-environments-and-how-to-manage-them-with-conda-85f155f4353c/) :::info See [Resources](https://hackmd.io/1ivIgqVYSCupC21MuAW9FA?view#Resources) for more info on channels! ::: We will update the channel list order and add `bioconda` since we are using bioinformatic tools today. **The order of the channels matters!** First, add the `defaults` channel: ```bash=5 conda config --add channels defaults conda config --get channels ``` Then add the `bioconda` channel: ```bash=7 conda config --add channels bioconda conda config --get channels ``` Lastly, add the `conda-forge` channel to move it to top of the list, following [Bioconda's recommended channel order](https://bioconda.github.io/user/install.html#set-up-channels): ```bash=9 conda config --add channels conda-forge conda config --get channels ``` With this configuration, conda will search for packages in this order: 1) `conda-forge`, 2) `bioconda`, and 3) `defaults` :::info Another way to add channels is: ``` conda config --prepend channels bioconda ``` ::: :question: Questions? --- **Instructor switch!** ### Install Software We will install FastQC which is a software tool that provides a simple way to run quality control checks on raw sequencing data. Search for software (fastqc): ```bash=1 conda search fastqc ``` Create conda environment and install fastqc: ```bash=2 conda create -y --name fqc fastqc ``` Activate environment: ```bash=3 conda activate fqc ``` Check fastqc version: ```bash=4 fastqc --version ``` :::success :heavy_check_mark: Put up a :hand: on Zoom if your command prompt shows the name of the environment in parentheses: `(fqc) ~ $` ::: :::info To go back to `(base) ~ $` environment: ``` conda deactivate ``` ::: --- High-throughput sequencing data quality control steps often involve fastqc and trimmomatic. Trimmomatic is useful for read trimming (i.e., adapters). There are multiple ways we could create a conda environment that contains both software programs: #### Method 1: install software in existing environment We could add `trimmomatic` to the `fqc` environment: ```bash=5 conda install -y trimmomatic=0.36 conda list # check installed software ``` We can specify the exact software version :point_up_2: The default is to install the most current version, but sometimes your workflow may depend on a different version. --- #### Method 2: install both software during environment creation When you switch conda environments, conda changes the PATH (and other environment variables) so it searches for software packages in different places. Let's check the PATH for method 1: ``` echo $PATH ``` You should see that the first element in the PATH changes each time you switch environments! ```bash= conda deactivate conda create -y --name fqc_trim fastqc trimmomatic=0.36 conda activate fqc_trim conda list # check installed software echo $PATH # path for method 2 ``` --- The following methods use an external file to specify the packages to install. #### Method 3: specify software to install with a YAML file Often, it's easier to create environments and install software using a YAML file (YAML is a file format) that specifies all the software to be installed. For our example, we are using a file called `test.yml`. Let's start back in the `(base)` environment. ```bash=1 conda deactivate ``` The `test.yml` file contains the following in YAML format: ```yaml name: qc_yaml #this specifies environment name channels: - conda-forge - bioconda - defaults dependencies: - fastqc - trimmomatic=0.36 ``` Create the environment - note the difference in conda syntax: ```bash=2 conda env create -f test.yml #since environment name specified in yml file, we do not need to use -n flag here conda activate qc_yaml conda list # check installed software ``` :::info See [Resources](https://hackmd.io/RweX2WZ7RGGtfLfCDuEubQ?view#How-do-I-recreate-an-environment-with-exactly-the-same-versions-of-all-software-packages) for a 4th method of exporting exact environments. Software can also be installed by specifying the channel with `-c` flag i.e.: ``` conda install -c conda-forge -c bioconda sourmash ``` ::: --- ### Managing Environments At this point, we have several conda environments! To see a list, there are 2 commands (they do the same thing!): ```bash conda env list ``` or ```bash conda info --envs ``` :::warning Generally, you want to avoid installing too many software packages in one environment. It takes longer for conda to resolve compatible software versions for an environment the more software you install. For this reason, in practice, people often manage software for their workflows with multiple conda environments. ::: :question: Questions? --- ### Running FastQC in the fqc Environment If not already done, activate one of the environments we created, e.g.,: ```bash conda activate fqc ``` Let's make sure the software was installed correctly: ```bash fastqc --help ``` :::success Output should look like: ``` FastQC - A high throughput sequence QC analysis tool SYNOPSIS fastqc seqfile1 seqfile2 .. seqfileN fastqc [-o output dir] [--(no)extract] [-f fastq|bam|sam] [-c contaminant file] seqfile1 .. seqfileN ... ``` ::: Download data (a yeast sequence file): ```bash= curl -L https://osf.io/5daup/download -o ERR458493.fastq.gz ``` Check out the data: ```bash=2 gunzip -c ERR458493.fastq.gz | wc -l ``` <!-- 4375828 lines --> :::success :heavy_check_mark: How many lines are in this fastq file? (add number to Zoom chat) ::: What does the fastq file look like? ```bash=3 gunzip -c ERR458493.fastq.gz | head ``` Run FastQC! ```bash=4 fastqc ERR458493.fastq.gz ``` :::success :heavy_check_mark: Put up a :hand: on Zoom if you see an html file in the directory. ::: :question: Questions? --- **Instructor switch!** ## Exercise 1 :writing_hand: - **First**, install the `blast` software with version 2.9.0 using conda. :::spoiler Hint! :bulb: You can use one of these approaches to install `blast`: - install the software in an existing env using `conda install -y <name of the software>` - create a new env using `conda create -y --name <name of env> <software to install>` ::: - **Second**, try this example BLAST analysis in the conda environment. In this example, we are comparing the sequence similarity of a mouse protein sequence to a reference zebra fish sequence - as you might imagine, they are not that similar! But for today, this exercise will demonstrate running a quick analysis in a conda environment and bonus points if you find out how similar/dissimilar they are! (More details on BLAST and what each step is for [here](https://training.nih-cfde.org/en/latest/Bioinformatics-Skills/Command-Line-BLAST/BLAST4/)). Run each line of code below in the terminal: - Make a directory for the exercise files: ```bash= mkdir exercise1 cd exercise1 ``` - Download with `curl` command and unzip data files: ```bash=3 curl -o mouse.1.protein.faa.gz -L https://osf.io/v6j9x/download curl -o zebrafish.1.protein.faa.gz -L https://osf.io/68mgf/download gunzip *.faa.gz ``` - Subset the data for a test run: ```bash=6 head -n 11 mouse.1.protein.faa > mm-first.faa ``` - Format zebra fish sequence as the blast database to search against: ```bash=7 makeblastdb -in zebrafish.1.protein.faa -dbtype prot ``` - Run a protein blast search with `blastp`! ```bash=8 blastp -query mm-first.faa -db zebrafish.1.protein.faa -out mm-first.x.zebrafish.txt -outfmt 6 ``` What does the output look like? :::info Note that if you `conda deactivate`, you can still access the input/intermediate/output files from the BLAST analysis. They are not 'stuck' inside the conda environment! ::: --- ## Exercise 2 :writing_hand: Conda allows you to revert to a previous version of your software using the `--revision` flag: Usage: ``` # list all revisions conda list --revisions # revert to previous state conda install --revision <number> # for example: conda install --revision 1 ``` Earlier, we installed an older version of trimmomatic (0.36). Try updating it to the most recent version and then revert back to the old version. :::spoiler Hint! :bulb: You can do this exercise in any of the conda environments we created earlier with trimmomatic. You can update software with `conda update <software name>` ::: --- **Tidying up** To remove old conda environments: ``` conda env remove --name <conda env name> ``` To remove software: ``` conda remove <software name> ``` :::warning Be sure to save any work/notes you took in the binder to your computer. Any new files/changes are not available when the binder session is closed! For example, select a file, click "More", click "Export": ![](https://i.imgur.com/js8eX0l.png) ::: ## What else can we use Conda for? - **Reproducing analyses** - **Why**: removes the guesswork on what version of software to use or how to install it! :::spoiler For example, it's a lot easier to replicate a software environment from a publication or share software versions used in your own analysis using conda (particularly method 3 & 4 mentioned above ways to create conda environments from YAML or exact package list files). ::: - **Packaging software** - **Why**: to share your cool software with the world! :::spoiler The gist is that you write a recipe that has all the specs about your software that is submitted to a channel, e.g., conda-forge or bioconda. Once correctly formatted and tested (with continuous integration automation) so it works on different operating systems, it's added to the channel and the world can use and install your software with conda! - https://python-packaging-tutorial.readthedocs.io/en/latest/conda.html ::: - **Running parts of analysis workflows in their own environment** - **Why**: avoid software version conflicts, easier to keep track of software/versions used for a specific analysis, easier for others to reproduce :::spoiler This is a very helpful feature for workflows. For example, in [Snakemake](https://training.nih-cfde.org/en/latest/Bioinformatics-Skills/Snakemake/) workflows, you can specify that each step (called a "rule") is executed in an isolated conda environment by adding a `conda:` directive: ```python rule fastqc_raw: input: "rnaseq/raw_data/{sample}.fq.gz" output: "rnaseq/raw_data/fastqc/{sample}_fastqc.html" params: outdir="rnaseq/raw_data/fastqc" conda: "rnaseq-env.yml" shell: """ fastqc {input} --outdir {params.outdir} """ ``` ::: - **Creating binders** - **Why**: teaching tool for software or analysis demos, share reproducible analysis :::spoiler Examples: - the Rstudio binder we're using today was created with https://binder.pangeo.io/ - [metENP binder](https://github.com/metabolomicsworkbench/MetENP): tool for metabolite enrichment analysis and their associated enriched pathways ::: ## Wrapping up There are many actions you can perform with conda environments. Today we have mentioned these! - init - config - search - create - activate/deactivate - list - remove - update - revert - export :::success :pencil: Please fill out our post-workshop survey! We use the feedback to help improve our training materials and future workshops. Link here: ==link== ::: :question: Questions? ## Resources - [CFDE training webite](https://training.nih-cfde.org/en/latest/) - Common conda commands: - [CFDE conda cheat sheets](https://training.nih-cfde.org/en/latest/Cheat-Sheets/conda_cheatsheet/) - [official conda cheat sheet](https://docs.conda.io/projects/conda/en/latest/user-guide/cheatsheet.html) - [Workshop additional resources/FAQ](https://hackmd.io/RweX2WZ7RGGtfLfCDuEubQ) - [CFDE events & workshops](https://www.nih-cfde.org/events/) - [DIB Lab video about conda](https://www.youtube.com/watch?v=Ef1QwhELuMs) ::: warning Links for Moderator to share: - pre-workshop resources wiki: https://github.com/nih-cfde/training-and-engagement/wiki/Resources-for-Workshop-Attendees - workshop notes: https://hackmd.io/btrlf-F3QbKbh2ZJeYbAjA?view - pre-workshop survey: ==link== - exercise 1: https://hackmd.io/btrlf-F3QbKbh2ZJeYbAjA?view#Exercise-1- - exercise 2: https://hackmd.io/btrlf-F3QbKbh2ZJeYbAjA?view#Exercise-2- - post-workshop survey: ==link== - CFDE training website: https://training.nih-cfde.org/en/latest/ - workshop additional resources/FAQ: https://hackmd.io/RweX2WZ7RGGtfLfCDuEubQ :::

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully