Search
Question: Finding distance between end of all ORFs in utr and start of first cds exon in transcript coordinates
0
7 months ago by
hauken_heyken40 wrote:

This is a speedup question like my last, my data is too big to do what I would normally do, I'm doing several TB of data.

So my question is how to match two GRangeslist by name and calculate distance between each match( that is, they are from the same transcript)

, where the first list contains several ORFs per transcript while cds only have unique rows, namely the first exon.

#uorfs: list of ORFs in utr

#cdsFirstExon: list of all first exons that have uorfs, so it only contains transcripts that have uorfs.

merged = merge( uorfs, cdsFirstExon, by.x = names(uorfs), by.y = names(cdsFirstExon)

distances = merged$uorf.end - merged$cdsFirstExon.start # distances now contains what I want

But the merging step is too slow with big data, is there a vectorized way ?

modified 7 months ago by Michael Lawrence10.0k • written 7 months ago by hauken_heyken40
1
7 months ago by
Michael Lawrence10.0k
United States
Michael Lawrence10.0k wrote:

Well merge() is vectorized but it's a more general case than you require, and so is slower than something simpler. I think you can sort the first exons, flatten them to a GRanges, flatten the ORFs and expand the first exons accordingly. It may be easier and faster in the long run to keep the data as GRanges.

cdsFirstExon_gr <- unlist(cdsFirstExon[names(uorfs)])
uorfs_gr <- unlist(uorfs)
cdsFirstExon_long <- rep(cdsFirstExon_gr, lengths(uorfs))
distance(uorfs_gr, cdsFirstExon_long)