def makeGraph(baseName, lowRange, highRange): lowRange = int(lowRange) highRange = int(highRange) histDict = {} for i in range(lowRange, highRange + 1): f = open(baseName + str(i), 'r') for line in f: targets = line.strip().split('\t')[4] numTargets = len(targets.split(',')) try: histDict[i].append(numTargets) except KeyError: histDict[i] = [numTargets] f.close() print histDict for m in histDict: cgPlot.plotHistogram(histDict[m], name = str(m) + ' mismatches')
def makeFigure(fN, targetFN, alignmentFN, cName): #make targetDict f = open(targetFN, 'r') targetDict = {} # tID: tLoc for line in f: ls = line.strip().split('\t') targetDict[int(ls[0])] = ls[1] f.close() #make alignmentDict alignDict = {} # sid: {target: offset} f = open(alignmentFN, 'r') for line in f: ls = line.strip().split(' ') sID = int(ls[0]) tID = int(ls[1]) offset = int(ls[4]) if not sID in alignDict: alignDict[sID] = {} alignDict[sID][tID] = offset #assumes one source to target... f.close() f = open(fN, 'r') histoVals = [] for line in f: ls = line.strip().split('\t') sID = int(ls[0]) sLoc = ls[1] sChrom, sStrand, sStart, sEnd = bioLibCG.tccSplit(sLoc) sLen = sEnd - sStart tIDs = ls[4].split(',') for tID in tIDs: tID = int(tID) tLoc = targetDict[tID] chrom, strand, start, end = bioLibCG.tccSplit(tLoc) offset = alignDict[sID][tID] if sStrand == '1': start = start - 19 + offset end = start + sLen else: end = end + 19 - offset start = end - sLen scanRange = bioLibCG.makeTcc(chrom, strand, start, end) stretch = cgPeaks.stretch(scanRange, cName) highest = stretch.getHighestLevel() sortedKeys = stretch.profile.keys() if sStrand == '-1': sortedKeys.reverse() i = 0 for key in sortedKeys: level = stretch.profile[key] for j in range(0,level): histoVals.append(i) i += 1 cgPlot.plotHistogram(histoVals)
tcc = 'chr1:1:1102538:1103319' stretch = cgPeaks.stretch(tcc, 'agoProfile.conf') stretch.createContBlocks() sortedKeys = stretch.profile.keys() sortedKeys.sort() for key in sortedKeys: print key, stretch.profile[key] for block in stretch.blocks: print block ''' ''' #histogram test a = [5,5,5,5,5,5,4,4,4,3,3,2,1] cgPlot.plotHistogram(a, name = 'testHistogram') ''' #svCoord test tcc = 'chr1:1:1103298:1103298' eLevels = sv.svCoord([tcc], 'siPeaks.conf') for coord in eLevels: print coord, eLevels[coord] ''' tcc = 'chr1:1:1102539:1103319'
import cgPlot import bioLibCG as cg f = open('cb.20.ago', 'r') lengths = [] for line in f: lengths.append(cg.getTccLength(line.strip())) cgPlot.plotHistogram(lengths, name = 'cbLengths20')
def makeFigure(fN, targetFN, alignmentFN, cName): # make targetDict f = open(targetFN, "r") targetDict = {} # tID: tLoc for line in f: ls = line.strip().split("\t") targetDict[int(ls[0])] = ls[1] f.close() # make alignmentDict alignDict = {} # sid: {target: offset} f = open(alignmentFN, "r") for line in f: ls = line.strip().split(" ") sID = int(ls[0]) tID = int(ls[1]) offset = int(ls[4]) if not sID in alignDict: alignDict[sID] = {} alignDict[sID][tID] = offset # assumes one source to target... f.close() f = open(fN, "r") histoVals = [] for line in f: ls = line.strip().split("\t") sID = int(ls[0]) sLoc = ls[1] sChrom, sStrand, sStart, sEnd = bioLibCG.tccSplit(sLoc) sLen = sEnd - sStart tIDs = ls[4].split(",") for tID in tIDs: tID = int(tID) tLoc = targetDict[tID] chrom, strand, start, end = bioLibCG.tccSplit(tLoc) offset = alignDict[sID][tID] if sStrand == "1": start = start - 19 + offset end = start + sLen else: end = end + 19 - offset start = end - sLen scanRange = bioLibCG.makeTcc(chrom, strand, start, end) stretch = cgPeaks.stretch(scanRange, cName) highest = stretch.getHighestLevel() sortedKeys = stretch.profile.keys() if sStrand == "-1": sortedKeys.reverse() i = 0 for key in sortedKeys: level = stretch.profile[key] for j in range(0, level): histoVals.append(i) i += 1 cgPlot.plotHistogram(histoVals)
import cgPlot import bioLibCG as cg f = open('cb.20.ago', 'r') lengths = [] for line in f: lengths.append(cg.getTccLength(line.strip())) cgPlot.plotHistogram(lengths, name='cbLengths20')