def test_overlaps(self): lunch = Interval(14, 16) meeting2 = Interval(12, 14) meeting3 = Interval(13, 15) self.assertFalse(meeting2.overlaps(lunch)) self.assertTrue(meeting2.overlaps(meeting3)) self.assertTrue(meeting3.overlaps(lunch))
def search_available_equips(equip_type, strDate, b_time, e_time): if equip_type == 'MASSAGE': print('Not Support Now!!!') return from interval import Interval equipUsageURL = base_url + '/LeaseEquip/equipUsage.jsp' payload = [('q_from_date', strDate), ('q_from_time', ''), ('q_to_date', strDate), ('q_to_time', ''), ('q_equip_type', equip_type)] payload.extend([('ID_keyD', e) for e in meeting_rooms.keys()]) result = getSession().post(equipUsageURL, data=payload) soup = bs(result.text, 'html.parser') equips = [ equip.text.strip() for equip in soup.select('div[id="equips"] td[align="center"]') ] # print(equips) availList = list() for index, elem in enumerate(soup.select('td[nowrap]')): availList.insert(index, 1) if '目前無人預約' in elem.text: continue target = Interval(int(b_time), int(e_time), closed=False) periods = [x.text.split('~') for x in elem.select('b')] periodIntvs = [ Interval(x[0], x[1]) for x in list(map(lambda bb: [int(x) for x in bb], periods)) ] # print(equips[index]) # for pp in periodIntvs:ontext['lifespanCount'] = 0 # print(pp,'\n') for periodIntv in periodIntvs: if target.overlaps(periodIntv): availList[index] = 0 break # print(availList) for index, avail in enumerate(availList): if avail == 1: print('{}\n'.format(equips[index]))
def judgeFusion_same(tmp): tmpStrand = tmp['strand'] tmpChr = list(tmp['chr']) tmpChr_unique = list(set(tmpChr)) tmpChr2Num = [] tmpChr_len = len(tmpChr_unique) tmpNrow = tmp.shape[0] tmp_query_start = tmp['query_start'].values tmp_query_end = tmp['query_end'].values if tmpNrow == 2: #if len(set(tmpStrand))>1: #return('U') r1S = tmp['reference_start'].values[0] r1E = tmp['reference_end'].values[0] r2S = tmp['reference_start'].values[tmpNrow - 1] r2E = tmp['reference_end'].values[tmpNrow - 1] r1 = Interval(r1S, r1E, lower_closed=False) r2 = Interval(r2S, r2E, lower_closed=False) if r1.overlaps(r2): #return('NC',-1) return ('N', -1) # revised for more sensitive type, rowID = read2ref(tmp, 'U') return (type, rowID) elif tmpNrow == 3: #if len(set(tmpStrand))>1: #return('U') r1S = tmp['reference_start'].values[0] r1E = tmp['reference_end'].values[0] r2S = tmp['reference_start'].values[tmpNrow - 1] r2E = tmp['reference_end'].values[tmpNrow - 1] r1 = Interval(r1S, r1E, lower_closed=False) r2 = Interval(r2S, r2E, lower_closed=False) arr1 = np.zeros(tmpNrow - 1) arr2 = np.zeros(tmpNrow - 1) for j in range(1, tmpNrow): cS1 = tmp['reference_start'].values[j] cE1 = tmp['reference_end'].values[j] cS2 = tmp['reference_start'].values[j - 1] cE2 = tmp['reference_end'].values[j - 1] c1 = Interval(cS1, cE1, lower_closed=False) c2 = Interval(cS2, cE2, lower_closed=False) arr1[j - 1] = r1.overlaps(c1) arr2[j - 1] = r2.overlaps(c2) if sum(arr1) > 0 and sum(arr2) > 0: if arr1[0]: return ('N', -1) else: type, rowID = read2ref(tmp, 'FC2') return (type, rowID) #return('FC2') else: type, rowID = read2ref(tmp, 'C2') return (type, rowID) elif tmpNrow > 3: r1S = tmp['reference_start'].values[np.where( tmp['exon_length'].values == max(tmp['exon_length'].values))[0][0]] r1E = tmp['reference_end'].values[np.where( tmp['exon_length'].values == max(tmp['exon_length'].values))[0][0]] r1 = Interval(r1S, r1E, lower_closed=False) arr1 = np.zeros(tmpNrow) for j in range(0, tmpNrow): cS1 = tmp['reference_start'].values[j] cE1 = tmp['reference_end'].values[j] c1 = Interval(cS1, cE1, lower_closed=False) arr1[j] = r1.overlaps(c1) #if len(set(tmpStrand[np.array(arr1)==0]))>1 or len(set(tmpStrand[np.array(arr1)==1]))>1: # return('U') if sum(arr1 == 1) > (tmpNrow - 2): return ('N', -1) else: targetNum = [0, 1] for j in range(2 * tmpNrow): targetNum.extend([0, 1]) arr1 = [int(i) for i in arr1] targetNum = np.array(targetNum[arr1[0]:(arr1[0] + tmpNrow)]) if sum(targetNum == arr1) == tmpNrow: if (tmp_query_start[2] - tmp_query_end[0]) > 40 and ( tmp_query_start[3] - tmp_query_end[1] ) > 40 and (tmp_query_end[1] - tmp_query_end[0]) > 40 and ( tmp_query_end[2] - tmp_query_end[1] ) > 40 and (tmp_query_end[3] - tmp_query_end[2]) > 40 and ( tmp_query_start[1] - tmp_query_end[0]) > -40 and ( tmp_query_start[2] - tmp_query_end[1]) > -40 and ( tmp_query_start[3] - tmp_query_end[2]) > -40: type, rowID = read2ref(tmp, 'F2') return (type, rowID) else: type, rowID = read2ref(tmp, 'FC2') return (type, rowID) else: type, rowID = read2ref(tmp, 'C2') return (type, rowID) else: return ('U', -1)
def calReadSplice(i): tmp=FL_noDup.iloc[i,:] readArr=[] targetI=Interval(tmp['start']-1,tmp['end']) tmpRegionS=tmp['chr']+':'+str(tmp['start'])+'-'+str(tmp['start']) tmpRegionE=tmp['chr']+':'+str(tmp['end'])+'-'+str(tmp['end']) tmpFileS=RG_tmp_outPrefix+str(i)+'_FO_s.sam' tmpFileE=RG_tmp_outPrefix+str(i)+'_FO_e.sam' CMDS='samtools view -h %s %s>%s' % (bamFile,tmpRegionS,tmpFileS) CMDE='samtools view -h %s %s>%s' % (bamFile,tmpRegionE,tmpFileE) tmpSAM_s='' tmpSAM_e='' isPass=True if not os.system(CMDS): tmpSAM_s=pysam.AlignmentFile(tmpFileS) else: isPass=False if not os.system(CMDE): tmpSAM_e=pysam.AlignmentFile(tmpFileE) else: isPass=False if not isPass: return([1,1]) readDict_tmp={} for read in tmpSAM_s.fetch(): readDict_tmp[read.qname]=1 if read.flag & 260 >0: continue if dict_ID2type.__contains__(read.qname): continue readInfo=getReadInfo(read) for i in range(len(readInfo[0])): readI=Interval(readInfo[0][i],readInfo[1][i]) if readI.overlaps(targetI): readArr.append(readInfo) for read in tmpSAM_e.fetch(): if readDict_tmp.__contains__(read.qname): continue if read.flag & 260 >0: continue if dict_ID2type.__contains__(read.qname): continue readInfo=getReadInfo(read) for i in range(len(readInfo[0])): readI=Interval(readInfo[0][i],readInfo[1][i]) if readI.overlaps(targetI): readArr.append(readInfo) count_s=0 count_i=0 for readInfo in readArr: tmpS=0 tmpI=0 if len(readInfo[0])>1: for j in range(len(readInfo[0])-1): readI=Interval(readInfo[1][j],readInfo[0][j+1]) if readI.overlaps(targetI): tmpS=1 #print(readInfo) break else: tmpI=1 count_s+=tmpS count_i+=tmpI os.system('rm %s' % tmpFileS) os.system('rm %s' % tmpFileE) return([count_s,count_i])