API reference¶
The modules the guides use, in the same order: residue tables, pairwise matrices, peptide features, then the IEDB assay loaders.
Residue properties and alphabets¶
amino_acid_properties ¶
Quantify amino acids by their physical/chemical properties
mass
module-attribute
¶
mass = crasp_properties['33. Average isotopic mass (Biemann, 1990)']
Solvent accessibility of AA in known protein structures
Figure 1.
S 0.70 0.20 0.10 T 0.71 0.16 0.13 A 0.48 0.35 0.17 G 0.51 0.36 0.13 P 0.78 0.13 0.09 C 0.32 0.54 0.14 D 0.81 0.09 0.10 E 0.93 0.04 0.03 Q 0.81 0.10 0.09 N 0.82 0.10 0.08 L 0.41 0.49 0.10 I 0.39 0.47 0.14 V 0.40 0.50 0.10 M 0.44 0.20 0.36 F 0.42 0.42 0.16 Y 0.67 0.20 0.13 W 0.49 0.44 0.07 K 0.93 0.02 0.05 R 0.84 0.05 0.11 H 0.66 0.19 0.15
parse_property_table ¶
parse_property_table(table_string)
Parse lines like 1.80000 A ALA into a residue property dictionary.
Parameters:
-
table_string(str) –One line per residue: the value, the one-letter code and, optionally, further fields that are ignored. Blank lines are skipped.
Returns:
-
dict of str to float–Property value for each one-letter residue code, in line order.
Raises:
-
ValueError–If a line has fewer than two fields, a value is not a number, or a residue is repeated.
read_crasp_properties ¶
read_crasp_properties(path=CRASP_PROPERTIES_PATH)
Read every table of the CRASP amino-acid property file.
The file is a sequence of blocks separated by blank lines. Each block is
a numbered header such as 19. Hydropathy (Kyte and Doolittle 1982), a
line with the literature citation, and one value letter code line per
canonical residue. Blocks without a numbered header, such as the source
URL on the first line, are skipped.
Parameters:
-
path(str or path - like, default:CRASP_PROPERTIES_PATH) –Location of the property file; defaults to the copy shipped with pepdata.
Returns:
-
dict of str to dict of str to float–Residue property dictionaries keyed by their header, written as
"<number>. <title>"with a single space after the period.
Raises:
-
ValueError–If a header is repeated, a table is malformed, or a table does not cover exactly the 20 canonical residues.
amino_acid_alphabet ¶
Quantify amino acids by their physical/chemical properties
Pairwise tables¶
pairwise_table ¶
Read whitespace-delimited tables of amino-acid pair coefficients.
One parser serves the BLOSUM substitution matrices, the PMBEC matrix and the
residue contact energy tables that ship in pepdata/matrices.
parse_pairwise_table ¶
parse_pairwise_table(text, column_order=None, coeff_type=float)
Parse the text of a table of pairwise amino-acid coefficients.
Blank lines and lines starting with # are ignored.
Parameters:
-
text(str) –Contents of the table.
-
column_order(sequence of str, default:None) –Residue labels of a table that has no header line and no row labels, such as the residue contact energy tables. The same labels name the rows and the columns, so the table must be square. When omitted, the first line holds the column labels and every later line starts with its row label.
-
coeff_type(callable, default:float) –Converts each coefficient string to a number, e.g.
intfor BLOSUM scores.
Returns:
-
dict of str to dict of str to number–Coefficients accessed like
table[row_label][column_label].
Raises:
-
ValueError–If the table is empty, a label is repeated, a row has the wrong number of fields, or a coefficient is not a number.
read_pairwise_table ¶
read_pairwise_table(path, column_order=None, coeff_type=float)
Read a file holding a table of pairwise amino-acid coefficients.
Parameters:
-
path(str or path - like) –Location of the table.
-
column_order(sequence of str, default:None) –Residue labels of a table without a header line or row labels; see
parse_pairwise_table. -
coeff_type(callable, default:float) –Converts each coefficient string to a number.
Returns:
-
dict of str to dict of str to number–Coefficients accessed like
table[row_label][column_label].
Raises:
-
ValueError–If the table is malformed; see
parse_pairwise_table.
rekey_pairwise_table ¶
rekey_pairwise_table(table, key_type='row')
Convert a nested pairwise table to one of the legacy key layouts.
Exists to support the deprecated key_type argument of
pepdata.blosum.parse_blosum_table and
pepdata.pmbec.read_pmbec_coefficients.
Parameters:
-
table(dict of str to dict of str to number) –Coefficients accessed like
table[row_label][column_label]. -
key_type((row, pair, pair_string), default:'row') –'row'returns the nested layout unchanged,'pair'keys each coefficient by a(row_label, column_label)tuple and'pair_string'by the two labels joined into one string.
Returns:
-
dict–The coefficients in the requested layout.
Raises:
-
ValueError–If
key_typeis not one of the three layouts.
blosum ¶
parse_blosum_table ¶
parse_blosum_table(table, coeff_type=int, key_type='row')
Parse a table of pairwise amino acid coefficient (e.g. BLOSUM50)
Deprecated since 1.3.8: use
pepdata.pairwise_table.parse_pairwise_table or
pepdata.pairwise_table.read_pairwise_table. This wrapper will be
removed in a future release.
Parameters:
-
table(str) –Contents of a table with a header line of column labels.
-
coeff_type(callable, default:int) –Converts each coefficient string to a number.
-
key_type((row, pair, pair_string), default:'row') –Layout of the returned dictionary; see
pepdata.pairwise_table.rekey_pairwise_table.
Returns:
-
dict–Coefficients in the requested layout.
Raises:
-
ValueError–If the table is malformed, has fewer than 20 column labels, or
key_typeis unknown.
pmbec ¶
read_pmbec_coefficients ¶
read_pmbec_coefficients(key_type='row', verbose=False, filename=PMBEC_PATH)
Read the PMBEC coefficient matrix.
Deprecated since 1.3.8: use
pepdata.pairwise_table.read_pairwise_table. This wrapper will be
removed in a future release.
Parameters:
-
key_type(str, default:'row') –'row' : every key is a single amino acid, which maps to a dictionary for that row 'pair' : every key is a tuple of amino acids 'pair_string' : every key is a string of two amino acid characters
-
verbose(bool, default:False) –Ignored. Earlier releases printed the header and residue list to stdout by default; nothing is printed any more.
-
filename(str, default:PMBEC_PATH) –Location of PMBEC coefficient matrix
Returns:
-
dict–Coefficients in the requested layout.
Raises:
-
ValueError–If the table is malformed, does not have exactly 20 columns, or
key_typeis unknown.
residue_contact_energies ¶
parse_interaction_table ¶
parse_interaction_table(table, amino_acid_order=CONTACT_TABLE_AMINO_ACID_ORDER)
Parse a headerless 20x20 table of residue contact energies.
Deprecated since 1.3.8: use
pepdata.pairwise_table.parse_pairwise_table with its column_order
argument. This wrapper will be removed in a future release.
Parameters:
-
table(str) –Contents of a table with one row of coefficients per residue.
-
amino_acid_order(str, default:CONTACT_TABLE_AMINO_ACID_ORDER) –Residue letters naming both the rows and the columns.
Returns:
-
dict of str to dict of str to float–Coefficients accessed like
d[row_letter][column_letter].
Raises:
-
ValueError–If the table does not have one row per residue or a row has the wrong number of coefficients.
Peptide features¶
PeptideVectorizer ¶
Bases: object
Make n-gram frequency vectors from peptide sequences
fit_transform ¶
fit_transform(amino_acid_strings)
Learn the n-gram vocabulary of the given sequences and vectorize them.
Parameters:
-
amino_acid_strings(list of str) –Peptide or protein sequences.
Returns:
-
ndarray–Array of shape (len(amino_acid_strings), number of distinct n-grams) with n-gram counts, or per-row frequencies (each row divided by its total) when normalize_row is True.
transform ¶
transform(amino_acid_strings)
Vectorize sequences with the vocabulary learned by fit.
n-grams that weren't seen during fitting are not counted. Input sequences are unreduced, even when training_already_reduced was used during fitting.
Parameters:
-
amino_acid_strings(list of str) –Peptide or protein sequences.
Returns:
-
ndarray–Array of shape (len(amino_acid_strings), size of the fitted vocabulary), normalized per row as in fit_transform.
Assay tables¶
common ¶
download_export ¶
download_export(filename, url, decompress=True, force=False, data_cache=None)
Download an IEDB export into the local pepdata cache and return its path.
local_export_path ¶
local_export_path(filename, url, decompress=True, auto_download=True, download_instruction=None, data_cache=None)
Return the local path to a cached IEDB export, optionally downloading it.
delete_export ¶
delete_export(filename, url, decompress=True, data_cache=None)
Remove a local cached IEDB export without downloading; missing files are ignored.
normalize_mhc_class ¶
normalize_mhc_class(mhc_class)
Normalize an MHC class selector (1, 2, 'I', or 'II') to 'I' or 'II'.
read_assay_csv ¶
read_assay_csv(path, nrows=None, warn_bad_lines=True)
Read an IEDB two-header-row CSV export and drop unnamed all-NaN columns.
filter_assay_table ¶
filter_assay_table(df, mhc_class=None, hla=None, exclude_hla=None, human_only=False, peptide_length=None, assay_method=None, only_standard_amino_acids=True)
Filter an IEDB assay DataFrame (MHC-binding or T-cell) using consistent semantics.
Columns are resolved via :mod:pepdata.iedb.columns so both legacy and
current IEDB two-level column headers are supported.
Parameters:
-
df(DataFrame) –Raw IEDB assay table with two-level column headers.
-
mhc_class((1, 2, 'I', 'II', None), default:1) –Restrict to MHC Class I or Class II using the table's own MHC class column (without downloading the IEDB allele XML catalogue). Raises
ValueErrorfor any other non-Nonevalue. -
hla(str, default:None) –Regex pattern restricting results to matching MHC allele names.
-
exclude_hla(str, default:None) –Regex pattern excluding matching MHC allele names.
-
human_only(bool, default:False) –Restrict to rows whose host organism starts with
"Homo sapiens". -
peptide_length(int, default:None) –Restrict epitopes to amino acid strings of this exact positive length.
-
assay_method(str, default:None) –Regex pattern restricting results to matching assay methods. Rows with missing assay methods do not match.
-
only_standard_amino_acids(bool, default:True) –Drop sequences containing ambiguous or non-standard residues (
U,X,J,B,Z).
Returns:
-
DataFrame–Filtered copy of
dfwith upper-cased epitope sequences.
mhc ¶
load_dataframe ¶
load_dataframe(mhc_class=None, hla=None, exclude_hla=None, human_only=False, peptide_length=None, assay_method=None, only_standard_amino_acids=True, warn_bad_lines=True, nrows=None)
Load IEDB MHC data without aggregating multiple entries for the same epitope.
Parameters:
-
mhc_class((1, 2, 'I', 'II', None), default:1) –Restrict to MHC Class I or Class II using the table's MHC class column.
-
hla(str, default:None) –Restrict results to specific MHC alleles matching this regex pattern.
-
exclude_hla(str, default:None) –Regex pattern to exclude matching MHC alleles.
-
human_only(bool, default:False) –Restrict to rows whose host organism starts with
"Homo sapiens". -
peptide_length(int, default:None) –Restrict epitopes to amino acid strings of given positive length.
-
assay_method(str, default:None) –Regex pattern limiting results to matching assay methods (null values do not match).
-
only_standard_amino_acids(bool, default:True) –Drop sequences which use non-standard amino acids, anything outside the core 20, such as X or U.
-
warn_bad_lines(bool, default:True) –The full MHC ligand dataset can contain lines with too many fields. When True, emit warnings from pandas; when False, skip them silently.
-
nrows(int, default:None) –Don't load the full IEDB dataset but instead read only the first nrows.
tcell ¶
load_dataframe ¶
load_dataframe(mhc_class=None, hla=None, exclude_hla=None, human_only=False, peptide_length=None, assay_method=None, only_standard_amino_acids=True, reduced_alphabet=None, nrows=None, warn_bad_lines=True)
Load IEDB T-cell data without aggregating multiple entries for the same epitope.
Parameters:
-
mhc_class((1, 2, 'I', 'II', None), default:1) –Restrict to MHC Class I or Class II using the table's MHC class column.
-
hla(str, default:None) –Restrict results to specific MHC alleles matching this regex pattern.
-
exclude_hla(str, default:None) –Regex pattern to exclude matching MHC alleles.
-
human_only(bool, default:False) –Restrict to rows whose host organism starts with
"Homo sapiens". -
peptide_length(int, default:None) –Restrict epitopes to amino acid strings of given positive length.
-
assay_method(str, default:None) –Regex pattern limiting results to matching assay methods (null values do not match).
-
only_standard_amino_acids(bool, default:True) –Drop sequences which use non-standard amino acids, anything outside the core 20, such as X or U.
-
reduced_alphabet(dict, default:None) –Retained for backwards signature compatibility (currently unused).
-
nrows(int, default:None) –Don't load the full IEDB dataset but instead read only the first nrows.
-
warn_bad_lines(bool, default:True) –When True, emit warnings from pandas on malformed CSV lines; when False, skip them silently.