Python reportlab.pdfgen.canvas.Canvas() Examples
The following are 30
code examples of reportlab.pdfgen.canvas.Canvas().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
reportlab.pdfgen.canvas
, or try the search function
.
Example #1
Source File: pdfgenerator.py From anti-XSS with MIT License | 7 votes |
def __init__(self, text=[], target='your website', pdfName='Report.pdf'): self.__target = target self.__pdfName = self.__path + pdfName self.__text = text if not os.path.exists('result/'): os.mkdir(r'result/') time = datetime.datetime.today() date = time.strftime("%h-%d-%Y %H:%M:%S") c = canvas.Canvas(self.__pdfName) c.setPageSize((16 * inch,22 * inch)) textobj = c.beginText() textobj.setTextOrigin(inch, 20 * inch) textobj.textLines(''' This is the scanning report of %s. ''' %self.__target) textobj.textLines(''' Date: %s ''' % date) for line in self.__text: textobj.textLine(line.strip()) c.drawText(textobj) c.showPage() c.save()
Example #2
Source File: doctemplate.py From Fluid-Designer with GNU General Public License v3.0 | 7 votes |
def build(self,flowables,onFirstPage=_doNothing, onLaterPages=_doNothing, canvasmaker=canvas.Canvas): """build the document using the flowables. Annotate the first page using the onFirstPage function and later pages using the onLaterPages function. The onXXX pages should follow the signature def myOnFirstPage(canvas, document): # do annotations and modify the document ... The functions can do things like draw logos, page numbers, footers, etcetera. They can use external variables to vary the look (for example providing page numbering or section names). """ self._calc() #in case we changed margins sizes etc frameT = Frame(self.leftMargin, self.bottomMargin, self.width, self.height, id='normal') self.addPageTemplates([PageTemplate(id='First',frames=frameT, onPage=onFirstPage,pagesize=self.pagesize), PageTemplate(id='Later',frames=frameT, onPage=onLaterPages,pagesize=self.pagesize)]) if onFirstPage is _doNothing and hasattr(self,'onFirstPage'): self.pageTemplates[0].beforeDrawPage = self.onFirstPage if onLaterPages is _doNothing and hasattr(self,'onLaterPages'): self.pageTemplates[1].beforeDrawPage = self.onLaterPages BaseDocTemplate.build(self,flowables, canvasmaker=canvasmaker)
Example #3
Source File: PlotDecomposition_SBS1536.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def gen_decomposition(denovo_name, basis_names, weights, output_path, project, reconstruction, statistics): # Note: 0th index contains the title of the column c = canvas.Canvas(output_path+"/"+denovo_name+"_decomposition_"+project+".pdf", pagesize=letter) c.setPageSize(landscape(letter)) c.setFont("Arial-Bold", 7.19) basis_plots = [] for i in range(0,len(basis_names)): basis_plots.append([basis_names[i], weights[i]]) # create for loop to iterate through list, then change second value in list of lists # Otherwise sorts strings and then 5.14% > 48.54% for j in range(0, len(basis_names)): basis_plots[j][1] = float(basis_plots[j][1].strip("%")) sorted_list = sorted(basis_plots, key=lambda tup: tup[1], reverse=True) gen_plot(denovo_name, sorted_list, output_path, project, c, reconstruction, statistics) c.save()
Example #4
Source File: PlotDecomposition_DBS78.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def gen_decomposition(denovo_name, basis_names, weights, output_path, project, reconstruction, statistics): c = canvas.Canvas(output_path+"/"+denovo_name+"_decomposition_"+project+".pdf", pagesize=letter) c.setPageSize(landscape(letter)) c.setFont("Arial-Bold", 7.19) basis_plots = [] for i in range(0,len(basis_names)): basis_plots.append([basis_names[i], weights[i]]) # create for loop to iterate through list, then change second value in list of lists # Otherwise sorts strings and then 5.14% > 48.54% for j in range(0, len(basis_names)): basis_plots[j][1] = float(basis_plots[j][1].strip("%")) sorted_list = sorted(basis_plots, key=lambda tup: tup[1], reverse=True) gen_plot(denovo_name, sorted_list, output_path, project, c, reconstruction, statistics) c.save()
Example #5
Source File: pycanvas.py From stdm with GNU General Public License v2.0 | 6 votes |
def __init__(self, *args, **kwargs) : """Initialize and begins source code.""" self._parent = self # nice trick, isn't it ? self._in = 0 self._contextlevel = 0 self._pagenumber = 1 self._formnumber = 0 self._footerpresent = 0 self._object = canvas.Canvas(*args,**kwargs) self._enforceColorSpace = self._object._enforceColorSpace self._pyfile = cStringIO.StringIO() self._PyWrite(PyHeader) try : del kwargs["filename"] except KeyError : pass self._PyWrite(" # create the PDF document\n %s = Canvas(file, %s)\n\n # Begins page 1" % (self._name, buildargs(*args[1:], **kwargs)))
Example #6
Source File: pdfencrypt.py From stdm with GNU General Public License v2.0 | 6 votes |
def __init__(self, userPassword, ownerPassword=None, canPrint=1, canModify=1, canCopy=1, canAnnotate=1, strength=40): ''' This class defines the encryption properties to be used while creating a pdf document. Once initiated, a StandardEncryption object can be applied to a Canvas or a BaseDocTemplate. The userPassword parameter sets the user password on the encrypted pdf. The ownerPassword parameter sets the owner password on the encrypted pdf. The boolean flags canPrint, canModify, canCopy, canAnnotate determine wether a user can perform the corresponding actions on the pdf when only a user password has been supplied. If the user supplies the owner password while opening the pdf, all actions can be performed regardless of the flags. Note that the security provided by these encryption settings (and even more so for the flags) is very weak. ''' self.ownerPassword = ownerPassword self.userPassword = userPassword if strength == 40: self.revision = 2 elif strength == 128: self.revision = 3 self.canPrint = canPrint self.canModify = canModify self.canCopy = canCopy self.canAnnotate = canAnnotate self.O = self.U = self.P = self.key = None
Example #7
Source File: PlotDecomposition_DBS78.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def draw_bracket(num_bases, c_draw): paths = cosmic.__path__[0] num_plts = num_bases - 1 if(num_bases>= 5): num_plts = 4 c_draw.drawImage(paths+"/src/Accolade_fermante.png", MID_WIDTH_LETTER - 15, \ BRACKET_SIZES[num_plts][0], width = 20, height = BRACKET_SIZES[num_plts][1], mask='auto') # Parameters: # de_novo_name - (String) The name of the denovo signature. # basis_names - (List of Strings) The names of the basis signatures # output_path - (String) Path to where to save the output. # project - (String) The project name that is appended to file names. # c - (Canvas) The canvas that is being drawn on. # reconstruction - (Boolean) True to create reconstruction # statistics - (Pandas Dataframe) If reconstructing, then include statistics. # Output: # A graph of the de_novo signature's decomposition.
Example #8
Source File: PlotDecomposition_DBS78.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def draw_statistics(c_draw, statistics): cos_sim = statistics["Cosine Similarity"][0] cor_coeff = statistics["Correlation Coefficient"][0] l1_norm_percent = statistics["L1 Norm %"][0] l2_norm_percent = statistics["L2 Norm %"][0] kl_divergence = statistics["KL Divergence"][0] c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-90, \ "Cosine Similarity: " + str(cos_sim)) c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-100, \ "Correlation: " + str(cor_coeff)) c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-110, \ "L1 Error %: " + str(l1_norm_percent) + "%") c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-120, \ "L2 Error %: " + str(l2_norm_percent) + "%") c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-130, \ "KL Divergence: " + str(kl_divergence)) # Helper function to resize bracket depending on number of bases plotted # Parameters: # num_bases - (Integer) The number of bases to be plotted. # c_draw - (Canvas) The canvas to draw the graph decomposition on.
Example #9
Source File: pdf_form_display.py From intake with MIT License | 6 votes |
def __init__(self, display_form, letter_display=None, canvas=None): self.file = io.BytesIO() self.width, self.height = letter self.canvas = canvas if not canvas: self.canvas = Canvas( self.file, pagesize=letter) self.canvas.setAuthor('Clear My Record, Code for America') self.frame = Margin( u('1in'), u('.75in'), u('1in'), u('.75in')) self.form = display_form self.letter = letter_display self.cursor = Position( self.frame.left, self.height - self.frame.top ) self.nice_date = \ self.form.date_received.get_current_value().strftime("%B %-d, %Y")
Example #10
Source File: PlotDecomposition_DBS78.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def plot_6_plus(bases, output_path, project, c_draw): for i in range(0,5): c_draw.drawImage(output_path+"/DBS_sub_plots/"+bases[i][0] + "_" + project+".png", \ LAYOUT_5_GRAPH[i][X_COORD], LAYOUT_5_GRAPH[i][Y_COORD], width=WIDTH_GRAPH, height=HEIGHT_GRAPH) c_draw.drawString(LAYOUT_5_TEXT[i][X_COORD], LAYOUT_5_TEXT[i][Y_COORD], str(bases[i][1]) + "%") extra_sigs = "* " for i in range(5, len(bases)-1): extra_sigs += str(bases[i][0]) + " (" + str(bases[i][1]) + "%), " extra_sigs += bases[len(bases)-1][0] + " (" + str(bases[len(bases)-1][1]) + "%)" c_draw.drawString(GRAPH_X_COORD, (TEXT_Y_COORD - HEIGHT_GRAPH * 6) - 10, extra_sigs) # Helper function to add calculations to layout # Parameters: # c_draw - (Canvas) The canvas to draw the graph decomposition on. # statistics - (Pandas Dataframe) Dataframe w/ calculations
Example #11
Source File: PlotDecomposition_SBS96.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def plot_6_plus(bases, output_path, project, c_draw): for i in range(0,5): c_draw.drawImage(output_path+"/SBS_sub_plots/"+bases[i][0] + "_" + project+".png", \ LAYOUT_5_GRAPH[i][X_COORD], LAYOUT_5_GRAPH[i][Y_COORD], width=WIDTH_GRAPH, height=HEIGHT_GRAPH) c_draw.drawString(LAYOUT_5_TEXT[i][X_COORD], LAYOUT_5_TEXT[i][Y_COORD], str(bases[i][1]) + "%") extra_sigs = "* " for i in range(5, len(bases)-1): extra_sigs += str(bases[i][0]) + " (" + str(bases[i][1]) + "%), " extra_sigs += bases[len(bases)-1][0] + " (" + str(bases[len(bases)-1][1]) + "%)" c_draw.drawString(GRAPH_X_COORD, (TEXT_Y_COORD - HEIGHT_GRAPH * 6) - 10, extra_sigs) # Helper function to add calculations to layout # Parameters: # c_draw - (Canvas) The canvas to draw the graph decomposition on. # statistics - (Pandas Dataframe) Dataframe w/ calculations
Example #12
Source File: PlotDecomposition_SBS96.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def draw_statistics(c_draw, statistics): cos_sim = statistics["Cosine Similarity"][0] cor_coeff = statistics["Correlation Coefficient"][0] l1_norm_percent = statistics["L1 Norm %"][0] l2_norm_percent = statistics["L2 Norm %"][0] kl_divergence = statistics["KL Divergence"][0] c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-90, \ "Cosine Similarity: " + str(cos_sim)) c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-100, \ "Correlation: " + str(cor_coeff)) c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-110, \ "L1 Error %: " + str(l1_norm_percent) + "%") c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-120, \ "L2 Error %: " + str(l2_norm_percent) + "%") c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-130, \ "KL Divergence: " + str(kl_divergence)) # Helper function to resize bracket depending on number of bases plotted # Parameters: # num_bases - (Integer) The number of bases to be plotted. # c_draw - (Canvas) The canvas to draw the graph decomposition on.
Example #13
Source File: PlotDecomposition_SBS96.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def draw_bracket(num_bases, c_draw): paths = cosmic.__path__[0] num_plts = num_bases - 1 if(num_bases >= 5): num_plts = 4 c_draw.drawImage(paths+"/src/Accolade_fermante.png", MID_WIDTH_LETTER - 15, BRACKET_SIZES[num_plts][0], width = 20, height = BRACKET_SIZES[num_plts][1], mask='auto') # Parameters: # de_novo_name - (String) The name of the denovo signature. # basis_names - (List of Strings) The names of the basis signatures # output_path - (String) Path to where to save the output. # project - (String) The project name that is appended to file names. # c - (Canvas) The canvas that is being drawn on. # reconstruction - (Boolean) True to create reconstruction # statistics - (Pandas Dataframe) If reconstructing, then include statistics. # Output: # A graph of the de_novo signature's decomposition.
Example #14
Source File: PlotDecomposition_SBS96.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def gen_decomposition(denovo_name, basis_names, weights, output_path, project, reconstruction, statistics): c = canvas.Canvas(output_path+"/"+denovo_name+"_decomposition_"+project+".pdf", pagesize=letter) c.setPageSize(landscape(letter)) c.setFont("Arial-Bold", 7.19) basis_plots = [] for i in range(0,len(basis_names)): basis_plots.append([basis_names[i], weights[i]]) # create for loop to iterate through list, then change second value in list of lists # Otherwise sorts strings and then 5.14% > 48.54% for j in range(0, len(basis_names)): basis_plots[j][1] = float(basis_plots[j][1].strip("%")) sorted_list = sorted(basis_plots, key=lambda tup: tup[1], reverse=True) gen_plot(denovo_name, sorted_list, output_path, project, c, reconstruction, statistics) c.save()
Example #15
Source File: PlotDecomposition_ID83.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def plot_6_plus(bases, output_path, project, c_draw): for i in range(0,5): c_draw.drawImage(output_path+"/ID_sub_plots/"+bases[i][0] + "_" + project+".png", LAYOUT_5_GRAPH[i][X_COORD], LAYOUT_5_GRAPH[i][Y_COORD], width=WIDTH_GRAPH, height=HEIGHT_GRAPH) c_draw.drawString(LAYOUT_5_TEXT[i][X_COORD], LAYOUT_5_TEXT[i][Y_COORD], str(bases[i][1]) + "%") extra_sigs = "* " for i in range(5, len(bases)-1): extra_sigs += str(bases[i][0]) + " (" + str(bases[i][1]) + "%), " extra_sigs += bases[len(bases)-1][0] + " (" + str(bases[len(bases)-1][1]) + "%)" c_draw.drawString(GRAPH_X_COORD, (TEXT_Y_COORD - HEIGHT_GRAPH * 6) + 30, extra_sigs) # Helper function to add calculations to layout # Parameters: # c_draw - (Canvas) The canvas to draw the graph decomposition on. # statistics - (Pandas Dataframe) Dataframe w/ calculations
Example #16
Source File: PlotDecomposition_ID83.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def draw_bracket(num_bases, c_draw): paths = cosmic.__path__[0] num_plts = num_bases - 1 if(num_bases >= 5): num_plts = 4 c_draw.drawImage(paths+"/src/Accolade_fermante.png", MID_WIDTH_LETTER - 15, BRACKET_SIZES[num_plts][0], width = 15, height = BRACKET_SIZES[num_plts][1], mask='auto') # Parameters: # de_novo_name - (String) The name of the denovo signature. # basis_names - (List of Strings) The names of the basis signatures # output_path - (String) Path to where to save the output. # project - (String) The project name that is appended to file names. # c - (Canvas) The canvas that is being drawn on. # reconstruction - (Boolean) True to create reconstruction # statistics - (Pandas Dataframe) If reconstructing, then include statistics. # Output: # A graph of the de_novo signature's decomposition.
Example #17
Source File: PlotDecomposition_ID83.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def gen_decomposition(denovo_name, basis_names, weights, output_path, project, reconstruction, statistics): # Note: 0th index contains the title of the column c = canvas.Canvas(output_path+"/"+denovo_name+"_decomposition_"+project+".pdf", pagesize=letter) c.setPageSize(landscape(letter)) c.setFont("Arial-Bold", 7.19) basis_plots = [] for i in range(0,len(basis_names)): basis_plots.append([basis_names[i], weights[i]]) # create for loop to iterate through list, then change second value in list of lists # Otherwise sorts strings and then 5.14% > 48.54% for j in range(0, len(basis_names)): basis_plots[j][1] = float(basis_plots[j][1].strip("%")) sorted_list = sorted(basis_plots, key=lambda tup: tup[1], reverse=True) gen_plot(denovo_name, sorted_list, output_path, project, c, reconstruction, statistics) c.save()
Example #18
Source File: PlotDecomposition_DBS78.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def plot_6_plus(bases, output_path, project, c_draw): for i in range(0,5): c_draw.drawImage(output_path+"/DBS_sub_plots/"+bases[i][0] + "_" + project+".png", \ LAYOUT_5_GRAPH[i][X_COORD], LAYOUT_5_GRAPH[i][Y_COORD], width=WIDTH_GRAPH, height=HEIGHT_GRAPH) c_draw.drawString(LAYOUT_5_TEXT[i][X_COORD], LAYOUT_5_TEXT[i][Y_COORD], str(bases[i][1]) + "%") extra_sigs = "* " for i in range(5, len(bases)-1): extra_sigs += str(bases[i][0]) + " (" + str(bases[i][1]) + "%), " extra_sigs += bases[len(bases)-1][0] + " (" + str(bases[len(bases)-1][1]) + "%)" c_draw.drawString(GRAPH_X_COORD, (TEXT_Y_COORD - HEIGHT_GRAPH * 6) - 10, extra_sigs) # Helper function to add calculations to layout # Parameters: # c_draw - (Canvas) The canvas to draw the graph decomposition on. # statistics - (Pandas Dataframe) Dataframe w/ calculations
Example #19
Source File: PlotDecomposition_DBS78.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def draw_statistics(c_draw, statistics): cos_sim = statistics["Cosine Similarity"][0] cor_coeff = statistics["Correlation Coefficient"][0] l1_norm_percent = statistics["L1 Norm %"][0] l2_norm_percent = statistics["L2 Norm %"][0] kl_divergence = statistics["KL Divergence"][0] c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-90, \ "Cosine Similarity: " + str(cos_sim)) c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-100, \ "Correlation: " + str(cor_coeff)) c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-110, \ "L1 Error %: " + str(l1_norm_percent) + "%") c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-120, \ "L2 Error %: " + str(l2_norm_percent) + "%") c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-130, \ "KL Divergence: " + str(kl_divergence)) # Helper function to resize bracket depending on number of bases plotted # Parameters: # num_bases - (Integer) The number of bases to be plotted. # c_draw - (Canvas) The canvas to draw the graph decomposition on.
Example #20
Source File: PlotDecomposition_DBS78.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def draw_bracket(num_bases, c_draw): paths = cosmic.__path__[0] num_plts = num_bases - 1 if(num_bases>= 5): num_plts = 4 c_draw.drawImage(paths+"/src/Accolade_fermante.png", MID_WIDTH_LETTER - 15, \ BRACKET_SIZES[num_plts][0], width = 20, height = BRACKET_SIZES[num_plts][1], mask='auto') # Parameters: # de_novo_name - (String) The name of the denovo signature. # basis_names - (List of Strings) The names of the basis signatures # output_path - (String) Path to where to save the output. # project - (String) The project name that is appended to file names. # c - (Canvas) The canvas that is being drawn on. # reconstruction - (Boolean) True to create reconstruction # statistics - (Pandas Dataframe) If reconstructing, then include statistics. # Output: # A graph of the de_novo signature's decomposition.
Example #21
Source File: PlotDecomposition_SBS1536.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def plot_6_plus(bases, output_path, project, c_draw): for i in range(0,5): c_draw.drawImage(output_path+"/SBS_sub_plots/"+bases[i][0] + "_" + project+".png", \ LAYOUT_5_GRAPH[i][X_COORD], LAYOUT_5_GRAPH[i][Y_COORD], width=WIDTH_GRAPH, height=HEIGHT_GRAPH) c_draw.drawString(LAYOUT_5_TEXT[i][X_COORD], LAYOUT_5_TEXT[i][Y_COORD], str(bases[i][1]) + "%") extra_sigs = "* " for i in range(5, len(bases)-1): extra_sigs += str(bases[i][0]) + " (" + str(bases[i][1]) + "%), " extra_sigs += bases[len(bases)-1][0] + " (" + str(bases[len(bases)-1][1]) + "%)" c_draw.drawString(GRAPH_X_COORD, (TEXT_Y_COORD - HEIGHT_GRAPH * 6) - 10, extra_sigs) # Helper function to add calculations to layout # Parameters: # c_draw - (Canvas) The canvas to draw the graph decomposition on. # statistics - (Pandas Dataframe) Dataframe w/ calculations
Example #22
Source File: PlotDecomposition_SBS1536.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def draw_statistics(c_draw, statistics): cos_sim = statistics["Cosine Similarity"][0] cor_coeff = statistics["Correlation Coefficient"][0] l1_norm_percent = statistics["L1 Norm %"][0] l2_norm_percent = statistics["L2 Norm %"][0] kl_divergence = statistics["KL Divergence"][0] c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-90, \ "Cosine Similarity: " + str(cos_sim)) c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-100, \ "Correlation: " + str(cor_coeff)) c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-110, \ "L1 Error %: " + str(l1_norm_percent) + "%") c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-120, \ "L2 Error %: " + str(l2_norm_percent) + "%") c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-130, \ "KL Divergence: " + str(kl_divergence)) # Helper function to resize bracket depending on number of bases plotted # Parameters: # num_bases - (Integer) The number of bases to be plotted. # c_draw - (Canvas) The canvas to draw the graph decomposition on.
Example #23
Source File: PlotDecomposition_SBS1536.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def draw_bracket(num_bases, c_draw): num_plts = num_bases - 1 if(num_bases >= 5): num_plts = 4 c_draw.drawImage(paths+"src/Accolade_fermante.png", MID_WIDTH_LETTER - 15, \ BRACKET_SIZES[num_plts][0], width = 20, height = BRACKET_SIZES[num_plts][1], \ mask='auto') # Parameters: # de_novo_name - (String) The name of the denovo signature. # basis_names - (List of Strings) The names of the basis signatures # output_path - (String) Path to where to save the output. # project - (String) The project name that is appended to file names. # c - (Canvas) The canvas that is being drawn on. # reconstruction - (Boolean) True to create reconstruction # statistics - (Pandas Dataframe) If reconstructing, then include statistics. # Output: # A graph of the de_novo signature's decomposition.
Example #24
Source File: PlotDecomposition_SBS1536.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def gen_decomposition(denovo_name, basis_names, weights, output_path, project, reconstruction, statistics): # Note: 0th index contains the title of the column c = canvas.Canvas(output_path+"/"+denovo_name+"_decomposition_"+project+".pdf", pagesize=letter) c.setPageSize(landscape(letter)) c.setFont("Arial-Bold", 7.19) basis_plots = [] for i in range(0,len(basis_names)): basis_plots.append([basis_names[i], weights[i]]) # create for loop to iterate through list, then change second value in list of lists # Otherwise sorts strings and then 5.14% > 48.54% for j in range(0, len(basis_names)): basis_plots[j][1] = float(basis_plots[j][1].strip("%")) sorted_list = sorted(basis_plots, key=lambda tup: tup[1], reverse=True) gen_plot(denovo_name, sorted_list, output_path, project, c, reconstruction, statistics) c.save()
Example #25
Source File: PlotDecomposition_SBS96.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def plot_6_plus(bases, output_path, project, c_draw): for i in range(0,5): c_draw.drawImage(output_path+"/SBS_sub_plots/"+bases[i][0] + "_" + project+".png", \ LAYOUT_5_GRAPH[i][X_COORD], LAYOUT_5_GRAPH[i][Y_COORD], width=WIDTH_GRAPH, height=HEIGHT_GRAPH) c_draw.drawString(LAYOUT_5_TEXT[i][X_COORD], LAYOUT_5_TEXT[i][Y_COORD], str(bases[i][1]) + "%") extra_sigs = "* " for i in range(5, len(bases)-1): extra_sigs += str(bases[i][0]) + " (" + str(bases[i][1]) + "%), " extra_sigs += bases[len(bases)-1][0] + " (" + str(bases[len(bases)-1][1]) + "%)" c_draw.drawString(GRAPH_X_COORD, (TEXT_Y_COORD - HEIGHT_GRAPH * 6) - 10, extra_sigs) # Helper function to add calculations to layout # Parameters: # c_draw - (Canvas) The canvas to draw the graph decomposition on. # statistics - (Pandas Dataframe) Dataframe w/ calculations
Example #26
Source File: PlotDecomposition_SBS96.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def draw_bracket(num_bases, c_draw): paths = cosmic.__path__[0] num_plts = num_bases - 1 if(num_bases >= 5): num_plts = 4 c_draw.drawImage(paths+"/src/Accolade_fermante.png", MID_WIDTH_LETTER - 15, BRACKET_SIZES[num_plts][0], width = 20, height = BRACKET_SIZES[num_plts][1], mask='auto') # Parameters: # de_novo_name - (String) The name of the denovo signature. # basis_names - (List of Strings) The names of the basis signatures # output_path - (String) Path to where to save the output. # project - (String) The project name that is appended to file names. # c - (Canvas) The canvas that is being drawn on. # reconstruction - (Boolean) True to create reconstruction # statistics - (Pandas Dataframe) If reconstructing, then include statistics. # Output: # A graph of the de_novo signature's decomposition.
Example #27
Source File: PlotDecomposition_SBS96.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def gen_decomposition(denovo_name, basis_names, weights, output_path, project, reconstruction, statistics): c = canvas.Canvas(output_path+"/"+denovo_name+"_decomposition_"+project+".pdf", pagesize=letter) c.setPageSize(landscape(letter)) c.setFont("Arial-Bold", 7.19) basis_plots = [] for i in range(0,len(basis_names)): basis_plots.append([basis_names[i], weights[i]]) # create for loop to iterate through list, then change second value in list of lists # Otherwise sorts strings and then 5.14% > 48.54% for j in range(0, len(basis_names)): basis_plots[j][1] = float(basis_plots[j][1].strip("%")) sorted_list = sorted(basis_plots, key=lambda tup: tup[1], reverse=True) gen_plot(denovo_name, sorted_list, output_path, project, c, reconstruction, statistics) c.save()
Example #28
Source File: PlotDecomposition_ID83.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def plot_6_plus(bases, output_path, project, c_draw): for i in range(0,5): c_draw.drawImage(output_path+"/ID_sub_plots/"+bases[i][0] + "_" + project+".png", LAYOUT_5_GRAPH[i][X_COORD], LAYOUT_5_GRAPH[i][Y_COORD], width=WIDTH_GRAPH, height=HEIGHT_GRAPH) c_draw.drawString(LAYOUT_5_TEXT[i][X_COORD], LAYOUT_5_TEXT[i][Y_COORD], str(bases[i][1]) + "%") extra_sigs = "* " for i in range(5, len(bases)-1): extra_sigs += str(bases[i][0]) + " (" + str(bases[i][1]) + "%), " extra_sigs += bases[len(bases)-1][0] + " (" + str(bases[len(bases)-1][1]) + "%)" c_draw.drawString(GRAPH_X_COORD, (TEXT_Y_COORD - HEIGHT_GRAPH * 6) + 30, extra_sigs) # Helper function to add calculations to layout # Parameters: # c_draw - (Canvas) The canvas to draw the graph decomposition on. # statistics - (Pandas Dataframe) Dataframe w/ calculations
Example #29
Source File: PlotDecomposition_ID83.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def draw_statistics(c_draw, statistics): cos_sim = statistics["Cosine Similarity"][0] cos_dist = statistics["Cosine Distance"][0] cor_dist = statistics["Correlation Distance"][0] cor_coeff = statistics["Correlation Coefficient"][0] l1_norm_percent = statistics["L1 Norm %"][0] l2_norm_percent = statistics["L2 Norm %"][0] kl_divergence = statistics["KL Divergence"][0] c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-90, \ "Cosine Similarity: " + str(cos_sim)) c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-100, \ "Correlation: " + str(cor_coeff)) c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-110, \ "L1 Error %: " + str(l1_norm_percent) + "%") c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-120, \ "L2 Error %: " + str(l2_norm_percent) + "%") c_draw.drawString(WIDTH_GAP+15, LAYOUT_2_TEXT[1][Y_COORD]-130, \ "KL Divergence: " + str(kl_divergence)) # Helper function to resize bracket depending on number of bases plotted # Parameters: # num_bases - (Integer) The number of bases to be plotted. # c_draw - (Canvas) The canvas to draw the graph decomposition on.
Example #30
Source File: PlotDecomposition_ID83.py From SigProfilerExtractor with BSD 2-Clause "Simplified" License | 6 votes |
def draw_bracket(num_bases, c_draw): paths = cosmic.__path__[0] num_plts = num_bases - 1 if(num_bases >= 5): num_plts = 4 c_draw.drawImage(paths+"/src/Accolade_fermante.png", MID_WIDTH_LETTER - 15, BRACKET_SIZES[num_plts][0], width = 15, height = BRACKET_SIZES[num_plts][1], mask='auto') # Parameters: # de_novo_name - (String) The name of the denovo signature. # basis_names - (List of Strings) The names of the basis signatures # output_path - (String) Path to where to save the output. # project - (String) The project name that is appended to file names. # c - (Canvas) The canvas that is being drawn on. # reconstruction - (Boolean) True to create reconstruction # statistics - (Pandas Dataframe) If reconstructing, then include statistics. # Output: # A graph of the de_novo signature's decomposition.