hackathon-nf-workflows-nov-2020
      • 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
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners 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
    • 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 Help
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
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners 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
    --- title: Hackathon P1 - From Snakemake to Nextflow slides tags: crg, bovreg, faang, nextflow, nf-core, hackathon, talk description: View the slide with "Slide Mode". --- ![](https://i.imgur.com/8shLI1g.jpg =300x)![](https://imgur.com/s6arYRT.jpg =200x) # Hackathon November 2020 --- <!-- Put the link to this slide here so people can follow --> slides: https://hackmd.io/@Hackathon-November-2020/B1HgcJk5v --- # Project 1: From Snakemake to Nextflow --- ## Primary focus Convert an existing Snakemake pipeline in a Nextflow pipeline: - equivalence between snakemake and nextflow functionnalities - other advices on nextflow --- ## People involved ### Proposed by - Maria Bernard (INRAE) - Mathieu Charles (INRAE) ### Group members - Maria Bernard (INRAE, BovReg) - Mathieu Charles (INRAE) - Christophe Klopp (INRAE) - Daniel Fisher (LUKE, BovReg) - Jose Espinosa (CRG) - Emilio Palumbo (CRG) - Alessio Vignoli (CRG) - Suzanna Jin (CRG) --- # Nextflow(/Snakemake equivalence) technical questions * **how to perform a dryrun** snakemake option --dryrun there is no nextflow equivalent, just run your workflow on toy dataset (that is a recommendation of nf-core) * **how to deal with temporary files** snakemake statement is `temp()` in the rules output files definition In nextflow there is no equivalent system (removing temp file when they become useless). The adviced method is the play with scratch (have a look to the `process.scratch = true` statement), work and published folders. Or you can manually manage temporary files by defining cleaning processes (but take care to remove the actual files not only the symlink). * **how to limit the number of jobs launched in parallel** snakemake options is `--jobs` In nextflow, the number of jobs is by default 100, to change it we need to use the nextflow workflow config file : nextflow.config and add a section `executor` : https://www.nextflow.io/docs/latest/config.html#scope-executor, and modify the `queueSize` attribute ``` executor { name = 'sge' queueSize = 200 pollInterval = '30 sec' } ``` * **what about logging** In snakemake use `--prinshellcmds` to have a verbose log off all launched shell. In Nextflow there is .nextflow.log file which precised nextflow technical log information( number of process pass, cached, failed ...). For actual shell command line, we need to use `nextflow log` command and precise a particular session to see what have been done. * **how to deal with dependencies** snakemake work (among other system) with conda by the rules section `conda`, or by using an `env.yaml` file that specifies conda dependencies. In nextflow, there is a very similar system, we need to add conda statement in the process definition (https://www.nextflow.io/docs/latest/conda.html?highlight=conda#) and then use the `-with-conda` option in the nextflow run command line. example: write a my-env.yaml file, something like: ``` name: my-env channels: - conda-forge - bioconda - defaults dependencies: - star=2.5.4a - bwa=0.7.15 ``` and use this yaml file in the process ``` process foo { conda '/some/path/my-env.yaml' ''' your_command --here ''' } ``` there is different syntaxes to precise conda dependencies. You could also simple precise name of the conda dependencies separated by space. `conda 'bwa samtools multiqc'` * **how to perform a conditionnal process** We do not know how to do it with Snakemake. Use the `when` statement on an input, like: ``` params.iter = [1,2,3] iter_ch = Channel.fromList(params.iter) // iter_ch could be output of an other process process conditionnal_process { input: val x from iter_ch when: x <= 2 output: stdout into result """ printf $x """ } result.view() ``` * **Dynamic resources allocation** In snakemake there is a global cluster configuration file that is used to allocate the resources for the used rules. That means, resources need to be allocated on a worse case estimation so that the rule does not fail (e.g. out of memory, out of time, etc.). Nextflow, however, can change they requested resources on runtime/error code depending. E.g. if for one sample the allocated RAM is not enough, the process can be restarted with increased amount RAM, for details see: https://www.nextflow.io/docs/latest/process.html?highlight=when#dynamic-computing-resources * **workflow organisation** In snakemake it's recommended to have a rules directory with small snakefiles that define rules and one snakefile that import rules and defines the workflow outputs In Nextflow (in DSL1 ), everything is written in one file. * **general differences : file manipulation** We need to put file in channels for nextflow to understand its a file and not the string corresponding to the path of the file. ``` params.genome = 'genome.fa' genome_ch = Channel.fromPath(params.genome) process foo { input: file genome from genome_ch } ``` or ``` params.genome = "$baseDir/genome.fa" process foo { input: path genome from params.genome } ``` !!! we need an absolute path, doesn't seem to work with a relative path # Additional notes * **Config profile to precise computing environment** There is a dedicated cluster profile for the Genotoul cluster (INRAE, Toulouse, France) documentation : https://github.com/nf-core/configs/blob/master/docs/genotoul.md config file : https://github.com/nf-core/configs/blob/master/conf/genotoul.config * **How to make a workflow nf-core compatible** There is a command to help how to start a nf-core compatible workflow ( https://nf-co.re/tools#creating-a-new-workflow) : `nf-core create` # STIP Nextflow implementation workflow ## Goal : Find regulatory SNP candidate (rSNP) Does the SNP impact the sequence affinity with a Transcription Factor ? (likelihood the TF will bind with this sequence) * How does it work - step1: We expect to find rSNP candidate in a 2kb window upstream of TSS start. We filter the SNP file, keeping only the corresponding SNP. - step2: For each filtered SNP, we create ref and alt sequences correponding to SNP ref and alt base and its surrounding sequences (+/- 14bp) - step3: We download the matrices from existing database (TRANSFAC,JASPAR, HOCOMOCO) and prepare them (PWM <-> PFM, ratio, distrib) - step4: For each filtered SNP, we compare the ref and alt sequences to each TF matrices Does ref and/or alt sequence have a strong affinity with TF (putative TFBS)? Does the SNP impact the putative TFBS ? * inputs - Genome reference file: Fasta and annotation in GTF file - Variant file : in VCF format - TFBS pattern matrices : directory of PWM files (one file per TFBS) * outputs - TSV file with regulatory variant, and metadata such as TFBS name, score of affinity, impacting score ## git repository https://github.com/MathieuCharlesINRAE/Hackathon_NextFlow_Nov2020/tree/main ## nextflow question - create of composite inputs from non paired files in trainings we saw that we can create composite inputs, for example for pair end reads, which results of element composed of an id and a paire of file : ``` reads_ch = Channel.fromFilePairs('data/ggal/gut*_{1,2}.fq') // and then in a process set val(sample_id), file(sample_files) from reads_ch ``` which results in something like: ``` [gut, [/home/ec2-user/environment/data/ggal/gut_1.fq, /home/ec2-user/environment/data/ggal/gut_2.fq]] ``` How to obtain same composite input but with single end reads ? or for this pipeline something like `[tfbs1,/path/to/tfbs1.pwm]` Solution ``` reads_ch = Channel.fromPath('data/ggal/*_1.fq') .map { file -> [ file.name.replace("_1.fq",""), file ] } .view() // it returns // [lung, /home/ec2-user/environment/data/ggal/lung_1.fq] // [gut, /home/ec2-user/environment/data/ggal/gut_1.fq] // [liver, /home/ec2-user/environment/data/ggal/liver_1.fq] // // and then in a process process echo { echo true input: set val(sample_id), file(sample_file) from reads_ch output: stdout into result script: """ echo $sample_id" sequence file is "$sample_file """ } ``` - how to bypass part of process executions In this pipeline we have a preprocessing step which can be quite long For each TFBS a affinitiy score distribution and score ratio distribution are computed. Imagine a process that take as input one PFM file and return the two distribution. For each TFBS the distributions files will be written in work/random_id/, with a different random_id for each process so each TFBS. For a next execution of the pipeline, how could we indicate to nextflow to not resume this process for already existing distribution ? solution 1 \- using a preprocessedFolder with the distributions files already computed ``` params.matrixPreprocessedFolder = "$baseDir/results/matrix_processed" matrixPreprocessedFolder_ch = Channel.fromPath("${params.matrixPreprocessedFolder}/*.pfm") .map { file -> [ file.name.replace(".pfm",""), file, "${params.matrixPreprocessedFolder}/" + file.name.replace(".pfm",".score_distrib"), "${params.matrixPreprocessedFolder}/" + file.name.replace(".pfm",".ratio_distrib") ] } .view() ``` \- and then using a when statement ? But how to test if a file exists ?

    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