2015-10-14 29 views
1

我已經編輯了上一個問題,因爲它太長而且令人討厭,現在我已經知道了我想要的東西,我發現在下面的代碼中的某些操作中有一個小故障。尋求建議。如何將文件中的列粘貼到另一個臨時文件?

我有代碼,現在它工作正如我所料,但我得到一個額外的0行,我不明白爲什麼?有什麼建議?

代碼

#!/bin/bash 
#$ -S /bin/bash 

cd /path/vdas/client/ChIP-Seq/output/merge_MACS2_peaks_patient_specific/EOC/test 

cut -f 1,2,3 /path/vdas/client/ChIP-Seq/output/merge_MACS2_peaks_patient_specific/EOC/test_merge.bed > tmp 
printf "chr\tstart\tend" > tsamples 
for file in `ls *.bed`; do 
    printf "\t" >> tsamples 
    printf `basename $file .bed` >> tsamples 
    #echo $file | cut -d_ -f 1,2,3 >> tsamples 
    intersectBed -wao -a /path/vdas/client/ChIP-Seq/output/merge_MACS2_peaks_patient_specific/EOC/test_merge.bed -b $file -f 0.20 | cut -f 9 | tail -n+1 | paste tmp - > tmp2 
    mv tmp2 tmp 
done 
echo "" >> tsamples 
cat tsamples tmp > histone_marks.map 
rm tsamples tmp 

輸出

chr start end test_K27ac_S12818 test_K27ac_S12838 test_K27me3_S12815_5cols test_K27me3_S12830_5cols test_K4me1_S12816 test_K4me1_S12831 test_K4me1_S12836 
chr1 754118 754696 0 0 0 0 290 576 0 
chr1 804929 805633 0 0 704 0 277 0 704 
chr1 826069 826438 0 0 0 0 369 0 0 
chr1 839340 839608 0 0 268 0 268 0 0 
chr1 840388 843628 0 0 3240 0 816 2434 923 
chr1 845517 847768 0 0 2251 820 1113 2106 1677 
chr1 850950 854146 0 0 3196 3196 2184 3196 1302 
chr1 855361 857280 0 0 1919 0 1911 1919 979 
chr1 857930 859278 0 0 1348 0 1139 1125 923 
chr1 859906 860677 351 0 771 463 0 0 771 
    0 

一切都很好,除了最後一行顯示爲0,不知道爲什麼?任何建議

+1

你的問題是在你的printf語句之前intersectBed:在你的printf語句中的數字3之後刪除逗號 – pcantalupo

+0

是的我想通了,謝謝但問題是輸出沒有頭,我也想輸出到具有文件名的典型標題以及輸出文件的前3個字段將合併,如我在輸出中所示。 –

+0

如果您自己回答了問題,請考慮發佈答案並接受答案。 – pcantalupo

回答

1

我相信我做正確的,所以我做的代碼改變自己,這是我做的

#!/bin/bash 
#$ -S /bin/bash 

cd /path/vdas/client/ChIP-Seq/output/merge_MACS2_peaks_patient_specific/EOC/test 

cut -f 1,2,3 /path/vdas/client/ChIP-Seq/output/merge_MACS2_peaks_patient_specific/EOC/test_merge.bed > tmp 
printf "chr\tstart\tend" > tsamples 
for file in `ls *.bed`; do 
    printf "\t" >> tsamples 
    printf `basename $file .bed` >> tsamples 
    #echo $file | cut -d_ -f 1,2,3 >> tsamples 
    intersectBed -wao -a /path/vdas/client/ChIP-Seq/output/merge_MACS2_peaks_patient_specific/EOC/test_merge.bed -b $file -f 0.20 | cut -f 9 | tail -n+1 | paste tmp - > tmp2 
    mv tmp2 tmp 
done 
echo "" >> tsamples 
cat tsamples tmp > histone_marks.map 
rm tsamples tmp 
sed '$d' histone_marks.map 

這並不工作,但我知道它是做一個非常粗略的方式它。我無法弄清楚爲什麼最後一行0出來了,但它是用bash相信的某種操作,但不是爲了intesectBed操作,因爲列很好。

相關問題