Receber por email
← Voltar para o catálogo

degenerate-input-filtering

Filter degenerate, uninformative inputs before statistical tests: single-sequence alignments, empty files, constant features, zero-variance inputs, all-NaN columns. See nan-safe-correlation for NaN-aware correlation; statistical-analysis for test guidance.

207estrelas
Atualizado há 4 meses

Ver no GitHub ↗ Licença: NOASSERTION

Como adicionar

/plugin marketplace add jaechang-hits/SciAgent-Skills

O comando exato pode variar conforme o repositório. Confira o README no GitHub.

Para o autor da skill

Cole no README do seu repo

Mostra que sua skill está catalogada na Skillteca, gera backlink e tráfego rastreável.

[![Skillteca](https://www.skillteca.com.br/api/badge/degenerate-input-filtering/svg)](https://www.skillteca.com.br/skills/degenerate-input-filtering)

Skills relacionadas

Ver todas de Desenvolvimento →

Alerta por categoria

Receba novas skills de Desenvolvimento toda segunda

1 email curto, só com as skills novas de Desenvolvimento. 4 minutos de leitura, sem spam, cancela com 1 clique.

Você confirma o email no primeiro envio. Sem spam. Cancela com 1 clique.

Ler descrição completa

Degenerate Input Filtering Guide

Overview

Degenerate inputs are data points that carry no statistical information: constant-value features, all-NaN columns, single-sequence alignments, empty files, and similar edge cases. When these reach a statistical test or model, the result is meaningless -- a correlation of NaN, a p-value of 1.0, a score of 0.0, or an outright crash. This guide establishes the mandatory practice of detecting and removing such inputs before any analysis, and of reporting every removal so that downstream consumers know the effective sample size.

Key Concepts

What Counts as Degenerate

A data point is degenerate when it cannot contribute to the statistic being computed. The root cause is always the same: the input lacks the variation or completeness that the method requires.

| Type | Example | Why It Fails | |---|---|---| | Constant-value feature | Gene with identical expression across all samples | Variance = 0; correlation, t-test, fold-change are all undefined | | All-NaN feature | Column with no valid observations | Every aggregation returns NaN | | Single-sequence alignment | BLAST result with one sequence | Score = 0.0; no pairwise comparison is possible | | Empty file | 0-byte FASTA or CSV | Parser crashes or returns an empty frame | | Single value after grouping | One sample in a treatment group | Within-group variance is undefined; group comparison is meaningless | | Zero-length sequence | Empty FASTA entry | Alignment and k-mer tools fail or produce nonsense | | Near-constant feature | Gene with one outlier and N-1 identical values | Technically non-zero variance but correlation is dominated by a single point |

Why Silent Failures Are Dangerous

Many numerical libraries do not raise errors on degenerate input. Instead they return sentinel values:

  • numpy.corrcoef returns nan for constant columns without warning.
  • scipy.stats.spearmanr returns (nan, nan) when one array is constant.
  • scipy.stats.ttest_ind returns (nan, nan) for zero-variance groups.

These NaN values propagate silently through pipelines, contaminating aggregated statistics, heatmaps, volcano plots, and ranked gene lists. By the time a researcher notices the problem, it may be unclear which upstream step introduced the NaN.

The Reporting Obligation

Filtering without reporting is nearly as harmful as not filtering. When items are silently dropped, the effective sample or feature count differs from what the user expects, leading to incorrect power calculations and misleading summary statistics. Every filtering step must print:

  1. The count of items removed.
  2. The reason for removal.
  3. The count of items remaining.

Decision Framework

Use this tree to determine which filtering checks apply to your data before running a statistical analysis:

Is the input tabular (DataFrame)?
├── Yes
│   ├── Are there columns with zero unique values (all NaN)? → Remove, report count
│   ├── Are there columns with exactly one unique value (constant)? → Remove, report count
│   ├── Are there columns with fewer than N valid observations? → Remove, report count
│   └── Are there near-constant columns (1 outlier, rest identical)? → Flag or remove
└── No (file list, sequence set, etc.)
    ├── Are there empty files (0 bytes)? → Skip, report count
    ├── Are there single-entry collections (e.g., 1-sequence alignment)? → Skip, report count
    └── Are there zero-length entries within a file? → Filter entries, report count

| Scenario | Recommended Check | Threshold | |---|---|---| | Gene expression matrix before DE analysis | Remove zero-variance genes, remove genes detected in fewer than N samples | N = max(3, 10% of samples) | | Correlation analysis between two feature sets | Remove features constant in either set; require >= 10 shared non-NaN pairs | nunique >= 2 in both vectors; shared observations >= 10 | | Multiple sequence alignment scoring | Skip alignments with < 2 sequences | Sequence count >= 2 | | Survival analysis with grouped covariates | Remove groups with < 2 events | Events per group >= 2 | | PCA or clustering on a feature matrix | Remove zero-variance and all-NaN features | Variance > 0 and at least 1 non-NaN value | | Batch correction (e.g., ComBat) | Remove features absent in any batch | Feature detected in all batches |

Best Practices

  1. Filter before any statistical computation, not after. Degenerate inputs can cause division-by-zero, NaN propagation, and inflated multiple-testing corrections. Filtering after the test means the damage is already done.
  1. Use a single reusable filtering function. Centralizing the logic prevents inconsistencies between scripts and ensures the reporting format is uniform. See the reference implementation in the Workflow section below.
  1. Print counts at every filtering step. Even when the count is zero, printing "0 items removed" confirms that the check ran. This makes logs self-documenting and auditable.
  1. Set domain-appropriate thresholds rather than relying on generic defaults. A gene expression analysis might require detection in at least 10% of samples, while a proteomics dataset with more missingness might use 5%. Document the threshold and the rationale.
  1. Treat near-constant features with caution. A feature with one non-identical value technically has non-zero variance, but its correlation with anything is driven entirely by that single point. Consider flagging these separately rather than including them blindly.
  1. Never filter silently. Dropping data without reporting is a form of hidden data manipulation. Every removal must be logged with the reason and the count, so that the effective sample size is always transparent.
  1. Re-check after transformations. Log-transforming expression data can introduce negative infinities from zero counts. Merging datasets can introduce new NaN columns. Run the degenerate check again after any transformation or merge step.

Common Pitfalls

  1. Running a correlation on constant-valued columns and getting NaN without realizing it. The NaN result silently propagates into downstream rankings, heatmaps, or enrichment inputs, producing misleading figures.
  2. How to avoid: Always check nunique() >= 2 for every column before computing correlations. Use the reference implementation below.
  1. Scoring single-sequence alignments and reporting a score of 0.0 as a real result. Alignment scores require at least two sequences; a single-sequence "alignment" is not a failed alignment, it is a non-alignment.
  2. How to avoid: Count sequences before scoring. Skip and report any alignment file with fewer than 2 sequences.
  1. Filtering data but not reporting the count, leading to confusion about effective sample size. A volcano plot based on 15,000 genes looks very different from one based on 18,500, but without a log message, no one knows which it is.
  2. How to avoid: Always print three things: count removed, reason, count remaining. Include this in every notebook and script.
  1. Applying a minimum-samples threshold that is too low, retaining genes detected in only 1-2 samples. These genes produce unstable variance estimates and unreliable p-values that inflate the false discovery rate.
  2. How to avoid: Use max(3, int(0.1 * n_samples)) as a floor. Adjust upward for small studies where even 10% is fewer than 3.
  1. Forgetting to re-check after a merge or transformation step. Joining two datasets can introduce all-NaN columns from non-overlapping features. Log-transforming zeros creates negative infinities. Both are degenerate.
  2. How to avoid: Run the degenerate filter again after every merge, join, or mathematical transformation.
  1. Using df.var() > 0 without handling NaN correctly. If a column is all NaN, var() returns NaN, which is not > 0, so the column is dropped -- but the reason logged is "zero variance" rather than "all NaN," which is misleading.
Compartilhar X LinkedIn