jpegdna.format package

Module contents

Formatter collections for the Jpeg DNA codecs

class jpegdna.format.AbstractFormatter[source]

Bases: abc.ABC

Abstract class for formatter definition

abstract deformat(oligos)[source]

Decoding method

Parameters

code (list) – Formated oligos to deformat

Returns

Deformated strand

Return type

str

abstract format(inp)[source]

Encoding method

Parameters

inp (str) – Strand to format

Returns

Formatted oligos

Return type

list

full_deformat(oligos, *args)[source]

Encoding method

Parameters
  • code (list) – Formated oligos to deformat

  • args (any) – Deformatting arguments

Returns

Deformated strand

Return type

str

full_format(inp, *args)[source]

Encoding method

Parameters
  • inp (str) – Strand to format

  • args (any) – Header info

Returns

Formatted oligos

Return type

list

get_state(case=None)[source]

Helper method to get the state of the codec if necessary

Return type

any

set_state(*args, case=None)[source]

Helper method to set the state of the codec if necessary

Return type

None

exception jpegdna.format.AutomataException[source]

Bases: Exception

exception jpegdna.format.AutomataGetterException[source]

Bases: jpegdna.format.AutomataException

exception jpegdna.format.AutomataGetterExceptionDeformat[source]

Bases: jpegdna.format.AutomataGetterException

exception jpegdna.format.AutomataGetterExceptionFormat[source]

Bases: jpegdna.format.AutomataGetterException

exception jpegdna.format.AutomataSetterException[source]

Bases: jpegdna.format.AutomataException

exception jpegdna.format.AutomataSetterExceptionDeformat[source]

Bases: jpegdna.format.AutomataSetterException

exception jpegdna.format.AutomataSetterExceptionFormat[source]

Bases: jpegdna.format.AutomataSetterException

jpegdna.format.dataformatter module

Formatting method for data oligo

class jpegdna.format.dataformatter.DataFormatter(header, oligo_length=200, debug=False)[source]

Bases: jpegdna.format.AbstractFormatter

Formatter for the strand coming out of the compression algorithm

Variables

oligo_length – Size of the oligos used for formatting

DEFAULT_OFFSET_CODE_LENGTH = 8[source]
deformat(oligos)[source]

Methods deformatting the oligos and rebuilding the data strand

Parameters

oligos (list(str)) – data oligos

Returns

data strand resulting from compression

Return type

str

format(inp)[source]

Method formatting the data strand into oligos

Parameters

inp (str) – strand resulting from the compression algorithm

Returns

list of formatted oligos of size self.oligo_length

Return type

list(str)

jpegdna.format.frequenciesformatter module

Formatting method for frequencies

class jpegdna.format.frequenciesformatter.GrayFrequenciesFormatter(max_cat, max_runcat, dc_freq_len, ac_freq_len, header, dc_header, ac_header, oligo_length=200, debug=False)[source]

Bases: jpegdna.format.AbstractFormatter

Formatter for the gray DC and AC frequencies

Variables
  • max_cat – max value for the categories

  • max_runcat – max value for the run/categories

  • dc_freq_len – codeword length for encoding the dc frequencies

  • ac_freq_len – codeword length for encoding the ac frequencies

  • oligo_length – Size of the oligos used for formatting

DEFAULT_FREQUENCIES_OFFSET_CODE_LENGTH = 7[source]
decode_frequencies(strand, freq_type)[source]

Decode the frequencies using fixed-length codebooks

Parameters
  • strand (str) – encoded frequency values

  • freq_type (str) – DC/AC frequency indicator

Returns

list of frequency values

Return type

list(int)

deformat(oligos)[source]

Deformats and decodes both DC and AC frequency oligos

Parameters

oligos (list(str)) – formatted frequency oligos for AC and DC

Returns

decoded frequency tables

Return type

tuple(list(int))

deformat_frequencies(oligos)[source]

Deformat the oligos describing either the DC or the AC frequencies

Parameters
  • oligos – oligos to deformat

  • freq_type (str) – DC/AC frequency indicator

Returns

strand encoding the frequencies

Return type

str

encode_frequencies(freqs, freq_type)[source]

Encode the frequencies using fixed-length codebooks

Parameters
  • freqs (list(int)) – frequency values to encode

  • freq_type (str) – DC/AC frequency indicator

Returns

strand encoding the frequencies

Return type

str

format(inp)[source]

Encodes and formats both DC and AC frequencies

Parameters

inp (tuple(list(int))) – frequencies for DC categories and AC run/categories

Returns

formatted frequency oligos

Return type

list(str)

format_frequencies(inp, freq_type)[source]

Format the strand encoding either the DC or the AC frequencies

Parameters
  • inp (str) – strand to format

  • freq_type (str) – DC/AC frequency indicator

Returns

formatted AC or DC frequency oligos

Return type

list(str)

class jpegdna.format.frequenciesformatter.RGBFrequenciesFormatter(max_cat, max_runcat, dc_freq_len, ac_freq_len, header, dc_header, ac_header, oligo_length=200, debug=False)[source]

Bases: jpegdna.format.frequenciesformatter.GrayFrequenciesFormatter

Formatter for the RGB DC and AC frequencies

Variables
  • max_cat – max value for the categories

  • max_runcat – max value for the run/categories

  • dc_freq_len – codeword length for encoding the dc frequencies

  • ac_freq_len – codeword length for encoding the ac frequencies

  • oligo_length – Size of the oligos used for formatting

deformat(oligos)[source]

Deformats and decodes both DC and AC frequency oligos

Parameters

oligos (list(str)) – formatted frequency oligos for AC and DC

Returns

decoded frequency tables

Return type

tuple(tuple(list(int)))

format(inp)[source]

Encodes and formats both DC and AC frequencies

Parameters

inp (tuple(tuple(list(int)))) – frequencies for DC categories and AC run/categories

Returns

formatted frequency oligos

Return type

list(str)

jpegdna.format.generalinfoformatter module

Formatting method for general info oligo

class jpegdna.format.generalinfoformatter.GeneralInfoFormatter(alpha, freq_origin, m, n, blockdims, max_cat, max_runcat, dc_freq_len, ac_freq_len, image_type, sampler, header, oligo_length=200, debug=False)[source]

Bases: jpegdna.format.AbstractFormatter

Formatter for the general information related to the compression

Variables
  • alpha – alpha value of the compression, if it is known

  • freq_origin – origin of the frequencies (“default” or “from_img”)

  • m – first dimension of the image

  • n – second dimension of the image

  • blockdims – dimensions of the block used for DCT

  • max_cat – max value for the categories

  • max_runcat – max value for the run/categories

  • dc_freq_len – codeword length for encoding the dc frequencies

  • ac_freq_len – codeword length for encoding the ac frequencies

  • oligo_length – Size of the oligos used for formatting

IMAGE_TYPES = ['gray', 'RGB'][source]
colored_image()[source]

Check if image is colored or gray level

Return type

bool

deformat(oligos)[source]

Decoding method

Parameters

code (list) – Formated oligos to deformat

Returns

Deformated strand

Return type

str

format(inp)[source]

Encoding method

Parameters

inp (str) – Strand to format

Returns

Formatted oligos

Return type

list

jpegdna.format.jpegdnaformatter module

Gray-level strand formatter

class jpegdna.format.jpegdnaformatter.JpegDNAFormatter(alpha, image_type, sampler='4:2:2', freq_origin=None, primer='illumina', oligo_length=200, debug=False)[source]

Bases: jpegdna.format.AbstractFormatter

Jpeg DNA gray level formatter class

Parameters
  • aplha – Alpha value (quantization step multiplier)

  • freq_origin (str) – Choose between default and adapted frequencies

  • primer (str) – Primer name used

DEFAULT_AC_FREQ_HEADER = 'AGAG'[source]
DEFAULT_AC_FREQ_LEN = 10[source]
DEFAULT_BLOCKDIMS = (8, 8)[source]
DEFAULT_CENTERING_OFFSET = 75[source]
DEFAULT_DATA_INFO_HEADER = 'TTGAGGA'[source]
DEFAULT_DC_FREQ_HEADER = 'ATTC'[source]
DEFAULT_DC_FRQ_LEN = 7[source]
DEFAULT_FREQS_INFO_HEADER = 'ATCCGTC'[source]
DEFAULT_GENERAL_INFO_HEADER = 'AATAATA'[source]
DEFAULT_MAX_CAT = 11[source]
DEFAULT_MAX_RUNCAT = 162[source]
PRIMERS = {'illumina': ('GTTCAGAGTTCTACAGTCCGACGATC', 'TGGAATTCTCGGGTGCCAAGG'), 'none': ('', '')}[source]
PRIMER_LENGTHS = {'illumina': (26, 21), 'none': (0, 0)}[source]
add_ids(oligos, n)[source]

Adding primers to formatted oligos

Parameters

oligos (list) – list of formatted oligos without offset

Returns

list of oligos with offset added at the beginning of each oligo

Rtpye

list

add_parity_strand(data, image_id, sense_nt)[source]

Computes the parity strand for the current oligo

Parameters
  • data (str) – strand on which to compute parities for each base

  • image_id (str) – id of the image

  • sense_nt – sense nucelotide

add_primers_and_sense(oligos)[source]

Adding primers to formatted oligos

Parameters

oligos (list) – list of formatted oligos without primers

Returns

list of oligos with primers added at the beginning and at the end of each oligo

Rtpye

list

add_sense_nt(pos)[source]

Compute the sens nucleotide either the beginning one or the ending one

Parameters

pos (str) – either “begin” or “end”, position of the sense nt to compute

Returns

sense nucleotide

Return type

str

cut_payload(el, n)[source]

Cuts the payoad in two halves after the n-th nucleotide

Parameters

el (string) – Stand to be cut

Returns

Two cuts

Return type

Tuple(string)

deformat(oligos)[source]

Decoding method

Parameters

code (list) – Formated oligos to deformat

Returns

Deformated strand

Return type

str

format(inp)[source]

Encoding method

Parameters

inp (str) – Strand to format

Returns

Formatted oligos

Return type

list

full_deformat(oligos, *args)[source]

Encoding method

Parameters
  • code (list) – Formated oligos to deformat

  • args (any) – Deformatting arguments

Returns

Deformated strand

Return type

str

full_format(inp, *args)[source]

Encoding method

Parameters
  • inp (str) – Strand to format

  • args (any) – Header info

Returns

Formatted oligos

Return type

list

get_payload(oligos)[source]

Taking primers and sense nts off formatted oligos

Parameters

oligos (list) – list of formatted oligos without primers

Returns

list of oligos with primers added at the beginning and at the end of each oligo

Rtpye

list

get_state(case=None)[source]

Helper method to get the state of the codec if necessary

set_alpha(alpha)[source]

Set alpha value

set_freq_origin(choice)[source]

Set frequency origin

set_primer()[source]

Sets the primer from the primer type

set_state(*args, case=None)[source]

Helper method to set the state of the codec if necessary