Coder Social home page Coder Social logo

one-liners's Introduction

one-liners, frequently used commands in Bioinformatics

Select region from 1KGP chr.vcf.gz, extract, compress, and tabix
region="3:10000-11000"
infile="ALL.chr3.phase3_shapeit2_mvncall_integrated_v5a.20130502.genotypes.vcf.gz"
outfile="1KGP.chr3.region"
tabix -h ${infile} ${region} > ${outfile}.vcf
bgzip -c ${outfile}.vcf > ${outfile}.vcf.gz
tabix -p vcf ${outfile}.vcf.gz

Select a subset of samples (list here contains GBR individuals from 1KGP), and tabix
outfile="1KGP.chr3"
lista="pop_GBR"
suffix="GBR"
vcf-subset -c ${lista} ${outfile}.vcf.gz | bgzip -c > ${outfile}.${suffix}.vcf.gz
tabix -p vcf ${outfile}.${suffix}.vcf.gz


Remove "chr" string in variants in a VCF
awk '{gsub(/^chr/,""); print}' infile.vcf > infile.no_chr.vcf


Add "chr" string in variants in VCF
awk '{if($0 !~ /^#/) print "chr"$0; else print $0}' infile.no_chr.vcf > infile.vcf


Sort karyotipically a VCF (version 1)
##Notice that header must be removed at some point
grep '^#' in.vcf > out.vcf && grep -v '^#' in.vcf | sort -V -k1,1 -k2,2n >> out.vcf

Sort karyotypically a VCF (version 2). Use '-V', natural sort of (version) numbers within text
sort -V -k1,1 -k2,2n infile.vcf > outfile.vcf


Replace spaces with a single tab
sed 's/ +/\t/g' infile > outfile


Compute BAM coverage with BEDtools
bedtools genomecov -ibam infile.bam -bg > coverage.txt


Find duplicated lines in a VCF matching the whole line
awk ' !uniq[$0]++ ' infile.vcf


Find duplicated lines in a VCF matching files 1, 2, and 5
awk ' !uniq[$1 FS $2 FS $5]++ ' infile.vcf


Find a line by a field on it, delete it, and save the result
string=abc
grep -v $string infile > outfile


Count the number of mapped reads for each read in PE reads
samtools view -F 0x40 infile.bam | cut -f1 | sort | uniq | wc -l
#Left read: view the BAM content filtering by the provided SAM flags, cut the first column, sort the data on that column, keep only the uniq data on that column, and count the number of lines.
samtools view -f 0x40 -F 0x4 infile.bam | cut -f1 | sort | uniq | wc -l
#Right read
samtools view -f 0x80 -F 0x4 infile.bam | cut -f1 | sort | uniq | wc -l

Note: for flags information, see page 5 of https://samtools.github.io/hts-specs/SAMv1.pdf

Replace white spaces with tabs
awk -v OFS="\t" '$1=$1' infile > outfile

one-liners's People

Contributors

genomicsiter avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.