Ejemplo n.º 1
0
 def __call__(self, **kw):
     sample = track(kw['sample'],chrmeta="guess")
     by_chrom = kw.get('by_chrom',False)
     if isinstance(by_chrom, basestring):
         by_chrom = (by_chrom.lower() in ['1', 'true', 't','on'])
     outf = kw.get('output')
     if outf not in output_list:
         outf = output_list[0]
     output = self.temporary_path(fname=sample.name+'_stats.'+outf)
     if outf == 'txt':
         out = open(output,"w")
     else:
         out = {}
     if by_chrom:
         chromlist = sample.chrmeta.keys()
     else:
         chromlist = [None]
     for chrom in chromlist:
         if outf == 'txt':
             if chrom:
                 out.write("Chromosome %s\n--------------------\n"%chrom)
             stats(sample,out=out,selection=chrom)
         else:
             out[chrom] = {}
             stats(sample,out=out[chrom],selection=chrom)
         if outf == 'txt' and chrom:
             out.write("\n--------------------\n")
     if outf == 'txt':
         out.close()
         self.new_file(output, 'stats')
     else:
         self._plot_pdf(output,out,sample.name)
         self.new_file(output, 'pdf')
     return self.display_time()
Ejemplo n.º 2
0
 def __call__(self, **kw):
     sample = track(kw['sample'],chrmeta="guess")
     by_chrom = kw.get('by_chrom',False)
     if isinstance(by_chrom, basestring):
         by_chrom = (by_chrom.lower() in ['1', 'true', 't','on'])
     outf = kw.get('output')
     if outf not in output_list:
         outf = output_list[0]
     output = self.temporary_path(fname=sample.name+'_stats.'+outf)
     if outf == 'txt':
         out = open(output,"w")
     else:
         out = {}
     if by_chrom:
         chromlist = sample.chrmeta.keys()
     else:
         chromlist = [None]
     for chrom in chromlist:
         if outf == 'txt':
             if chrom:
                 out.write("Chromosome %s\n--------------------\n"%chrom)
             stats(sample,out=out,selection=chrom)
         else:
             out[chrom] = {}
             stats(sample,out=out[chrom],selection=chrom)
         if outf == 'txt' and chrom:
             out.write("\n--------------------\n")
     if outf == 'txt':
         out.close()
         self.new_file(output, 'stats')
     else:
         self._plot_pdf(output,out,sample.name)
         self.new_file(output, 'pdf')
     return self.display_time()
Ejemplo n.º 3
0
def stats(*args, **kw):
    if len(args) < 1: raise Usage("No input file provided")
    if kw['selection']:
        if kw['selection'].count("{"):
            jsonargs = json.loads(kw['selection'])
            for k, v in jsonargs.iteritems():
                if isinstance(v, basestring): jsonargs[k] = str(v)
            kw['selection'] = dict(
                (str(k), v) for k, v in jsonargs.iteritems())
        elif kw['selection'].count(":"):
            chr, coord = kw['selection'].split(':')
            start, end = coord.split('-')
            kw['selection'] = {
                'chr': chr,
                'start': (start, end),
                'end': (start, end)
            }
        else:
            kw['selection'] = str(kw['selection']).split(",")
    fields = None
    if kw['fields']:
        fields = str(kw['fields']).split(",")
    if kw['output'] is None:
        output = sys.stdout
    else:
        output = open(kw['output'], 'w')
    chrmeta = _get_chrmeta(**kw)
    for infile in args:
        intrack = track.track(infile, format=kw['format'], chrmeta=chrmeta)
        if intrack.info:
            fileinfo = ",".join(
                ["%s=%s" % (k, v) for k, v in intrack.info.iteritems()])
        else:
            fileinfo = 'None'
        chromlist = ",".join(sorted(intrack.chrmeta.keys())) or "None"
        fields = ",".join(intrack.fields)
        output.write(\
"""*****************************************
File '%s' (%s):
Infos: %s
Chromosomes: %s
Fields: %s
*****************************************\n
""" %(os.path.basename(infile), intrack.format, fileinfo, chromlist, fields))
        track.stats(intrack, out=output, **kw)
        intrack.close()
    output.close()
    return 0
Ejemplo n.º 4
0
def stats(*args,**kw):
    if len(args) < 1: raise Usage("No input file provided")
    if kw['selection']:
        if kw['selection'].count("{"):
            jsonargs = json.loads(kw['selection'])
            for k,v in jsonargs.iteritems():
                if isinstance(v,basestring): jsonargs[k] = str(v)
            kw['selection'] = dict((str(k),v) for k,v in jsonargs.iteritems())
        elif kw['selection'].count(":"):
            chr,coord = kw['selection'].split(':')
            start,end = coord.split('-')
            kw['selection'] = {'chr':chr,'start':(start,end),'end':(start,end)}
        else:
            kw['selection'] = str(kw['selection']).split(",")
    fields = None
    if kw['fields']:
        fields = str(kw['fields']).split(",")
    if kw['output'] is None:
        output = sys.stdout
    else:
        output = open(kw['output'],'w')
    chrmeta = _get_chrmeta(**kw)
    for infile in args:
        intrack = track.track(infile,format=kw['format'],chrmeta=chrmeta)
        if intrack.info:
            fileinfo = ",".join(["%s=%s" %(k,v) for k,v in intrack.info.iteritems()])
        else: fileinfo = 'None'
        chromlist = ",".join(sorted(intrack.chrmeta.keys())) or "None"
        fields = ",".join(intrack.fields)
        output.write(\
"""*****************************************
File '%s' (%s):
Infos: %s
Chromosomes: %s
Fields: %s
*****************************************\n
""" %(os.path.basename(infile), intrack.format, fileinfo, chromlist, fields))
        track.stats(intrack,out=output,**kw)
        intrack.close()
    output.close()
    return 0