snpex
ipyrad2 snpex can be used to export subsampled and filtered SNP datasets in a variety of
common formats, including PLINK, PHYLIP, NEXUS, and FASTA, as well as several more complex supported
formats, including TreeMix and EEMS that group individual data into population frequencies.
The subsampling, filtering, and optional imputation options allow for easily generating multiple
datasets with different thresholds for dealing with missing data.
Quick guide
Use snpex to filter/subsample/impute and write SNP data
ipyrad2 snpex \
--data HDF5 \
--out SNPS/ \
--min-sample-coverage 20 \
--max-sample-missing 0.5 \
--out-format plink fasta
Note: If you are using Analysis tools inside ipyrad2, sich as its pca, popgen, baba, and related tools,
you do not need to use snpex as its filtering options are implemented within those commands directly.
Input and output
-d, --data: input SNP HDF5-o, --out: ...-O, --out-format: write one or more additional formats selected fromplink,phylip,nexus,fasta,treemix, andeems-i, --imap: sample-to-population map for subsetting and population-aware filtering-g, --minmap: per-population minimum coverage checks applied on top of-mwhenimapis used
Filtering
If an --imap is entered the dataset will be subset to include only the samples listed in the file.
-m, --min-sample-coverage: minimum number of samples with data required at a SNP-r, --max-sample-missing: drop samples whose missing-data fraction exceeds this threshold, then rerun SNP filtering-a, --min-minor-allele-frequency: drop low-frequency SNPs after coverage filtering-e, --exclude: exclude one or more named samples-R, --include-reference: includeassembly_reference_sequence--no-subsample: By defaultsnpexwrites one SNP per RAD locus. Use--no-subsampleto keep linked SNPs.--seedUse this when you want reproducible one-SNP-per-locus subsampling.
Imputation
By default snpex preserves missing genotypes. If you pass --impute-method, imputation is applied
once before any outputs are written, and every written format uses that same imputed SNP view.
Supported imputation modes are:
sample: sample missing diploid genotypes from within-group allele frequencieszero-fill: replace missing genotypes with homozygous reference calls
Core Outputs
Every run writes these baseline files:
NAME.genos.npy: diploid genotype matrix coded as0,1,2, or255for missing unless imputedNAME.snps.npy: SNP character matrix using nucleotide and IUPAC SNP codesNAME.snpsmap.tsv: SNP metadata withloc,loc_idx,loc_pos,scaff, andposNAME.samples.txt: retained sample orderNAME.sample_data_summary.tsv: per-sample missingness before and after optional imputationNAME.stats.txt: export summary, filter statistics, imputation summary, and written formats
These baseline outputs are useful even if you do not request any additional external format.
Optional Export Formats
Use -O/--out-format followed by one or more format names to add external-tool files:
plink:NAME.bed,NAME.bim,NAME.famphylip:NAME.phynexus:NAME.nexfasta:NAME.fatreemix:NAME.treemix.gzeems:NAME.eems
For example, -O plink fasta writes both formats from the same selected SNP matrix. If -O is omitted, snpex writes only the core outputs listed above.
Format Notes
PLINK
PLINK export writes BED/BIM/FAM from the selected SNP view.
PHYLIP, NEXUS, and FASTA
These formats write SNP characters as nucleotide/IUPAC alignments:
- homozygous reference sites write the reference base
- homozygous alternate sites write the alternate base
- heterozygotes write the corresponding IUPAC ambiguity code
- missing sites write
Nunless imputed beforehand
These are SNP alignments, not locus alignments. If you want clipped sequence windows or whole loci instead of one-character-per-SNP matrices, use seqex.
TreeMix
TreeMix export writes gzipped counts in the usual ancestral,derived text format.
- if you supplied
imap, columns are populations - if you did not supply
imap, each retained sample is treated as its own column
EEMS
EEMS export writes only the genetic dissimilarity matrix, named NAME.eems.
- rows and columns follow the sample order in
NAME.samples.txt - if global SNP imputation was requested, the EEMS matrix is built from that imputed genotype matrix
- otherwise
snpexfollows the usual EEMS SNP convention of filling missing genotypes with per-site means before forming the pairwise dissimilarity matrix
This command does not write the spatial .coord or habitat .outer files. Those remain external inputs you prepare separately.
Common Patterns
filter for missing data and write unlinked SNPs matrix
ipyrad2 snpex \
-d assembly.hdf5 \
-o SNP_OUT/ \
-m 10
filter for missing data and write linked SNPs to PLINK format
ipyrad2 snpex \
-d assembly.hdf5 \
-o SNP_OUT/ \
-m 10 \
--no-subsample \
-O plink
filter, impute, and write to FASTA
ipyrad2 snpex \
-d assembly.hdf5 \
-o SNP_OUT/ \
-m 10 \
--impute-method sample \
-O fasta
filter and impute population-aware and write to TREEMIX
ipyrad2 snpex \
-d assembly.hdf5 \
-o SNP_OUT/ \
-i pops.tsv \
-g minmap.tsv \
-O treemix
Common Failures
- Wrong input type:
snpexexpects SNP-capable HDF5, not raw VCF. Convert VCF first withanalysis vcf-to-hdf5. - Empty result after filtering: coverage, missingness, MAF,
imap, andminmapcan combine to remove all SNPs or all samples. - Reference-related errors: PLINK export and global imputation both require the HDF5
referencedataset. - IMAP mismatch: sample names in
imapmust match names in the HDF5 exactly. - Existing output files: use
--forceto overwrite an existing export set.
Related Pages
Native-evidence BCF export
-O bcf writes NAME.bcf and NAME.bcf.csi from an assembly made with
--evidence snps (HDF5 v3) or --evidence loci (HDF5 v4).
The BCF contains the same selected samples
and filtered/subsampled SNPs as the core matrices, with original coordinates,
ordered alleles, and GT:DP:AD:GQ:PL:FT. Native evidence is not recalculated.
PL contains genotype likelihoods, not posterior probabilities. This export
does not write a GP field or apply a population prior; posterior summaries
are available separately through popgen --genotype-mode likelihoods.
FT=ExportMask identifies hard calls additionally masked by snpex while their
read evidence remains available. Assembly hard masks continue to suppress
evidence. BCF export cannot be combined with imputation or a synthetic
assembly_reference_sequence row. --force applies to both BCF and index.
ipyrad2 snpex -d OUT/assembly.hdf5 -o SNP_EXPORT -O bcf --no-subsample
Without --no-subsample, the usual one-SNP-per-locus selection applies. Other
output formats work unchanged on lean databases assembled with the default
--evidence none; BCF export reports an error explaining that snps or loci
evidence is required. Even with loci evidence, this exporter selects SNPs;
it does not export invariant-site records.