2
$\begingroup$

I have two file that have overlapping regions. One file has chromosomes, position, CNV data and samples.Other file has chromosomes, positions and ensemble ids of genes.

Here is some lines of two files.

contig  start   end     type  bi-allelic  S1  S2  S3
chr1    12048   177033    DUP FALSE   -1  22  24
chr1    12048   89237     DUP FALSE   12  10  -1
chr1    2985712 3355300   DEL   TRUE  2   2   2

Second file is like this

chr1    901877  911245  gene_id "ENSG00000187583.6"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
chr1    22013   41670 gene_id "ENSG00000160075.10"                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
chr1    2985732 3355185 gene_id "ENSG00000142611.12"

I want output like this.

chr1    22013   41670 gene_id "ENSG00000160075.10"  DUP FALSE   12  10  -1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
chr1    2985732 3355185 gene_id "ENSG00000142611.12" DEL   TRUE  2   2   2 

Is there any way to do this?

$\endgroup$
3
$\begingroup$

You can use bedtools intersect and cut the results:

$ cat file1.bed
chr1    12048   177033  DUP FALSE   -1  22  24
chr1    12048   89237   DUP FALSE   12  10  -1
chr1    2985712 3355300 DEL TRUE    2   2   2

$ cat file2.gtf
chr1    22013   41670   gene_id "ENSG00000160075.10"
chr1    22013   41670   gene_id "ENSG00000160075.10"
chr1    2985732 3355185 gene_id "ENSG00000142611.12"

$ bedtools intersect -a file2.gtf -b file1.bed -wb | cut -f 1-4,8-11
chr1    22013   41670   gene_id "ENSG00000160075.10"    DUP FALSE   12  10
chr1    22013   41670   gene_id "ENSG00000160075.10"    DUP FALSE   -1  22
chr1    2985732 3355185 gene_id "ENSG00000142611.12"    DEL TRUE    2   2
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.