Beispiel #1
0
            else :
                stats[row[10]] += 1
                all_stats[row[10]] += 1

        tot_reads = sum(stats.values())/1.-stats.get('QC',0)
        unique_reads = sum([v for k,v in stats.items() if k.startswith('chr')])
        repeat_reads = stats.get('multiread',0)
        nomap_reads = stats.get('NM',0)
        data_row = [fn,format_with_commas(int(tot_reads)),
                    '%.1f'%(unique_reads/tot_reads*100),format_with_commas(unique_reads),
                    '%.1f'%(repeat_reads/tot_reads*100),format_with_commas(repeat_reads),
                    '%.1f'%(nomap_reads/tot_reads*100),format_with_commas(nomap_reads)]

        data_rows.append(data_row)

    out_f = open(opts.output,'w') if opts.output is not None else sys.stdout

    if opts.format == 'python' :
        out_f.write(dict(all_stats))
    elif opts.format == 'rst' :
        doc = ReStDocument(out_f)
        table = ReStSimpleTable(header=stats_fields,data=data_rows)
        doc.add(table)
        doc.write()
    elif opts.format == 'tab' :
        out_w = writer(out_f,delimiter='\t')
        out_w.writerow(stats_fields)
        out_w.writerows(data_rows)

    if opts.output is not None : out_f.close()
import sys
from reStUtil import ReStDocument, ReStSimpleTable, ReStTable

doc = ReStDocument(sys.stdout)

# very simple
header = ["Column A","Column B","Column C"]
data = [['012','345','678']]

doc.add('Simple simple_table, no text wrap')
doc.add(ReStSimpleTable(header,data))

# word wrapped text
header = ["Food", "Deliciousness", "Notes"]
data = [["hot dogs","moderate-high","Depending on the meat used, hot dogs can provide a delicious snack or a mysterious culinary experiment"],
        ["cabbage","low-moderate","Best results often enjoyed when cooked with corned beef or braughwurst"],
        ["pickles and ice cream","low/very high","For pregnant women only"],
       ]

doc.add('Text wrapped simple_table')
doc.add(ReStSimpleTable(header,data,40))

doc.add('Table directive with title and word wrapped data')
doc.add(ReStTable(header,data,title="Food Analysis",max_col_width=40))

doc.write()
import sys
from reStUtil import ReStDocument, ReStSection, ReStTable

doc = ReStDocument(sys.stdout)

# section 1
sec1 = ReStSection("Section 1",level=1)
sec1.add("The text in section 1")

sec1_1 = ReStSection("Subsection 1.1",level=2)
sec1_1.add("The text in subsection 1.1")
sec1 += sec1_1

sec2 = ReStSection("Section 2",level=1)
sec2.add("The text in section 2")

sec2_1 = ReStSection("Subsection 2.1",level=2)
sec2_1.add("The text in subsection 2.1")

sec2_2 = ReStSection("Subsection 2.2",level=2)
sec2_2.add("Text in subsection 2.2")
sec2.add(sec2_1,sec2_2)

sec3 = ReStSection("Section 3",level=1)
sec3.add("This section has many nested subsections")

sec3.add(ReStSection("Subsection 3.1",level=2))
sec3.add(ReStSection("Subsubsection 3.1.1",level=3))
sec3.add(ReStSection("Subsubsubsection 3.1.1.1",level=4))
sec3.add(ReStSection("Subsubsubsubsection 3.1.1.1.1",level=5))
sec3.add(ReStSection("Subsubsubsubsubsection 3.1.1.1.1.1",level=6))