C. Titus Brown
    • 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 New
    • 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 Note Insights Versions and GitHub Sync 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: ggg, ggg2020, ggg201b --- # GGG 201b, jan 2020 - lab 3 - NOTES [toc] ## Friday Lab Outline - 1/24 You can do collaborative note taking [here](https://hackmd.io/cZ9ehhV7TQONFu5EYx2JgA) if you like! Outline: * even more on variant calling * even more on snakemake * discuss "real" variant calling on big genomes (GATK, etc.) ## Learning goals * Start using farm, github, and conda. * Learn about default rules. * Learn about wildcards. ## Day 3: More variant calling with more snakemake ### Log into farm Using the username/password I provided, log into farm. You should end up at a prompt that looks like this: ``` (base) USERNAME@farm:~$ ``` the (base) means you've installed conda, USERNAME is your username, 'farm' is the name of the computer, and `~` is your location - ~ means your home directory. The `$ ` indicates you're at the command line prompt. ### Clone a repository from github Let's start by taking the binder repository from last week and making a local copy in your account: ``` git clone https://github.com/ngs-docs/2020-ggg-201b-variant-calling variants/ -b week3 ``` This takes the data at https://github.com/ngs-docs/2020-ggg-201b-variant-calling, in the week3 branch, and makes a local copy in the directory `./variants/`. You can do `ls` to look at this directory: ``` ls ~/variants/ ``` You should see that there's a `Snakefile` in there. That's what we've been working with in previous weeks. ### Installing necessary software with 'conda' Before doing anything else, we need to install some software. Conveniently that's something that conda can do for us all in one fell swoop -- run ``` conda env create -f variants/binder/environment.yml ``` which will take ~3 minutes. This will install [the packages listed in this file](https://github.com/ngs-docs/2020-ggg-201b-variant-calling/blob/master/binder/environment.yml). If you want to know more about conda, please see [this week's GGG 298 tutorial](https://hackmd.io/@ctb/BkbkefV-U). ## Back to snakemake and actual variant calling. (Every time you log in you'll need to activate a conda environment and change to the right directory. For this week, we want to be in the `vc` environment and the `variants/` directory.) Activate the conda `vc` environment, which was created by the previous conda command: ``` conda activate vc ``` and change to the `variants/` directory: ``` cd ~/variants/ ``` Your prompt should now look like this: `(vc) USERNAME@farm:~/variants$ ` reflecting the new environment (vc) and the location (~/variants/). ### Note new data copy rule in Snakefile Because we're all working off of `farm`, we have a shared filesystem! So now instead of downloading the data we can just link it in from one copy, using `ln -s`. ([You can see all of the differences in the Snakefile between last week and this week here](https://github.com/ngs-docs/2020-ggg-201b-variant-calling/compare/week3)). ### Running lots of commands all at once Last week, we fixed the rules `index_genome_bwa` and `map_reads`; I added the right input and output to the two remaining rules as well. So now you should be able to run everything up to the rule `make_vcf` by just specifying `make_vcf` - try it! ``` snakemake -p make_vcf ``` ### Re-running everything You can tell snakemake to delete everything it knows how to make for a particular rule (including all preceding rules) by running ``` snakemake --delete-all-output make_vcf ``` (This can also be a good way to check to make sure you have all the output: information right, because you'll have files left over if you forgot to put them in output: :) ### Using filenames instead of rule names You don't actually need to use the rule names (this will be important later on!). You can just tell snakemake what file you want produced, and run that. So: ``` snakemake -p variants.vcf ``` will also work to run the rule `samtools_sort`, but you don't have to remember the rule name (which can be arbitrary...) ### Running the whole workflow! And now you should be able to run `snakemake -p make_vcf` and have it all work! But it's kind of annoying that you have to specify `make_vcf`, isn't it? Can we make that default as well? ### Create a good "default" rule By default, if you don't specify a rule snakemake runs the first rule in the file. (This is actually the only case where the order of rules in the Snakefile matters!) So it's conventional to define a rule named `all` at the top; try it! Add with `nano -ET4 Snakefile`, ``` rule all: input: "variants.vcf" ``` (Reminder: use CTRL-X, y, ENTER to exit the nano editor and save things) Question: why specify the _input_ for this rule, and no output or shell command!? Answer: there's no real answer. It's just a cute trick that matches the way snakemake thinks; snakemake knows the first thing it needs to do for a rule is find the inputs, so this `all:` rule forces it to build the inputs. Then there's nothing else for snakemake to do so it claims success! This turns out to be an important distinction, though. As you'll see with wildcards, below, we'll end up having two kinds of rules in the Snakefile: what I'll call "concrete" rules, and what I'll call "abstract" rules. Abstract rules are generic recipes - "here's how you cook spaghetti." Concrete rules are specific directives: "make me this much spaghetti, please." ### Looking at VCF files A reminder that we are actually doing bioinformatics in all of this :). Let's look at the output: ``` cat variants.vcf ``` ### Looking at alignments and we can dig into any given alignment by running: ``` samtools tview -p ecoli:4202391 SRR2584857.sorted.bam ecoli-rel606.fa ``` ## "Real" variant calling, digression I feel compelled to mention that this is not the variant calling workflow you would necessarily use. Many people do indeed use samtools, but if you may also want to look into [GATK](https://gatk.broadinstitute.org/hc/en-us) if you have a big or complex genome. You should also look into the various parameters used for mapping, mpileup, and so on. I'm happy to chat about this, but I'm not really an expert; I do have experts in my lab, though, and there are many on campus! ### Digression in a digression: MAD You might be interested in [Meet and Analyze Data](https://mad.oxli.org). More on that in a bit... ## Next workflow steps: more snakemake ### Using wildcards: `{sample}` A big problem right now is that all our rules are tied to a specific filename. Let's fix that: In the rule map_reads, change things to: ``` rule map_reads: input: "ecoli-rel606.fa.amb", "{sample}.fastq.gz" output: "{sample}.sam" shell: "bwa mem -t 4 ecoli-rel606.fa {wildcards.sample}.fastq.gz > {wildcards.\ sample}.sam" ``` ### Changing outputs, too The one remaining problem with the outputs is that the final rule specifes a single `variants.vcf` when what we really want is `{wildcards.sample}-variants.vcf` -- one for each input sample. Fix it to read like this: ``` rule make_vcf: input: "{sample}-variants.raw.bcf" output: "{sample}-variants.vcf" shell: "bcftools view {wildcards.sample}-variants.raw.bcf > {wildcards.samp\ le}-variants.vcf" ``` ## Wildcards, in summary * In the 'input' and 'output' tags, put wildcard terms in curly brackets, e.g. `{sample}` or `{reads}`. * In the shell command, use matching wildcard terms in like so: `{wildcards.sample}` or `{wildcards.reads}` * wildcards operate entirely within a single rule, not across rules. * you will need (somewhere) to provide them snakemake with a concrete rule that asks for the wildcard rules to be applied, e.g. if you have a rule that says "produce a `.sam` file from a `.fastq.gz` file" somewhere you need to ask for a specific `.sam` file. ### Q: What if I get a workflow error? If you get the error >WorkflowError: >Target rules may not contain wildcards. Please specify concrete files or a rule without wildcards. > then what's happening is you're trying to directly run a rule with a wildcard in it (i.e. an abstract rule), and snakemake can't figure out what the wildcard should be; instead, ask snakemake to build a specific file. For example, with the rule immediately above that adds wildcards to `map_reads`, ``` snakemake map_reads ``` will complain about the target rule containing wildcards. You should instead run ``` snakemake SRR2584857_1.sam ``` which snakemake can use to figure out what the wildcards should be. An alternative to specifying the file on the command line is to put it in the default rule, e.g. `rule all:` (see [the section on default rules](https://hackmd.io/cGYzxz07SseGxH0y2gjYJw?view#Create-a-good-%E2%80%9Cdefault%E2%80%9D-rule)) and then you can run `snakemake`. ### A quick checklist: * Are you asking snakemake to create a _specific_ file? * either by executing `snakemake <filename>` * or by specifying a rule that has an input or an output without wildcards, * or by providing a default rule? * for any rule that you expect to be executed automatically (because some other rule needs its output), have you specified `output:`?

    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