BedInverseExons: Difference between revisions

From genomewiki
Jump to navigationJump to search
No edit summary
(No difference)

Revision as of 16:33, 14 September 2006

When you export exons as bed with the table browser, they are numbered 0,1,2,3... by default, but always 5' to 3'. This is uncommon for biologists, they usually call the most upstream one exon 1. This scripts inverses the numbers.

#!/usr/bin/python 

# input: bed file with exons as exported from ucsc
# output: bed file with exons numbers reversed if strand="-"

from sys import *
    
f = open(argv[1], "r")
maxExon = {}
for l in f:
    fs = l.split()
    (gene,dummy,exon) = fs[3].split("_")
    maxExon[gene] = int(exon)
    
f = open(argv[1], "r")
    
for l in f:
    fs = l.split()
    if fs[5]=="-":
        (gene,dummy,exon) = fs[3].split("_")
        name = gene + "_exon_" + str(maxExon[gene] - int(exon))
        print "\t".join([fs[0], fs[1], fs[2],name,fs[4],fs[5]])
    else:
        print l,