Biostar Beta. Not for public use.
How to filter/edit some BED lines.
0
Entering edit mode
13 months ago
star • 150
Netherlands

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
linux bedtools • 429 views
ADD COMMENTlink
1
Entering edit mode

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

ADD REPLYlink
1
Entering edit mode

@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.

ADD REPLYlink
1
Entering edit mode

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

chr1    59362359        59364245        .       -1      -1      .       0
chrX    112062100       112062600       chrX    112062339       112062646       120     261
chrX    118920850       118927075       chrX    118922235       118922524       50      289

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

bedtools intersect -a A.bed -b B.bed  -wao | awk -F$'\t' -v OFS="\t" '$4=="."{$4=0}$7=="."{$7=0}1'
ADD REPLYlink

Login before adding your answer.

Similar Posts
Loading Similar Posts
Powered by the version 2.1