Entering edit mode
6.4 years ago
star
▴
350
I have two tables and I did intersect using bedtools, but after interacting i just get coordinate as out put and I would like to know how can I add one column to out put using If and else function?
data A:
chr1 59362359 59364245
chrX 112062100 112062600
chrX 118920850 118927075
data B:
chr1 69362320 79364245
chrX 112062339 112062646 120
chrX 118922235 118922524 50
intersect:
bedtools intersect -a data_A.bed -b data_B.bed -wao
current out put:
chr1 59362359 59364245 . -1 -1 0
chrX 112062100 112062600 chrX 112062339 112062646 261
chrX 118920850 118927075 chrX 118922235 118922524 289
I like to add last column of data B to out put, if the columns 4,5 and 6 of intersect output have overlap with coordinate of data B put column 4 of data B otherwise put zero value:
chr1 59362359 59364245 . -1 -1 0 0
chrX 112062100 112062600 chrX 112062339 112062646 261 120
chrX 118920850 118927075 chrX 118922235 118922524 289 50
Hello star
How do you think the title "If and else in linux?" justifies here? Please use appropriate titles while asking questions here. You will loose a lot of attention of the people who could possibly answer this question.
Thanks
@OP: I am getting a different output than you posted. Please cross check output from bed files. Try to recreate the issue from the text posted here and see if it's matching output posted here.
Bedtools version 27:
While giving the OP's data as is with tab separation, the following error occurs:
"Error: Type checker found wrong number of fields while tokenizing data line."
Error goes if the there is a 4th column value in 1st row of B (I filled in with 0)
Output comes as below
Also see that outputs are not as mentioned. May be bedtools version differences. Anyways wao in version 27 do bring in the 4th column. Therefore the if else based substitution required can be done with awk like below