當前位置: 首頁>>代碼示例>>Python>>正文


Python Helper.getTime方法代碼示例

本文整理匯總了Python中Helper.Helper.getTime方法的典型用法代碼示例。如果您正苦於以下問題:Python Helper.getTime方法的具體用法?Python Helper.getTime怎麽用?Python Helper.getTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Helper.Helper的用法示例。


在下文中一共展示了Helper.getTime方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: deleteOverlapsFromVcf

# 需要導入模塊: from Helper import Helper [as 別名]
# 或者: from Helper.Helper import getTime [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)
開發者ID:djhn75,項目名稱:RNAEditor,代碼行數:31,代碼來源:VariantSet.py

示例2: deleteNonEditingBases

# 需要導入模塊: from Helper import Helper [as 別名]
# 或者: from Helper.Helper import getTime [as 別名]
 def deleteNonEditingBases(self):
     startTime=Helper.getTime()
     Helper.info("Delete non Editing Bases (keep only T->C and A->G)",self.logFile,self.textField)
     
     for varTuple in self.variantDict.keys():
         chr,pos,ref,alt = varTuple
         if (ref =="A" and alt == "G") or (ref=="T" and alt=="C"):
             pass
         else:
             del self.variantDict[varTuple]
開發者ID:djhn75,項目名稱:RNAEditor,代碼行數:12,代碼來源:VariantSet.py

示例3: annotateVariantDict

# 需要導入模塊: from Helper import Helper [as 別名]
# 或者: from Helper.Helper import getTime [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)
開發者ID:djhn75,項目名稱:RNAEditor,代碼行數:17,代碼來源:VariantSet.py

示例4: getOverlapsFromBed

# 需要導入模塊: from Helper import Helper [as 別名]
# 或者: from Helper.Helper import getTime [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
開發者ID:djhn75,項目名稱:RNAEditor,代碼行數:43,代碼來源:VariantSet.py

示例5: printClusters

# 需要導入模塊: from Helper import Helper [as 別名]
# 或者: from Helper.Helper import getTime [as 別名]
 def printClusters(self, outFile):
     
     if type(outFile) == str:
         try:
             outFile=open(outFile,"w")
             
         except IOError:
             Helper.warning("Could not open %s to write Variant" % outFile ,self.logFile,self.textField)
     if type(outFile) != file:   
         raise AttributeError("Invalid outfile type in 'printVariantDict' (need string or file, %s found)" % type(outFile))
     
     startTime=Helper.getTime()
     Helper.info("[%s] Print Clusters to %s" %  (startTime.strftime("%c"),outFile.name),self.logFile,self.textField)
     
     
     outFile.write("\t".join(["#Chr","Start","Stop","IslandID","GeneID","Gene Symbol","Cluster Length","Number of Editing_sites","Editing_rate","\n"]))
     
     for cluster in self.clusterDict.keys():
         end = max(v.position for v in self.clusterDict[cluster])
         start = min(v.position for v in self.clusterDict[cluster])
         
         length = end - start
         editingRate=float(len(self.clusterDict[cluster]))/float(length)
         geneIdSet=set()
         geneNameSet=set()
         for v in self.clusterDict[cluster]:
             try: 
                 gene = v.attributes['GI'][0][0]
                 if type(gene) == Gene:
                     geneIdSet.add(gene.geneId)
                     geneNameSet |= set(gene.names)
                     #geneList.append(v.attributes['GI'][0][0])
                 else:
                     geneIdSet.add("Intergenic")
                     geneNameSet.add("Intergenic")
             except KeyError:
                 geneIdSet.add("N/A") #when variant has no attribute GI
         
         outFile.write("\t".join([v.chromosome,str(start),str(end),"Island"+str(cluster), #Chr","Start","Stop","Cluster Name",
                                  ",".join(map(str,geneIdSet)),",".join(map(str,geneNameSet)), #"GeneID","Gene Symbol"
                                  str(length),str(len(self.clusterDict[cluster])),'%1.2f'%float(editingRate),"\n"]))
開發者ID:djhn75,項目名稱:RNAEditor,代碼行數:43,代碼來源:VariantSet.py

示例6: removeEdgeMismatches

# 需要導入模塊: from Helper import Helper [as 別名]
# 或者: from Helper.Helper import getTime [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()
開發者ID:djhn75,項目名稱:RNAEditor,代碼行數:40,代碼來源:VariantSet.py

示例7: printVariantDict

# 需要導入模塊: from Helper import Helper [as 別名]
# 或者: from Helper.Helper import getTime [as 別名]
 def printVariantDict(self,outfile):
     '''
     print the variants from the dictionary to the outfile if defined
     '''
     if type(outfile) == str:
         try:
             outfile=open(outfile,"w")
         except IOError:
             Helper.warning("Could not open %s to write Variant" % outfile ,self.logFile,self.textField)
     if type(outfile) != file:   
         raise AttributeError("Invalid outfile type in 'printVariantDict' (need string or file, %s found)" % type(outfile))
     
     startTime=Helper.getTime()
     Helper.info("[%s] Print Variants to %s" %  (startTime.strftime("%c"),outfile.name),self.logFile,self.textField)
         
     outfile.write("\t".join(["#CHROM", "POS", "ID", "REF", "ALT", "QUAL", "FILTER", "INFO", "\n"]))
     for v in self.variantDict.values():
         attributeString=""
         for key in v.attributes.keys():
             if key=="BaseCounts":
                 attributeString+= "BaseCounts=" + ",".join(v.attributes["BaseCounts"]) + ";"
                 continue                
             elif key =="GI":
                 a=""
                 for anno in v.attributes["GI"]:
                     gene,segment = anno
                     if gene == "-":
                         a += gene+":"+"|".join(segment)  
                     else:
                         if type(gene)==str: #when variantDict was not annotated yet
                             a+=gene +":"+"|".join(segment)+","
                         else:     
                             a+=gene.names[0]+":"+"|".join(segment)+","
                         
                 attributeString+=key+"="+a[:-1]+";"
                 continue
             attributeString+= key+"="+str(v.attributes[key])+";"
         outfile.write("\t".join([v.chromosome,str(v.position),v.id,v.ref,v.alt,str(v.qual),v.filter, attributeString+"\n"]))    
開發者ID:djhn75,項目名稱:RNAEditor,代碼行數:40,代碼來源:VariantSet.py

示例8: parseVcf

# 需要導入模塊: from Helper import Helper [as 別名]
# 或者: from Helper.Helper import getTime [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
開發者ID:djhn75,項目名稱:RNAEditor,代碼行數:26,代碼來源:VariantSet.py

示例9: names

# 需要導入模塊: from Helper import Helper [as 別名]
# 或者: from Helper.Helper import getTime [as 別名]
from Helper import Helper


parser = argparse.ArgumentParser(description='Merges the GVF Files and recalculates the base Counts after RnaEditor is finished.')
parser.add_argument('-f', '--files', metavar='N', type=str, nargs='+', help='the list of files')
parser.add_argument('-b', '--bams', metavar='N', type=str, nargs='+', help='the list of bam files')
parser.add_argument('-t', '--top', metavar='N', type=str, nargs="+", help='list of header names (space separated)')
parser.add_argument('-o', '--outFile', metavar='output File', type=str,help='Output File', default="baseCounts_combined.txt")
parser.add_argument('-c', '--columns', metavar='N', type=int, nargs='+', help='columns to keep (space separated)',default=[2],)
parser.add_argument('-k', '--keys', metavar='N', nargs='+', type=int, help='columnnumber on which to join',default=[1])
parser.add_argument('-d', '--delimiter', metavar='N', type=str, help='delimiter', default="\t")
parser.add_argument('-e', '--empty', metavar='N', type=str, help='Sign for empty Values', default="--")
args = parser.parse_args()

startTime = Helper.getTime()


def fillDicts(files,columns,keys):
    '''
        creates the table and fills the set of keys
    '''
    fileNumber=len(files)
    fileCounter=0
    keySet=()
    fileCounter=0
    for file in files: #loop through all files
        i=0
        Helper.info("Get information from %s" % file)
        file = open(file)
        
開發者ID:djhn75,項目名稱:RNAEditor,代碼行數:31,代碼來源:recountReads.py

示例10: splitByBed

# 需要導入模塊: from Helper import Helper [as 別名]
# 或者: from Helper.Helper import getTime [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
開發者ID:djhn75,項目名稱:RNAEditor,代碼行數:64,代碼來源:VariantSet.py

示例11: printGeneList

# 需要導入模塊: from Helper import Helper [as 別名]
# 或者: from Helper.Helper import getTime [as 別名]
    def printGeneList(self,genome,outfile,printSummary=True):
        '''
        print List of genes with all the variants
        Gene-Variation-File
        "Gene_ID","gene_Name","SEGMENT","#CHROM","GENE_START","GENE_STOP","VAR_POS","REF","ALT","QUAL","BaseCount(A,C,T,G)"
        
        Gene Summary File
        "Gene_ID",Gene_Name,#3'UTR,#5'UTR,#EXON,'INTRON,#TOTAL
        :param genome:  object of class Genome
        :param outfile: 
        :param printSummary: boolean wether to print summary-file
        '''

        sumDict={}
        
        if type(genome) != Genome:
            raise AttributeError("Type of genome is %s, but has to be an object of Genome" % type(genome))
        
        if type(outfile) == str:
            try:
                outfile=open(outfile,"w")
                
            except IOError:
                Helper.warning("Could not open %s to write Variant" % outfile ,self.logFile,self.textField)
        if type(outfile) != file:   
            raise AttributeError("Invalid outfile type in 'printVariantDict' (need string or file, %s found)" % type(outfile))
        
        startTime=Helper.getTime()
        Helper.info("[%s] Print Genes and Variants to %s" %  (startTime.strftime("%c"),outfile.name),self.logFile,self.textField)
        
        sumFile=open(outfile.name[:outfile.name.rfind(".")]+".summary","w")        
        
        outfile.write("\t".join(["#Gene_ID","Name","SEGMENT","#CHROM","GENE_START","GENE_STOP","VAR_ID","VAR_POS",
                                 "REF","ALT","QUAL","#A","#C","#G","#T","Reads_Total","Edited_Reads","Editing_Ratio","\n"]))
        
        for v in self.variantDict.values():
            anno = v.attributes["GI"]
            for a in anno:
                gene,segments = a
                totalReads=str(int(sum(map(int,v.attributes["BaseCounts"]))))
                if v.ref =="A" and v.alt == "G":
                    editedReads=str(v.attributes["BaseCounts"][2])
                    ratio=str(round(float(editedReads)/float(totalReads),2))
                elif (v.ref=="T" and v.alt=="C"):
                    editedReads=str(v.attributes["BaseCounts"][1])
                    ratio=str(round(float(editedReads)/float(totalReads),2))
                else:
                    editedReads="0"
                    ratio="0"
                    
                
                if gene == "-":
                    out=["-", "-",",".join(segments),v.chromosome,"-","-",v.id,str(v.position),
                                             v.ref,v.alt,str(v.qual),"\t".join(v.attributes["BaseCounts"]),totalReads,editedReads,ratio,"\n"]
                    outfile.write("\t".join(out))
                else:
                    out=[gene.geneId, gene.names[0],",".join(segments),v.chromosome,str(gene.start),str(gene.end),v.id,str(v.position),
                                             v.ref,v.alt,str(v.qual),"\t".join(v.attributes["BaseCounts"]),totalReads,editedReads,ratio,"\n"]
                    outfile.write("\t".join(out))
                
                #count variations per gene
                if gene not in sumDict:
                    sumDict[gene]= [0,0,0,0,0]
                
                for seg in segments:
                    if seg == "3'UTR":
                        sumDict[gene][0]+=1
                    elif seg == "5'UTR":
                        sumDict[gene][1]+=1
                    elif seg in ("coding-exon","noncoding-exon"):
                        sumDict[gene][2]+=1
                    elif seg == "intron":
                        sumDict[gene][3]+=1
                    sumDict[gene][4]+=1
        
        

                     
        #print number of variants per gene
        if printSummary:

            
            sumDictGeneIds=set()
            sumFile.write("\t".join(["#Gene_ID","Name","#3'UTR","#5'UTR","#EXON","INTRON","#TOTAL","\n"]))
            for gene in sumDict.keys():
                numbers=map(str,sumDict[gene])
                if gene=="-":
                    sumFile.write("\t".join(["intergenic","-"]+["-","-","-","-",numbers[4]]+["\n"]))
                else:
                    sumFile.write("\t".join([gene.geneId,gene.names[0]]+numbers+["\n"]))
                    sumDictGeneIds.add(gene.geneId)        
            #print non effected Genes
            #this was added to have the whole set og genes in the summary file
            #so that it is easier to compare results in Excel
            genesByGeneId=genome.getGenesByGeneID()
            a=set(genesByGeneId.keys())
            b=sumDictGeneIds
            nonEffectedGenes = a-b
            for geneId in nonEffectedGenes:
                gene=genesByGeneId[geneId]
#.........這裏部分代碼省略.........
開發者ID:djhn75,項目名稱:RNAEditor,代碼行數:103,代碼來源:VariantSet.py


注:本文中的Helper.Helper.getTime方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。