ranmk
    • 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
    # Remove Human Reads from Metagenomic Sample FASTQ files (Test with 1 sample) Using information from:https://sites.google.com/site/wiki4metagenomics/tools/short-read/remove-host-sequences ## Overall Steps 1. Download Human Reference Genome 2. Build Bowtie2 index using the human reference genome 3. Map sample fastqs against the reference genome using bowtie2 4. Convert resulting SAM files to BAM files using samtools 5. Get unmapped pairs (did not match Human genome) using Samtools 6. Split bam files back into separated fastq files using bedtools <br> #### Download Human Reference Genome & uncompress ``` wget -c ftp://ftp.ncbi.nlm.nih.gov/refseq/H_sapiens/annotation/GRCh38_latest/refseq_identifiers/GRCh38_latest_genomic.fna.gz gunzip GRCh38_latest_genomic.fna.gz ``` <br> #### Build Bowtie2 index using the human reference genome ``` bowtie2-build GRCh38_latest_genomic.fna host_db ``` > Total time for backward call to driver() for mirror index: 00:59:58 <br> #### bowtie2 mapping against host sequence database, keep both mapped and unmapped reads ``` bowtie2 -x host_db -1 SH5971_SA48774_S4_L008_R1_trimmed.fastq -2 SH5971_SA48774_S4_L008_R2_trimmed.fastq \ -S SH5971_SA48774_S4_L008_mapped_and_unmapped.sam ``` > 5856764 reads; of these: 5856764 (100.00%) were paired; of these: 3352513 (57.24%) aligned concordantly 0 times 2202085 (37.60%) aligned concordantly exactly 1 time 302166 (5.16%) aligned concordantly >1 times ---- 3352513 pairs aligned concordantly 0 times; of these: 345368 (10.30%) aligned discordantly 1 time ---- 3007145 pairs aligned 0 times concordantly or discordantly; of these: 6014290 mates make up the pairs; of these: 5790862 (96.29%) aligned 0 times 92875 (1.54%) aligned exactly 1 time 130553 (2.17%) aligned >1 times 50.56% overall alignment rate <br> #### convert file .sam to .bam ``` samtools view -bS SH5971_SA48774_S4_L008_mapped_and_unmapped.sam > SH5971_SA48774_S4_L008_mapped_and_unmapped.bam ``` <br> ### Filter required unmapped reads #### SAMtools SAM-flag filter: get unmapped pairs (both ends unmapped) ``` samtools view -b -f 12 -F 256 SH5971_SA48774_S4_L008_mapped_and_unmapped.bam > SH5971_SA48774_S4_L008_bothEndsUnmapped.bam ``` -f 12 Extract only (-f) alignments with both reads unmapped: <read unmapped><mate unmapped> -F 256 Do not(-F) extract alignments which are: <not primary alignment> <br> #### Sort bam file by read name (-n) to have paired reads next to each other as required by bedtools ``` samtools sort -n SH5971_SA48774_S4_L008_bothEndsUnmapped.bam > SH5971_SA48774_S4_L008_bothEndsUnmapped_sorted.bam ``` <br> #### Split sorted unmapped BAM file to R1 & R2 Fastq files ``` bedtools bamtofastq -i SH5971_SA48774_S4_L008_bothEndsUnmapped_sorted.bam -fq SH5971_SA48774_S4_L008_host_removed_r1.fastq -fq2 SH5971_SA48774_S4_L008_host_removed_r2.fastq ``` ## Success!!! ## Testing with non-trimmed fq & host_db in diff directory ``` cd /home/chiranjit/new_pipeline/batch8_fastqs mkdir host_rem ln -s SH5971_SA48774_S4_L008_R1_001.fastq.gz host_rem/sample1_R1_001.fastq.gz ln -s SH5971_SA48774_S4_L008_R2_001.fastq.gz host_rem/sample1_R2_001.fastq.gz cd host_rem bowtie2 -x /home/chiranjit/databases/hg38/host_db -1 SH5971_SA48774_S4_L008_R1_001.fastq.gz -2 \ SH5971_SA48774_S4_L008_R2_001.fastq.gz -S SH5971_SA48774_S4_L008_mapped_and_unmapped.sam samtools view -bS SH5971_SA48774_S4_L008_mapped_and_unmapped.sam > SH5971_SA48774_S4_L008_mapped_and_unmapped.bam samtools view -b -f 12 -F 256 SH5971_SA48774_S4_L008_mapped_and_unmapped.bam > SH5971_SA48774_S4_L008_bothEndsUnmapped.bam samtools sort -n SH5971_SA48774_S4_L008_bothEndsUnmapped.bam > SH5971_SA48774_S4_L008_bothEndsUnmapped_sorted.bam bedtools bamtofastq -i SH5971_SA48774_S4_L008_bothEndsUnmapped_sorted.bam -fq SH5971_SA48774_S4_L008_nohuman_R1.fastq \ -fq2 SH5971_SA48774_S4_L008_nohuman_R2.fastq grep -c "@" SH5971_SA48774_S4_L008_nohuman_R1.fastq ``` > 3349850 ## Success! # Test with small fileset ``` cd /home/chiranjit/batch8_fastqs mkdir hum_test gunzip -c SH5971_SA48774_S4_L008_R1_001.fastq.gz > sample1_R1_001.fastq gunzip -c SH5971_SA48774_S4_L008_R2_001.fastq.gz > sample1_R2_001.fastq head -1000 sample1_R1_001.fastq > hum_test/sample1a_R1_001.fastq head -1000 sample1_R2_001.fastq > hum_test/sample1a_R2_001.fastq tail -1000 sample1_R1_001.fastq > hum_test/sample1b_R1_001.fastq tail -1000 sample1_R2_001.fastq > hum_test/sample1b_R2_001.fastq cd hum_test find . -name "*fastq" -exec gzip '{}' \; mkdir host_rem_test mv hum_test host_rem_test cd host_rem_test /home/chiranjit/scripts/jpl_metg_hum_rem.sh 8 hum_test 12 ``` > total 180K drwxrwxr-x 4 chiranjit chiranjit 4.0K Oct 19 18:34 . drwxrwxr-x 4 chiranjit chiranjit 4.0K Oct 19 18:28 .. drwxrwxr-x 2 chiranjit chiranjit 4.0K Oct 19 18:29 batch8_human_removed drwxrwxr-x 2 chiranjit chiranjit 4.0K Oct 19 18:29 batch8_hum_intermeds -rw-rw-r-- 1 chiranjit chiranjit 15K Oct 19 18:28 sample1a_R1_001.fastq.gz -rw-rw-r-- 1 chiranjit chiranjit 17K Oct 19 18:28 sample1a_R2_001.fastq.gz -rw-rw-r-- 1 chiranjit chiranjit 15K Oct 19 18:28 sample1b_R1_001.fastq.gz -rw-rw-r-- 1 chiranjit chiranjit 20K Oct 19 18:28 sample1b_R2_001.fastq.gz ## Success!! find /home/chiranjit/batch8_fastqs/host_rem_test/batch8_fastqs/batch8_human_removed/ -maxdepth 1 -type f -exec ln -s {} \;

    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