# Finding matched genes for each genomic range

I have called structural variants and now I have

Sample  Type    Chrom1   Start1        End1 Strand1
t_005   DEL 1   28677074    28677079    +
t_005   INS 1   186383731   186383738   +
t_005   DEL 1   245902589   245902590   +
t_005   DEL 2   56345643    56345645    +
t_005   DEL 3   59766214    59766217    +
t_005   DEL 3   60270545    60270548    +


I have an annotation file like

> head(sv[,1:5])
ENSG00000233440 13 23708313 23708703   HMGA1P6
1 ENSG00000207157 13 23726725 23726825    RNY3P4
2 ENSG00000229483 13 23743974 23744736 LINC00362
3 ENSG00000229483 13 23743974 23744736 LINC00362
4 ENSG00000252952 13 23791571 23791673  RNU6-58P
5 ENSG00000235205 13 23817659 23821323  TATDN2P3
6 ENSG00000232849 13 93708910 93710179 LINC00363
>


How I could relate each gene name from annotation file to my genomic range file?

EDITED

Sample  Type    Chrom1  Start1  End1    Strand1 Chrom2  Start2  End2    Strand2
t_005   DEL 1   28677074    28677079    +   1   28706324    28706329    -
t_005   INS 1   186383731   186383738   +   1   186383731   186383732   -
t_005   DEL 1   245902589   245902590   +   1   246007384   246007385   -
t_005   DEL 2   56345643    56345645    +   2   56345829    56345830    -
t_005   DEL 3   59766214    59766217    +   3   59785325    59785328    -
t_005   DEL 3   60270545    60270548    +   3   60705591    60705594    -
t_005   DUP 3   60744344    60744345    -   3   60806306    60806307    +
t_005   DUP 3   60882109    60882112    -   3   60934155    60934158    +
t_005   DEL 3   77973091    77973093    +   3   77991398    77991400    -
t_005   DEL 3   95972796    95972800    +   3   95974511    95974515    -

• Hey Feresh, please use dput to present a reproducible example for both files then I can give it a shot. You just want to merge the sv file based on the range of start1 and end1 correct? May 2 '19 at 15:50
• Yes likely I only need to know which gene locate in each genomic range. Genes are in sv file and my called structural variants are in the first file. May 2 '19 at 16:09
• so why does end1 just have '+' and strand1 is empty? May 2 '19 at 16:43
• Because structural variant data are too weird, I have added full called SV in edited post May 2 '19 at 16:49
• I won't be able to help you without you posting a reproducible example using dput.. Please do this with a small snippet of your data as you have provided visually. May 2 '19 at 18:55

You can adapt the code they gave you to compare Chrom1 == sv[2] & Start1 >= sv[3] & End1<=sv[4] to find events that happen within a gene. For events spanning genes, you're going to need to write a collapsing function for the gene names and a different way to compare overlaps instead of Start >= sv[3] & End <= sv[4].