Пример #1
0
 def insert(self, intervals, newInterval):
     
     if len(intervals) == 0:
         return [newInterval]
     
     r = []
     overlapWithNewInterval = Interval(newInterval.start, newInterval.end)
     didAddNewInterval = False
     
     for i in intervals:
         if (i.start < overlapWithNewInterval.start
               and i.end < overlapWithNewInterval.start):
             r.append(i)
         elif (i.start < overlapWithNewInterval.start
               and i.end >= overlapWithNewInterval.start
               and i.end <= overlapWithNewInterval.end):
             overlapWithNewInterval.start = i.start 
         elif (i.start < overlapWithNewInterval.start
               and i.end > overlapWithNewInterval.end):
             return intervals
         elif (i.start >= overlapWithNewInterval.start
               and i.end <= overlapWithNewInterval.end):
             pass
         elif (i.start >= overlapWithNewInterval.start
               and i.start <= overlapWithNewInterval.end
               and i.end >= overlapWithNewInterval.end):
             overlapWithNewInterval.end = i.end
         else:   # hxl: i is after overlapWithNewInterval
             if didAddNewInterval == False:
                 r.append(overlapWithNewInterval)
                 didAddNewInterval = True
             r.append(i)
     
     # hxl: It's possible that the new interval is not added yet!
     if didAddNewInterval == False:
         r.append(overlapWithNewInterval)
         didAddNewInterval = True
     return r
            pos=exon.getBegin()-2
            end=exon.getEnd()
    else:
        if(siteType=="donor"):
            begin=exons[exonIndex-1].getEnd()
            pos=exon.getBegin()-2
            end=exon.getEnd()
        else:
            begin=exon.getBegin()
            pos=exon.getEnd()
            end=exons[exonIndex+1].getBegin()
    exclusions=exclude.get(substrate,{})
    begin=int(begin); pos=int(pos); end=int(end)
    interval=Interval(pos-70,pos+70)
    if(interval.begin<begin): interval.begin=begin
    if(interval.end>end): interval.end=end
    juncs=junctions.get(substrate,[])
    #print("substrate=",substrate)
    sum=0
    for junc in juncs:
        (substrate,begin,end,count)=junc
        key=str(begin)+"-"+str(end)
        if(exclusions.get(key,False)): 
            continue
        if(interval.contains(begin) or interval.contains(end)): sum+=int(count)
    geneCount=readCounts.get(geneID,0)
    #print("gene=",geneID)
    if(rex.find("(\S+)_\d",geneID)): geneID=rex[1]
    print(indiv,hap,geneID,transID,strand,exonIndex,siteType,interval.begin,pos,
          interval.end,sum,geneCount,totalMappedReads,sep="\t",flush=True)