Sunday 14 October 2018

A Unix one-liner to call bacterial variants

Introduction

Variant finding is the generic term for finding differences between two genome sequences. These differences can take many forms, such as SNPs and small INDELs, large changes in DNA content caused by mobile elements, and structural changes like chromosomal inversions.

The genomes we want to compare could either be assemblies (complete or draft) or just sequencing reads (FASTQ files). The bulk of microbial variant finding tools focus on small differences (< 20 bp), and work by comparing a FASTQ sample to a assembled genome, typically called the "reference". A common use case is to sequence your isolate of interest, and see how it differs to the type strain in Genbank.

Calling SNPs with a one-liner

Let us assume we have a reference genome in FASTA format in the REF variable, the paired Illumina FASTQ files in R1 and R2, and the number of CPU cores you want to use in CPUS. Then, the follow "one-liner" will generate a VCF file with no intermediate files.

CPUS=4
REF=ref.fa
R1=R1.fastq.gz
R2=R2.fastq.gz

minimap2 -a -x sr -t "$CPUS" "$REF" "$R1" "$R2" \
 | samtools sort -l 0 --threads "$CPUS" \
 | bcftools mpileup -Ou -B --min-MQ 60 -f "$REF" - \
 | bcftools call -Ou -v -m - \
 | bcftools norm -Ou -f "$REF" -d all - \
 | bcftools filter -Ov -e 'QUAL<40 || DP<10 || GT!="1/1"' 
 > variants.vcf

The reads are aligned to the reference, and sorted by coordinate. Instead of saving the BAM file, we pipe it directly to a series of BCF tool steps. Note the use of -l 0 and -Ou to keep the piped data in an uncompressed form, to avoid repeated compression/decompression steps. The --min-MQ 60 ensures only uniquely mapped reads are used. The final filter step removes low quality variant calls, heterzygous calls (this is haploid bacteria), and any regions with less than 10 supporting reads.

Here is a summary of the results of this one-liner using some data for Pasteurella multocida. You can download with these links: REF (.fa.gz), R1 (.fastq.gz) and R2 (.fastq.gz).

bcftools stats variants.vcf | grep '^SN' | cut -f3-

number of samples:      1
number of records:      36618
number of no-ALTs:      0
number of SNPs: 36408
number of MNPs: 0
number of indels:       210
number of others:       0
number of multiallelic sites:   0
number of multiallelic SNP sites:       0

The one-liner found ~36,000 SNPs and 210 INDELs.

Existing software

This is not exhaustive list; just those I have encountered that are useful for bacterial data.

Full pipelines

Variant caller only

Conclusion

Variant calling in bacteria is both "easy" and "hard". If your sequencing data is high quality, not contaminated, and came from a pure colony, then finding most of variants will be relatively easy. The problems crop up when alignments aren't filtered correctly, reads are a mix of isolates, and the reference is too divergent from the isolate.

I have made many mistakes in SNP calling over the years. My own pipeline Snippy is now at version 4.3 and I'm still not completely happy with its performance, but it is "good enough" for its primary task which is to generate core-genome SNP phylogenies and find differences between mutants and wildtype in mutagenesis experiments.

Should you use the one-liner presented above? Probably not - the various available SNP pipelines have done a lot of tuning and offer extra useful features. However it is an excellent learning opportunity to examine each of the steps involved and the parameters that affect the output results.

It's always a trade-off between false positives and false negatives!

Further reading

9 comments:

  1. Replies
    1. I want to thank Dr Emu a very powerful spell caster who help me to bring my husband back to me, few month ago i have a serious problem with my husband, to the extend that he left the house, and he started dating another woman and he stayed with the woman, i tried all i can to bring him back, but all my effort was useless until the day my friend came to my house and i told her every thing that had happened between me and my husband, then she told me of a powerful spell caster who help her when she was in the same problem I then contact Dr Emu and told him every thing and he told me not to worry my self again that my husband will come back to me after he has cast a spell on him, i thought it was a joke, after he had finish casting the spell, he told me that he had just finish casting the spell, to my greatest surprise within 48 hours, my husband really came back begging me to forgive him, if you need his help you can contact him with via email: Emutemple@gmail.com or add him up on his whatsapp +2347012841542 is willing to help any body that need his help.

      Delete
    2. Hello, I know a genuine spell caster who helped me when my Husband divorced me, he made my husband come back to me and beg me to forgive him for the pains he has caused me, if you are in need of help to solve your relationship or marriage problem, contact DR. KALA, he is the right choice. He is a great man that has been casting spells with years of experience and he will help you to get your love back and cancel your divorce.

      Contact DR. KALA on email: kalalovespell@gmail.com or WhatsApp +2347051705853

      Delete
    3. My husband and I have been married for about 7 yrs now. We were happily married with two kids, a boy and a girl. 3 months ago, I started to notice some strange behavior from him and a few weeks later I found out that my husband is seeing someone. He started coming home late from work, he hardly care about me or the kids anymore, Sometimes he goes out and doesn't even come back home for about 2-3 days. I did all I could to rectify this problem but all to no avail. I became very worried and needed help. As I was browsing through the Internet one day, I came across a website that suggested that Dr Great can help solve marital problems, restore broken relationships and so on. So, I felt I should give him a try. I contacted him and he did a spell for me. Two days later, my husband came to me and apologized for the wrongs he did and promise never to do it again. Ever since then, everything has returned back to normal. I and my family are living together happily again.. All thanks to Dr Great . If you need a spell caster that can cast a spell that truly works, I suggest you contact him. He will not disappoint you. This is his E-mail: 

      infinitylovespell@gmail.com or infinitylovespell@yahoo.com

      WhatsApp +2348118829899

      Blog http://infinitylovespell1.blogspot.com






      My husband and I have been married for about 7 yrs now. We were happily married with two kids, a boy and a girl. 3 months ago, I started to notice some strange behavior from him and a few weeks later I found out that my husband is seeing someone. He started coming home late from work, he hardly care about me or the kids anymore, Sometimes he goes out and doesn't even come back home for about 2-3 days. I did all I could to rectify this problem but all to no avail. I became very worried and needed help. As I was browsing through the Internet one day, I came across a website that suggested that Dr Great can help solve marital problems, restore broken relationships and so on. So, I felt I should give him a try. I contacted him and he did a spell for me. Two days later, my husband came to me and apologized for the wrongs he did and promise never to do it again. Ever since then, everything has returned back to normal. I and my family are living together happily again.. All thanks to Dr Great . If you need a spell caster that can cast a spell that truly works, I suggest you contact him. He will not disappoint you. This is his E-mail: 

      infinitylovespell@gmail.com or infinitylovespell@yahoo.com

      WhatsApp +2348118829899

      Blog http://infinitylovespell1.blogspot.com

      Delete
  2. Hello, I know a genuine spell caster who helped me when my Husband divorced me, he made my husband come back to me and beg me to forgive him for the pains he has caused me, if you are in need of help to solve your relationship or marriage problem, contact DR. KALA, he is the right choice. He is a great man that has been casting spells with years of experience and he will help you to get your love back and cancel your divorce.

    Contact DR. KALA on email: kalalovespell@gmail.com or WhatsApp +2347051705853

    ReplyDelete
  3. I WANT MY EX LOVER BACK AND HOW TO GET YOUR EX LOVER BACK.I just want to give quick advice to anyone out there that is having difficulty in his or her relationship to contact Dr.Omokpo because he is the only one that is capable of bringing back broken relationships or broken marriages within the time limit of 2days. He brought back my ex lover back to me and this is a sign of appreciation to him that I am grateful for his help in my life, home and marriage. You can contact him via: dromokpo@gmail.com

    ReplyDelete
  4. IS IT POSSIBLE TO ACTUALLY GET BACK FUNDS LOST TO CRYPTOCURRENCY SCAM? ABSOLUTELY YES! BUT, YOU MUST CONTACT THE RIGHT AGENCY TO ACHIEVE THIS.

    Recovery Precinct is a financial regulator, private investigation and funds recovery body. We specialize in cases concerning cryptocurrency, FAKE investment schemes and recovery scam.

    Visit WWW. RECOVERYPRECINCT. COM now to report your case or contact our support team via the contact information below to get started.

    📊 RECOVERYPRECINCT (@) G MAIL . COM

    Stay Safe !

    ReplyDelete
  5. āļšāļĢิāļāļēāļĢāđ€āļāļĄāļŠāļĨ็āļ­āļ•āļ­āļ­āļ™āđ„āļĨāļ™์āļ›ี 2022 āđ€āļāļĄāđƒāļŦ้āđ€āļĨืāļ­āļāđ€āļĨ่āļ™āļĄāļēāļāļāļ§่āļē 1,000 āđ€āļāļĄāļŠāļĨ็āļ­āļ•āļ­āļ­āļ™āđ„āļĨāļ™์ d grdegr

    ReplyDelete
  6. Thank to Dr. Ogaga for bring back my lover in just 24 hours, when my lover left me i was sad and unhappy i wanted to kill my self because i love him so much i try to do what i can to get him but it did not work than I reach my friends and beg for them to help me beg him that am so sorry for what i have done, but it never work when i was browsing on my face-book. i saw some testimony of the great man and how he help people to bring back their lost lover back that is when i contacted him on Whats-App +2347059387282 in just 24 hours my story change, my lover that left me come back and beg after five month i was so happy that my lover is back to me all my appreciation goes to Dr Ogaga for bring back my lover back contact him if you are having any similar problem like this are any problem you may have Dr. Ogaga is the solution man, Whats-App him on +2347059387282

    ReplyDelete