I have the following sets of data:
file1:
1 15776220 15776240 GTGACCAGCAGGTGTCTCTG 16855676 16855696 CTGTCCAGCAGAGGGCGGTG
file2:
1 15776231 2 5008 G:5002 A:6
1 15776239 3 5008 C:3358 A:14 G:1636
file3:
1 16855677 2 5008 A:5003 C:5
1 16855689 3 5008 G:4957 A:41 T:10
Most lines have 6 columns but a few lines also have 7 columns which have data that I want to preserve.
Can a script be written which does the following:
if $2
of file2 comes in between $2
and $3
of file1 (between the interval of $2
and $3
) and $2
of file3 comes in between $5
and $6
of file1 (between the interval of $5
and $6
), then the output would be $1,$2,$3,$4
from file1 and $2,$3,$4,$5,$6,$7
from file2 and $5,$6,$7
from file1 and $2,$3,$4,$5,$6,$7
from file 3, all in one line. So something like this:
1 15776220 15776240 GTGACCAGCAGGTGTCTCTG 15776231 2 5008 G:5002 A:6 16855676 16855696 CTGTCCAGCAGAGGGCGGTG 16855677 2 5008 A:5003 C:5
1 15776220 15776240 GTGACCAGCAGGTGTCTCTG 15776239 3 5008 C:3358 A:14 G:1636 16855676 16855696 CTGTCCAGCAGAGGGCGGTG 1 16855689 3 5008 G:4957 A:41 T:10
Something like bedtools does but I am not able to use bedtools one this since I don't have two columns in file2 and file3. The intersection is based on $2 in both the files, and all the other columns after it are just copied
(There could be many lines from file2 and file3 intersecting in the same line in file1,so that line could be repeated based on the number of intersections)
bedtools intersect
? For exampleawk '{$3 = $2+1 FS $3}' file2 > file2.modified
, assuming the coordinates are 0-based. $\endgroup$ – Devon Ryan♦ Jan 2 '18 at 14:42