Mercurial > repos > melissacline > ucsc_cancer_utilities
comparison seg2matrix/segToProbeMap.py @ 39:61f03b481b0d
new tool
author | jingchunzhu |
---|---|
date | Fri, 31 Jul 2015 20:38:27 -0700 |
parents | |
children | 3e5680fecd7a |
comparison
equal
deleted
inserted
replaced
38:84eb11adc22f | 39:61f03b481b0d |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 import sys,string | |
4 sys.path.insert(0,"../CGDataNew") | |
5 | |
6 import CGData.GenomicSegment | |
7 import CGData.SegToMatrix | |
8 import CGData.RefGene | |
9 import CGData.GeneMap | |
10 import optparse | |
11 | |
12 class segs: | |
13 def __init__(self): | |
14 self.probes = [] | |
15 | |
16 def load (self, handle): #handle bed6 | |
17 fin =open(handle,'r') | |
18 while 1: | |
19 line =string.strip(fin.readline()) | |
20 if line =="": | |
21 break | |
22 if line[0]=="#": | |
23 continue | |
24 tmp = string.split(line,"\t") | |
25 if len(tmp)== 5: | |
26 p = probeseg(tmp[0], tmp[1], int(tmp[3]), int(tmp[4]),tmp[2]) | |
27 self.probes.append(p) | |
28 fin.close() | |
29 | |
30 | |
31 class probeseg: | |
32 def __init__(self, name, chrom, chrom_start, chrom_end, strand): | |
33 self.name = name | |
34 self.chrom = chrom | |
35 self.chrom_start = chrom_start | |
36 self.chrom_end = chrom_end | |
37 self.strand = strand | |
38 | |
39 | |
40 if __name__ == "__main__": | |
41 def printUsage(): | |
42 print "python segToProbeMap.py segInput(name,chr,strand,start,end) refGene(eg hg18) probeMapOut --mode=cnv|exp\n" | |
43 | |
44 if len(sys.argv) != 5: | |
45 printUsage() | |
46 sys.exit() | |
47 | |
48 parser = optparse.OptionParser() | |
49 parser.add_option("--mode", action="store", type="string", dest="mode") | |
50 (options, args) = parser.parse_args() | |
51 | |
52 if (not options.mode) or (options.mode not in ["cnv","exp"]): | |
53 printUsage() | |
54 sys.exit() | |
55 | |
56 probes=segs() | |
57 probes.load(sys.argv[1]) | |
58 | |
59 refgene = CGData.RefGene.RefGene() | |
60 refgene.load(sys.argv[2]) | |
61 | |
62 handle = open(sys.argv[3], "w") | |
63 if options.mode=="cnv": | |
64 probeMapper = CGData.GeneMap.ProbeMapper('b') | |
65 if options.mode=="exp": | |
66 probeMapper = CGData.GeneMap.ProbeMapper('g') | |
67 | |
68 handle.write("%s\t%s\t%s\t%s\t%s\t%s\n" % ("#id", "gene","chrom","chromStart","chromEnd","strand")) | |
69 for probe in probes.probes: | |
70 hits = [] | |
71 for hit in probeMapper.find_overlap( probe, refgene ): | |
72 if hit.name not in hits: | |
73 hits.append(hit.name) | |
74 handle.write("%s\t%s\t%s\t%s\t%s\t%s\n" % (probe.name, ",".join(hits), probe.chrom, probe.chrom_start, probe.chrom_end, probe.strand)) | |
75 handle.close() | |
76 | |
77 |