生物信息學(xué)中常用的文件轉(zhuǎn)換命令

放置在最前面的參考鏈接

支持的文件轉(zhuǎn)換類型

  • text file to wig
  • bed to wig
  • wig to bed
  • wig to bigwig
  • bed to bigbed
  • BAM to bedGraph for UCSC genome browser
  • bam to bigwig
  • bed to gff
  • Split bed file by chromosome
  • gff to gtf
  • gtf to bed
  • blat to gff
  • ...

由于需要翻墻,所以這里直接將整個網(wǎng)頁復(fù)制粘貼過來(這應(yīng)該不侵權(quán)吧烟具!)

Convert text file to wig

 Sample command:
   txt2wig.pl foo.txt trackName(one word) > foo.wig

Convert bed to wig

    Sample command:
    bed2wig.pl inputBed sampleName(one word) probeWidth > outputWig
    Note: It assumes that the probe width in all records is constant.
          If probe width is not constant, you can use bedGraph format.
          To convert bed to bedGraph format, just change the track name to bedGraph, and minus chromosome end position in bed format by 1.

Convert wig to bed

  Sample command with variableStep wig format:
   wig2bed.pl inputWig sampleName(one word) > outputBed
  
   Sample command with fixedStep wig format:
   wig2bed_fixedStep.pl inputWig > outputBed

Convert wig to bigwig

  Sample commands:
  Get chromosome lengths
   fetchChromSizes  hg18 > chrSize.txt
  Convert wig to big wig:  
   wigToBigWig foo.wig chrSize.txt foo.bw

Convert bed to bigbed

 Sample commands:
  Get chromosome lengths
   fetchChromSizes  hg18 > chrSize.txt
  Convert bed to big bed:  
   bedToBigBed foo.bed chrSize.txt foo.bb

Convert BAM to bedGraph for UCSC genome browser

  To view BAM files on UCSC browser, both foo.sorted.bam and foo.sorted.bam.bai have to be on a http or ftp server. One way to get around this is to convert BAM files into bedGraph files, which should be small enough that they can be simply uploaded.
   genomeCoverageBed -split -bg -ibam sorted.bam -g hg19.genome    
   where hg19.genome file is tab delimited and structured as follows:
       <chromName><TAB><chromSize>
       chr1    249250621
   One can use the UCSC Genome Browser's MySQL database to extract chromosome sizes. For example, H. sapiens:
       mysql --user=genome --host=genome-mysql.cse.ucsc.edu -A -e "select chrom, size from hg19.chromInfo" > hg19.genome

Convert bam to bigwig

  • Method 1: Single-base resolution across the genome
  Step1: convert bam to bedGraph format:
genomeCoverageBed -split -bg -ibam accepted_hits.bam -g /nfs/genomes/mouse_gp_jul_07/anno/mm9.size > accepted_hits.bedGraph

  Step2: convert bedGraph to bigwig format:
bedGraphToBigWig  accepted_hits.bedGraph /nfs/genomes/mouse_gp_jul_07/anno/mm9.size accepted_hits.bw
    where mm9.size file is tab delimited and structured as follows:
        <chromName><TAB><chromSize>
  • Method 2: Resolution of desired window size (after creating windows across desired regions or genome)
coverageBed -a Human.hg19.1000.500.bed -b Sample_1.sorted.bam | cut -f1-4 > Sample_1.1000.500.coverage.bedgraph

Update/fix UCSC GTF file

  • GTF files from UCSC Table Browser use RefSeq (NM* ids) for both gene_id and transcript_id which may not be compatible for some programs (eg. counting by genes using HTSeq)
  • Some Refseq gtf files (such as for the hg19, hg18, mm9, and dm3 assemblies) are in /nfs/genomes/, under gtf/ in each species folder. If you would like to create additional files, here are the steps:
  Step 1: Use UCSC Table Browser to download RefSeq id and gene symbol.
    Use "Genes and Gene Prediction Tracks" for group, "RefSeq Genes" for track and "refGene" for table.  Choose  "selected fields from primary and related tables" for output format and click "get output".  In the next page select "name" and "name2" for the fields.  
    output format should be : NM_017940       NBPF1
  Step 2: Download a gtf file from the UCSC Table Browser
    This uses refseq ID as gene_id and transcript_id, so we need to replace it with the gene symbol.
    sample command:  
      /nfs/BaRC_Public/BaRC_code/Perl/fix_gtf_refSeq_ensembl.pl hg19.refgene.gtf refseq2symbol > hg19.refgene.gtf
  Step 3: About 50-70 genes in the gtf file from UCSC are incorrect; they include exons with a start coordinate that is larger than the end coordinate.  
    Software such as cufflinks fails to deal with this situation and ignores these exons. 
    Since this only affects the last 1-3 bases of a transcript, a temporary solution is to remove these records.
      sample command: awk -F"\t" '{ if($4<=$5) print $0 }' hg19.refgene.gtf > hg19.refgene_new.gtf

Convert bed to gff

  • Note that bed and gff use slightly different coordinate conventions
  • Use /nfs/BaRC_Public/BaRC_code/Perl/bed2gff/bed2gff.pl
    USAGE: bed2gff.pl bedFile > gffFile
    Ex: bed2gff.pl foo.bed WIBR exon > foo.gff

Split bed file by chromosome

  • Sometimes it's easier working with only one chromosome of regions at a time
  • Output files will be named like "Sample_1.chr1.bed".
 awk '{close(f);f=$1}{print > "Sample_1."f".bed"}' Sample_1_all_chrs.bed

Convert gff to gtf

  • Use ?gffread: Try 'gffread -h' too see the program's many options
gffread My_transcripts_genes.gff3 -T -E -o My_transcripts_genes.gtf

Convert gtf to bed

  • convert gtf to genePhred
  gtfToGenePred my.gtf my.genePhred
  • convert genePhred to bed:
   awk -f genePhredToBed my.genePhred > my.bed
  • genePhredToBed is a awk script by Katrina Learned, downloaded from UCSC Genome Browser discussion list
#!/usr/bin/awk -f

#
# Convert genePred file to a bed file (on stdout)
#
BEGIN {
     FS="\t";
     OFS="\t";
}
{
     name=$1
     chrom=$2
     strand=$3
     start=$4
     end=$5
     cdsStart=$6
     cdsEnd=$7
     blkCnt=$8

     delete starts
     split($9, starts, ",");
     delete ends
     split($10, ends, ",");
     blkStarts=""
     blkSizes=""
     for (i = 1; i <= blkCnt; i++) {
         blkSizes = blkSizes (ends[i]-starts[i]) ",";
         blkStarts = blkStarts (starts[i]-start) ",";
     }

     print chrom, start, end, name, 1000, strand, cdsStart, cdsEnd, 0, blkCnt, blkSizes, blkStarts
}

Convert blat to gff

  • Use /nfs/BaRC_Public/BaRC_code/Perl/blat2gff/blat2gff.pl
 Convert BLAT output file (PSL format) into GFF format (v1.1 14 Dec 2010)
   blat2gff.pl blatFile dataSource(ex:WIBR) > gffFile

Create wiggle files for visualizing paired-end data mapping to the + and - strands

  • split by strand by matched strand
# input:    accepted_hits.bam
# output:   accepted_hits_negStrand.bam: mapped to negative strand
#       accepted_hits_posStrand.bam: mapped to positive strand

bsub "samtools view -f 16 -b accepted_hits.bam >| accepted_hits_negStrand.bam"
bsub "samtools view -F 16 -b accepted_hits.bam >| accepted_hits_posStrand.bam"
  • split reads by pair
# input:    accepted_hits_posStrand.bam or accepted_hits_negStrand.bam
# output:   1st pair: *_1stPair.bam
#           2nd pair: *_2ndPair.bam
bsub "samtools view -b -f 0x0040 accepted_hits_posStrand.bam > accepted_hits_posStrand_1stPair.bam"
bsub "samtools view -b -F 0x0040 accepted_hits_posStrand.bam > accepted_hits_posStrand_2ndPair.bam"
bsub "samtools view -b -f 0x0040 accepted_hits_negStrand.bam > accepted_hits_negStrand_1stPair.bam"
bsub "samtools view -b -F 0x0040 accepted_hits_negStrand.bam > accepted_hits_negStrand_2ndPair.bam"
  • convert from bam to bedgraph format
# input:    bam format: accepted_hits_*Strand_*Pair.bam
#           /nfs/genomes/mouse_gp_jul_07/anno/mm9.size: length of each chromosome, format like 
#                                   chr1    197195432
# output:   bedgraph format: accepted_hits_*Strand_*Pair.bedgraph
bsub "genomeCoverageBed -split -bg -ibam accepted_hits_posStrand_1stPair.bam -g mm9.size >| accepted_hits_posStrand_1stPair.bedgraph"
bsub "genomeCoverageBed -split -bg -ibam accepted_hits_posStrand_2ndPair.bam -g mm9.size >| accepted_hits_posStrand_2ndPair.bedgraph"
bsub "genomeCoverageBed -split -bg -ibam accepted_hits_negStrand_1stPair.bam -g mm9.size >| accepted_hits_negStrand_1stPair.bedgraph"
bsub "genomeCoverageBed -split -bg -ibam accepted_hits_negStrand_2ndPair.bam -g mm9.size >| accepted_hits_negStrand_2ndPair.bedgraph"
  • join the reads sharing the same strand
# This step is for fr-firststrand library (such as dUTP). which is
    1+-,1-+,2++,2--

    read1 mapped to ‘+’ strand indicates parental gene on ‘-‘ strand
    read1 mapped to ‘-‘ strand indicates parental gene on ‘+’ strand
    read2 mapped to ‘+’ strand indicates parental gene on ‘+’ strand
    read2 mapped to ‘-‘ strand indicates parental gene on ‘-‘ strand
 
# input:    bedgraph file from the same strand
# output:   merged bedgraph: pos.bedgraph or neg.bedgraph
unionBedGraphs -i accepted_hits_posStrand_2ndPair.bedgraph accepted_hits_negStrand_1stPair.bedgraph |awk '{ print $1"\t"$2"\t"$3"\t"$4+$5 }' >|pos.bedgraph
unionBedGraphs -i accepted_hits_posStrand_1stPair.bedgraph accepted_hits_negStrand_2ndPair.bedgraph |awk '{ print $1"\t"$2"\t"$3"\t-"$4+$5 }' >|neg.bedgraph
infer_experiment.py -r mm9.refseq.bed12 -i accepted_hits.bam
  • convert bedgraph to bigwig
# get rid of header lines of mm9.size: the header line with "chrom   size" is removed
# input:    mm9.size: length of each chromosome
# output:   mm9.size_noHeader
tail --line=+2 mm9.size > mm9.size_noHeader
# convert bedgraph to bigwig
# input:    bedgraph file: neg.bedgraph or pos.bedgraph
#           mm9.size_noHeader: length of each chromosome
# *output:  bigwig format: neg.bw or pos.bw
#           neg.bw or pos.bw can be visualized with IGV/UCSC genome browser
bsub bedGraphToBigWig neg.bedgraph mm9.size_noHeader neg.bw
bsub bedGraphToBigWig pos.bedgraph mm9.size_noHeader pos.bw
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市谎势,隨后出現(xiàn)的幾起案子藤韵,更是在濱河造成了極大的恐慌虐沥,老刑警劉巖,帶你破解...
    沈念sama閱讀 206,126評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件泽艘,死亡現(xiàn)場離奇詭異欲险,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)匹涮,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,254評論 2 382
  • 文/潘曉璐 我一進(jìn)店門天试,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人然低,你說我怎么就攤上這事喜每。” “怎么了雳攘?”我有些...
    開封第一講書人閱讀 152,445評論 0 341
  • 文/不壞的土叔 我叫張陵带兜,是天一觀的道長。 經(jīng)常有香客問我吨灭,道長鞋真,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,185評論 1 278
  • 正文 為了忘掉前任沃于,我火速辦了婚禮涩咖,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘繁莹。我一直安慰自己檩互,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,178評論 5 371
  • 文/花漫 我一把揭開白布咨演。 她就那樣靜靜地躺著闸昨,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上饵较,一...
    開封第一講書人閱讀 48,970評論 1 284
  • 那天拍嵌,我揣著相機(jī)與錄音,去河邊找鬼循诉。 笑死横辆,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的茄猫。 我是一名探鬼主播狈蚤,決...
    沈念sama閱讀 38,276評論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼划纽!你這毒婦竟也來了脆侮?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 36,927評論 0 259
  • 序言:老撾萬榮一對情侶失蹤勇劣,失蹤者是張志新(化名)和其女友劉穎靖避,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體比默,經(jīng)...
    沈念sama閱讀 43,400評論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡筋蓖,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,883評論 2 323
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了退敦。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片粘咖。...
    茶點(diǎn)故事閱讀 37,997評論 1 333
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖侈百,靈堂內(nèi)的尸體忽然破棺而出瓮下,到底是詐尸還是另有隱情,我是刑警寧澤钝域,帶...
    沈念sama閱讀 33,646評論 4 322
  • 正文 年R本政府宣布讽坏,位于F島的核電站,受9級特大地震影響例证,放射性物質(zhì)發(fā)生泄漏路呜。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,213評論 3 307
  • 文/蒙蒙 一织咧、第九天 我趴在偏房一處隱蔽的房頂上張望胀葱。 院中可真熱鬧,春花似錦笙蒙、人聲如沸抵屿。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,204評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽轧葛。三九已至搂抒,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間尿扯,已是汗流浹背求晶。 一陣腳步聲響...
    開封第一講書人閱讀 31,423評論 1 260
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留衷笋,地道東北人芳杏。 一個月前我還...
    沈念sama閱讀 45,423評論 2 352
  • 正文 我出身青樓,卻偏偏與公主長得像右莱,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子档插,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,722評論 2 345

推薦閱讀更多精彩內(nèi)容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,292評論 0 10
  • Introduction What is Bowtie 2? Bowtie 2 is an ultrafast a...
    wzz閱讀 5,565評論 0 5
  • 本文資料來源 https://web.archive.org/web/20161125133249/http://...
    x2yline閱讀 2,772評論 0 4
  • 1 我慢蜓,剛滿九個月,20斤重郭膛,70厘米高晨抡,身體圓潤,皮膚白皙则剃,昵稱寶寶耘柱,當(dāng)然,你們叫我小仙女或小女神也是可以的棍现。 ...
    寫意人閱讀 415評論 28 11
  • 因?yàn)楣ぷ鞯脑虻骷澹诠P者開始持續(xù)關(guān)注一些安全咨詢網(wǎng)站,一來是多了解業(yè)界安全咨詢提升自身安全知識己肮,二來也是需要從各類...
    半夜菊花茶閱讀 2,161評論 0 10