Question: How to filter/edit some BED lines.
0
gravatar for star
13 months ago by
star190
Netherlands
star190 wrote:

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 • 469 views
ADD COMMENTlink modified 12 months ago by Biostar ♦♦ 20 • written 13 months ago by star190
1

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 written 13 months ago by lakhujanivijay4.3k
1

@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 modified 13 months ago • written 13 months ago by cpad011211k
1

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 modified 13 months ago • written 13 months ago by Jeffin Rockey1.1k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1284 users visited in the last hour