Alignment class

class pytadbit.alignment.Alignment(name, alignment, experiments, consensus, score=None)[source]

Alignment of TAD borders

draw(focus=None, extras=None, ymax=None, ali_colors=('grey',), normalized=True, savefig=None, shape='ellipse')[source]

Draw alignments as a plot.

Parameters
  • focus (None) – can pass a tuple (bin_start, bin_stop) to display the alignment between these genomic bins

  • extras (None) – list of coordinates (genomic bin) where to draw a red cross

  • ymax (None) – limit the y axis up to a given value

  • ) (('grey',) – successive colors for alignment

  • normalized (True) – normalized Hi-C count are plotted instead of raw data.

  • shape ('ellipse') – which kind of shape to use as schematic representation of TADs. Implemented: ‘ellipse’, ‘rectangle’, ‘triangle’

  • savefig (None) – path to a file where to save the image generated; if None, the image will be shown using matplotlib GUI (the extension of the file name will determine the desired format).

get_column(cond1, cond2=None, min_num=None)[source]

Get a list of column responding to a given characteristic.

Parameters
  • cond1 – can be either a column number or a function to search for a given condition that may fulfill boundaries.

  • cond2 (None) – a second function to search for a given condition that may fulfill boundaries.

  • min_num (None) – Number of boundaries in a given column that have to pass the defined conditions (all boundaries may pass them by default).

Returns

a list of column, each column represented by a tuple which first element is the column number in the alignment and second element is the list of boundaries in this column.

Example

ali = Alignment('ALL', crm.get_alignment('ALL'),
                crm.experiments, score)
ali.get_column(3)
# [(3, [>55<, ,>56<, >55<, >58<])]

# now we want boundaries with high scores
cond1 = lambda x: x['score'] > 5
# and we want boundaries to be detected in Experiments exp1 and exp2
cond2=lambda x: x['exp'] in ['exp1', 'exp2']

ali.get_column(cond1=cond1, cond2=cond2, min_num=2)
# [(33, [>268<, >192<, >-<, >-<]),
#  (46, [>324<, >323<, >335<, >329<]),
#  (51, [>348<, >335<, >357<, >347<]),
#  (56, [>374<, >358<, >383<, >-<]),
#  (64, [>397<, >396<, >407<, >-<]),
#  (77, [>444<, >442<, >456<, >-<])]
itercolumns()[source]

Iterate over columns in the alignment

iteritems()[source]

Iterate over experiment names and aligned boundaries

itervalues()[source]

Iterate over experiment names and aligned boundaries

write_alignment(names=None, xpers=None, string=False, title='', ftype='ansi')[source]
Print alignment of TAD boundaries between different experiments.

Alignments are displayed with colors according to the TADbit confidence score for each boundary.

Parameters
  • names (None) – if None print all experiments

  • xpers (None) – if None print all experiments

  • string (False) – return string instead of printing

  • ftype (ansi) – display colors in ‘ansi’ or ‘html’ format

class pytadbit.alignment.TAD(thing, i, exp)[source]

Specific class of TADs, used only within Alignment objects. It is directly inheriting from python dict. a TAD these keys:

  • ‘start’: position of the TAD

  • ‘end’: position of the TAD

  • ‘score’: of the prediction of boundary

  • ‘brk’: same as ‘end’

  • ‘pos’: in the alignment (column number)

  • ‘exp’: Experiment this TAD belongs to

  • ‘index’: of this TAD within all TADs in the Experiment

pytadbit.alignment.randomization_test(xpers, score=None, num=1000, verbose=False, max_dist=100000, rnd_method='interpolate', r_size=None, method='reciprocal')[source]

Return the probability that original alignment is better than an alignment of randomized boundaries.

Parameters
  • tads – original TADs of each experiment to align

  • distr – the function to interpolate TAD lengths from probability

  • score (None) – just to print it when verbose

  • num (1000) – number of random alignment to generate for comparison

  • verbose (False) – to print something nice

  • method (interpolate) – how to generate random tads (alternative is ‘shuffle’). ‘interpolate’ will calculate the distribution of TAD lengths, and generate a random set of TADs according to this distribution (see pytadbit.alignment.generate_rnd_tads()). In contrast, the ‘shuffle’ method uses directly the set of observed TADs and shuffle them (see pytadbit.alignment.generate_shuffle_tads()).

pytadbit.alignment.generate_rnd_tads(chromosome_len, distr, start=0)[source]

Generates random TADs over a chromosome of a given size according to a given distribution of lengths of TADs.

Parameters
  • chromosome_len – length of the chromosome

  • distr – function that returns a TAD length depending on a p value

  • bin_size – size of the bin of the Hi-C experiment

  • start (0) – starting position in the chromosome

Returns

list of TADs

pytadbit.alignment.generate_shuffle_tads(tads)[source]

Returns a shuffle version of a given list of TADs

Parameters

tads – list of TADs

Returns

list of shuffled TADs