def export_appendix(self): appendix = [] appendix.append(Chapter('참조')) content = Description() endnotes = list(filter(lambda x: x.endnote != None, self.content)) for note in endnotes: content.add_item(note.title, note.endnote) appendix.append(content) appendix = list(map(lambda x: x.dumps().replace('\\', '\\\\'), appendix)) return '\n'.join(appendix)
def test_lists(): # Lists itemize = Itemize() itemize.add_item(s="item") itemize.append("append") enum = Enumerate() enum.add_item(s="item") enum.append("append") desc = Description() desc.add_item(label="label", s="item") desc.append("append")
def add_shopping_list(doc: Document, camp: Camp): # content for this page doc.append(Section('Einkaufsliste', numbering=False)) # space between colums doc.append(Command('setlength')) doc.append(Command('columnsep', arguments='40pt')) doc.packages.add(Package('multicol')) doc.packages.add(Package('enumitem')) doc.packages.add(Package('setspace')) for _ in range(1): doc.append(Subsubsection('Gemüse und Früchte', numbering=False)) with doc.create(Multicols(arguments='2')) as multicols: multicols.append(Command('small')) with multicols.create( Description( options='leftmargin=1.75cm, itemsep=4pt')) as itemize: # space between colums itemize.append( Command('setlength', arguments=Command('itemsep'), extra_arguments='0pt')) itemize.append( Command('setlength', arguments=Command('parskip'), extra_arguments='0pt')) itemize.add_item('100g', 'the first item') itemize.add_item('23 Stk.', 'Bananen') itemize.add_item('100g', 'the first item') itemize.add_item('10g', 'the item')
def generate_info_list(doc, testnumber): section_name = 'Test {} results'.format(testnumber) with doc.create(Section(section_name)): with doc.create(Description()) as desc: desc.add_item("\t", get_log(testnumber)[0]) desc.add_item("\t", get_log(testnumber)[1])
def test_lists(): # Lists itemize = Itemize() itemize.add_item(s="item") itemize.append("append") repr(itemize) enum = Enumerate(enumeration_symbol=r"\alph*)", options={'start': 172}) enum.add_item(s="item") enum.add_item(s="item2") enum.append("append") repr(enum) desc = Description() desc.add_item(label="label", s="item") desc.append("append") repr(desc)
def test_lists(): # Lists itemize = Itemize() itemize.add_item(s="item") itemize.append("append") repr(itemize) empty_itemize = Itemize() assert empty_itemize.dumps() == '' repr(empty_itemize) enum = Enumerate() enum.add_item(s="item") enum.append("append") repr(enum) desc = Description() desc.add_item(label="label", s="item") desc.append("append") repr(desc)
def render(img_dir, img_name, pdf_name, output_list): image_filename = os.path.join(img_dir, img_name) geometry_options = {"tmargin": "1cm", "lmargin": "1cm"} doc = Document(geometry_options=geometry_options) with doc.create(Section("Xcos")): with doc.create(Figure(position='h!')) as abs_pic: abs_pic.add_image(image_filename, width='120px') with doc.create(Description()) as desc: for i in output_list: for key, value in i.parameters().items(): desc.add_item(key, value) doc.generate_pdf(pdf_name, clean_tex=False)
def generate_info_list(doc, testnumber): """ Generate a list which contains last 2 line of tests from log.txt :param doc: LaTeX object, a instance of Document Class :return: null """ section_name = 'Test' + str(testnumber) + ': Last 2 lines in log_test_' + str(testnumber ) + '.txt' ## Create a long table object in LaTeX object with doc.create(Section(section_name)): with doc.create(Description()) as desc: desc.add_item("Second last line: ", get_log(testnumber)[0]) desc.add_item("Last line: ", get_log(testnumber)[1]) doc.append(NewPage())
def do(): doc = Document() # create a bulleted "itemize" list like the below: # \begin{itemize} # \item The first item # \item The second item # \item The third etc \ldots # \end{itemize} with doc.create(Section('"Itemize" list')): with doc.create(Itemize()) as itemize: itemize.add_item("the first item") itemize.add_item("the second item") itemize.add_item("the third etc") # you can append to existing items itemize.append(Command("ldots")) # create a numbered "enumerate" list like the below: # \begin{enumerate} # \item The first item # \item The second item # \item The third etc \ldots # \end{enumerate} with doc.create(Section('"Enumerate" list')): with doc.create(Enumerate()) as enum: enum.add_item("the first item") enum.add_item("the second item") enum.add_item(NoEscape("the third etc \\ldots")) # create a labelled "description" list like the below: # \begin{description} # \item[First] The first item # \item[Second] The second item # \item[Third] The third etc \ldots # \end{description} with doc.create(Section('"Description" list')): with doc.create(Description()) as desc: desc.add_item("First", "The first item") desc.add_item("Second", "The second item") desc.add_item("Third", NoEscape("The third etc \\ldots")) doc.generate_pdf('lists', clean_tex=False)
def add_list(self, lists, type=1): """ 添加列表 :param list lists: 列表名称 :param int type: 列表类型 :return: 无返回值 """ if type == 1: items = Itemize() elif type == 2: items = Enumerate() elif type == 3: items = Description() else: items = Itemize() for item in lists: items.add_item(item) self.doc.append(items)
def add_meals(doc: Document, camp: Camp): doc.packages.append(Package('xcolor')) doc.packages.append(Package('tabularx')) doc.packages.append(Package('colortbl')) doc.packages.append(Package('enumitem')) doc.packages.append(Package('float')) doc.packages.append(Package('subcaption')) doc.packages.append( Package('caption', options=[ NoEscape(r'textfont={large, bf}'), 'labelformat=empty', 'justification=raggedright' ])) # for each meal for meal in camp.get_meals_for_meal_page(): add_header(doc, meal) # general Infos with doc.create(Description()) as enum: if meal['meal_gets_prepared']: enum.add_item( 'Vorbereiten:', 'am ' + meal['meal_prepare_date'].strftime("%A %d. %b %Y")) if meal['meal_description'] != '': enum.add_item('Beschreibung / Notizen:', meal['meal_description']) # add recipes if 'recipe' in meal: for recipe in meal['recipe']: add_recipe(doc, recipe) else: doc.append('Diese Mahlzeit enthält keine Rezepte.') doc.append(Command(r'clearpage')) doc.append(Command(r'pagebreak'))
def add_message_to_doc(doc, message): att_queryset = message.foiattachment_set.filter( is_redacted=False, is_converted=False ) with doc.create(Description()) as descr: descr.add_item(str(_('From:')), message.real_sender) descr.add_item(str(_('To:')), message.get_text_recipient()) descr.add_item(str(_('Date:')), formats.date_format(message.timestamp, "DATETIME_FORMAT")) descr.add_item(str(_('Via:')), message.get_kind_display()) descr.add_item(str(_('URL:')), message.get_accessible_link()) descr.add_item(str(_('Subject:')), message.subject) if len(att_queryset): itemize = Itemize() for att in att_queryset: itemize.add_item(att.name) descr.add_item(str(_('Attachments:')), itemize) doc.append(NoEscape('\\noindent\\makebox[\\linewidth]{\\rule{\\textwidth}{1pt}}')) doc.append(LineBreak()) append_text(doc, message.plaintext)
a = Axis(data=None, options=None) p = Plot(name=None, func=None, coordinates=None, options=None) # Utils escape_latex(s='') fix_filename(path='') dumps_list(l=[], escape=False, token='\n') bold(s='') italic(s='') verbatim(s='', delimiter='|') # Lists itemize = Itemize() itemize.add_item(s="item") itemize.append("append") enum = Enumerate() enum.add_item(s="item") enum.append("append") desc = Description() desc.add_item(label="label", s="item") desc.append("append")
def create_pdf(self): # R1 # ---------------------------------------------------------------------------------- # 2) Put summary.txt and fastqc_data.txt files into dataframes then dictionaries # i) Trimmed data summary_df_trim = pd.read_table('%sR1_001.qfilter_fastqc/summary.txt' % self.sample, header=None, names=['Score', 'Parameter'], usecols=[0, 1]) score_list_trim = summary_df_trim['Score'].tolist( ) # not currently used, may be needed parameter_list_trim = summary_df_trim['Parameter'].tolist() sum_dict_trim = dict(zip(parameter_list_trim, score_list_trim)) # ii) Original non-trimmed data summary_df = pd.read_table('%sR1_001_fastqc/summary.txt' % self.sample, header=None, names=['Score', 'Parameter'], usecols=[0, 1]) score_list = summary_df_trim['Score'].tolist( ) # not currently used, may be needed parameter_list = summary_df_trim['Parameter'].tolist() sum_dict = dict(zip(parameter_list, score_list)) # basic stats files # Trimmed data basic_stats_df_trim = pd.read_table( '%sR1_001.qfilter_fastqc/fastqc_data.txt' % self.sample, header=None, names=['Property', 'Value'], usecols=[0, 1], skiprows=3, nrows=7) property_list_trim = basic_stats_df_trim['Property'].tolist() value_list_trim = basic_stats_df_trim['Value'].tolist() stats_dict_trim = dict(zip(property_list_trim, value_list_trim)) # Original, non-trimmed data basic_stats_df = pd.read_table('%sR1_001_fastqc/fastqc_data.txt' % self.sample, header=None, names=['Property', 'Value'], usecols=[0, 1], skiprows=3, nrows=7) property_list = basic_stats_df['Property'].tolist() value_list = basic_stats_df['Value'].tolist() stats_dict = dict(zip(property_list, value_list)) # 3) Create PDF with basic statistics, summary data and png images doc = Document() doc.packages.append( Package( 'geometry', options=['tmargin=0.75in', 'lmargin=0.5in', 'rmargin=0.5in'])) doc.packages.append(Package('subcaption')) doc.packages.append(Package('xcolor')) doc.append(Command('makeatletter')) doc.append(Command('setlength', NoEscape(r'\@fptop}{0pt'))) doc.append(Command('makeatother')) doc.append(Command(NoEscape(r'renewcommand{\baselinestretch}'), '1.0')) doc.append(Command('begin', 'center')) doc.append(Command('Large', bold('Sample Quality Results'))) doc.append(Command('end', 'center')) with doc.create(Section('Basic Statistics')): with doc.create(Description()) as desc: desc.add_item("Filename:", "%s" % stats_dict.get('Filename')) desc.add_item("File type:", "%s" % stats_dict.get('File type')) desc.add_item("Encoding:", "%s" % stats_dict.get('Encoding')) with doc.create(Tabular(NoEscape(r'p{5.5cm}|c|c'))) as table: table.add_row(('', 'Before trimming', 'After trimming')) table.add_hline() table.add_row(('Total Sequences', '%s' % stats_dict.get('Total Sequences'), '%s' % stats_dict_trim.get('Total Sequences'))) table.add_row( ('Sequences flagged as poor quality', '%s' % stats_dict.get('Sequences flagged as poor quality'), '%s' % stats_dict_trim.get('Sequences flagged as poor quality'))) table.add_row(('Sequence length', '%s' % stats_dict.get('Sequence length'), '%s' % stats_dict_trim.get('Sequence length'))) table.add_row(('%GC', '%s' % stats_dict.get('%GC'), '%s' % stats_dict_trim.get('%GC'))) with doc.create(Section('FastQC')): with doc.create( Figure(position='htbp', placement=NoEscape(r'\centering'))): doc.append(Command('centering')) with doc.create(SubFigure()) as plot: plot.add_image('%s_fastqc/Images/per_base_quality.png' % self.sample) plot.add_caption( 'Per base sequence quality BEFORE trimming') with doc.create(SubFigure()) as plot: if sum_dict_trim.get( 'Per base sequence quality') == 'PASS': colour = 'green' elif sum_dict_trim.get( 'Per base sequence quality') == 'WARN': colour = 'orange' elif sum_dict_trim.get( 'Per base sequence quality') == 'FAIL': colour = 'red' else: colour = 'black' plot.add_image( '%s.qfilter_fastqc/Images/per_base_quality.png' % self.sample) plot.add_caption( NoEscape( r'Per base sequence quality AFTER trimming \textcolor{%s}{%s}' % (colour, sum_dict_trim.get('Per base sequence quality')))) with doc.create(SubFigure()) as plot: doc.append(Command('vspace', '5 mm')) plot.add_image( '%s_fastqc/Images/per_sequence_gc_content.png' % self.sample) plot.add_caption('Per sequence GC content BEFORE trimming') with doc.create(SubFigure()) as plot: doc.append(Command('vspace', '5 mm')) if sum_dict_trim.get('Per sequence GC content') == 'PASS': colour = 'green' elif sum_dict_trim.get( 'Per sequence GC content') == 'WARN': colour = 'orange' elif sum_dict_trim.get( 'Per sequence GC content') == 'FAIL': colour = 'red' else: colour = 'black' plot.add_image( '%s.qfilter_fastqc/Images/per_sequence_gc_content.png' % self.sample) plot.add_caption( NoEscape( r'Per sequence GC content AFTER trimming \textcolor{%s}{%s}' % (colour, sum_dict_trim.get('Per sequence GC content')))) with doc.create( Figure(position='htbp', placement=NoEscape(r'\centering'))): doc.append(Command('ContinuedFloat')) doc.append(Command('centering')) with doc.create(SubFigure()) as plot: plot.add_image( '%s_fastqc/Images/sequence_length_distribution.png' % self.sample) plot.add_caption( 'Sequence Length Distribution BEFORE trimming') with doc.create(SubFigure()) as plot: doc.append(Command('hspace', '10 mm')) if sum_dict_trim.get( 'Sequence Length Distribution') == 'PASS': colour = 'green' elif sum_dict_trim.get( 'Sequence Length Distribution') == 'WARN': colour = 'orange' elif sum_dict_trim.get( 'Sequence Length Distribution') == 'FAIL': colour = 'red' else: colour = 'black' plot.add_image( '%s.qfilter_fastqc/Images/sequence_length_distribution.png' % self.sample) plot.add_caption( NoEscape( r'Sequence Length Distribution AFTER trimming \textcolor{%s}{%s}' % (colour, sum_dict_trim.get('Sequence Length Distribution')) )) with doc.create(SubFigure()) as plot: doc.append(Command('vspace', '10 mm')) plot.add_image('%s_fastqc/Images/adapter_content.png' % self.sample) plot.add_caption('Adapter content BEFORE trimming') with doc.create(SubFigure()) as plot: doc.append(Command('vspace', '10 mm')) doc.append(Command('hspace', '10 mm')) if sum_dict_trim.get('Adapter Content') == 'PASS': colour = 'green' elif sum_dict_trim.get('Adapter Content') == 'WARN': colour = 'orange' elif sum_dict_trim.get('Adapter Content') == 'FAIL': colour = 'red' else: colour = 'black' plot.add_image( '%s.qfilter_fastqc/Images/adapter_content.png' % self.sample) plot.add_caption( NoEscape( r'Adapter content AFTER trimming \textcolor{%s}{%s}' % (colour, sum_dict_trim.get('Adapter Content')))) with doc.create(Section('BamStats')): with doc.create( Figure(position='htbp', placement=NoEscape(r'\centering'))): doc.append(Command('centering')) with doc.create(SubFigure()) as plot: plot.add_image('%s.bwa.drm.sorted.bam.stats-quals-hm.png' % self.sample) plot.add_caption('Base quality per cycle') with doc.create(SubFigure()) as plot: doc.append(Command('hspace', '10 mm')) plot.add_image( '%s.bwa.drm.sorted.bam.stats-insert-size.png' % self.sample) plot.add_caption('Fragment size') with doc.create(SubFigure()) as plot: doc.append(Command('vspace', '10 mm')) plot.add_image('%s.bwa.drm.sorted.bam.stats-quals2.png' % self.sample) plot.add_caption('Quality per cycle') pdflatex = '/usr/local/texlive/2015/bin/x86_64-linux/pdflatex' doc.generate_pdf('%s_Sample_Quality' % self.sample, clean_tex=False, compiler=pdflatex)
def create_pdf(self): """Creates the PDF using the PyLatex module. Notes:- """ r1_summary_trim_dict, r1_stats_trim_dict, r2_summary_trim_dict = self.get_trimmed_data( ) r1_stats_dict = self.get_original_data() doc = Document() doc.packages.append(Package('geometry', options=['margin=0.75in'])) doc.packages.append(Package('subcaption')) doc.packages.append(Package('xcolor')) doc.packages.append(Package('placeins')) doc.append(Command('makeatletter')) doc.append(Command('setlength', NoEscape(r'\@fptop}{0pt'))) doc.append(Command('makeatother')) doc.append(Command(NoEscape(r'renewcommand{\baselinestretch}'), '1.0')) doc.append(Command('begin', 'center')) doc.append(Command('Large', bold('Sample Quality Results'))) doc.append(Command('end', 'center')) with doc.create(Section('Basic Statistics')): with doc.create(Description()) as desc: desc.add_item("Sample:", "%s" % r1_stats_dict.get('Filename')[:-16]) desc.add_item("File type:", "%s" % r1_stats_dict.get('File type')) desc.add_item("Encoding:", "%s" % r1_stats_dict.get('Encoding')) with doc.create(Tabular(NoEscape(r'p{5.5cm}|c|c'))) as table: table.add_row(('', 'Before trimming', 'After trimming')) table.add_hline() table.add_row( ('Total Sequences', '%s' % r1_stats_dict.get('Total Sequences'), '%s' % r1_stats_trim_dict.get('Total Sequences'))) table.add_row(( 'Sequences flagged as poor quality', '%s' % r1_stats_dict.get('Sequences flagged as poor quality'), '%s' % r1_stats_trim_dict.get('Sequences flagged as poor quality') )) table.add_row( ('Sequence length', '%s' % r1_stats_dict.get('Sequence length'), '%s' % r1_stats_trim_dict.get('Sequence length'))) table.add_row(('%GC', '%s' % r1_stats_dict.get('%GC'), '%s' % r1_stats_trim_dict.get('%GC'))) with doc.create(Section('FastQC')): with doc.create( Figure(position='!htb', placement=NoEscape(r'\centering'))) as fig: fig.add_caption('Per base sequence quality') doc.append(Command('centering')) with doc.create(SubFigure()) as plot: plot.add_image( '%sR1_001_fastqc/Images/per_base_quality.png' % self.sample) plot.add_caption('R1 BEFORE trimming') with doc.create(SubFigure()) as plot: if r1_summary_trim_dict.get( 'Per base sequence quality') == 'PASS': colour = 'green' elif r1_summary_trim_dict.get( 'Per base sequence quality') == 'WARN': colour = 'orange' elif r1_summary_trim_dict.get( 'Per base sequence quality') == 'FAIL': colour = 'red' else: colour = 'black' plot.add_image( '%sR1_001.qfilter_fastqc/Images/per_base_quality.png' % self.sample) plot.add_caption( NoEscape(r'R1 AFTER trimming \textcolor{%s}{%s}' % (colour, r1_summary_trim_dict.get( 'Per base sequence quality')))) with doc.create(SubFigure()) as plot: plot.add_image( '%sR2_001_fastqc/Images/per_base_quality.png' % self.sample) plot.add_caption('R2 BEFORE trimming') with doc.create(SubFigure()) as plot: if r2_summary_trim_dict.get( 'Per base sequence quality') == 'PASS': colour = 'green' elif r2_summary_trim_dict.get( 'Per base sequence quality') == 'WARN': colour = 'orange' elif r2_summary_trim_dict.get( 'Per base sequence quality') == 'FAIL': colour = 'red' else: colour = 'black' plot.add_image( '%sR2_001.qfilter_fastqc/Images/per_base_quality.png' % self.sample) plot.add_caption( NoEscape(r'R2 AFTER trimming \textcolor{%s}{%s}' % (colour, r2_summary_trim_dict.get( 'Per base sequence quality')))) with doc.create( Figure(position='!htb', placement=NoEscape(r'\centering'))) as fig: fig.add_caption('Per sequence GC content') doc.append(Command('centering')) with doc.create(SubFigure()) as plot: doc.append(Command('vspace', '5 mm')) plot.add_image( '%sR1_001_fastqc/Images/per_sequence_gc_content.png' % self.sample) plot.add_caption('R1 BEFORE trimming') with doc.create(SubFigure()) as plot: doc.append(Command('vspace', '5 mm')) if r1_summary_trim_dict.get( 'Per sequence GC content') == 'PASS': colour = 'green' elif r1_summary_trim_dict.get( 'Per sequence GC content') == 'WARN': colour = 'orange' elif r1_summary_trim_dict.get( 'Per sequence GC content') == 'FAIL': colour = 'red' else: colour = 'black' plot.add_image( '%sR1_001.qfilter_fastqc/Images/per_sequence_gc_content.png' % self.sample) plot.add_caption( NoEscape(r'R1 AFTER trimming \textcolor{%s}{%s}' % (colour, r1_summary_trim_dict.get( 'Per sequence GC content')))) with doc.create(SubFigure()) as plot: doc.append(Command('vspace', '5 mm')) plot.add_image( '%sR2_001_fastqc/Images/per_sequence_gc_content.png' % self.sample) plot.add_caption('R2 BEFORE trimming') with doc.create(SubFigure()) as plot: doc.append(Command('vspace', '5 mm')) if r2_summary_trim_dict.get( 'Per sequence GC content') == 'PASS': colour = 'green' elif r2_summary_trim_dict.get( 'Per sequence GC content') == 'WARN': colour = 'orange' elif r2_summary_trim_dict.get( 'Per sequence GC content') == 'FAIL': colour = 'red' else: colour = 'black' plot.add_image( '%sR2_001.qfilter_fastqc/Images/per_sequence_gc_content.png' % self.sample) plot.add_caption( NoEscape(r'R2 AFTER trimming \textcolor{%s}{%s}' % (colour, r2_summary_trim_dict.get( 'Per sequence GC content')))) with doc.create( Figure(position='!htb', placement=NoEscape(r'\centering'))) as fig: fig.add_caption('Sequence Length Distribution') doc.append(Command('centering')) with doc.create(SubFigure()) as plot: plot.add_image( '%sR1_001_fastqc/Images/sequence_length_distribution.png' % self.sample) plot.add_caption('R1 BEFORE trimming') with doc.create(SubFigure()) as plot: if r1_summary_trim_dict.get( 'Sequence Length Distribution') == 'PASS': colour = 'green' elif r1_summary_trim_dict.get( 'Sequence Length Distribution') == 'WARN': colour = 'orange' elif r1_summary_trim_dict.get( 'Sequence Length Distribution') == 'FAIL': colour = 'red' else: colour = 'black' plot.add_image( '%sR1_001.qfilter_fastqc/Images/sequence_length_distribution.png' % self.sample) plot.add_caption( NoEscape(r'R1 AFTER trimming \textcolor{%s}{%s}' % (colour, r1_summary_trim_dict.get( 'Sequence Length Distribution')))) with doc.create(SubFigure()) as plot: plot.add_image( '%sR2_001_fastqc/Images/sequence_length_distribution.png' % self.sample) plot.add_caption('R2 BEFORE trimming') with doc.create(SubFigure()) as plot: if r2_summary_trim_dict.get( 'Sequence Length Distribution') == 'PASS': colour = 'green' elif r2_summary_trim_dict.get( 'Sequence Length Distribution') == 'WARN': colour = 'orange' elif r2_summary_trim_dict.get( 'Sequence Length Distribution') == 'FAIL': colour = 'red' else: colour = 'black' plot.add_image( '%sR2_001.qfilter_fastqc/Images/sequence_length_distribution.png' % self.sample) plot.add_caption( NoEscape(r'R2 AFTER trimming \textcolor{%s}{%s}' % (colour, r2_summary_trim_dict.get( 'Sequence Length Distribution')))) with doc.create( Figure(position='!htb', placement=NoEscape(r'\centering'))) as fig: fig.add_caption('Adapter Content') doc.append(Command('centering')) with doc.create(SubFigure()) as plot: plot.add_image( '%sR1_001_fastqc/Images/adapter_content.png' % self.sample) plot.add_caption('R1 BEFORE trimming') with doc.create(SubFigure()) as plot: if r1_summary_trim_dict.get('Adapter Content') == 'PASS': colour = 'green' elif r1_summary_trim_dict.get('Adapter Content') == 'WARN': colour = 'orange' elif r1_summary_trim_dict.get('Adapter Content') == 'FAIL': colour = 'red' else: colour = 'black' plot.add_image( '%sR1_001.qfilter_fastqc/Images/adapter_content.png' % self.sample) plot.add_caption( NoEscape( r'R1 AFTER trimming \textcolor{%s}{%s}' % (colour, r1_summary_trim_dict.get('Adapter Content')))) with doc.create(SubFigure()) as plot: plot.add_image( '%sR2_001_fastqc/Images/adapter_content.png' % self.sample) plot.add_caption('R2 BEFORE trimming') with doc.create(SubFigure()) as plot: if r2_summary_trim_dict.get('Adapter Content') == 'PASS': colour = 'green' elif r2_summary_trim_dict.get('Adapter Content') == 'WARN': colour = 'orange' elif r2_summary_trim_dict.get('Adapter Content') == 'FAIL': colour = 'red' else: colour = 'black' plot.add_image( '%sR2_001.qfilter_fastqc/Images/adapter_content.png' % self.sample) plot.add_caption( NoEscape( r'R2 AFTER trimming \textcolor{%s}{%s}' % (colour, r2_summary_trim_dict.get('Adapter Content')))) ''' doc.append(Command('FloatBarrier')) with doc.create(Section('BamStats')): with doc.create(Figure(position='htbp', placement=NoEscape(r'\centering'))): doc.append(Command('centering')) with doc.create(SubFigure()) as plot: plot.add_image('%s.bwa.drm.sorted.bam.stats-quals-hm.png' % self.sample) plot.add_caption('Base quality per cycle') with doc.create(SubFigure()) as plot: doc.append(Command('hspace', '10 mm')) plot.add_image('%s.bwa.drm.sorted.bam.stats-insert-size.png' % self.sample) plot.add_caption('Fragment size') with doc.create(SubFigure()) as plot: doc.append(Command('vspace', '10 mm')) plot.add_image('%s.bwa.drm.sorted.bam.stats-quals2.png' % self.sample) plot.add_caption('Quality per cycle') ''' pdflatex = '/usr/local/texlive/2015/bin/x86_64-linux/pdflatex' doc.generate_pdf('%s' % self.sample, clean_tex=False, compiler=pdflatex) os.system( 'mv /home/cuser/PycharmProjects/amlpipeline/%s.pdf /media/sf_sarah_share/160620_M01622_0286_000000000-AR4UH/QC/' % self.sample)
def export_endpaper(self): options = ['itemsep=1pt', 'parsep=1pt'] book = Description(options=options) book.add_item('제목', self.title) book.add_item('저자', self.author) book.add_item('편집', '미루') book.add_item('디자인', '써드엔지니어링카르텔') book.add_item('출간일', '2018-06-01') publisher = Description(options=options) publisher.add_item('출판', '금치산자레시피') publisher.add_item('웹사이트', 'http://gtszrcp.com') cover = Description(options=options) cover.add_item('표지', NoEscape(self.cover.export_citation())) cover.add_item('표지 그림 저작권', self.cover.license) license = Description(options=options) license.add_item('저작권', NoEscape('이 책에 수록된 저작물 중 별도로 표기되지 않은 모든 저작물의 저작권은 저자에게 있습니다. %s에 의해 이용할 수 있습니다.'%italic(self.license))) license.add_item('', '이 책은 BartlebyMachine으로 제작되었습니다.') endpaper = map(lambda x: x.dumps().replace('\\', '\\\\'), [ book, publisher, cover, license ]) return '\n'.join(list(endpaper))
# you can append to existing items itemize.append(Command("ldots")) # create a numbered "enumerate" list like the below: # \begin{enumerate} # \item The first item # \item The second item # \item The third etc \ldots # \end{enumerate} with doc.create(Section('"Enumerate" list')): with doc.create(Enumerate()) as enum: enum.add_item("the first item") enum.add_item("the second item") enum.add_item(NoEscape("the third etc \\ldots")) # create a labelled "description" list like the below: # \begin{description} # \item[First] The first item # \item[Second] The second item # \item[Third] The third etc \ldots # \end{description} with doc.create(Section('"Description" list')): with doc.create(Description()) as desc: desc.add_item("First", "The first item") desc.add_item("Second", "The second item") desc.add_item("Third", NoEscape("The third etc \\ldots")) doc.generate_pdf('lists')
def create_pdf_indi(self, test_spec_dict, test_description, path, name): array_dimension = self.metrics_dict['con_matrix'].shape row_dimensions = array_dimension[0] array = self.metrics_dict['TpFpFnTn'][0] code = self.metrics_dict['class_code'][0] doc = Document("metrics") with doc.create(Section('Test description')): doc.append(test_description) with doc.create(Description()) as desc: for key, value in test_spec_dict.iteritems(): desc.add_item(key, value) section = Section('Metrics overview') test4 = Subsection('Confusion Matrix') crop_array = np.array([ 'Spring Barly(1)', 'Winter Barley(10)', 'Winter Wheat(11)', 'Winter Rape(22)', 'Maize(216)' ]) # Create TN, TP, FP, FN table table4 = Tabular('cccccc') table4.add_hline() table4.add_row(('', 'Spring Barly', 'Winter Barley', 'Winter Wheat', 'Winter Rape', 'Maize')) table4.add_hline() for x in range(0, row_dimensions): table4.add_row([ crop_array[x], self.metrics_dict['con_matrix'][x][0], self.metrics_dict['con_matrix'][x][1], self.metrics_dict['con_matrix'][x][2], self.metrics_dict['con_matrix'][x][3], self.metrics_dict['con_matrix'][x][4] ]) table4.add_hline() test4.append(table4) test1 = Subsection('Rate matrix') # Create TN, TP, FP, FN table table1 = Tabular('cccccc') table1.add_hline() table1.add_row(("Class", 'True-Positive', 'False-Positive', 'False-Negative', 'True-Negative', 'Accuracy')) table1.add_hline() for x in range(0, row_dimensions): table1.add_row([ self.metrics_dict['class_code'][x], self.metrics_dict['TpFpFnTn'][x][0], self.metrics_dict['TpFpFnTn'][x][1], self.metrics_dict['TpFpFnTn'][x][2], self.metrics_dict['TpFpFnTn'][x][3], self.metrics_dict['Acc_Indi'][x] ]) table1.add_hline() test1.append(table1) test3 = Subsection('Class metrics') table3 = Tabular('ccccc') table3.add_hline() table3.add_row(("Class", 'True-Positive Rate (TPR)', 'Precision', 'True-Negative Rate (TNR)', 'F1-Score')) table3.add_hline() for x in range(0, row_dimensions): table3.add_row([ self.metrics_dict['class_code'][x], self.metrics_dict['recall_all'][x], self.metrics_dict['precision_all'][x], self.metrics_dict['TNR'][x], self.metrics_dict['f1_score_all'][x] ]) table3.add_hline() test3.append(table3) test2 = Subsection('Other') table2 = Tabular('cc') table2.add_hline() table2.add_row(("Class", "Value")) table2.add_hline() table2.add_row( ["F1 Micro (Globally)", self.metrics_dict['f1_score_micro']]) table2.add_row( ["F1 Macro (Each label)", self.metrics_dict['f1_score_macro']]) table2.add_row([ "F1 Weighted (Each label)", self.metrics_dict['f1_score_weighted'] ]) table2.add_hline() table2.add_row( ["Recall Micro (Globally)", self.metrics_dict['recall_micro']]) table2.add_row( ["Recall Macro (Each label)", self.metrics_dict['recall_macro']]) table2.add_row([ "Recall Weighted (Each label)", self.metrics_dict['recall_weighted'] ]) table2.add_hline() table2.add_row([ "Precision Micro (Globally)", self.metrics_dict['precision_micro'] ]) table2.add_row([ "Precision Macro (Each label)", self.metrics_dict['precision_macro'] ]) table2.add_row([ "Precision Weighted (Each label)", self.metrics_dict['precision_weighted'] ]) table2.add_hline() table2.add_row(["Kappa", self.metrics_dict['kappa_all']]) table2.add_row( ["Kappa (Linear weighted)", self.metrics_dict['kappa_linear']]) table2.add_row([ "Kappa (Quadratic weighted)", self.metrics_dict['kappa_quadratic'] ]) table2.add_hline() table2.add_row([ "Accuracy (Correct classified)", self.metrics_dict['accuracy_all'] ]) table2.add_row([ "Accuracy (Normalized)", self.metrics_dict['accuracy_normalized'] ]) table2.add_hline() table2.add_row(["Jaccard (Sum)", self.metrics_dict['jaccard_all']]) table2.add_row( ["Jaccard (Average)", self.metrics_dict['jaccard_normalized']]) table2.add_hline() table2.add_row([ "Zero-one classification loss (Misclassifications)", self.metrics_dict['zero_one_all'] ]) table2.add_row([ "Zero-one classification loss (Fraction of misclassifications)", self.metrics_dict['zero_one_normalize'] ]) table2.add_hline() table2.add_row(["Hamming loss", self.metrics_dict['hamming_loss']]) test2.append(table2) section.append(test4) section.append(test1) section.append(test3) section.append(test2) doc.append(section) try: doc.generate_pdf(name + '_' + 'Metrics', compiler='pdflatex') except Exception: print "" shutil.move(name + '_' + 'Metrics' + '.pdf', path) try: os.remove(name + '_' + 'Metrics' + '.tex') except OSError: pass try: os.remove(name + '_' + 'Metrics' + '.log') except OSError: pass try: os.remove(name + '_' + 'Metrics' + '.aux') except OSError: pass return