• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python xplib.TableIO类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中xplib.TableIO的典型用法代码示例。如果您正苦于以下问题:Python TableIO类的具体用法?Python TableIO怎么用?Python TableIO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了TableIO类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: main

def main():
    ''' main scripts '''
    args = parse_argument()
    
    PromoterList =[]
    feature = []

    print "# loading and reading the promoter of Gene ... "
    if args.genefile:
        for g in TableIO.parse(args.genefile, "genebed"):
            a = g.promoter(args.bp)
            PromoterList.append(a)
    if args.rna:
        for g in TableIO.parse(args.rna, "genebed"):
            a = g.promoter(args.bp)
            PromoterList.append(a)
    if args.feature:
        feature = TableIO.parse(args.feature, 'bed')
    print "# loading and reading Done !" 
    
    PromoterData = readIntoBinIndex(PromoterList)
    FeatureData  = readIntoBinIndex(feature)
    
    for i in TableIO.parse(args.bed, 'bed'):
        overlapGene, overlapFeature, overlap_string = [], [], ''
        if i.strand not in ['+','-']: continue
        else:
            OverlapGene = getOverlapFeatures(i, PromoterData)
            if FeatureData:
                overlapFeature = getOverlapFeatures(i, FeatureData)
            for g in overlapGene +  overlapFeature:
                overlap_string += g.id+';'
            print i, "\t", overlap_string
开发者ID:purcaro,项目名称:bam2x,代码行数:33,代码来源:xCmpBed_with_genePromoter.py


示例2: __init__

 def __init__(self, tabix_file_name, **dict):
     """
     wrapped in DBI.init(filename,"tabix")
     """
     self.tabix_file_name = tabix_file_name
     self.dict = dict
     try:
         self.data = pysam.Tabixfile(tabix_file_name)
     except:
         print >>sys.stderr, "WARNING: Can't init the tabix file", tabix_file_name
     self.header = None
     if dict.has_key("header") and dict["header"] == True:
         f = TableIO.parse(tabix_file_name)
         h = f.next()
         l = len(h)
         for i in range(l):
             h[i] = h[i].strip()
         self.header = h
         f.close()
     elif dict.has_key("header") and isinstance(dict["header"], list):
         self.header = dict["header"]
     elif dict.has_key("header") and isinstance(dict["header"], str):
         fh = TableIO.parse(dict["header"])
         self.header = fh.next()
         # print >>sys.stderr,self.header
     self.tabix_format = "simple"
     if self.dict.has_key("tabix"):
         self.tabix_format = self.dict["tabix"]
开发者ID:nimezhu,项目名称:xplib,代码行数:28,代码来源:DB.py


示例3: Main

def Main():
    '''
    IO TEMPLATE
    '''
    global args,out
    args=ParseArg()
    fin=IO.fopen(args.input,"r")
    out=IO.fopen(args.output,"w")
    '''
    END OF IO TEMPLATE 
    '''
    print >>out,"# This data was generated by program ",sys.argv[0]," (version: %s)"%VERSION,
    print >>out,"in bam2x ( https://github.com/nimezhu/bam2x )"
    print >>out,"# Date: ",time.asctime()
    print >>out,"# The command line is :"
    print >>out,"#\t"," ".join(sys.argv)
    dbi=DBI.init(args.db,Tools.guess_format(args.db))
    references=dbi.bamfiles[0].references
    for i in TableIO.parse(fin,args.format):
        print i
        n=0
        c_count=0
        reads=dbi.query(i,args.method)
        for read in reads:
            compatible=Tools.compatible_with_transcript(read,i,references=references,strand=args.strand)
            print "HT:"
            for i0,r in enumerate(TableIO.parse(read.reads,"bam2bed12",references=references)):
                print "READ"+str(i0)+"\t",r
            print "COMPATIBLE:",compatible,"\n\n"
            if compatible: c_count+=1
            n+=1
        print "COMPATIBLE / ALL OVERLAP READS =  ",c_count,"/",n
        print "RATIO\t%.4f"%float(c_count)/n
开发者ID:purcaro,项目名称:bam2x,代码行数:33,代码来源:xIsoformCmpReads.py


示例4: Main

def Main():
    global args,out,SHIFTSIZE,data
    args=ParseArg()
    if args.output=="stdout":
        out=sys.stdout
    else:
        try:
            out=open(args.output,"w")
        except IOError:
            print >>sys.stderr,"can't open file ",args.output,"to write. Using stdout instead"
            out=sys.stdout


    SHIFTSIZE=args.shiftsize
    data={}
    for x in TableIO.parse(args.chr_length_file,"simple"):
        data[x[0].strip()]=[0 for row in range((long(x[1]>>SHIFTSIZE)+1))] 
    parseAnnotationFile(args.input)
    for x in TableIO.parse(args.chr_length_file,"simple"):
        chrom=x[0].strip()
        length=long(x[1])
        for i,bin in enumerate(data[chrom]):
            start=i<<SHIFTSIZE
            stop=(i+1)<<SHIFTSIZE
            if stop > length: stop=length
            print >>out,chrom+"\t"+str(start)+"\t"+str(stop)+"\t"+str(bin)
开发者ID:purcaro,项目名称:bam2x,代码行数:26,代码来源:xHist.py


示例5: Main

def Main():
    '''
    IO TEMPLATE
    '''
    global args,out
    args=ParseArg()
    if args.output=="stdout":
        out=sys.stdout
    else:
        try:
            out=open(args.output,"w")
        except IOError:
            print >>sys.stderr,"can't open file ",args.output,"to write. Using stdout instead"
            out=sys.stdout
    if args.input=="stdin":
        fin=sys.stdin
    else:
        try:
            x=args.input.split(".")
            if x[-1]=="gz":
                fin=gzip.open(args.input,"r")
            else:
                fin=open(args.input,"r")
        except IOError:
            print >>sys.stderr,"can't read file",args.input
            fin=sys.stdin
    '''
    END OF IO TEMPLATE 
    '''
    if args.genome is not None:
        chr_sizes={}
        for x in TableIO.parse(args.genome):
            chr_sizes[x[0]]=int(x[1])
    bins=b()
    print >>out,"# This data was generated by program ",sys.argv[0]," (version: %s)"%VERSION,
    print >>out,"in bam2x ( https://github.com/nimezhu/bam2x )"
    print >>out,"# Date: ",time.asctime()
    print >>out,"# The command line is :"
    print >>out,"#","\t".join(sys.argv)
    print >>out,"chr\tstart\tstop\tbinindex\tcoverage\tcoverage_nt\tbinlevel\tbinsize " 
    header=False
    if (args.format=="metabed"): header=True

    for i,x in enumerate(TableIO.parse(fin,args.format,header=header)):
        if i%1000==0:
            print >>sys.stderr,"reading %d entries\r"%i,
        bins.append(x)
    c=b.bin2cov(bins)
    for chr in sorted(c.keys()):
        for i,x in enumerate(c[chr]):
            (start,end)=b.bin2range(i)
            if args.genome is not None:
                if start > chr_sizes[chr]:
                    continue
                if end > chr_sizes[chr]:
                    end=chr_sizes[chr]
            print >>out,chr,"\t",start,"\t",end,"\t",i,"\t",float(x)/(end-start),"\t",x,"\t",b.bin2level(i),"\t",end-start
开发者ID:purcaro,项目名称:bam2x,代码行数:57,代码来源:xbin2cov.py


示例6: Main

def Main():
    global args,out
    args=ParseArg()
    if args.output=="stdout":
        out=sys.stdout
    else:
        try:
            out=open(args.output,"w")
        except IOError:
            print >>sys.stderr,"can't open file ",args.output,"to write. Using stdout instead"
            out=sys.stdout
    h=[[0,0],[0,0]]
    l=[[0,0],[0,0]]
    d=Utils.readIntoBinIndex(TableIO.parse(args.centromere,"bed"))
    print >>out,"# Coverage Threshold: ",args.t
    print >>out,"# Chi2 Threshold:",args.chi2
    for i in TableIO.parse(args.input,"oddsratiosnp"):
        mark=0
        for j in Utils.iterOverlapFeature(i,d):
            mark+=1
        if mark>1: mark=1
        if sum(i.A_nt_dis) > args.t and sum(i.B_nt_dis) > args.t:
            if i.odds_ratio > args.chi2:
                h[mark][1]+=1
            else:
                h[mark][0]+=1
            print >>out,i,"\tHigh\t",mark
        else:
            print >>out,i,"\tLow\t",mark
            if i.odds_ratio > args.chi2:
                l[mark][1]+=1
            else:
                l[mark][0]+=1
    print >>out,"# HighOddsRatio:",h[0][1]+l[0][1]+h[1][1]+l[1][1]
    print >>out,"# LowOddsRatio:",h[0][0]+l[0][0]+h[1][0]+l[1][0]
    print >>out,"#"
    print >>out,"# HighCoverage:",sum(h[1])+sum(h[0])
    print >>out,"# LowCoverage :",sum(l[1])+sum(l[0])
    print >>out,"#"
    print >>out,"# HighCoverage, HighOddsRatio",h[1][1]+h[0][1]
    print >>out,"# HighCoverage, LowOddsRatio",h[1][0]+h[0][0]
    print >>out,"#"
    print >>out,"# HighCoverage, InCentromere",sum(h[1])
    print >>out,"# HighCoverage, NotInCentromere",sum(l[1])
    print >>out,"#"

    print >>out,"# HighCoverage, HighOddsRatio, InCentromere",h[1][1]
    print >>out,"# HighCoverage, HighOddsRatio, NotInCentromere",h[0][1]
    print >>out,"# HighCoverage, LowOddsRatio,  InCentromere",h[1][0]
    print >>out,"# HighCoverage, LowOddsRatio, NotInCentromere",h[0][0]
    print >>out,"# LowCoverage, HighOddsRatio, InCentromere",l[1][1]
    print >>out,"# LowCoverage, HighOddsRatio, NotInCentromere",l[0][1]
    print >>out,"# LowCoverage, LowOddsRatio, InCentromere",l[1][0]
    print >>out,"# LowCoverage, LowOddsRatio, NotInCentromere",l[0][0]
开发者ID:purcaro,项目名称:bam2x,代码行数:54,代码来源:OddsRatioSummary.py


示例7: Main

def Main():
    '''
    IO TEMPLATE
    '''
    global args,out
    args=ParseArg()
    fin=IO.fopen(args.input,"r")
    out=IO.fopen(args.output,"w")
    '''
    END OF IO TEMPLATE 
    '''
    print >>out,"# This data was generated by program ",sys.argv[0]," (version: %s)"%VERSION,
    print >>out,"in bam2x ( https://github.com/nimezhu/bam2x )"
    print >>out,"# Date: ",time.asctime()
    print >>out,"# The command line is :"
    print >>out,"#\t"," ".join(sys.argv)

    dbi=[];
    for i,bam in enumerate(args.bams):
        print >>out,"# SAMPLE_"+str(i+1)+" BAM File:",bam
        dbi.append(DBI.init(bam,"bam"))
    print >>out,"#",VCF.header(),
    for i,bam in enumerate(args.bams):
        print >>out,"\t","Sample_"+str(i+1),
    print >>out,""
    for i,vcf in enumerate(TableIO.parse(fin,"vcf")):
        vcf.chr=args.chr_prefix+vcf.chr
        if(i%100==0):
            print >>sys.stderr,"processing",i,"vcf\r",
        print >>out,vcf,
        for d in dbi:
            print >>out,"\t",
            for r in d.query(vcf):
                print >>out,format(r),
        print >>out,""
开发者ID:purcaro,项目名称:bam2x,代码行数:35,代码来源:xQueryVCF.py


示例8: Main

def Main():
    global args,out
    CellLine=["H1"]
    HM=("input","H3K27ac","H3K27me3","H3K36me3","H3K4me1","H3K4me3","H3K9me3")
    marks=[]
    dbi={}

    args=ParseArg()
    if args.output=="stdout":
        out=sys.stdout
    else:
        try:
            out=open(args.output,"w")
        except IOError:
            print >>sys.stderr,"can't open file ",args.output,"to write. Using stdout instead"
            out=sys.stdout
    for cell in CellLine:
        for hm in HM:
            mark=cell+"_"+hm
            marks.append(mark)
            dbi[mark]=DBI.init("/data/zhuxp/bam2x/data/bamlist/"+mark+".bamlist","bamlist")
    for i,x in enumerate(TableIO.parse(args.input,args.input_format)):
        print >>out,"QR\t",x
        if i%100==0: print >>sys.stderr,"query %d entries\r"%i,
        for mark in marks:
            print >>out,mark,"\t"
            for j in DBI.query(x,dbi[mark]):
                print >>out,"HT\t",j
开发者ID:nimezhu,项目名称:bam4x,代码行数:28,代码来源:QueryH1.py


示例9: Main

def Main():
    global args,out
    args=ParseArg()
    if args.output=="stdout":
        out=sys.stdout
    else:
        try:
            out=open(args.output,"w")
        except IOError:
            print >>sys.stderr,"can't open file ",args.output,"to write. Using stdout instead"
            out=sys.stdout

    count={}
    dbi1=DBI.init(args.db,"bed") # the DBI init file for bed6 file of all kinds of RNA
    dbi2=DBI.init(args.db_detail,"bed") # the DBI init file for bed12 file of lincRNA and mRNA with intron, exon, UTR
    genome=Genome('mouse', Release=67, account=None)
    for bed in TableIO.parse(args.input,args.format):
        [typ,name,subtype]=annotation(bed,dbi1,dbi2,genome)
        if count.has_key(typ):
            count[typ]+=1
        else:
            count[typ]=1
        print >>out, "\t".join (str(f) for f in [bed.chr,bed.start,bed.stop,bed.id,name,bed.strand,typ, subtype])

    print >>out, "\n".join ("#"+typ+"\t%d"%(count[typ]) for typ in count.keys())
开发者ID:Jia340,项目名称:MARIO,代码行数:25,代码来源:RNA_composition.py


示例10: parseIterChrom

def parseIterChrom(fn):
    last_chrom= None
    fin=open(fn)
    positions=[]
    x2s=[]
    coverage=[]
    for x in TableIO.parse(fin,'simple'):
        (chrom,pos,snp,x2,x2_matrix,nt_dist)=x
        b=x2_matrix.replace("( ","")
        b=b.replace(" )","")
        a=b.split(" ")
        x2_matrix=[]
        s=0
        for y in a:
            s+=int(y)
            x2_matrix.append(int(y))

        if (last_chrom==None) or (chrom==last_chrom):
            coverage.append(s)
            positions.append(pos)
            x2s.append(x2)
            last_chrom=chrom
            continue
        yield last_chrom,positions,x2s,coverage
        positions=[]
        x2s=[]
        coverage=[]
        coverage.append(s)
        x2s.append(x2)
        positions.append(pos)
        last_chrom=chrom
    yield last_chrom,positions,x2s,coverage
开发者ID:purcaro,项目名称:bam2x,代码行数:32,代码来源:xAPS2Fig.py


示例11: Main

def Main():
    global args,out
    MAX_SCORE=200
    args=ParseArg()
    if args.output=="stdout":
        out=sys.stdout
    else:
        try:
            out=open(args.output,"w")
        except IOError:
            print >>sys.stderr,"can't open file ",args.output,"to write. Using stdout instead"
            out=sys.stdout
    i=0
    x=args.input.split("/")
    name=x[-1]
    name=name.replace(".OddsRatio.peaks","")
    name=name.replace(".LogR.Peaks","")
    name=name.replace(".out","")
    name=args.prefix+name

    for x in TableIO.parse(args.input,"simple"):
        if x[0]=="REGION":
            i+=1
            if x[4]==0:
                score=MAX_SCORE
            else:
                score=-10*math.log(x[4],10)
            if score > MAX_SCORE:
                score=MAX_SCORE
            ID=name+"_ORP_"+str(i)
            print >>out,x[1]+"\t"+str(x[2])+"\t"+str(x[3])+"\t"+ID+"\t",
            print >>out,"%.2f"%score        
开发者ID:purcaro,项目名称:bam2x,代码行数:32,代码来源:OddsRatioPeaks2Bed.py


示例12: main

def main():
    ''' main scripts '''
    args = parse_argument()
    bed  = args.bed
    gene = readIntoBinIndex(TableIO.parse( args.genefile, "genebed") )
    for i in TableIO.parse(args.bed, 'bed'):
        if i.strand not in ['+','-']: continue
        else:
            OverlapGene    = getOverlapFeatures(i, gene)
            Overlap_dict   = Classify_Overlap(i, OverlapGene)
            overlap_string = ''
            for k,v in Overlap_dict.iteritems():
                if v:
                    overlap_string += "".join([ str(k+'_'+each)+';' for each in v])
            if not overlap_string:
                overlap_string = 'intergenic'
            print i, overlap_string
开发者ID:purcaro,项目名称:bam2x,代码行数:17,代码来源:xCmpBed_with_genePred.py


示例13: Main

def Main():
    global args
    args=ParseArg()
    if args.output=="stdout":
        out=sys.stdout
    else:
        try:
            out=open(args.output,"w")
        except IOError:
            print >>sys.stderr,"can't open file ",args.output,"to write. Using stdout instead"
            out=sys.stdout

    dbi=DBI.init(args.db,"genebed")
    count={}
    count["Intergenic"]=0
    for x in TableIO.parse(args.input,args.input_format):
        flag=0
        gene=""
        for hit in dbi.query(x):
            flag=1
            if hit.align_id==gene:
                continue
            gene=hit.align_id
            #print hit
            #print hit.cds_start,hit.cds_stop
            if (hit.cds_start==hit.cds_stop):
                if hit.align_id[0:3]=="Mir":
                    loc="MiRNA"
                else:
                    loc="Non-coding"
            elif hit.strand=="+":
                if x.stop<=hit.cds_start:
                    loc="5-UTR"
                elif x.start>=hit.cds_stop:
                    loc="3-UTR"
                else:
                    loc=judge_exon(x,hit)
                        
            else:
                if x.stop<=hit.cds_start:
                    loc="3-UTR"
                elif x.start>=hit.cds_stop:
                    loc="5-UTR"
                else:
                    loc=judge_exon(x,hit)
            print >>out,"\t".join (str(f) for f in [x.chr,x.start,x.stop,x.id,x.score,x.strand,hit.align_id,loc])
            if count.has_key(loc):
                count[loc]+=1
            else:
                count[loc]=1

        if flag==0:
            print >>out, "\t".join (str(f) for f in [x.chr,x.start,x.stop,x.id,x.score,x.strand,"None","Intergenic"])
            count["Intergenic"]+=1
    
    out2=open(args.output.split(".")[0]+".cisStat","w")
    for key in sorted(count.keys()):
        print >>out2,key+"\t"+str(count[key])
开发者ID:Jia340,项目名称:MARIO,代码行数:58,代码来源:bed_annotation.py


示例14: query

 def query(self,x,**kwargs):
     '''
     yield the overlap feature in tabix index files
     '''
     try:
         for item in TableIO.parse(self.data.fetch(x.chr,x.start,x.stop),format=self.tabix_format,header=self.header):
             yield item
     except:
        raise StopIteration
开发者ID:purcaro,项目名称:bam2x,代码行数:9,代码来源:DB.py


示例15: toBed12Tuple

 def toBed12Tuple(self,chr="chr",strand="read2"):
     '''
     test now
     '''
     from xplib import TableIO
     x=list()
     for i in TableIO.parse(self.reads,"bam2bed12tuple",references=chr,strand=strand):
         x.append(i)
     return x
开发者ID:nimezhu,项目名称:xplib,代码行数:9,代码来源:__init__.py


示例16: Main

def Main():
    '''
    IO TEMPLATE
    '''
    global args,out
    args=ParseArg()
    if args.output=="stdout":
        out=sys.stdout
    else:
        try:
            out=open(args.output,"w")
        except IOError:
            print >>sys.stderr,"can't open file ",args.output,"to write. Using stdout instead"
            out=sys.stdout
    if args.input=="stdin":
        fin=sys.stdin
    else:
        try:
            x=args.input.split(".")
            if x[-1]=="gz":
                fin=gzip.open(args.input,"r")
            else:
                fin=open(args.input,"r")
        except IOError:
            print >>sys.stderr,"can't read file",args.input
            fin=sys.stdin
    '''
    END OF IO TEMPLATE 
    '''
    print >>out,"# This data was generated by program ",sys.argv[0]," (version: %s)"%VERSION,
    print >>out,"in bam2x ( https://github.com/nimezhu/bam2x )"
    print >>out,"# Date: ",time.asctime()
    print >>out,"# The command line is :"
    print >>out,"#\t"," ".join(sys.argv)
    h1={}
    h2={}

    for i in TableIO.parse(fin):
        h1[i[args.c1-1]]=i
    for j in TableIO.parse(args.input2):
        h2[j[args.c2-1]]=j

        if h1.has_key(j[args.c2-1]):
            print >>out,TableIO.format_string(h1[j[args.c2-1]])+"\t"+TableIO.format_string(j)
开发者ID:purcaro,项目名称:bam2x,代码行数:44,代码来源:xMergeTab.py


示例17: __init__

 def __init__(self,file,**dict):
     '''
     Wrapped in xplib.DBI.init()
     '''
     if type(file)==type([1,2,3]):
         f=file
     else:
         format=dict['format']
         f=TableIO.parse(file,format)
     self.data=binindex(f)
开发者ID:yu68,项目名称:bam2x,代码行数:10,代码来源:DB.py


示例18: test

def test():
    if len(sys.argv)==1:
        print >>sys.stderr,"Usage: Utils.py file.bed"
        exit()
    a=TableIO.parse(sys.argv[1],'bed')
    data=readIntoBinIndex(a)
    bed=Bed(["chr1",100000,200000,".",".","."])
    g=getOverlapFeatures(bed,data)
    print "Overlap with",bed
    for i in g:
        print i
开发者ID:bchen4,项目名称:bam2x,代码行数:11,代码来源:Utils.py


示例19: query

 def query(self,x):
     '''
     yield the overlap feature in tabix index files
     '''
     f="simple"
     if self.dict.has_key("tabix"):
         f=self.dict["tabix"]
     try:
         for item in TableIO.parse(self.data.fetch(x.chr,x.start,x.stop),format=f,header=self.header):
             yield item
     except:
        raise StopIteration
开发者ID:yu68,项目名称:bam2x,代码行数:12,代码来源:DB.py


示例20: parseAnnotationFile

def parseAnnotationFile(fn):
    format=args.format
    if format=="bam":
        format="bam2bed"
    for x in TableIO.parse(fn,format):
        if not data.has_key(x.chr):
            print >>sys.stderr,"ignore",x
            print >>sys.stderr,"since this chromosome size is not in ",args.chr_length_file
            continue
        bin_start=x.start>>SHIFTSIZE
        bin_stop=x.stop>>SHIFTSIZE
        for bin in range(bin_start,bin_stop+1):
            data[x.chr][bin]+=1
开发者ID:purcaro,项目名称:bam2x,代码行数:13,代码来源:xHist.py



注:本文中的xplib.TableIO类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python gtk_client_base.GTKXpraClient类代码示例发布时间:2022-05-26
下一篇:
Python xpidl.unaliasType函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap