一个经常会有些小脚本操作代码的网站-ecseq之脚本收集

http://www.ecseq.com/support/

image.png

干货很多,收了不看系列就不好了

1、Convert BAM to BED file format using command line perl

samtools view file.bam | perl -F'\t' -ane '$strand=($F[1]&16)?"-":"+";$length=1;$tmp=$F[5];$tmp =~ s/(\d+)[MD]/$length+=$1/eg;print "$F[2]\t$F[3]\t".($F[3]+$length)."\t$F[0]\t0\t$strand\n";'

2、Convert an interleaved fasta file to a single line fasta using only the Linux command line

awk '{if(NR==1) {print $0} else {if($0 ~ /^>/) {print "\n"$0} else {printf $0}}}' interleaved.fasta > singleline.fasta

3、How to get a coverage graph in WIG file format directly from an alignment (BAM)

samtools mpileup -BQ0 run.sorted.bam | perl -pe '($c, $start, undef, $depth) = split;if ($c ne $lastC || $start != $lastStart+1) {print "fixedStep chrom=$c start=$start step=1 span=1\n";}$_ = $depth."\n";($lastC, $lastStart) = ($c, $start);' | gzip -c > run.wig.gz

4、Convert FASTQ to FASTA on the command line

paste - - - - < file.fq | cut -f 1,2 | sed 's/^@/>/' | tr "\t" "\n" > file.fa

5、Add gzip/gunzip support to a program that doesn't have it (e.g. bowtie)

mkfifo mate1.fastq
mkfifo mate2.fastq
gunzip -c mate1.fastq.gz > mate1.fastq &
gunzip -c mate2.fastq.gz > mate2.fastq &
bowtie -S genome -1 mate1.fastq -2 mate2.fastq > sample.sam

6、Annotate mapping entries of a BAM file based on overlaps with BED files using BEDtools

tagBam -i run.bam -files RefSeq.bed -names -tag GA > run.tagged.bam

7、Extract a list of specific read IDs from a bam file

samtools view file.bam | fgrep -w -f IDs.txt

8、Run time-consuming processes in parallel on Unix systems

# Example usage of xargs (-P is the number of parallel processes started - don't use more than the number of cores you have available):
samtools view -H yourFile.bam | grep "\@SQ" | sed 's/^.*SN://g' | cut -f 1 | xargs -I {} -n 1 -P 24 sh -c "samtools mpileup -BQ0 -d 100000 -uf yourGenome.fa -r {} yourFile.bam | bcftools view -vcg - > tmp.{}.vcf"

# To merge the results afterwards, you might want to do something like this:
samtools view -H yourFile.bam | grep "\@SQ" | sed 's/^.*SN://g' | cut -f 1 | perl -ane 'system("cat tmp.$F[0].bcf >> yourFile.vcf");'
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,505评论 0 10
  • 我也喜欢 想你的那种疼 喜欢 和你心有灵犀的 缘!! 想你时 心中就有一种 毛茸茸的痒 我的思念 随风潜入夜 依附...
    相约蒲公英阅读 286评论 0 0
  • 这是一个农村的世界,油菜花海,白雪皑皑,好像冰雪世界,这一年,我大二上学期,刚刚拿了国家励志奖学金,这一个学期我很...
    梦曦笔谈阅读 126评论 0 0
  • 2016-08-31 - ETC 能用复制 ETH 上项目的方式成长壮大吗? 山寨币没有什么超越比特币思想的创新,...
    杜WD阅读 181评论 0 0
  • 今天介绍《高效能人士的七个习惯》从依赖走向独立的第三个习惯:要事第一。 我们大部分人每天需要做很多工作:赶项目进度...
    MKK记录频道阅读 686评论 0 1