Thank you so much for the pipeline.It worked wonderfully well. I have made few modifications. See below.
grep ";" perContigTranscriptsWithSizes.txt > overlapped.bed
awk '{split($0, components, "|"); transcriptsStr = components[1]; lengthsStr = components[2]; max = 0; maxIdx = -1; numLengths = split(lengthsStr, lengths, ";"); for (idx = 1; idx <= numLengths; idx++) { if (lengths[idx] > max) {maxIdx = idx; max = lengths[idx];}} split(transcriptsStr, transcripts, ";"); maxTranscript = transcripts[maxIdx]; print maxTranscript;}' overlapped.bed > overlapped.filtered.bed
sort-bed overlapped.filtered.bed > overlapped.filtered.sorted.bed
cut -f 4 overlapped.filtered.bed > overlapped.filtered.genes
grep -f overlapped.filtered.genes input.sorted.bed > overlapped.filtered.genes.bed
grep -v -c ";" perContigTranscriptsWithSizes.txt > non_overlapped_final.bed
cat non_overlapped_final.bed overlapped.filtered.genes.bed > final.bed
Hope this is ok. Thanks anyway for all the help with this. Now here is the new image after uploading final.bed file onto UCSC GB. Thanks
Upendra

Hi,
I have bed file and i am trying to merge the overlapping transcripts based on genomic coordinates into a single transcript. For this i used mergeBed but what i found was mergeBed basically make a long single contig without keeping the intron exon structure of the overlapping transcripts (see attached picture and example below). Is there a way to keep the structure? Also the output from the mergeBed basically is different from input bed file (see below again)![enter image description here][2] and so i am wondering is there a way to keep the structure of original bed file as well and still make an overalpping contig from the overalpped transcripts?
Please post an example of "wanted output".
Ok all. I have edited my post to give more information of what i wanted. Basically i have bed file that have four overlapping transcripts (see Denovo filtered track in the picture) and all i wanted is to have a consensus/overlapping contig. For this i have used mergedBed/bedops tools but both of them gave me a bed file that have a single contig without preserving intron-exon structure (See merged Track above). Am i not thinking well here? I don't know if it can be done with any tool.
Can you write up a sample BED file that hints at the format of what you need, given the example images provided? It's likely the use of
bedopsandbedmapalone won't do what you need, but perhaps those two apps withawkmay work. Hopefully this helps clarify the request for clarification.This is what want
The
desired bedcategory looks like the fourth line ofinput.That is right in this case. Basically all i wanted is for those overlapped transcripts pick the one that is longest without merging the introns and exons.