Skip to content

MAF Conversion & Summary

Convert and summarize multiple alignment format (MAF) files, such as whole-genome alignments. See the CLI guidelines for MAF conversion and MAF summary for details on the output files.

import pysegul
def convert_maf():
convert = pysegul.MafConversion(
output_path='tests/output',
output_fmt='nexus',
)
counts = convert.from_dir('tests/maf-data')

To extract loci, provide a BED file. Each block goes to every locus it overlaps.

convert = pysegul.MafConversion(
'tests/output',
bed='loci.bed',
output_prefix='loci',
)
counts = convert.from_files(['alignment.maf'])
print(counts['loci_written'])
OptionDefaultDescription
output_pathRequiredOutput directory
output_fmt'fasta''fasta', 'nexus', 'phylip', or interleaved 'fasta-int', 'nexus-int', 'phylip-int'
group_by'block'Without a BED file, write one file per 'block' or per reference chromosome ('chrom')
bedNoneBED file of loci (.bed or .bed.gz)
clipTrueClip blocks to the loci. Set to False to keep whole blocks. Requires bed
strand_awareFalseReverse complement loci on the minus strand. Requires bed
full_source_nameFalseUse full source names (e.g. hg18.chr7) as sample names instead of the assembly prefix (hg18)
ref_speciesNoneReference species. Defaults to the first species in the first block
speciesNoneList of species to keep. The reference is still used for coordinates
min_block_lenNoneSkip blocks with fewer reference bases (gaps excluded)
min_speciesNoneSkip blocks with fewer species, counting the reference
min_scoreNoneSkip blocks with a lower score. Blocks without a score pass
write_unmatchedFalseWrite blocks that match no locus to the unmatched directory. Requires bed
output_prefixNoneName of the locus report CSV written with bed

Errors, such as an unreadable BED file, raise a ValueError.

MethodDescription
from_dir(input_dir)Convert the MAF files in a directory
from_files(input_files)Convert a list of MAF files

Both return a dictionary of counts:

KeyCount
filesMAF files read
blocks_readBlocks read
blocks_no_refBlocks without a row from the reference species
blocks_filteredBlocks skipped by min_block_len, min_species, or min_score
blocks_unmatchedBlocks that overlap no BED locus
duplicate_rowsRows dropped because a sample appears more than once in a block
overlapping_piecesBlock pieces dropped because they overlap another piece of the same locus
loci_writtenLoci written
loci_emptyBED loci without any aligned data

Summarize MAF files per species and per file.

import pysegul
def summarize_maf():
summary = pysegul.MafSummary(
output_path='tests/output',
output_prefix='maf',
)
outputs = summary.from_dir('tests/maf-data')
OptionDefaultDescription
output_pathRequiredOutput directory
output_prefixNoneName of the output files
full_source_nameFalseUse full source names as sample names
ref_speciesNoneReference species. Defaults to the first species in the first block
speciesNoneList of species to report
plotNoneChart options. See Charts and Reports
MethodDescription
from_dir(input_dir)Summarize the MAF files in a directory
from_files(input_files)Summarize a list of MAF files

Both return a dictionary of output paths: per_file, per_species, and plots.

summary = pysegul.MafSummary('tests/output', plot=pysegul.PlotOptions(format='svg'))
outputs = summary.from_dir('tests/maf-data')
print(outputs['per_species'], outputs['plots'])

This material is based upon work supported by the National Science Foundation under grant numbers: DEB-1754393 and DEB-2244754. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of the National Science Foundation.