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
lubertorubior / one-liners Goto Github PK
View Code? Open in Web Editor NEWThis project forked from genomicsiter/one-liners
Frequently used commands in Bioinformatics