<p>You received an answer from Kamil for a similar question here: <a href="https://bioinformatics.stackexchange.com/a/8532/650">https://bioinformatics.stackexchange.com/a/8532/650</a></p>

<p>You can adapt the code they gave you to compare <code>Chrom1 == sv[2] &amp; Start1 &gt;= sv[3] &amp; End1&lt;=sv[4]</code> 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 <code>Start &gt;= sv[3] &amp; End &lt;= sv[4]</code>.</p>

CC BY-SA 4.0
2019-05-02T16:17:02.273Z
2019-05-02T16:17:02.273Z
Ram RS
<p>I have called structural variants and now I have</p>

<pre><code>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    +
</code></pre>

<p>I have an annotation file like</p>

<pre><code>&gt; 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
&gt; 
</code></pre>

<p>How I could relate each gene name from annotation file to my genomic range file?</p>

<blockquote>
  <p>EDITED</p>
</blockquote>

<pre><code>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    -
</code></pre>

CC BY-SA 4.0
2019-05-02T15:50:10.180Z
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?
h3ab74
CC BY-SA 4.0
2019-05-02T16:09:33.283Z
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.
Zizogolu
CC BY-SA 4.0
2019-05-02T16:43:33.137Z
so why does end1 just have '+' and strand1 is empty?
h3ab74
CC BY-SA 4.0
2019-05-02T16:49:05.033Z
Because structural variant data are too weird, I have added full called SV in edited post
Zizogolu
CC BY-SA 4.0
2019-05-02T18:55:30.213Z
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.
h3ab74
<r><structural-variation><wgs>
Finding matched genes for each genomic range
# Finding matched genes for each genomic range

(Asked by: username_0 on 2019-05-02)

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    -

**Tags:** r, structural-variation, wgs
> **Comments:**
> **username_1**: 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?  
> **username_0**: 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.  
> **username_1**: so why does end1 just have '+' and strand1 is empty?  
> **username_0**: Because structural variant data are too weird, I have added full called SV in edited post  
> **username_1**: 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.  

---

## 1 answers

### Answer by username_2 on 2019-05-02. Score: 3

You received an answer from Kamil for a similar question here: <https://bioinformatics.stackexchange.com/a/8532/650>

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]`.


---

