def test_graphics(): f = Figure(data=None, position=None) f.add_image(filename='', width=r'0.8\textwidth', placement=r'\centering') f.add_caption(caption='') repr(f) # Subfigure s = SubFigure(data=None, position=None, width=r'0.45\linewidth') s.add_image(filename='', width='r\linewidth', placement=None) s.add_caption(caption='') repr(s) # Matplotlib plot = Figure(data=None, position=None) x = [0, 1, 2, 3, 4, 5, 6] y = [15, 2, 7, 1, 5, 6, 9] pyplot.plot(x, y) plot.add_plot(width=r'0.8\textwidth', placement=r'\centering') plot.add_caption(caption='I am a caption.') repr(plot)
def test_graphics(): f = Figure(data=None, position=None) f.add_image(filename="", width=r"0.8\textwidth", placement=r"\centering") f.add_caption(caption="") # Subfigure s = SubFigure(data=None, position=None, width=r"0.45\linewidth", seperate_paragraph=False) s.add_image(filename="", width="r\linewidth", placement=None) s.add_caption(caption="") # Matplotlib plot = MatplotlibFigure(data=None, position=None) x = [0, 1, 2, 3, 4, 5, 6] y = [15, 2, 7, 1, 5, 6, 9] pyplot.plot(x, y) plot.add_plot(width=r"0.8\textwidth", placement=r"\centering") plot.add_caption(caption="I am a caption.") # Quantities Quantity(quantity=1 * pq.kg) Quantity(quantity=1 * pq.kg, format_cb=lambda x: str(int(x)))
def writeQuestion(doc, question, result, figpie, figbar): doc.append(TextColor("blue",question)) width_pie = NoEscape(r"{}\textwidth".format(settings.scale_pie)) width_bar = NoEscape(r"{}\textwidth".format(settings.scale_bar)) with doc.create(Figure(position="H")) as main_fig: with doc.create(SubFigure(position='b')) as left_fig: left_fig.add_image(settings.fig_path + figbar, width = width_bar, placement=NoEscape("\centering")) left_fig.add_caption("") #doc.append(HFill()) with doc.create(SubFigure(position='b')) as right_fig: right_fig.add_image(settings.fig_path + figpie, width = width_pie, placement=NoEscape("\centering")) right_fig.add_caption("") main_fig.add_caption("")
def _add_kernel_structure_subsection( self, doc: Document, width: str, title: str = 'Kernel Structure Evolution', *args, **kwargs) -> None: """Add kernel structure sub-section to document. :param doc: :param width: :param title: :param args: :param kwargs: :return: """ with doc.create(Subsection(title)): doc.append('A summary of the structure of gp_models searched.') with doc.create(Figure(position='h!')) as plot: with doc.create( SubFigure(position='t', width=NoEscape(r'0.45\linewidth'))) as left: plot_distribution(self.experiment.median_n_hyperparameters, self.experiment.std_n_hyperparameters, self.experiment.best_n_hyperparameters, value_name='median', metric_name='# Hyperparameters') left.add_plot(width=NoEscape(width), *args, **kwargs) left.add_caption( 'A plot of the number of hyperparameters for each iteration of the best model, \ the median number of hyperparameters, and the standard deviation.' ) plot.append(HorizontalSpace("10pt")) with doc.create( SubFigure(position='t', width=NoEscape(r'0.45\linewidth'))) as right: plot_distribution(self.experiment.median_n_operands, self.experiment.std_n_operands, self.experiment.best_n_operands, value_name='median', metric_name='# Operands') right.add_plot(width=NoEscape(width), *args, **kwargs) right.add_caption( 'A plot of the number of operands (number of 1-D gp_models) over time including \ the best model, the median number of operands, and the standard deviation.' ) plot.add_caption( 'These two figures show how the structure of the compositional gp_models changed over \ time. The left figure shows the hyperparameter distribution and the right one shows operand \ distribution.')
def add_sub_figure(doc, graphics_dir, image_names=[], captioning="Metrics"): """ Helper function to create multiple sub figures Arguments: doc: document to add figure graphics_dir: directory containing .png image image_names: the list of image names without extension captioning: global captioning for the figure """ num_figures = len(image_names) scale = 1.0 / num_figures sub_width = str(scale) + r"\linewidth" with doc.create(Figure(position="h!")) as fig: for image in image_names: image_filename = os.path.join(os.path.dirname(__file__), graphics_dir, image + ".png") with doc.create(SubFigure(position="b", width=NoEscape(sub_width))) as sub_fig: sub_fig.add_image(image_filename, width=NoEscape(r"\linewidth")) sub_fig.add_caption(image) fig.add_caption(captioning)
def _add_population_subsection(self, doc: Document, width: str, title: str = 'Population Evolution', *args, **kwargs) -> None: """Add population sub-section to document. :param doc: :param width: :param title: :param args: :param kwargs: :return: """ with doc.create(Subsection(title)): doc.append('A summary of the population of gp_models searched.') with doc.create(Figure(position='h!')) as plot: with doc.create( SubFigure(position='t', width=NoEscape(r'0.45\linewidth'))) as left: plot_distribution(self.experiment.mean_cov_dists, self.experiment.std_cov_dists, metric_name='covariance distance') left.add_plot(width=NoEscape(width), *args, **kwargs) left.add_caption( 'This plot shows the mean Euclidean covariance distance over time of all \ pairs of kernel matrices. It represents the heterogeneity of the population.' ) plot.append(HorizontalSpace("10pt")) with doc.create( SubFigure(position='t', width=NoEscape(r'0.45\linewidth'))) as right: plot_distribution(self.experiment.diversity_scores, metric_name='diversity', value_name='population') right.add_plot(width=NoEscape(width), *args, **kwargs) right.add_caption( 'This plot shows the mean Euclidean distance of all pairs of kernel expressions \ in additive form. It represents the diversity/heterogeneity of the population.' ) plot.add_caption( 'Two figures showing the evolution of the population heterogeneity.' )
def test_graphics(): f = Figure(data=None, position=None) f.add_image(filename='', width=r'0.8\textwidth', placement=r'\centering') f.add_caption(caption='') repr(f) # Subfigure s = SubFigure(data=None, position=None, width=r'0.45\linewidth') s.add_image(filename='', width='r\linewidth', placement=None) s.add_caption(caption='') repr(s) # Matplotlib plot = Figure(data=None, position=None) x = [0, 1, 2, 3, 4, 5, 6] y = [15, 2, 7, 1, 5, 6, 9] pyplot.plot(x, y) plot.add_plot(width=r'0.8\textwidth', placement=r'\centering') plot.add_caption(caption='I am a caption.') repr(plot) # StandAloneGraphic stand_alone_graphic = StandAloneGraphic( filename='', image_options=r"width=0.8\textwidth") repr(stand_alone_graphic)
def _append2latexdoc(doc, content): if isinstance(content, list): for item in content: if item.get('title'): doc.append(_get_section(**item)) _append2latexdoc(doc, item['content']) else: _append2latexdoc(doc, item) else: section = _get_last_section(doc) if content.get('text'): if isinstance(content['text'], dict): section.append(open(content['text']['filename']).read()) else: temp = '' if isinstance(content['text'],list): for subtext in content['text']: temp += subtext elif isinstance(content['text'],str): temp = content['text'] else: raise Exception(f'Did not understand format of text string: \n {content["text"]}') section.append(temp) if content.get('latex_code'): if isinstance(content['latex_code'], dict): section.append(NoEscape(open(content['latex_code']['filename']).read())) else: section.append(NoEscape(content['latex_code'])) if content.get('table'): for table in content['table']: section.append(NoEscape('\\begin{table}[H]')) # note require float latex package for H command if table.get('filename'): df = pd.read_excel(table['filename'], **table['kwargs']) elif isinstance(table.get('dataframe'),pd.DataFrame): df = table.get('dataframe') section.append(NoEscape(df.to_latex(longtable=True,multicolumn_format='c'))) section.append(NoEscape('\\end{table}')) if content.get('image'): for image in content.get('image'): section.append(NoEscape('\\begin{figure}[H]')) # note require float latex package for H command Figure.add_image(section, image['filename']) section.append(NoEscape('\\end{figure}')) if content.get('subimage'): figure = Figure(position='H') for i, subimage in enumerate(content['subimage']): subfigure = SubFigure(width=NoEscape( r'{}\linewidth'.format(np.round(1. / subimage.get('nr_horizontal_subimages', 2), 2) - 0.01))) subfigure.add_image(subimage['filename']) if subimage.get('caption', False): subfigure.add_caption(subimage['caption']) if subimage.get('figure_caption', False) and i == 0: figure.add_caption(subimage['figure_caption']) figure.append(subfigure) if (i + 1) % subimage.get('nr_horizontal_subimages', 2) == 0 and i != 0 or subimage.get( 'nr_horizontal_subimages', 2) == 1: section.append(figure) figure = Figure(arguments=NoEscape('\ContinuedFloat'), position='H') section.append(figure) if content.get('packages'): [doc.packages.append(Package(package)) for package in content['packages']]
def _add_model_scores(self, doc: Document, width: str, title: str = 'Model Score Evolution', *args, **kwargs) -> \ None: """Add model scores sub-section to document. :param doc: :param width: :param title: :param args: :param kwargs: :return: """ with doc.create(Subsection(title)): doc.append('A summary of the distribution of model scores.') with doc.create(Figure(position='h!')) as plot: with doc.create( SubFigure(position='t', width=NoEscape(r'0.45\linewidth'))) as left: plot_best_so_far(self.experiment.best_scores) left.add_plot(width=NoEscape(width), *args, **kwargs) left.add_caption( 'A plot of the maximum score over each iteration.') plot.append(HorizontalSpace("10pt")) with doc.create( SubFigure(position='t', width=NoEscape(r'0.45\linewidth'))) as right: plot_distribution(self.experiment.mean_scores, self.experiment.std_scores, self.experiment.best_scores) right.add_plot(width=NoEscape(width), *args, **kwargs) right.add_caption( 'A distribution of the maximum model score, the mean model score, and standard \ deviation of models scores per iteration.') plot.add_caption( 'These two figures show the model scores. The left shows a best-so-far curve and the \ right one shows a distribution of scores.')
def test_graphics(): f = Figure(data=None, position=None) f.add_image(filename='', width=r'0.8\textwidth', placement=r'\centering') f.add_caption(caption='') # Subfigure s = SubFigure(data=None, position=None, width=r'0.45\linewidth', seperate_paragraph=False) s.add_image(filename='', width='r\linewidth', placement=None) s.add_caption(caption='') # Matplotlib plot = MatplotlibFigure(data=None, position=None) x = [0, 1, 2, 3, 4, 5, 6] y = [15, 2, 7, 1, 5, 6, 9] pyplot.plot(x, y) plot.add_plot(width=r'0.8\textwidth', placement=r'\centering') plot.add_caption(caption='I am a caption.') # Quantities Quantity(quantity=1 * pq.kg) Quantity(quantity=1 * pq.kg, format_cb=lambda x: str(int(x)))
def importLinedFigures(doc, listImages): num = 0 for artLine in breakUp(listImages, defaults.get('lineWidth')): num += 1 with doc.create(Figure(position='H')) as line: for eachArt in artLine: with doc.create( SubFigure(position='b', width=NoEscape(r'0.2\linewidth'))) as image: name = f'{defaults.get("thumbNailDirectory")}{eachArt["path"]}/{eachArt["name"]}' print(name) image.add_image(name, width=NoEscape(r'\linewidth')) image.add_caption(f'{eachArt["name"][0:5]}') if num % 5 == 0: doc.append(NoEscape(r'\clearpage'))
def test_graphics(): f = Figure(data=None, position=None) f.add_image(filename="", width=r"0.8\textwidth", placement=r"\centering") f.add_caption(caption="") # Subfigure s = SubFigure(data=None, position=None, width=r"0.45\linewidth", separate_paragraph=False) s.add_image(filename="", width="r\linewidth", placement=None) s.add_caption(caption="") # Matplotlib plot = Figure(data=None, position=None) x = [0, 1, 2, 3, 4, 5, 6] y = [15, 2, 7, 1, 5, 6, 9] pyplot.plot(x, y) plot.add_plot(width=r"0.8\textwidth", placement=r"\centering") plot.add_caption(caption="I am a caption.")
# Command c = Command(command='documentclass', arguments=None, options=None, packages=None) # Figure f = Figure(data=None, position=None) f.add_image(filename='', width=r'0.8\textwidth', placement=r'\centering') f.add_caption(caption='') # Subfigure s = SubFigure(data=None, position=None, width=r'0.45\linewidth', seperate_paragraph=False) s.add_image(filename='', width='r\linewidth', placement=None) s.add_caption(caption='') # Plt plot = Plt(data=None, position=None) x = [0, 1, 2, 3, 4, 5, 6] y = [15, 2, 7, 1, 5, 6, 9] pyplot.plot(x, y) plot.add_plot(plt=pyplot, width=r'0.8\textwidth', placement=r'\centering')
def createImage(self, filename, captionString): fig = SubFigure(position="h") file, typ = filename.split(".") fig.add_image("\"{}\".{}".format(file, typ), width="240px") fig.add_caption(captionString) return fig
def create_report(header, data, metrics): """Function creating Latex report of analysis if selected by user Args: header(string): title for report data(dictionary): output data from calculation of metrics metrics(list): metrics selection from user """ # Importing these libraries here so that these are 'optional' dependencies only required if user # wants to use these functionalities from pylatex import Document, Section, Command, LongTabu, Figure, SubFigure, NoEscape from pylatex.utils import bold challenges = data.keys() geometry_options = { "margin": "1.5in", "headheight": "20pt", "headsep": "10pt", "includeheadfoot": True } doc = Document(header, page_numbers=True, geometry_options=geometry_options) with doc.create(Section('Tables')): fmt = "X[r] X[r]" for i in range(len(metrics)): fmt += " X[r]" with doc.create(LongTabu(fmt, spread="1.5pt")) as data_table: header_row1 = ["Challenge", "Tracker"] for m in metrics: header_row1.append(m) data_table.add_row(header_row1, mapper=[bold]) for c in challenges: data_table.add_hline() row = [c, ' '] for i in range(len(metrics)): row.append(' ') data_table.add_row(row) data_table.add_hline() for t in data[c].keys(): row = [' ', t] if 'Accuracy' in metrics: row.append(data[c][t]['tracker_acc']) if 'Robustness' in metrics: row.append(data[c][t]['tracker_robust']) if 'Precision(Center Location Error)' in metrics: row.append(data[c][t]['tracker_precision']) data_table.add_row(row) if 'Accuracy' and 'Robustness' in metrics: doc.append(Command('newpage')) with doc.create(Section('AR-Plots')): width = 2/(len(challenges)) width_str = str(width) + '\linewidth' with doc.create(Figure(position='h!')) as plots: for c in challenges: with doc.create(SubFigure(width=NoEscape(r'%s'%width_str))) as subfig: image_filename = 'AR_%s.png'%c subfig.add_image(image_filename, width=NoEscape(r'\linewidth')) subfig.add_caption('%s'%c) doc.append(Command('hfill')) plots.add_caption('Accuracy-Robustness') doc.generate_tex()
def manhattan_sec(self, qq_pre_path, qq_pos_path, man_pre_path, man_pos_path, table_results): self.append(NewPage()) with self.create(Section('Manhattan')): with self.create(Subsection('Basic stats')): with self.create(Center()) as centered: with centered.create(Tabular('|c|c|c|')) as table: table.add_hline() table.add_row((bold('Description'), bold('Pre-QC'), bold('Post-QC'))) table.add_hline() table.add_row(('Number of GWAS hits', table_results[0], table_results[1])) table.add_hline() table.add_row( ('Lambda GC', table_results[2], table_results[3])) table.add_hline() # calculate lambda 1000 table.add_row(('Lambda 1000', table_results[4], table_results[5])) table.add_hline() self.append(NewPage()) with self.create(Subsection('Manhattan Plot - pre-QC')): with self.create(Figure(position='h!')) as pre_man_images: self.append(Command('centering')) with self.create( SubFigure(position='c', width=NoEscape( r'1\linewidth'))) as man_pre_images: man_pre_images.add_image( man_pre_path, width=NoEscape(r'1\linewidth')) with self.create(Figure(position='h!')) as pre_man_images: self.append(Command('centering')) with self.create( SubFigure( position='c', width=NoEscape( r'0.85\linewidth'))) as qq_pre_images: qq_pre_images.add_image( qq_pre_path, width=NoEscape(r'0.85\linewidth')) self.append(NewPage()) with self.create(Subsection('Manhattan Plot - post-QC')): with self.create(Figure(position='h!')) as pos_man_images: self.append(Command('centering')) with self.create( SubFigure(position='c', width=NoEscape( r'1\linewidth'))) as man_pos_images: man_pos_images.add_image( man_pos_path, width=NoEscape(r'1\linewidth')) with self.create(Figure(position='h!')) as pos_man_images: self.append(Command('centering')) with self.create( SubFigure( position='c', width=NoEscape( r'0.85\linewidth'))) as qq_pos_images: qq_pos_images.add_image( qq_pos_path, width=NoEscape(r'0.85\linewidth'))
def topdf(self,pdfname=None): if pdfname is None: pdfname = self.pdfname filename = pdfname[:-4] geometry_options = {"margin": "2cm"} doc = Document( default_filepath=filename, geometry_options=geometry_options ) doc.documentclass = Command( 'documentclass', options=['12pt','landscape'], arguments=['article'], ) doc.packages.append(Package('fancyhdr')) for group in self.grouplist: doc.preamble.append(NoEscape(r'\fancypagestyle{{{0}}}{{\fancyhf{{}}\fancyhead[L]{{\textbf{{{1}/{2}}}}}\fancyhead[R]{{{3}}}\fancyfoot[R]{{Page\ \thepage\ of \pageref{{LastPage}}}}}}'.format(group.name.replace('_',''),self.case,self.subcase,group.head))) width = 0.25 #min(int(0.9/nplot*100.)/100.,0.25) nplot_per_line = 4 for group in self.grouplist: doc.append(NoEscape(r'\pagestyle{{{0}}}'.format(group.name.replace('_','')))) all2D = True all1D = True for diag in group.diaglist: all2D = all2D and (diag.diag_type == 'plot2D') all1D = all1D and ((diag.diag_type == 'plotTS') or (diag.diag_type == 'plotAvgP') or\ (diag.diag_type == 'plotInitP')) if all2D: for diag in group.diaglist: header = PageStyle("header") keys = diag.output.keys() nplot = len(keys) nlines = nplot/nplot_per_line for i in range(0,nlines+1): with doc.create(Figure(position='h!')) as fig: for j in range(0,nplot_per_line): if i*nplot_per_line+j < nplot: with doc.create(SubFigure( position='b', width=NoEscape(r'{0}\linewidth'.format(width))) ) as subfig: subfig.add_image(diag.output[keys[i*nplot_per_line+j]],width=NoEscape(r'\linewidth')) if nlines > 0: doc.append(NoEscape(r'\clearpage')) elif all1D: nplot = len(group.diaglist) nlines = nplot/nplot_per_line for i in range(0,nlines+1): with doc.create(Figure(position='h!')) as fig: for j in range(0,nplot_per_line): if i*nplot_per_line+j < nplot: with doc.create(SubFigure( position='b', width=NoEscape(r'{0}\linewidth'.format(width))) ) as subfig: subfig.add_image(group.diaglist[i*nplot_per_line+j].output,width=NoEscape(r'\linewidth')) else: print 'ERROR: mixed case not coded yet' raise ValueError doc.append(NoEscape(r'\clearpage')) doc.generate_pdf(clean_tex=True) os.system('mv {0}.pdf {1}/'.format(filename,self.pdf_dir))
def report(model=False, examples=False, tr_pr=False, lo_acc=False, pr_rec=False, score=False, conf_matrix=False, roc_auc=False, auc_pr=False, hist=False, hist2D=False, name=False): import numpy as np import os from pylatex import Document, Section, Subsection, Tabular, Math, TikZ, Axis, FlushLeft, MediumText from pylatex import Plot, Figure, Matrix, Alignat, MultiColumn, Command, SubFigure, NoEscape, HorizontalSpace from pylatex.utils import italic, bold geometry_options = {"tmargin": "1.5cm", "lmargin": "2.5cm"} doc = Document(geometry_options=geometry_options) with doc.create(Section('CLASSIFICATION REPORT', numbering=0)): # CNN architecture if model == True: if os.path.exists('images/model.pdf'): model = 'images/model.pdf' with doc.create( Subsection('Architecture of the Neural Network', numbering=0)): with doc.create(Figure(position='!htb')) as loss_acc: loss_acc.add_image(model, width=NoEscape(r'0.65\textheight')) else: print("Model architecture image not found! Skipping.") # plot some example images if examples == True: if (os.path.exists('images/TP.pdf') and os.path.exists('images/TN.pdf')): example_TP = 'images/TP.pdf' example_TN = 'images/TN.pdf' with doc.create( Subsection('TP/FP/TN/FN Test Set Examples', numbering=0)): doc.append( 'TP - true positives, TN - true negatives, FP - false positives, FN - False negaties' ) with doc.create(Figure(position='!htb')) as imagesRow1: doc.append(Command('centering')) with doc.create( SubFigure( position='c', width=NoEscape( r'0.33\linewidth'))) as left_image: left_image.add_image( example_TP, width=NoEscape(r'0.95\linewidth')) left_image.add_caption("Examples of TP") with doc.create( SubFigure( position='c', width=NoEscape( r'0.33\linewidth'))) as right_image: right_image.add_image( example_TN, width=NoEscape(r'0.95\linewidth')) right_image.add_caption("Examples of TN") if (os.path.exists('images/FP.pdf') and os.path.exists('images/FN.pdf')): example_FP = 'images/FP.pdf' example_FN = 'images/FN.pdf' with doc.create(Figure(position='!htb')) as imagesRow2: doc.append(Command('centering')) with doc.create( SubFigure( position='c', width=NoEscape( r'0.33\linewidth'))) as left_image: left_image.add_image( example_FP, width=NoEscape(r'0.95\linewidth')) left_image.add_caption("Examples of FP") with doc.create( SubFigure( position='c', width=NoEscape( r'0.33\linewidth'))) as right_image: right_image.add_image( example_FN, width=NoEscape(r'0.95\linewidth')) right_image.add_caption("Examples of FN") else: print("Example images not found! Skipping.") # True values VS predicted output values if tr_pr == True: if os.path.exists('images/true_pred.pdf'): true_pred = 'images/true_pred.pdf' with doc.create( Subsection( 'Comparison of True Labes and Output Values for Test Set', numbering=0)): with doc.create(Figure(position='!htb')) as tr_pr: tr_pr.add_image(true_pred, width='200px') else: print( "Image comparing true labes and output values not found! Skipping." ) # True values VS predicted output values if lo_acc == True: if os.path.exists('images/loss_acc.pdf'): lo_acc = 'images/loss_acc.pdf' with doc.create( Subsection('Training and Validation Loss and Accuracy', numbering=0)): with doc.create(Figure(position='!htb')) as loss_acc: loss_acc.add_image(lo_acc, width='260px') else: print("Loss Accuracy plot not found! Skipping.") # Training precision / recall if pr_rec == True: if os.path.exists('images/prec_recall.pdf'): pr_rec = 'images/prec_recall.pdf' with doc.create( Subsection('Test Set Precission and Recall', numbering=0)): doc.append( '''Precision/Recall curve shows the trade-off between returning accurate results (high precision), as well as returning a majority of all positive results (high recall) for different tresholds. It should be used when class imbalance problem occurs. A model with perfect classification skill is depicted as a point at (1,1). Area Under the Curve (AUC) for the perfect classifier will be 1.''') with doc.create(Figure(position='!htb')) as pre_recall: pre_recall.add_image(pr_rec, width='220px') doc.append(HorizontalSpace("2cm")) doc.append(MediumText('AUC = ' + str(auc_pr))) else: print("Precision Recall plot not found! Skipping.") # plot confusion matrix if conf_matrix == True: if os.path.exists('images/conf.pdf'): conf_matrix = 'images/conf.pdf' with doc.create( Subsection('Test Set Confusion Matrix', numbering=0)): with doc.create(Figure(position='!htb')) as conf: conf.add_image(conf_matrix, width='230px') else: print("Confusion matrix not found! Skipping.") # all scoring matrics if score == True: if os.path.exists('images/scoring.npy'): scoring = np.load('images/scoring.npy') acc = scoring[0] precision = scoring[1] recall = scoring[2] f1 = scoring[3] brier = scoring[4] with doc.create( Subsection('Classification Scoring for Test Set', numbering=0)): doc.append( 'TP - true positives, TN - true negatives, FP - false positives, FN - False negaties \n\n' ) doc.append( 'The performance of a classifier can be described by:\n' ) doc.append(bold('Accuracy ')) doc.append(' - (TP+TN)/(TP+TN+FP+FN) \n') doc.append(bold('Precision ')) doc.append( ' (Purity, Positive Predictive Value) - TP/(TP+FP) \n') doc.append(bold('Recall ')) doc.append( ' (Completeness, True Positive Rate - TP/(TP+FN) \n ') doc.append(bold('F1 Score ')) doc.append( ' = 2 (Precision * Recall)/(Precision + Recall).\n') doc.append(bold('Brier Score ')) doc.append( ''' - mean squared error (MSE) between predicted probabilities (between 0 and 1) and the expected values (0 or 1). Brier score summarizes the magnitude of the forecasting error and takes a value between 0 and 1 (with better models having score close to 0).\n\n''' ) with doc.create(Tabular('|l|l|')) as table: table.add_hline() table.add_row((bold('Metric'), bold('Score'))) table.add_hline() table.add_row(('Accuracy', '%.2f' % acc)) table.add_row(('Precision', '%.2f' % precision)) table.add_row(('Recall', '%.2f' % recall)) table.add_row(('F1 Score', '%.2f' % f1)) table.add_row(('Brier Score', '%.2f' % brier)) table.add_hline() doc.append('\n\n') else: print("Scoring file not found! Skipping.") # plot ROC and AUC if roc_auc == True: if (os.path.exists('images/ROC.pdf') and os.path.exists('images/auc.npy')): roc = 'images/ROC.pdf' auc_save = np.load('images/auc.npy') auc = auc_save with doc.create( Subsection( 'Reciever Operating Characteristic (ROC) and Area Under the Curve (AUC) for Test Set', numbering=0)): doc.append( '''The ROC curve graphically shows the trade-off between between true-positive rate and false-positive rate.The AUC summarizes the ROC curve - where the AUC is close to unity, classification is successful, while an AUC of 0.5 indicates the model is performs as well as a random guess.''') with doc.create(Figure(position='!htb')) as roc_curve: roc_curve.add_image(roc, width='220px') doc.append(HorizontalSpace("2cm")) doc.append( MediumText('AUC = ' + str(auc) + '\n\n\n\n\n\n\n\n')) else: print("Roc curve image and/or AUC not found! Skipping.") # plot histogram of output values if hist == True: if os.path.exists('images/histogram.pdf'): hist = 'images/histogram.pdf' with doc.create( Subsection( 'Histogram of the Output Probabilities for Test Set', numbering=0)): with doc.create(Figure(position='!htb')) as histogram: histogram.add_image(hist, width='230px') else: print("Histogram image not found! Skipping.") # plot 2D histogram of output values and some object parameter if hist2D == True: if os.path.exists('images/2Dhistogram.pdf'): hist_2d = 'images/2Dhistogram.pdf' with doc.create( Subsection( '2D Histogram of the Output vs One Object Feature for Test Set', numbering=0)): with doc.create(Figure(position='!htb')) as histogram_2d: histogram_2d.add_image(hist_2d, width='230px') else: print("2D Histogram image not found! Skipping.") if name == False: doc.generate_pdf('report', clean_tex=False) else: doc.generate_pdf(name, clean_tex=False) return
def report(qfilename, profiles): with open(qfilename + ".log", 'r') as file: log = file.read() from bs4 import BeautifulSoup import pandas as pd import numpy as np import matplotlib.pyplot as plt import sys import math from io import StringIO soup = BeautifulSoup(log, 'html.parser') if len(profiles) > 0: profileResults = dict() maxIts = 0 for p in profiles: tagName = "p" + str(p) profileResults[p] = pd.read_csv(StringIO( soup.find(tagName).string), names=["lanes", "iters"]) profileResults[p] = profileResults[p].iloc[1:] maxIts = max(maxIts, max(profileResults[p].iters)) nRows = math.ceil(len(profiles) / 2) nCols = min(2, len(profiles)) fig, axs = plt.subplots(nRows, nCols, figsize=(nCols * 4, nRows * 2.4)) fig.tight_layout(pad=3.0) SMALL_SIZE = 8 MEDIUM_SIZE = 10 BIGGER_SIZE = 14 plt.rc('axes', labelsize=BIGGER_SIZE) plt.rc('axes', titlesize=BIGGER_SIZE) fig.add_subplot(111, frameon=False) plt.tick_params(labelcolor='none', top=False, bottom=False, left=False, right=False) plt.xlabel("Active warp lanes") plt.ylabel("Iterations") for y in range(0, nRows): for x in range(0, 2): idx = y * 2 + x if len(profiles) == 1: ax = axs elif len(profiles) == 2: ax = axs[x] else: ax = axs[y, x] if idx >= len(profiles): if len(profiles) > 1: fig.delaxes(ax) break p = profiles[idx] ax.set_title('Profile P' + str(p)) ax.set_ylim(ymax=maxIts * 1.1, ymin=0) ax.set_xlim(xmax=32.7, xmin=0.3) ax.set_xticks([1, 4, 8, 12, 16, 20, 24, 28, 32]) ax.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) ax.bar(profileResults[p].lanes, profileResults[p].iters) plt.savefig('plots.pdf', bbox_inches='tight') geometry_options = {"hscale": "0.95", "vscale": "0.95"} doc = Document(geometry_options=geometry_options) doc.packages.append(Package('tikz')) doc.append(NoEscape("\\usetikzlibrary{shapes}")) doc.append(NoEscape("\\definecolor{colLR}{HTML}{FFA494}\n")) doc.append(NoEscape("\\definecolor{colP}{HTML}{98FB98}\n")) timings = "" for line in soup.timing.string.splitlines(): tokens = ["krnl_", "scanMulti", "totalKernel"] if any(tok in line for tok in tokens): timings += (line + "\n") import textwrap timings = textwrap.indent(textwrap.dedent(timings), " ") with doc.create(Figure(position='h!')): with doc.create( SubFigure(width=NoEscape(r'0.5\linewidth'))) as planSubfig: with planSubfig.create(Center()): planSubfig.add_image("qplan.pdf", width=NoEscape("8cm")) planSubfig.add_caption('Query execution plan for ' + qfilename) with doc.create( SubFigure(width=NoEscape(r'0.5\linewidth'))) as plotsSubfig: with plotsSubfig.create(MiniPage(width=r"\linewidth")) as mp: with mp.create(Center()) as c: if len(profiles) > 0: plotsSubfig.add_image("plots.pdf", width=NoEscape("9cm")) for line in timings.splitlines(): LRs = [] Ps = [] if "total" in line: mp.append(NoEscape("\\noindent\\rule{8cm}{0.4pt}\n")) start = line.find("LR") while start != -1: space = line.find(" ", start) colon = line.find(":", start) end = min(space, colon) LRs.append(line[start:end]) line = " " * (end - start + 1) + line[:start - 1] + line[end:] start = line.find("LR") start = line.find("P") while start != -1: space = line.find(" ", start) colon = line.find(":", start) end = min(space, colon) Ps.append(line[start:end]) line = " " * (end - start + 1) + line[:start - 1] + line[end:] start = line.find("P") mp.append( NoEscape("\\mbox{\\texttt{\\footnotesize" + escape_latex(line).replace(" ", "~") + "}}")) for lr in LRs: mp.append( NoEscape( "\,\,\\raisebox{-1ex}{\\tikz{\\node[ellipse,fill=colLR](l){\\tiny " + lr + "};}}")) for p in Ps: mp.append( NoEscape( "\,\,\\raisebox{-1ex}{\\tikz{\\node[ellipse,fill=colP](l){\\tiny " + p + "};}}")) mp.append("\n") plotsSubfig.add_caption('Profiling results') n = 0 fname = "profiling_report" + str(n) while path.exists(fname + ".pdf"): fname = "profiling_report" + str(n) n = n + 1 doc.generate_pdf(fname, clean_tex=False, silent=True)
def create_pdf(self): """Creates a LaTeX PDF using the Python module PyLatex (https://jeltef.github.io/PyLaTeX/latest/). Note: LaTeX must be installed in /usr/local/. Development employed TexLive 2015. """ pdflatex = '/usr/local/texlive/2015/bin/x86_64-linux/pdflatex' doc = Document() doc.packages.append(Package('geometry', options=['tmargin=0.75in', 'lmargin=0.75in', 'rmargin=0.75in'])) doc.packages.append(Package('datetime', options=['ddmmyyyy'])) doc.packages.append(Package('needspace')) doc.preamble.append(Command('newdateformat', NoEscape(r'mydate}{\twodigit{\THEDAY}/\twodigit{\THEMONTH}/\THEYEAR'))) doc.append(Command('begin', 'center')) doc.append(Command('Large', bold('MiSeq Quality Check'))) doc.append(Command('end', 'center')) doc.append(Command('begin', 'flushright')) doc.append(Command('Large', '<Run_name>')) doc.append(Command('end', 'flushright')) doc.append(Command('begin', 'flushright')) doc.append(Command('Large', NoEscape(r'\mydate\today'))) doc.append(Command('end', 'flushright')) avg_qual = self.get_avg_qual() self.get_qual_graph(avg_qual) first_read, second_read = self.get_avg_qual_per_read() doc.append(Command('needspace', '20em')) with doc.create(Section('Quality data')): with doc.create(Tabular(NoEscape(r'p{5cm}|c|c'))) as table: table.add_row(('Data', 'Value', 'Pass/Fail')) table.add_hline() table.add_row( ('Mean Cluster Density (k/mm2)', format(self.tile.mean_cluster_density / 1000, '.2f'), '')) table.add_row(('Clusters passed filter (%)', '%s' % (format(self.tile.percent_pf_clusters, '.2f')), '')) table.add_row(('Average >= Q30', '%s' % (format(avg_qual, '.2f')), '')) table.add_row(('1st full read >= Q30', '%s' % (format(first_read, '.2f')), '')) table.add_row(('2nd full read >= Q30', '%s' % (format(second_read, '.2f')), '')) with doc.create(Figure(position='htbp', placement=NoEscape(r'\centering'))): doc.append(Command('centering')) with doc.create(SubFigure()) as plot: plot.add_plot() plot.add_caption('Q-score distribution plot (all reads all cycles)') self.get_qual_heatmap() with doc.create(SubFigure()) as plot: plot.add_plot() plot.add_caption('Q-score heat map') self.get_clusters_heatmap() with doc.create(SubFigure()) as plot: plot.add_plot() plot.add_caption('Cluster density per tile') read_1_phas, read_1_prephas, read_2_phas, read_2_prephas = self.get_phas_prephas() with doc.create(Section('Phas/Prephas data')): with doc.create(Tabular(NoEscape(r'p{5cm}|c|c'))) as table: table.add_row(('Data', 'Value', 'Pass/Fail')) table.add_hline() table.add_row( ('1st full read', '%s / %s' % (format(read_1_phas, '.3f'), format(read_1_prephas, '.3f')), '')) table.add_row( ('2nd full read', '%s / %s' % (format(read_2_phas, '.3f'), format(read_2_prephas, '.3f')), '')) sample_id, index1, index2, percent_clusters, percent_pf, total_aligned_clusters, pf_aligned_clusters = \ self.get_indexing() total_samples = len(sample_id) doc.append(Command('needspace', '10em')) with doc.create(Section('Indexing')): doc.append(Command('begin', 'center')) with doc.create(Tabular(NoEscape(r'c|c|c|c|c'))) as table: table.add_row(('Total Reads', 'PF Reads', '% Reads Identified (PF)', 'Min', 'Max')) table.add_hline() table.add_row( ('%s' % int(total_aligned_clusters), '%s' % int(pf_aligned_clusters), '%s' % percent_pf, '%s' % min(percent_clusters), '%s' % max(percent_clusters))) doc.append(Command('end', 'center')) with doc.create(Figure(position='htbp', placement=NoEscape(r'\centering'))): with doc.create(Tabular(NoEscape(r'c|c|c|c'))) as table: table.add_row(('Sample_ID', 'Index', 'Index2', '% Reads Identified (PF)')) table.add_hline() item = 0 while item < total_samples: table.add_row(('%s' % sample_id[item], '%s' % index1[item], '%s' % index2[item], '%s' % percent_clusters[item])) item += 1 with doc.create(SubFigure()) as plot: plot.add_plot() doc.generate_pdf('%s_InterOp_Results' % self.worksheet, clean_tex=False, compiler=pdflatex)
# doc.append('Introduction.') # with doc.create(Section('I am a section')): # doc.append('Take a look at this beautiful plot:') with doc.create(Figure(position='h!')) as plotgrid: #first graph plt.bar(y_pos, benchMark, align='center', alpha=0.5) plt.bar(y_pos, unconInvest,bottom=benchMark, align='center', alpha=1, color="#f3e151") plt.xticks(y_pos, objects,fontsize=9, rotation=30) plt.ylabel('USD bn') plt.title('Brazil') with doc.create(SubFigure(position='b',width=NoEscape(r'0.5\linewidth'))) as Leftplot: Leftplot.add_plot(width=NoEscape(r'\linewidth'), dpi=300) plt.clf() #Second graph plt.bar(mex_y_pos, mex_benchMark, align='center', alpha=0.5) plt.bar(mex_y_pos, mex_unconInvest,bottom=mex_benchMark, align='center', alpha=1, color="#f3e151") plt.xticks(mex_y_pos, mex_obj, fontsize=9, rotation=30) plt.ylabel('USD bn') plt.title('Mexico') with doc.create(SubFigure(position='b',width=NoEscape(r'0.5\linewidth'))) as Rightplot: Rightplot.add_plot(width=NoEscape(r'\linewidth'), dpi=300) plt.clf() doc.append(NewLine())
def portada(Diccionario, eficiencia,T_Hornilla): global doc doc = Document() geometry_options = {"tmargin": "4cm", "rmargin": "2cm", "lmargin": "4cm", "bmargin": "3cm"} doc = Document(geometry_options=geometry_options) doc.packages.append(Package('babel', options=['spanish'])) doc.packages.append(Package('background', options=['pages=all'])) doc.packages.append(NoEscape('\\backgroundsetup{placement=center,\n angle=0, scale=1, contents={\includegraphics{Membrete.pdf}}, opacity=1}\n')) with doc.create(Center()) as centered: centered.append(TextColor('white','HH')) for i in range(10): centered.append(LineBreak()) centered.append(HugeText('PROPUESTA DE VALOR PARA LA CONSTRUCCIÓN DE UNA HORNILLA ')) centered.append(LineBreak()) centered.append(SmallText('(Generado por HornillAPP)')) for i in range(8): centered.append(LineBreak()) with doc.create(Figure(position='h!')) as imagesRow1: with doc.create(SubFigure( position='b', width=NoEscape(r'1\linewidth'))) as left_imagesRow1: left_imagesRow1.add_image('IconoAPP.png') imagesRow1.append(LineBreak()) with doc.create(Center()) as centered: centered.append(TextColor('white','HH')) for i in range(8): centered.append(LineBreak()) #centered.append(VerticalSpace('50')) centered.append(LargeText('Presentado por: AGROSAVIA')) centered.append(LineBreak()) centered.append(SmallText('(Corporación Colombiana de Investigación Agropecuaria)')) doc.append(NewPage()) with doc.create(MediumText(' ')) as tlg: tlg.append(TextColor('white','HH')) tlg.append(LineBreak()) tlg.append('Bogotá D.C., ') tlg.append(Command(' ',NoEscape('\\today'))) tlg.append('\n \n') #Salto de línea en parráfo tlg.append(LineBreak()) #Salto de línea en parráfo tlg.append('\nSeñor (es):') tlg.append('\n'+str(Diccionario['Nombre de usuario'])) if(str(Diccionario['Departamento'])=='--'): tlg.append('\n'+str(Diccionario['Pais'])+'.') else: tlg.append('\n'+str(Diccionario['Ciudad'])+', '+str(Diccionario['Departamento'])+'.') tlg.append('\n \n') #Salto de línea en parráfo tlg.append('\nApreciado(s) productor(es):') tlg.append('\n \n') #Salto de línea en parráfo Parrafo= ('Con base en la información suministrada, está aplicación propone (ver Sección 1) la construcción de una hornilla '+ T_Hornilla+' con capacidad de '+ str(Diccionario['Capacidad estimada de la hornilla']) +' kg/h'+' (la eficiencia estimada de la hornilla es del '+ str(round(Diccionario['Eficiencia de la hornilla']))+'%) '+'; adecuada para el procesamiento de hasta '+ str(Diccionario['Área cosechada al mes'])+ ' ha'+' de caña, con una producción de panela '+ str(round(float(Diccionario['Producción de panela por molienda [t]'])))+ ' t por molienda y un periodo vegetativo de '+ str(Diccionario['Periodo vegetativo'])+' meses. Teniendo en cuenta que'+ ' se realizan '+str(Diccionario['Número de moliendas al año'])+' moliendas al año se estableció una jornada laboral de '+ str(Diccionario['Días de trabajo de la hornilla por semana'])+ ' días a la semana de '+str(Diccionario['Horas de trabajo de la hornilla por día'])+ ' horas laborables cada una.'+ '\n Además, la aplicación estima que para garantizar una operación apropiada de la hornilla '+ ' se requiere de un área disponible de al menos '+str(round(Diccionario['Capacidad estimada de la hornilla']*4.3))+' m²' ) tlg.append(Parrafo) Parrafo= (', cuya productividad puede aumentar al incorporar el sistema de recuperación de calor (hasta '+str(round(Diccionario['Capacidad estimada de la hornilla']+25))+' kg/h) como se muestra en las tablas del análisis financiero y al final del informe.' +' No obstante, la corporación ofrece los siguientes servicios de asistencia técnica para ajustar los valores provistos en esta propuesta de valor:' ) tlg.append(Parrafo) with tlg.create(Itemize()) as itemize: itemize.add_item('Estudio detallado para la construcción e instalación de la hornilla.') itemize.add_item('Al menos tres visitas técnicas de dos funcionarios de AGROSAVIA para la puesta en marcha y '+ 'capacitación de los operarios en el manejo de la hornilla y en la producción de panela '+ 'saborizada, granulada o moldeada en presentación pastilla de chocolate.') itemize.add_item('Entrega de un ejemplar de la guía tecnológica para el manejo integral del sistema '+ 'productivo de la caña panelera y una para el mantenimiento de la hornilla.') Parrafo= ('Cualquier inquietud AGROSAVIA está presta a atenderla.\n'+ 'Cordial saludo.\n'+ '\n \n \n'+ 'AGROSAVIA (Corporación colombiana de investigación agropecuaria)') tlg.append(Parrafo) Parrafo= ('\n \n Nota: Está propuesta de valor se basa en condiciones del terreno ideales y estacionarias, por lo que, '+ 'AGROSAVIA no se hace responsable de la reproducción total o parcial del material aquí suministrado sin una aprobación '+ 'corporativa.') tlg.append(Parrafo) doc.append(NewPage()) with doc.create(MediumText(' ')) as tlg: tlg.append(LargeText(bold('Contenido'))) with tlg.create(Itemize()) as itemize: itemize.add_item('Sección 1') with itemize.create(Itemize()) as item: item.add_item('Información del usuario.') item.add_item('Características de la caña sembrada.') item.add_item('Características del molino.') item.add_item('Consideraciones generales para el manejo de la hornilla.') item.add_item('Análisis financiero.') itemize.add_item('Sección 2') with itemize.create(Itemize()) as item: item.add_item('Diagramas mecánicos de la hornilla.') item.add_item('Diagramas mecánicos de la camára.') item.add_item('Diagramas mecánicos de la chimenea.') item.add_item('Diagramas mecánicos del ducto.') item.add_item('Diagramas mecánicos de la hornilla con recuperador de calor.') doc.append(NewPage()) #PORTADA PARA LA SECCIÓN 1 with doc.create(Center()) as centered: centered.append(TextColor('white','HH')) for i in range(15): centered.append(LineBreak()) centered.append(HugeText('SECCIÓN 1:')) centered.append(LineBreak()) centered.append(HugeText('INFORMACIÓN TÉCNICA Y FINANCIERA')) doc.append(NewPage())
:license: MIT, see License for more details. """ # begin-doc-include from pylatex import Document, Section, Figure, SubFigure, NoEscape import os if __name__ == '__main__': doc = Document(default_filepath='subfigures') image_filename = os.path.join(os.path.dirname(__file__), 'kitten.jpg') with doc.create(Section('Showing subfigures')): with doc.create(Figure(position='h!')) as kittens: with doc.create( SubFigure( position='b', width=NoEscape(r'0.45\linewidth'))) as left_kitten: left_kitten.add_image(image_filename, width=NoEscape(r'\linewidth')) left_kitten.add_caption('Kitten on the left') with doc.create( SubFigure( position='b', width=NoEscape(r'0.45\linewidth'))) as right_kitten: right_kitten.add_image(image_filename, width=NoEscape(r'\linewidth')) right_kitten.add_caption('Kitten on the right') kittens.add_caption("Two kittens")
def snp_char(self, var_con_pre_path, var_cas_pre_path, var_all_path, data_type): self.append(NewPage()) with self.create(Section('Per SNP Characteristics Analysis')): with self.create(Subsection('Missing Rates - pre-QC')): if data_type == "Case-only": with self.create( Figure(position='h!')) as pre_varcr_images: self.append(Command('centering')) with self.create( SubFigure(position='c', width=NoEscape(r'1\linewidth')) ) as varcr_cas_pre_images: varcr_cas_pre_images.add_image( var_cas_pre_path, width=NoEscape(r'1\linewidth')) self.append(NewPage()) if data_type == "Control-only": with self.create( Figure(position='h!')) as pre_varcr_images: self.append(Command('centering')) with self.create( SubFigure(position='c', width=NoEscape(r'1\linewidth')) ) as varcr_con_pre_images: varcr_con_pre_images.add_image( var_con_pre_path, width=NoEscape(r'1\linewidth')) self.append(NewPage()) if data_type == "no-pheno": with self.create( Figure(position='h!')) as pre_varcr_images: self.append(Command('centering')) with self.create( SubFigure(position='c', width=NoEscape(r'1\linewidth')) ) as varcr_all_pre_images: varcr_all_pre_images.add_image( var_all_path, width=NoEscape(r'1\linewidth')) self.append(NewPage()) if data_type == "Case-Control": with self.create( Figure(position='h!')) as pre_varcr_images: self.append(Command('centering')) with self.create( SubFigure(position='c', width=NoEscape(r'1\linewidth')) ) as varcr_con_pre_images: varcr_con_pre_images.add_image( var_con_pre_path, width=NoEscape(r'1\linewidth')) with self.create( Figure(position='h!')) as pre_varcr_images: self.append(Command('centering')) with self.create( SubFigure(position='c', width=NoEscape(r'1\linewidth')) ) as varcr_cas_pre_images: varcr_cas_pre_images.add_image( var_cas_pre_path, width=NoEscape(r'1\linewidth')) self.append(NewPage())
def generar(self, Carrera, Asignatura, Curso, listaPreguntas, aleatorio): today = str(self.__fecha) geometry_options = { "head": "48pt", "margin": "0.5in", "bottom": "0.6in", "includeheadfoot": True } doc = Document(geometry_options=geometry_options) header = PageStyle("header") # DEFINIMOS LA VARIABLE CON ESTILO #image_filename = os.path.join(os.path.dirname("__file__"), '../static/zigmap.png') # IMAGEN UNAB #data_folder = os.path.join("../", "static/zigmap.png") #file_to_open = os.path.join(data_folder, "zigmap.png") #image_filename = data_folder image_filename = "zigmap.png" # Generating first page style first_page = PageStyle("firstpage") # Header image with first_page.create(Head("L")) as header_left: with header_left.create( SubFigure( position='L', width=NoEscape(r'0.10\linewidth'))) as logo_wrapper: print("IMAGEN") #logo_wrapper.add_image('zigmap.png', width=NoEscape(r'\linewidth')) # Add document title with first_page.create(Head("C")) as center_header: with center_header.create( MiniPage(width=NoEscape(r"0.49\textwidth"), pos='c', align='c')) as title_wrapper: title_wrapper.append(LargeText(bold(self.__nombre))) # Add document title with first_page.create(Head("R")) as right_header: with right_header.create( MiniPage(width=NoEscape(r"0.49\textwidth"), pos='c', align='r')) as title_wrapper: #title_wrapper.append(LargeText(bold("Solemne II"))) #title_wrapper.append(LineBreak()) title_wrapper.append(MediumText(bold( Asignatura.get_nombreA()))) # Add footer with first_page.create(Foot("C")) as footer: message = "Programación II" with footer.create( Tabularx("X X X X", width_argument=NoEscape( r"\textwidth"))) as footer_table: footer_table.add_row([ MultiColumn(4, align='l', data=TextColor("black", message)) ]) footer_table.add_hline(color="black") footer_table.add_empty_row() branch_address = MiniPage(width=NoEscape(r"0.45\textwidth"), pos='t', align='l') branch_address.append( MediumText("Facultad de " + Carrera.get_facultad())) branch_address.append("\n") branch_address.append("") branch_address2 = MiniPage(width=NoEscape(r"0.10\textwidth"), pos='t') branch_address2.append("") branch_address2.append("\n") branch_address2.append("") document_details = MiniPage(width=NoEscape(r"0.25\textwidth"), pos='t', align='r') document_details.append(self.__fecha) document_details.append(LineBreak()) document_details.append("") # simple_page_number() footer_table.add_row([ branch_address, branch_address2, branch_address2, document_details ]) doc.preamble.append(first_page) # End first page style ############################################ #################################################### # Add customer information with doc.create(Tabu("X[l] X[r]")) as first_page_table: customer = MiniPage(width=NoEscape(r"0.55\textwidth"), pos='h') customer.append("Nombre: ___________________________________") customer.append("\n") customer.append(" Rut: _______________") customer.append("\n") customer.append("Nota: ______________") customer.append("\n") customer.append("\n") # Add branch information branch = MiniPage(width=NoEscape(r"0.35\textwidth"), pos='t!', align='r') if self.__unidad == "unidad1": branch.append(bold("Unidad: 1")) elif self.__unidad == "unidad2": branch.append(bold("Unidad: 2")) else: branch.append(bold("Unidades: 1 & 2")) branch.append(LineBreak()) branch.append(bold("Curso: ")) branch.append(bold(Curso.get_cod())) branch.append(LineBreak()) branch.append(bold("Ponderación: ")) branch.append(bold(self.__ponderacion + "%")) branch.append(LineBreak()) first_page_table.add_row([customer, branch]) doc.append(LargeText(bold("Indicaciones:"))) # INDICACIONES with doc.create(Itemize()) as itemize: doc.append(LineBreak()) itemize.add_item( " Lea atentamente los enunciados de cada pregunta antes de contestar." ) itemize.add_item( " Conteste su evaluación en silencio, está prohibido conversar o gesticulizar en la sala durante la prueba." ) itemize.add_item( " Dispone de 90 minutos para realizar esta evaluación.") itemize.add_item( " Marque la alternativa con lapiz pasta, no se aceptan marcadas con lapiz grafito." ) itemize.add_item( " Utilice solamente sus materiales, está prohibido solicitar materiales a sus compañeros." ) # you can append to existing items itemize.append(Command("ldots")) doc.change_document_style("firstpage") doc.add_color(name="lightgray", model="gray", description="0.80") customer.append(LineBreak()) now = str(datetime.today()) for p in listaPreguntas: with doc.create(Section('Pregunta - ' + p.get_tipo())): doc.append(p.get_contenido()) doc.append(NewPage()) nombreFile = str( self.__nombre) + " - " + self.get_fecha() + " - " + str(aleatorio) print( "--------------------------ANTES DE DIR------------------------------" ) try: # GENERANDO PDF doc.generate_pdf(filepath="tests/" + nombreFile, clean_tex=True, clean=True) #doc.generate_pdf(dirName + "/" + nombreFile, clean_tex=False) except FileNotFoundError as e: doc.generate_pdf(filepath="../tests/" + nombreFile, clean_tex=True, clean=True)
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)
.. :copyright: (c) 2014 by Jelte Fennema. :license: MIT, see License for more details. """ # begin-doc-include from pylatex import Document, Section, Figure, SubFigure, NoEscape import os if __name__ == '__main__': doc = Document(default_filepath='subfigures') image_filename = os.path.join(os.path.dirname(__file__), 'kitten.jpg') with doc.create(Section('Showing subfigures')): with doc.create(Figure(position='h!')) as kittens: with doc.create(SubFigure( position='b', width=NoEscape(r'0.45\linewidth'))) as left_kitten: left_kitten.add_image(image_filename, width=NoEscape(r'\linewidth')) left_kitten.add_caption('Kitten on the left') with doc.create(SubFigure( position='b', width=NoEscape(r'0.45\linewidth'))) as right_kitten: right_kitten.add_image(image_filename, width=NoEscape(r'\linewidth')) right_kitten.add_caption('Kitten on the right') kittens.add_caption("Two kittens") doc.generate_pdf(clean_tex=False)
def individual_char(self, id_con_pre_path, id_cas_pre_path, id_all_path, fstat_fig_path, data_type): self.append(NewPage()) with self.create(Section('Per Individual Characteristics Analysis')): with self.create(Subsection('Missing Rates - pre-QC')): if data_type == "Case-only": with self.create(Figure(position='h!')) as pre_idcr_images: self.append(Command('centering')) with self.create( SubFigure(position='c', width=NoEscape(r'1\linewidth')) ) as idcr_cas_pre_images: idcr_cas_pre_images.add_image( id_cas_pre_path, width=NoEscape(r'1\linewidth')) self.append(NewPage()) if data_type == "Control-only": with self.create(Figure(position='h!')) as pre_idcr_images: self.append(Command('centering')) with self.create( SubFigure(position='c', width=NoEscape(r'1\linewidth')) ) as idcr_con_pre_images: idcr_con_pre_images.add_image( id_con_pre_path, width=NoEscape(r'1\linewidth')) self.append(NewPage()) if data_type == "no-pheno": with self.create(Figure(position='h!')) as pre_idcr_images: self.append(Command('centering')) with self.create( SubFigure(position='c', width=NoEscape(r'1\linewidth')) ) as idcr_all_pre_images: idcr_all_pre_images.add_image( id_all_path, width=NoEscape(r'1\linewidth')) self.append(NewPage()) if data_type == "Case-Control": with self.create(Figure(position='h!')) as pre_idcr_images: self.append(Command('centering')) with self.create( SubFigure(position='c', width=NoEscape(r'1\linewidth')) ) as idcr_con_pre_images: idcr_con_pre_images.add_image( id_con_pre_path, width=NoEscape(r'1\linewidth')) with self.create(Figure(position='h!')) as pre_idcr_images: self.append(Command('centering')) with self.create( SubFigure(position='c', width=NoEscape(r'1\linewidth')) ) as idcr_cas_pre_images: idcr_cas_pre_images.add_image( id_cas_pre_path, width=NoEscape(r'1\linewidth')) self.append(NewPage()) with self.create(Subsection('Fstat - Sex Violations')): with self.create(Figure(position='h!')) as fstat_image: self.append(Command('centering')) with self.create( SubFigure( position='c', width=NoEscape(r'1\linewidth'))) as fstat_fig: fstat_fig.add_image(fstat_fig_path, width=NoEscape(r'1\linewidth'))
def seccion1(D1, D2): global doc '''>>>>>>>>>>>>>>>Presentación de los datos de usuario<<<<<<<<<<<<<<<<<''' doc = Documento_Latex.titulos_I (doc, 'DATOS DEL USUARIO PARA GENERAR EL INFORME') with doc.create(Tabular('lccccl')) as table: for i in D1: if(str(i)=='DATOS DE ENTRADA'): break else: if((SM(None, 'Altura', i).ratio()<0.85) and (SM(None, 'Variedad de Caña', i).ratio()<0.85) and (SM(None, 'Usa fertilizante', i).ratio()<0.85) and (SM(None, 'Grados Brix de la panela (promedio)', i).ratio()<0.85) and (SM(None, '--', str(D1[i])).ratio()<0.85)): T1=str(D1[i]) #Arreglo para asignar unidades y mostrarlas en el informe if (str(i)=='Área caña sembrada'): T1=str(D1[i])+" ha" elif (str(i)=='Crecimiento aproximado del área sembrada'): T1=str(D1[i])+" ha" elif (str(i)=='Caña esperada por hectárea'): T1=str(D1[i])+" t/ha" elif (str(i)=='Número de moliendas'): T1=str(D1[i])+" semanal(es)" elif (str(i)=='Periodo vegetativo'): T1=str(D1[i])+" mes(es)" elif (str(i)=='Caña molida al mes'): T1=str(D1[i])+" t/mes" elif (str(i)=='Área cosechada al mes'): T1=str(D1[i])+" ha/mes" elif (str(i)=='Caña molida a la semana'): T1=str(D1[i])+" t/semana" elif (str(i)=='Caña molida por Hora'): T1=str(D1[i])+" t/hora" elif (str(i)=='Área cosechada al mes'): T1=str(D1[i]*12)+" L/año" elif (str(i)=='Caña molida al año'): T1=str(D1[i])+" t/año" elif (str(i)=='Jugo producido al año'): T1=str(D1[i])+" t/año" elif (str(i)=='Bagazo secado al año'): T1=str(D1[i])+" t/año" table.add_row((bold(str(i)), ' ', ' ', ' ', ' ',T1)) doc.append(NewPage()) '''>>>>>>>>>>>>>>>>>>>>Presentación de los datos de la caña<<<<<<<<<<<<<<<<<<<<<<<''' doc = Documento_Latex.titulos_I (doc, 'CARACTERÍSTICAS DE LAS VARIEDADES DE CAÑA SELECCIONADAS') Canas=pd.read_excel('static/Temp/Temp4.xlsx',skipcolumn = 0,) Carpe=pd.read_excel('static/Temp/Temp5.xlsx',skipcolumn = 0,) Eti = Canas.iloc[0].values Val = Canas.iloc[1].values Car = Carpe.iloc[0].values conta=1 for i in range (len(Car)-1): with doc.create(Tabular('lcccccl')) as table: for j in range (1,8): table.add_row((bold(str(Eti[conta])), ' ', ' ', ' ', ' ', ' ', str(Val[conta]))) conta=conta+1 conta=conta+1 doc.append(LineBreak()) doc.append('\n') doc.append(LineBreak()) for i in range (1,len(Car),3): with doc.create(Figure(position='h!')) as imagesRow1: for j in range(3): if((i+j)<len(Car)): with doc.create( SubFigure(width=NoEscape(r'0.33\linewidth'))) as left_imagesRow1: left_imagesRow1.add_image(Car[i+j], width=NoEscape(r'0.95\linewidth')) left_imagesRow1.add_caption('Variedad de caña '+str(i+j)) imagesRow1.append(LineBreak()) imagesRow1.append(NewPage()) doc.append(NewPage()) doc.append(TextColor('white','HH')) doc.append(NewPage()) '''>>>>>>>>>>>>>>>>>>>>Presentación de los molinos seleccionados<<<<<<<<<<<<<<<<<<<<<<<''' doc = Documento_Latex.titulos_I (doc, 'MOLINOS PRESELECCIONADOS PARA ESTE DISEÑO') Molino=pd.read_excel('static/Temp/Temp.xlsx',skipcolumn = 0,) Carpe=pd.read_excel('static/Temp/Temp5.xlsx',skipcolumn = 0,) Eti = Canas.iloc[0].values Val = Canas.iloc[1].values Car = Carpe.iloc[0].values Marca=Molino['Marca'].values Modelo=Molino['Modelo'].values Kilos=Molino['kg/hora'].values Diesel=Molino['Diesel'].values Electrico=Molino['Electrico'].values Valor=Molino['Precio'].values with doc.create(Tabular('lcccccl')) as table: table.add_row((TextColor('red',bold('VALOR APROXIMADO DE UN MOLINO: ')), ' ', ' ', ' ', ' ', ' ', TextColor('red', Documento_Latex.Formato_Moneda(sum(Valor)/len(Valor), "$", 2)))) doc.append(LineBreak()) with doc.create(Tabular('ccccc')) as table: table.add_row("MARCA", "MODELO", "KG POR HORA", "DIESEL O GASOLINA (HP)", "ELÉCTRICO (HP)") table.add_empty_row() for i in range(len(Marca)): table.add_row(str(Marca[i]), str(Modelo[i]), str(Kilos[i]), str(Diesel[i]), str(Electrico[i])) doc.append(LineBreak()) doc.append('\n') doc.append(LineBreak()) for i in range (1,len(Modelo),3): with doc.create(Figure(position='h!')) as imagesRow1: for j in range(3): if((i-1)+j<len(Modelo)): with doc.create( SubFigure(width=NoEscape(r'0.33\linewidth'))) as left_imagesRow1: left_imagesRow1.add_image('Molinos/'+str(Modelo[(i-1)+j]+'.jpg'), width=NoEscape(r'0.95\linewidth')) left_imagesRow1.add_caption(str(Modelo[(i-1)+j])) imagesRow1.append(LineBreak()) imagesRow1.append(NewPage()) doc.append(NewPage()) doc.append(TextColor('white','HH')) doc.append(NewPage()) #MANUAL DE OPERACIÓN DE LA HORNILLA with doc.create(MediumText(' ')) as tlg: tlg.append(LargeText(bold('Consideraciones para el manejo de la hornilla'))) Parrafo= ('\n \nEl trapiche panelero es un lugar donde se procesa la caña de azúcar para producir la panela. Está constituido por las áreas de molienda, prelimpieza, hornilla, moldeo y almacenamiento.') tlg.append(Parrafo) Parrafo= ('\n La hornilla panelera, está conformada, por el cenicero, la cámara, la chimenea y el ducto, sobre el cual se asientan directamente los intercambiadores de calor, en los que se deposita el jugo. En la hornilla panelera, se genera y transfiere el calor necesario para concentrar en un sistema de evaporación abierta, el jugo de la caña; de tal forma que la cantidad de energía aprovechada se relaciona directamente con el suministro de aire y bagazo, la eficiencia de la combustión, y la cantidad de energía disipada a los alrededores. Estas variables de operación y transferencia se relacionan entre si y debido a su complejidad y cantidad, dificultan las tareas de manipulación y diseño de la hornilla.') tlg.append(Parrafo) tlg.append(LargeText(bold('\n \n Manejo de las hornillas paneleras'))) with tlg.create(Itemize()) as itemize: itemize.add_item('Tenga en cuenta las siguientes indicaciones.') with itemize.create(Itemize()) as item: item.add_item('Durante las pruebas iniciales y periodos de capacitación, los operarios que manejan la hornilla deben tener experiencia para evitar la disminución en la calidad de la panela y vida util de los equipos instalados.') item.add_item('El trabajo continuo de la hornilla aumenta la capacidad de producción y evita la perdida de energía, puesto que, al no enfriarse durante las horas de la noche se reduce el efecto del cambio térmico sobre los ladrillos de la estructura.') item.add_item('La combustión en la hornilla será buena, si se alimenta con pequeñas cantidades de bagazo cada 150 segundos y la válvula de la chimenea tiene una apertura 60° para garantizar un flujo de aire suficientemente alto que produzca llama, sin arrastrar combustible en los gases residuales.') item.add_item('La entrada de aire por orificios diferentes a los proyectados en el diseño inicial debe evitarse a toda costa, para aumentar la eficiencia de la combustión y reducir el material particulado de los gases en la chimenea.') item.add_item('Elimine obstáculos en las entradas de aire diseñadas para la hornilla y retire periódicamente la ceniza la parrilla para evitar la formación de escoria.') item.add_item('El cenicero y su entrada deben mantenerse despejada a fin de no obstruir el paso del aire.') item.add_item('El bagazo para alimentar la hornilla debe tener las condiciones de humedad mencionadas en el diseño.') item.add_item('Almacene el bagazo por dos semanas en la bagacera, y así, obtendrá un bagazo con al menos un 30% de humedad.') item.add_item('Ajuste el tiro de la chimenea usando la válvula mariposa cuando tenga bagazo con mayor humedad.') item.add_item('La válvula no opera en tiempo real y cuando se encuentra a medio cerrar se aumenta la velocidad de calentamiento en la zona de evaporación al pie de la entrada del bagazo. Sin embargo, cuando se encuentra abierta el calentamiento se presenta al pie de la chimenea.') item.add_item('El tiempo de residencia del jugo en la hornilla, influye en la calidad de la panela y este es directamente proporcional al aumento de los azucares invertidos.') item.add_item('Las falcas en las pailas son de seguridad, no deben usarse para contener una mayor cantidad de jugo. Por tanto para aumentar la transferencia de calor al jugo y mejorar la calidad de la panela es importante manejar la cantidad de jugo mínima en cada paila.') item.add_item('El nivel del jugo en las pailas semiesféricas, siempre debe estar por encima de la línea de contacto de los gases de combustión con la paila a fin de evitar quemadura en la panela.') item.add_item('La paila clarificadora debe calentar lo más rápido posible para que permita remover la cachaza. Además, la velocidad mínima de calentamiento debe ser de 1.5°C/min.') item.add_item('Elimine residuos de la caña o jugos presentes sobre la superficie de las pailas concentradoras de panela y cachaza periódicamente, para que el producto se pegue al fondo. Lo cual disminuye el paso del calor y deterioran la calidad del producto.') tlg.append(LargeText(bold('Mantenimiento de la hornilla'))) with tlg.create(Itemize()) as itemize: itemize.add_item('Después de cada molienda.') with itemize.create(Itemize()) as item: item.add_item('Limpie y desinfecte las instalaciones, pailas, equipos y utensilios, antes de iniciar nuevamente la producción de panela.') item.add_item('Un encelamiento de los moldes, utensilios de madera y prelimpiadores.') item.add_item('Dejar en remojo con agua limpia las pailas durante el enfriamiento de la hornilla.') item.add_item('Retirar la ceniza del cenicero y el ducto.') with tlg.create(Itemize()) as itemize: itemize.add_item('Cada seis moliendas.') with itemize.create(Itemize()) as item: item.add_item('Retirar el hollín formado en la superficie de las pailas, por donde se transfiere el calor.') item.add_item('Limpiar los ductos de las pailas piro-tubulares, con ayuda de un raspador o un costal de fique.') with tlg.create(Itemize()) as itemize: itemize.add_item('Cada seis meses.') with itemize.create(Itemize()) as item: item.add_item('Realice una limpieza general e inspección del estado de los ductos.') item.add_item('Realice un mantenimiento de las paredes del ducto y la cámara.') tlg.append(LargeText(bold('Recomendaciones de construcción del trapiche'))) with tlg.create(Itemize()) as itemize: itemize.add_item('Algunos parámetros para tener en cuenta son.') with itemize.create(Itemize()) as item: item.add_item('El suministro de agua ser potable y continuo.') item.add_item('Los alrededores de las fábricas deben estar libre de posibles focos de infección.') item.add_item('Las áreas de trabajo de cada subproceso deben estar delimitadas.') item.add_item('Las áreas de procesamiento y empaque deben estar separadas de las áreas de recepción y desechos.') item.add_item('Las uniones de las baldosas deben recubrirse de materiales plásticos que faciliten la limpieza.') item.add_item('Las salientes de las paredes, dinteles de ventanas y suspensiones del techo deben ser curvas e inclinadas.') item.add_item('Los pisos y las paredes se deben construir con materiales anticorrosivos, no absorbentes y de alto transito.') item.add_item('Las áreas de procesos deben tener en el centro un canal de drenaje con 3° de inclinación y una parrilla removible para realizar su limpieza.') item.add_item('Los pisos deben tener una leve inclinación (3°) para realizar el drenado.') item.add_item('Los desagües deben tener rejillas de seguridad para impedir el paso de animales.') item.add_item('Los ambientes debe ser ventilados.') item.add_item('Los vapores deben contar con su propio escape para evitar la presencia de moho en paredes y techos.') item.add_item('Los ductos de ventilación deben estar cubiertos de mallas protectoras.') item.add_item('Los ambientes deben estar bien iluminados.') item.add_item('Las bases o cimientos deben ser lisos para evitar la presencia de insectos o residuos.') item.add_item('Los espacios entre los equipos o equipos y paredes deben estar sellados.') item.add_item('Los baños, habitaciones y casilleros, deben estar aseados y alejados de las áreas de procesamiento y producto terminado.') item.add_item('Las diferentes áreas deben disponer de un sitio para el aseo de las manos con sus respectivos implementos, tales como; jabón líquido, cepillos y toallas desechables.') tlg.append(LargeText(bold('Higiene y desinfección en el trapiche'))) with tlg.create(Itemize()) as itemize: itemize.add_item('Tenga en cuenta las siguientes indicaciones para su cuidado personal.') with itemize.create(Itemize()) as item: item.add_item('El objetivo de la higiene en los alimentos es alargar la vida útil del producto, y proteger al consumidor final de las enfermedades producidas al ingerir alimentos contaminados.') item.add_item('La higienización de un trapiche requiere de una limpieza con detergente y de una esterilización industrial o satanización (desinfectante y bactericida).') item.add_item('Los equipos y utensilios deben limpiarse y desinfectarse al final e inicio de cada molienda.') item.add_item('La limpieza se realiza siguiendo estas pautas: proteger las materias prima y los productos terminados, raspar los residuos sólidos con una espátula sobre un recogedor y lavar con agua limpia, cepillo y detergente') item.add_item('La esterilización se realiza con calor (vapor de agua, agua hirviendo), o un esterilizante químico (bactericida, desinfectante).Cuando se emplea agua caliente debe estar hirviendo (90°C) o en el caso del esterilizante químico puede usarse una solución clorada, de vinagre y una lechada de cal.') item.add_item('Las soluciones desinfectantes deben aplicarse en solución con un rociador, empezando por la parte inferior.') item.add_item('Antes de la esterilización la superficie debe estar limpia y totalmente escurrida.') item.add_item('Las superficies en contacto con el alimento deben ser lisas, exentas de huecos, grietas y evitar las esquinas cuadradas.') item.add_item('La industria de alimentos usa ampliamente el acero inoxidable y plásticos como el teflón por la facilidad de higienización, y su poca alteración al contacto con los alimentos.') item.add_item('No debe usarse el cobre, bronce, estaño, aluminio, madera y zinc para las superficies que están en contacto con el alimento.') item.add_item('No emplee en la limpieza esponjas o cepillos metálicos que rayen las superficies.') item.add_item('Las pailas se lavan con arena de peña y esponja para desmancharla.') item.add_item('Ningún tipo de rosca debe estar en contacto con el alimento.') item.add_item('Se debe mantener una inclinación de superficies y tubería para el drenaje de 1 centímetro por metro.') item.add_item('Se deben usar conexiones hidraulicas y uniones que sean de fácil limpieza.') item.add_item('Se debe evitar la unión de acero inoxidable con otros metales.') item.add_item('El hipoclorito ejerce una rápida acción bactericida sin dejar residuos tóxicos.') item.add_item('No es aconsejable el uso de cloro en material de acero inoxidable.') item.add_item('En la esterilización del acero inoxidable, puede utilizarse agua caliente, vapor o solución de 0.25 litros de vinagre en 10 litros de agua.') item.add_item('Los materiales plásticos se deben lavar con una solución de 5.0 gramos de bicarbonato (2 cucharadas) en l0 litros de agua clorada y dejar secar durante 30 minutos.') item.add_item('La esterilización del acero inoxidable puede hacerse con agua caliente, vapor o solución de 0.25 litros de vinagre en 10 litros de agua.') item.add_item('Las superficies de madera se limpian con espátula para eliminar los residuos sólidos. Después remojar en detergente durante 5 minutos, luego cepillar, lavar con agua limpia, y finalmente rociar con solución de 12 gramos de cal (una cucharadita) en 10 litros de agua dejar secar.') item.add_item('Los utensilios de madera se dejan en un recipiente plástico limpio, con solución de 12 gramos de cal (una cucharadita) en 10 litros de agua.') item.add_item('Cambiar la solución donde se sumergen los utensilios de madera cada cuatro horas.') item.add_item('Los utensilios y gaveras no deben dejarse sobre el suelo o superficies no desinfectadas.') item.add_item('Evitar la caída de grasa mecánica en los alimentos.') doc.append(NewPage())
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)