rotifer.genome.data.NeighborhoodDF#

class rotifer.genome.data.NeighborhoodDF(*args, **kwargs)[source]#

Bases: DataFrame, Annotatable

boundaries(nucleotide=None)[source]#

Find maximum and minimum values of block_id, feature_order and internal_id. Columns feature_order and internal_id are evaluated per nucleotide entry.

Returns a Pandas dataframe.

full_neighborhood(column='cluster', value='value', stats=False, new_query=True)[source]#

Function that filter a given value in a collumn and fetch all the loci within the block_id

group_strand()[source]#

A function to add the column strand_groups in the acc2operon dataframe.

neighbors(targets=['query == 1'], before=3, after=3, min_block_distance=0, strand='any', fttype='same')[source]#

Find sets of rows, representing genomic regions, that are located near a set of targets.

The user may choose a set of rows (targets) as anchors, whose neighbors will be evaluated by user-defined parameters, such as feature type, strand or distance.

The returned value is copy of a slice of the original NeighborhoodDF object with updated block_id, origin, is_fragment and query columns.

Arguments:
  • targets : (list of) boolean pd.Series or rules to select targets.

    Rules will used identify target rows using Pandas’s eval method.

    If all rules return True for a given row, the row is a target and its neighbors will be identified.

  • beforekeep at most this number of features, of the same type as the target,

    before each target

  • afterkeep at most this number of features, of the same type as the target,

    after each target

  • min_block_distanceminimum distance between two consecutive blocks

    Blocks separated by more features

  • strandhow to evaluate rows concerning the value of the strand column
    Possible values for this option are:
    • None : ignore strand

    • same : same strand as the targets

      • : positive strand features and targets only

      • : negative strand features and targets only

  • fttypehow to process feature types of neighbors
    Supported values:
    • same : consider only features of the same type as the target

    • anyignore feature type and count all features when

      setting neighborhood boundaries

same_strand(query='query')[source]#

Using the strand group and a query it will filter the self with strands that present one query at least.

select_neighbors(column='query', value=1, new_query=True, **kwargs)[source]#

Slice the self in x neighbors of a given value query. self : The Dataframe to be sliced. Column : The column that will be filtered. value: The value to be filtered. after and before: The numbers of neighbors filtered. strand:Filter for neighbors that are at the same strand of the query stats: If set it will give the stats of the column Examples: get_x_neighbors(DF_ATPases, column=’Pfam’, value=’AAA_9’,before=3,after=3). In this example the Dataframe DF_ATPases will be filtered by only blocks that present the AAA_9 ATPase and will return 3 before and 3 after neighbors get_x_neighbors(DF_ATPases, column=’cluster’, value=’sc_29’, before=3,after=3, stats=’pfam). The output of this example will be the stats of pfam column in the neighborhood of cluster sc_29.

series_to_compact_frequency(concat_string=': ', normalize=False)[source]#

Summarize the value counts of a series in a single string.

Each distinct value is written followed by its count inside parentheses, e.g. AAA(3): ABC_tran(1).

Parameters:
concat_stringstr, default “: “

Separator placed between each value(count) item.

normalizebool, default False

If True, report relative frequencies, formatted with two decimal places, instead of absolute counts.

Returns:
str

The value(count) items, sorted by decreasing count and joined by concat_string.

Notes

This is meant to be called on a pandas.Series, since it relies on pandas.Series.value_counts().

value_counts_full(column)[source]#

Calculate absolute and relative frequencies for a given column. If dropna is True, it will ignore the empty values to count the relative frequency.

vicinity(targets=['query == 1'], before=3, after=3, min_block_distance=0, fttype='same')[source]#

Locate genomic regions that contain features selected by some criteria.

Each region will be described by assembly, nucleotide and a pair of minimum and maximum internal IDs.

The user may choose a set of rows (targets) as anchors, whose neighbors will be evaluated by user-defined parameters, such as feature type, strand or distance.

Parameters:
targetsstr, pandas.Series or list of these, default [‘query == 1’]

Rules used to identify target rows.

Strings are evaluated with pandas.DataFrame.eval() and boolean pandas.Series are used as given.

If all rules return True for a given row, the row is a target and its neighbors will be identified.

beforeint, default 3

Keep at most this number of features before each target.

afterint, default 3

Keep at most this number of features after each target.

min_block_distanceint, default 0

Minimum distance between two blocks.

Blocks that are separated by a smaller number of features will be merged into a single block.

fttype{‘same’, ‘any’}, default ‘same’

How to count neighbors by feature type.

  • 'same': consider only features of the same type as the target.

  • 'any': ignore feature type and count all neighboring features (not yet supported).

Returns:
pandas.DataFrame

One row per region, with its location (assembly, nucleotide, type, block_id), the targets it contains (targets, tiids), its feature order limits (foup, fodown) and its first and last internal IDs (up, down). The origin column is non-zero for regions that cross the origin of circular replicons.

An empty DataFrame is returned when no target is found or fttype is not supported.

writer(output_format='table', **kwargs)[source]#
kwargs:
of | output_format: Output format (default: table)
Supported output formats:
  • table : pandas supported tabular output

  • compact : single row description of gene neighborhoods

  • gi2operons | gi2operon | gi2op : old TASS text view format