oncoplot_extractor package

oncoplot_extractor.errors module

General Error classes for OncoPlot Extractor

exception oncoplot_extractor.errors.OncoPlotExtractorError(msg)

Bases: Exception

Base class for all OncoPlot Extractor errors.

exception oncoplot_extractor.errors.OncoPlotPlotterError(msg)

Bases: Exception

Base class for all OncoPlot Plotter errors.

oncoplot_extractor.main module

Contains OncoPlotExtractor class.

class oncoplot_extractor.main.OncoplotExtractor(path: str, corners: Optional[tuple] = None, background_color: list = ['#ffffff'], gene_list: Optional[list] = None)

Bases: object

Extracts oncoplot data from oncoplot image and exports to excel.

Parameters
  • path – path to oncoplot image [str] : required

  • corners – (x1, y1, x2, y2) top left and bottom right corner of oncoplot [tuple] : optional

  • background_color – background color of oncoplot [list] : optional

  • gene_list – list of genes to extract [list] : optional

Example

oce = OncoplotExtractor(path="path/to/oncoplot.png", corners=(0,0,100,100), background_color=["#ffffff"])
oce.extract()
oce.export_to_excel("path/to/oncoplot.xlsx")
BG_COLOR: list
CORNERS: tuple
DATA_AS_DICT: DefaultDict = {}
FILEPATH: str
GENE_LIST: list
IMG: PIL.Image.Image
property as_dataframe: pandas.core.frame.DataFrame

Returns oncoplot data as pandas dataframe.

property as_dict: DefaultDict

Returns oncoplot data as dictionary.

background_color(coord: tuple) list

Returns background color of pixel at coord. :param coord: (x,y) coordinate of pixel

export_to_excel(filepath: str) None

Exports oncoplot data to excel. :param filepath: path to excel file to export to.

export_to_json(filepath: str) None

Exports oncoplot data to json. :param filepath: path to json file to export to.

extract() None

Extracts oncoplot data from image. Expects class to have been initialized with a valid image file

get_background_from_pixel(coord: tuple) None

sets background color of image at coord so this pixel is filtered. :param coord: (x,y) coordinate of pixel

pixel_to_hex(coord) str

Returns hex value of pixel at coord.

oncoplot_extractor.plotter module

Base file containing OncoPlotCreator

class oncoplot_extractor.plotter.OncoplotCreator(df: pandas.core.frame.DataFrame, cell_size: int = 60, workbook: openpyxl.workbook.workbook.Workbook = <openpyxl.workbook.workbook.Workbook object>, offset: int = 10)

Bases: object

Creates an oncoplot from a dataframe containing respective rows and columns with hexcolor data

Parameters
  • df – pandas dataframe containing hexcolor data [pandas.DataFrame]

  • cell_size – size of each cell in pixels [int]

  • workbook – openpyxl workbook object [openpyxl.Workbook]

  • offset – number of rows to offset inserted data [int]

Example

opc = OncoplotCreator(df=my_df, cell_size=60, workbook=wb, offset=10)
opc.gen_base_oncoplot()
opc.save(filename="my_oncoplot.xlsx")
CELL_SIZE: int
DF: pandas.core.frame.DataFrame
OFFSET: int
OUT_PATH: str = None
WORKBOOK: openpyxl.workbook.workbook.Workbook
WORKSHEET: <property object at 0x7fc742afcae0>
gen_base_oncoplot()

Generates base oncoplot from self.DF expects self.DF to be loaded to self.WS

gen_stack_plot(row_position: Optional[int] = None, column_position: int = 2, filter_colors: list = []) None

generates stacked barplot on top of base oncoplot :param row_position: row where the base of stackplot lies [int] (default: None) :param column_position: first column position [int] (default: 2) :param filter_colors: list of colors to filter out [list]

save(filename: str) None

saves generated workbook to file :param filename: filename to save workbook to [str]

Module contents