本文整理匯總了Python中xplib.TableIO.parse方法的典型用法代碼示例。如果您正苦於以下問題:Python TableIO.parse方法的具體用法?Python TableIO.parse怎麽用?Python TableIO.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類xplib.TableIO
的用法示例。
在下文中一共展示了TableIO.parse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from xplib import TableIO [as 別名]
# 或者: from xplib.TableIO import parse [as 別名]
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
示例2: __init__
# 需要導入模塊: from xplib import TableIO [as 別名]
# 或者: from xplib.TableIO import parse [as 別名]
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"]
示例3: Main
# 需要導入模塊: from xplib import TableIO [as 別名]
# 或者: from xplib.TableIO import parse [as 別名]
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
示例4: Main
# 需要導入模塊: from xplib import TableIO [as 別名]
# 或者: from xplib.TableIO import parse [as 別名]
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)
示例5: Main
# 需要導入模塊: from xplib import TableIO [as 別名]
# 或者: from xplib.TableIO import parse [as 別名]
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
示例6: Main
# 需要導入模塊: from xplib import TableIO [as 別名]
# 或者: from xplib.TableIO import parse [as 別名]
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]
示例7: Main
# 需要導入模塊: from xplib import TableIO [as 別名]
# 或者: from xplib.TableIO import parse [as 別名]
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,""
示例8: Main
# 需要導入模塊: from xplib import TableIO [as 別名]
# 或者: from xplib.TableIO import parse [as 別名]
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
示例9: Main
# 需要導入模塊: from xplib import TableIO [as 別名]
# 或者: from xplib.TableIO import parse [as 別名]
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())
示例10: parseIterChrom
# 需要導入模塊: from xplib import TableIO [as 別名]
# 或者: from xplib.TableIO import parse [as 別名]
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
示例11: Main
# 需要導入模塊: from xplib import TableIO [as 別名]
# 或者: from xplib.TableIO import parse [as 別名]
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
示例12: main
# 需要導入模塊: from xplib import TableIO [as 別名]
# 或者: from xplib.TableIO import parse [as 別名]
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
示例13: Main
# 需要導入模塊: from xplib import TableIO [as 別名]
# 或者: from xplib.TableIO import parse [as 別名]
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])
示例14: query
# 需要導入模塊: from xplib import TableIO [as 別名]
# 或者: from xplib.TableIO import parse [as 別名]
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
示例15: toBed12Tuple
# 需要導入模塊: from xplib import TableIO [as 別名]
# 或者: from xplib.TableIO import parse [as 別名]
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