本文整理汇总了Python中Helper.Helper.printTimeDiff方法的典型用法代码示例。如果您正苦于以下问题:Python Helper.printTimeDiff方法的具体用法?Python Helper.printTimeDiff怎么用?Python Helper.printTimeDiff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Helper.Helper
的用法示例。
在下文中一共展示了Helper.printTimeDiff方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: deleteOverlapsFromVcf
# 需要导入模块: from Helper import Helper [as 别名]
# 或者: from Helper.Helper import printTimeDiff [as 别名]
def deleteOverlapsFromVcf(self,variants):
'''
delete the variants from 'variantsA' which also are in 'variantsB'
'''
variantSetA = set(self.variantDict.keys())
#detrmine type of variantB
if type(variants) == str:
variantsB = open(variants)
elif type(variants) != file:
raise TypeError("variantB has wrong type, need str or file, %s found" % type(variantsB))
#TODO: variants could also be another object of VariantsSet
#get Start time
startTime = Helper.getTime()
Helper.info(" [%s] Delete overlapps from %s" % (startTime.strftime("%c"),variantsB.name),self.logFile,self.textField)
for line in variantsB:
if line.startswith("#"):
continue
for varTuple in self.getVariantTuble(line):
if varTuple in variantSetA:
#A.discard(varTuple)
variantSetA.remove(varTuple)
del self.variantDict[varTuple]
#calculate duration
Helper.printTimeDiff(startTime,self.logFile,self.textField)
示例2: annotateVariantDict
# 需要导入模块: from Helper import Helper [as 别名]
# 或者: from Helper.Helper import printTimeDiff [as 别名]
def annotateVariantDict(self,genome):
'''
adds the corresponding Gene and the exact segment wehre the SNP appears
:param genome: Genome
'''
startTime = Helper.getTime()
Helper.info(" [%s] Annotating Variants" % (startTime.strftime("%c")),self.logFile,self.textField)
for v in self.variantDict.values():
anno = genome.annotatePosition(v.chromosome,v.position) #[(gene1,segment1;segment2;..)..]
GI=[]
for a in anno:
GI.append(a)
v.attributes["GI"]=GI
Helper.printTimeDiff(startTime,self.logFile,self.textField)
示例3: getOverlapsFromBed
# 需要导入模块: from Helper import Helper [as 别名]
# 或者: from Helper.Helper import printTimeDiff [as 别名]
def getOverlapsFromBed(self,bedFile,getNonOverlaps=False):
'''
returns overlaps from bed file features
:param bedFile: as string or file
:param getNonOverlaps: boolean
:return new variantSet of overlaps
'''
if type(bedFile) == str:
bedFile = open(bedFile)
elif type(bedFile) != file:
raise TypeError("bedFile has wrong type, need str or file, %s found" % type(bedFile))
startTime=Helper.getTime()
Helper.info("[%s] Delete overlaps from %s" % (startTime.strftime("%c"),bedFile.name) ,self.logFile,self.textField)
variantsByChromosome = self.getVariantListByChromosome()
overlapps = set()
for line in bedFile:
try:
sl = line.split("\t")
#if "\t" in line else line.split(" ")
chromosome,start,stop = sl[:3]
start,stop=(int(start),int(stop))
except ValueError:
raise ValueError("Error in line '%s'" % line)
for v in variantsByChromosome[chromosome]:
if start < v.position < stop:
overlapps.add((v.chromosome,v.position,v.ref,v.alt))
if getNonOverlaps:
overlapps = set(self.variantDict.keys()) - overlapps #delete all accept the ones which are overlapping
newSet={}
for variantTuple in overlapps:
#del self.variantDict[variantTuple]
newSet[variantTuple]=self.variantDict[variantTuple]
Helper.printTimeDiff(startTime, self.logFile,self.textField)
return newSet
示例4: removeEdgeMismatches
# 需要导入模块: from Helper import Helper [as 别名]
# 或者: from Helper.Helper import printTimeDiff [as 别名]
def removeEdgeMismatches(self,bamFile,minDistance, minBaseQual):
startTime=Helper.getTime()
minDistance=int(minDistance)
counter=0;j=0
num_lines = len(self.variantDict)
Helper.info(" [%s] remove Missmatches from the first %s bp from read edges" % (startTime.strftime("%c"),str(minDistance)),self.logFile,self.textField)
bamFile = Samfile(bamFile, "rb")
for varKey in self.variantDict.keys():
variant = self.variantDict[varKey]
counter+=1
if counter%10000==0:
Helper.status('%s mm parsed ' % counter ,self.logFile, self.textField,"grey")
keepSNP=False
varPos=variant.position-1
iter = bamFile.pileup(variant.chromosome, variant.position-1, variant.position)
#walks up the region wich overlap this position
for x in iter:
if x.pos == varPos:
for pileupread in x.pileups: #walk through the single reads
if not pileupread.is_del and not pileupread.is_refskip:
distance=abs(pileupread.alignment.alen-pileupread.query_position) if pileupread.alignment.is_reverse else pileupread.query_position
if distance >= minDistance:
#check readBase and Base Quality
if pileupread.alignment.query_sequence[pileupread.query_position] == variant.alt and pileupread.alignment.query_qualities[pileupread.query_position]>=minBaseQual:
#if pileupread.alignment.query_sequence[pileupread.query_position] == variant.alt:
keepSNP=True
if keepSNP==False:
j+=1
del self.variantDict[varKey]
Helper.status('%s of %svariants were deleted' % (j,num_lines), self.logFile, self.textField,"black")
Helper.printTimeDiff(startTime, self.logFile, self.textField)
bamFile.close()
示例5: parseVcf
# 需要导入模块: from Helper import Helper [as 别名]
# 或者: from Helper.Helper import printTimeDiff [as 别名]
def parseVcf(self,vcfFile):
'''
Imports a given Variant File and returns the variants as Dictionary with Tuple of (chromosome,pos,ref,alt) as key and a the VariantObject as value
{(1,45435,"A","G"):VariantObject1,(1,45435,"A","G"):VariantObject1,.....}
'''
startTime = Helper.getTime()
Helper.info(" [%s] Parsing Variant Data from %s" % (startTime.strftime("%c"),vcfFile),self.logFile,self.textField)
#check correct Type
if type(vcfFile) == str:
if os.path.getsize(vcfFile) == 0: #getsize raises OSError if file is not existing
raise IOError("%s File is empty" % vcfFile)
vcfFile = open(vcfFile,"r")
elif type(vcfFile) != file:
raise TypeError("Invalid type in 'parseVcfFile' (need string or file, %s found)" % type(vcfFile))
variantDict = OrderedDict()
for v in self.iterator(vcfFile):
variantDict[(v.chromosome,v.position,v.ref,v.alt)]=v
#variantDict[(v.chromosome,v.position)]=v
Helper.printTimeDiff(startTime,self.logFile,self.textField)
return variantDict
示例6: splitByBed
# 需要导入模块: from Helper import Helper [as 别名]
# 或者: from Helper.Helper import printTimeDiff [as 别名]
def splitByBed(self,bedFile):
'''
returns overlaps and nonOverlaps from bed file features
:param bedFile: as string or file
:param getNonOverlaps: boolean
'''
if type(bedFile) == str:
bedFile = open(bedFile)
elif type(bedFile) != file:
raise TypeError("bedFile has wrong type, need str or file, %s found" % type(bedFile))
startTime=Helper.getTime()
Helper.info("[%s] Split Variants by Bed File %s" % (startTime.strftime("%c"),bedFile.name) ,self.logFile,self.textField)
variantsByChromosome = self.getVariantListByChromosome()
overlapSet = set()
i=0
for line in bedFile:
try:
sl = line.split("\t")
#if "\t" in line else line.split(" ")
chromosome,start,stop = sl[:3]
start,stop=(int(start),int(stop))
except ValueError:
raise ValueError("Error in line '%s'" % line)
for v in variantsByChromosome[chromosome]:
if start < v.position < stop:
overlapSet.add((v.chromosome,v.position,v.ref,v.alt))
i+=1
if i %100000==0:
Helper.status("%s Bed Feautes parsed" % i, self.logFile,self.textField,"grey")
Helper.info("finished parsing Bed file", self.logFile,self.textField)
Helper.printTimeDiff(startTime, self.logFile,self.textField)
#nonOverlapSet = set(self.variantDict.keys()) - overlapSet #delete all accept the ones which are overlapping
overlaps = {key: self.variantDict[key] for key in self.variantDict if key in overlapSet}
Helper.info("finished creating overlaps", self.logFile,self.textField)
Helper.printTimeDiff(startTime, self.logFile,self.textField)
nonOverlaps = {key: self.variantDict[key] for key in self.variantDict if key not in overlapSet}
"""
overlaps={}
for variantTuple in overlapSet:
#del self.variantDict[variantTuple]
overlaps[variantTuple]=self.variantDict[variantTuple]
nonOverlaps={}
for variantTuple in nonOverlapSet:
nonOverlaps[variantTuple]=self.variantDict
"""
Helper.printTimeDiff(startTime, self.logFile,self.textField)
return overlaps, nonOverlaps