### AbNumber Sequence Alignment and Statistics (Python) Source: https://context7.com/prihoda/abnumber/llms.txt Demonstrates how to perform pairwise sequence alignment using the `align()` method of the AbNumber Chain class. It shows how to print the alignment with identity markers and CDR highlighting, and how to retrieve alignment statistics such as the number of mutations, identical positions, and similar positions. The example also includes iterating over aligned positions. ```Python from abnumber import Chain seq1 = 'QVQLQQSGAELARPGASVKMSCKASGYTFTRYTMHWVKQRPGQGLEWIGYINPSRGYTNYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYCARYYDDHYCLDYWGQGTTLTVSSAKTTAP' chain1 = Chain(seq1, scheme='imgt') seq2 = 'QVQLVQSGAELDRPGATVKMSCKASGYTTTRYTMHWVKQRPGQGLDWIGYINPSDRSYTNYNQKFKDKATLTTDKSSSTAYMQKTSLTSEDSAVYYCARYYDDYLDRWGQGTTLTVSSAKTTAP' chain2 = Chain(seq2, scheme='imgt') # Create alignment alignment = chain1.align(chain2) # Print formatted alignment with identity markers alignment.print() # QVQLQQSGAELARPGASVKMSCKASGYTFTRYTMHWVKQRPGQGLEWIGYINPS-RGYTNYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYCARYYDDHYCLDYWGQGTTLTVSS # ||||.||||||.||||+|||||||||||.||||||||||||||||+||||||||.|.||||||||||||||||||||||||||.+|||||||||||||||||....||.||||||||||| # QVQLVQSGAELDRPGATVKMSCKASGYTTTRYTMHWVKQRPGQGLDWIGYINPSDRSYTNYNQKFKDKATLTTDKSSSTAYMQKTSLTSEDSAVYYCARYYD--DYLDRWGQGTTLTVSS # ^^^^^^^^ ^^^^^^^^^ ^^^^^^^^^^^^ # Get alignment statistics print(f"Number of mutations: {alignment.num_mutations()}") print(f"Number of identical positions: {alignment.num_identical()}") print(f"Number of similar positions: {alignment.num_similar()}") print(f"Has mutation: {alignment.has_mutation()}") # Iterate over aligned positions for pos, (aa1, aa2) in alignment: if aa1 != aa2: print(f"Position {pos}: {aa1} -> {aa2}") ``` -------------------------------- ### Install AbNumber via Bioconda Source: https://github.com/prihoda/abnumber/blob/master/README.md Command to install the AbNumber package using the conda package manager on UNIX or MacOS systems. ```bash conda install -c bioconda abnumber ``` -------------------------------- ### Raw Indexing Source: https://context7.com/prihoda/abnumber/llms.txt Use `chain.raw` for Python-style numeric indexing (0-based, exclusive end) instead of scheme numbering. Allows for raw slicing and getting positions by raw index. ```APIDOC ## Raw Indexing ### Description Use `chain.raw` for Python-style numeric indexing (0-based, exclusive end) instead of scheme numbering. ### Code Examples ```python from abnumber import Chain seq = 'QVQLQQSGAELARPGASVKMSCKASGYTFTRYTMHWVKQRPGQGLEWIGYINPSRGYTNYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYCARYYDDHYCLDYWGQGTTLTVSS' chain = Chain(seq, scheme='imgt') # Scheme-based indexing (string) print(chain['1']) # First position in scheme # Raw numeric indexing (0-based) print(chain.raw[0]) # First amino acid # Raw slicing (exclusive end, Python-style) first_10 = chain.raw[0:10] print(first_10.seq) # First 10 amino acids # Scheme-based slicing (inclusive end) positions_1_to_10 = chain['1':'10'] print(positions_1_to_10.seq) # Get position by raw index pos = chain.get_position_by_raw_index(0) print(pos) # H1 (imgt) ``` ``` -------------------------------- ### GET /alignment/metrics Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Retrieve statistical metrics for an alignment, such as identical residues, mutations, and similarity scores. ```APIDOC ## GET /alignment/metrics ### Description Calculate various metrics for the alignment object including identity counts, mutation counts, and BLOSUM62-based similarity. ### Method GET ### Parameters #### Query Parameters - **ignore_cdrs** (boolean) - Optional - If true, ignores CDR regions when counting identical residues. ### Response #### Success Response (200) - **num_identical** (integer) - Number of positions with identical residues. - **num_mutations** (integer) - Number of positions with more than one type of residue. - **num_similar** (integer) - Number of positions with similar residues based on BLOSUM62. ``` -------------------------------- ### GET /position/info Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Retrieve metadata and region information for a specific antibody position. ```APIDOC ## GET /position/info ### Description Returns information about a specific numbered position, including its region (FR/CDR) and formatting options. ### Method GET ### Parameters #### Query Parameters - **chain_type** (string) - Required - The chain type (e.g., 'H' or 'L'). - **number** (integer) - Required - The position number. - **scheme** (string) - Required - The numbering scheme used. ### Response #### Success Response (200) - **region** (string) - The region name (e.g., 'CDR1'). - **is_in_cdr** (boolean) - Whether the position falls within a CDR region. ``` -------------------------------- ### GET /find_human_germlines Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Finds the most identical V and J germline sequences for a given chain based on IMGT alignment. ```APIDOC ## GET /find_human_germlines ### Description Finds most identical V and J germline sequences based on IMGT alignment. ### Method GET ### Endpoint /find_human_germlines ### Parameters #### Query Parameters - **limit** (int) - Optional - Number of best matching germlines to return - **v_gene** (str) - Optional - Filter by V gene name - **j_gene** (str) - Optional - Filter by J gene name ### Response #### Success Response (200) - **v_chains** (list) - List of top V chains - **j_chains** (list) - List of top J chains ``` -------------------------------- ### Chain Initialization and Alignment Source: https://github.com/prihoda/abnumber/blob/master/examples/AbNumber_getting_started.ipynb Demonstrates creating a new chain object from a sequence and performing a sequence alignment between two chains. ```python seq2 = 'QVQLVQSGAELDRPGATVKMSCKASGYTTTRYTMHWVKQRPGQGLDWIGYINPSDRSYTNYNQKFKDKATLTTDKSSSTAYMQKTSLTSEDSAVYYCARYYDDERYDYLDRWGQGTTLTVSSAKTTAP' chain2 = Chain(seq2, scheme='imgt') alignment = chain.align(chain2) ``` -------------------------------- ### Exporting Chains to FASTA Format Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Illustrates how to save multiple `Chain` objects to a FASTA file using the `to_fasta` class method. Options include keeping the tail sequence and adding a description. ```python >>> # Assuming 'chains' is a list of Chain objects: >>> # path_or_fd = 'output.fasta' >>> # Chain.to_fasta(chains, path_or_fd, keep_tail=False, description='My Antibody Sequences') ``` -------------------------------- ### AbNumber Chain Object Initialization and Basic Usage Source: https://github.com/prihoda/abnumber/blob/master/README.md Demonstrates how to initialize a Chain object with a given antibody sequence and scheme, and how to access basic information like the sequence and CDR3. ```APIDOC ## AbNumber Chain Object Initialization and Basic Usage ### Description This section shows how to create a `Chain` object from a sequence, specify a numbering scheme, and retrieve basic sequence information and CDR3. ### Method N/A (Python Class) ### Endpoint N/A (Python Class) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```python from abnumber import Chain seq = 'QVQLQQSGAELARPGASVKMSCKASGYTFTRYTMHWVKQRPGQGLEWIGYINPSRGYTNYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYCARYYDDHYCLDYWGQGTTLTVSSAKTTAPSVYPLA' chain = Chain(seq, scheme='imgt') print(chain) print(chain.cdr3_seq) ``` ### Response #### Success Response (200) - **chain** (Chain object) - The initialized Chain object representing the antibody sequence. - **cdr3_seq** (string) - The amino acid sequence of the CDR3 region. #### Response Example ``` QVQLQQSGAELARPGASVKMSCKASGYTFTRYTMHWVKQRPGQGLEWIGYINPSRGYTNYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYCARYYDDHYCLDYWGQGTTLTVSS ARYYDDHYCLDY ``` ``` -------------------------------- ### AbNumber Chain Class Initialization and Basic Usage (Python) Source: https://context7.com/prihoda/abnumber/llms.txt Demonstrates how to initialize the AbNumber Chain class with a sequence and numbering scheme (e.g., IMGT). It shows how to print the chain with CDR highlighting, access chain properties like type, species, and scheme, and iterate over positions and amino acids. It also illustrates indexing and slicing chains using scheme-specific numbering. ```Python from abnumber import Chain # Parse a heavy chain sequence with IMGT numbering seq = 'QVQLQQSGAELARPGASVKMSCKASGYTFTRYTMHWVKQRPGQGLEWIGYINPSRGYTNYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYCARYYDDHYCLDYWGQGTTLTVSSAKTTAPSVYPLA' chain = Chain(seq, scheme='imgt') # Display chain with CDR highlighting chain.print() # QVQLQQSGAELARPGASVKMSCKASGYTFTRYTMHWVKQRPGQGLEWIGYINPSRGYTNYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYCARYYDDHYCLDYWGQGTTLTVSS # ^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^^^ # Access chain properties print(f"Chain type: {chain.chain_type}") # H (heavy), K (kappa), or L (lambda) print(f"Species: {chain.species}") print(f"Scheme: {chain.scheme}") # Iterate over positions and amino acids for pos, aa in chain: print(pos, aa) # H1 Q # H2 V # H3 Q # ... # Index by position number (string) print(chain['5']) # 'Q' # Slice using scheme numbering (inclusive) for pos, aa in chain['H2':'H5']: print(pos, aa) # H2 V # H3 Q # H4 L # H5 Q ``` -------------------------------- ### Initialize and Analyze Antibody Chain Source: https://github.com/prihoda/abnumber/blob/master/README.md Demonstrates how to initialize a Chain object from a sequence and extract CDR3 information or print the numbered sequence. ```python from abnumber import Chain seq = 'QVQLQQSGAELARPGASVKMSCKASGYTFTRYTMHWVKQRPGQGLEWIGYINPSRGYTNYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYCARYYDDHYCLDYWGQGTTLTVSSAKTTAPSVYPLA' chain = Chain(seq, scheme='imgt') print(chain.cdr3_seq) chain.print(numbering=True) ``` -------------------------------- ### Creating Chain Slices with Optional Replacement Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Illustrates how to create a slice of a chain, with an option to replace the sequence within that slice. It also shows direct slicing syntax and the use of raw indexing. ```python >>> # You can also slice directly using chain['111':'112A'] or chain.raw[10:20] >>> # Example of slicing with a replacement sequence: >>> new_chain = chain.slice(replace_seq='ABC', start='111A', stop='112A') >>> # Example of direct slicing: >>> sliced_chain = chain['111':'112A'] ``` -------------------------------- ### Using Different CDR Definitions with Same Numbering (Python) Source: https://context7.com/prihoda/abnumber/llms.txt Demonstrates how to utilize different CDR definitions (e.g., 'north') with the same sequence numbering scheme in AbNumber. ```python from abnumber import Chain seq = 'YOUR_SEQUENCE_HERE' north_cdr_chain = Chain(seq, scheme='imgt', cdr_definition='north') print(f"North CDR definition CDR1: {north_cdr_chain.cdr1_seq}") ``` -------------------------------- ### FASTA File I/O for Antibody Sequences (Python) Source: https://context7.com/prihoda/abnumber/llms.txt Shows how to read and write antibody sequences from/to FASTA files using the AbNumber library. Supports reading as a list, generator, or pandas Series, and writing with or without the constant region. ```python from abnumber import Chain # Read chains from FASTA file chains = Chain.from_fasta('antibodies.fasta', scheme='imgt') for chain in chains: print(f"{chain.name}: {chain.cdr3_seq}") # Read as generator (memory efficient for large files) for chain in Chain.from_fasta('large_file.fasta', scheme='imgt', as_generator=True): print(f"{chain.name}: {chain.chain_type}") # Read as pandas Series chains_series = Chain.from_fasta('antibodies.fasta', scheme='imgt', as_series=True) print(chains_series) # Write chains to FASTA file chains = [ Chain(seq1, scheme='imgt', name='heavy1'), Chain(seq2, scheme='imgt', name='heavy2') ] Chain.to_fasta(chains, 'output.fasta') # Include constant region (tail) in output Chain.to_fasta(chains, 'output_with_tail.fasta', keep_tail=True) ``` -------------------------------- ### Formatting Alignment Output Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Demonstrates the `format` method for the `Alignment` object, which allows for customizable string representations of the alignment, including marking identities, CDRs, and chain names. ```python >>> # Format alignment with identity and CDR marking: >>> formatted_string = alignment.format(mark_identity=True, mark_cdrs=True) >>> print(formatted_string) >>> >>> # Format alignment with chain names: >>> formatted_string_with_names = alignment.format(names=True) ``` -------------------------------- ### Batch Processing Antibody Sequences Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Demonstrates how to initialize multiple Chain objects from a dictionary of sequences using the batch class method. ```python from abnumber import Chain seqs = {'seq1': 'QVQLVQSGAEVKKPGASVKVSCKASGYTFT...', 'seq2': 'DIQMTQSPSSLSASVGDRVTITCRASQ...'} chains, errors = Chain.batch(seqs, scheme='imgt') ``` -------------------------------- ### Raw Indexing for Antibody Sequences (Python) Source: https://context7.com/prihoda/abnumber/llms.txt Illustrates how to use raw, 0-based Python-style indexing on antibody chains in AbNumber for sequence slicing and accessing positions, contrasting it with scheme-based numbering. ```python from abnumber import Chain seq = 'QVQLQQSGAELARPGASVKMSCKASGYTFTRYTMHWVKQRPGQGLEWIGYINPSRGYTNYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYCARYYDDHYCLDYWGQGTTLTVSS' chain = Chain(seq, scheme='imgt') # Scheme-based indexing (string) print(chain['1']) # First position in scheme # Raw numeric indexing (0-based) print(chain.raw[0]) # First amino acid # Raw slicing (exclusive end, Python-style) first_10 = chain.raw[0:10] print(first_10.seq) # First 10 amino acids # Scheme-based slicing (inclusive end) positions_1_to_10 = chain['1':'10'] print(positions_1_to_10.seq) # Get position by raw index pos = chain.get_position_by_raw_index(0) print(pos) # H1 (imgt) ``` -------------------------------- ### POST /batch Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Processes a dictionary of sequences to create multiple Chain objects. ```APIDOC ## POST /batch ### Description Creates multiple Chain objects from a dictionary of sequences using specified numbering schemes. ### Method POST ### Endpoint /batch ### Parameters #### Request Body - **seq_dict** (dict) - Required - Dictionary of sequence strings, keys are sequence identifiers - **scheme** (str) - Required - Numbering scheme to align the sequences - **cdr_definition** (str) - Optional - Numbering scheme for CDR regions - **assign_germline** (bool) - Optional - Assign germline name using ANARCI - **allowed_species** (list) - Optional - List of allowed species for germline assignment ### Response #### Success Response (200) - **result** (tuple) - A tuple containing (dict of Chain objects, dict of error strings) ### Response Example { "chains": { "id1": "ChainObject" }, "errors": {} } ``` -------------------------------- ### Exporting Chains to CSV Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Shows how to export multiple `Chain` objects into an ANARCI-compatible CSV file using the `to_anarci_csv` class method. ```python >>> # Assuming 'chains' is a list of Chain objects: >>> # from abnumber import Chain >>> # chains = [chain1, chain2] >>> # path = 'output.csv' >>> # Chain.to_anarci_csv(chains, path) ``` -------------------------------- ### Configure CDR Definitions Source: https://github.com/prihoda/abnumber/blob/master/examples/AbNumber_getting_started.ipynb Initializes a Chain object with custom CDR definitions such as Chothia or North. ```python Chain(seq, scheme='imgt', cdr_definition='chothia') Chain(seq, scheme='imgt', cdr_definition='north') ``` -------------------------------- ### Print Alignment Visualization Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Demonstrates how to print a visual representation of an alignment, including optional BLAST-style identity markers and CDR region highlighting. ```python >>> alignment.print() >>> alignment.print(mark_identity=False, mark_cdrs=False) ``` -------------------------------- ### Create and Use AbNumber Chain Object Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Demonstrates how to create a Chain object from an unaligned sequence and a numbering scheme. It also shows how to iterate through the chain by position and amino acid, and how to access specific residues or slices using scheme numbering. ```python from abnumber import Chain seq = 'QVQLQQSGAELARPGASVKMSCKASGYTFTRYTMHWVKQRPGQGLEWIGYINPSRGYTNYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYCARYYDDHYCLDYWGQGTTLTVSSAKTTAPSVYPLA' chain = Chain(seq, scheme='imgt') print(chain) for pos, aa in chain: print(pos, aa) print(chain['5']) for pos, aa in chain['H2':'H5']: print(pos, aa) ``` -------------------------------- ### Creating BioPython SeqRecord Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Shows how to convert a single `Chain` object into a BioPython `SeqRecord` object, with options to include the tail sequence and add a description. ```python >>> # Assuming 'chain' is a Chain object: >>> # from Bio.SeqRecord import SeqRecord >>> # seq_record = chain.to_seq_record(keep_tail=False, description='My Chain') ``` -------------------------------- ### Access and Slice Alignment Data Source: https://github.com/prihoda/abnumber/blob/master/examples/AbNumber_getting_started.ipynb Demonstrates how to retrieve specific alignment positions using keys or indices and how to iterate over ranges of positions using slicing syntax. ```python aa, bb = alignment['112A'] aa, bb = alignment.raw[10] for pos, (aa, bb) in alignment['108':'112A']: print(pos, aa, bb) for pos, (aa, bb) in alignment.raw[:10]: print(pos, aa, bb) ``` -------------------------------- ### AbNumber CDR and Framework Region Extraction (Python) Source: https://context7.com/prihoda/abnumber/llms.txt Shows how to extract Complementarity Determining Regions (CDRs) and framework regions (FRs) from an antibody chain using the AbNumber library. It demonstrates accessing CDR sequences directly via properties like `cdr1_seq`, `cdr2_seq`, and `cdr3_seq`, as well as framework sequences. It also covers retrieving all regions as a dictionary. ```Python from abnumber import Chain seq = 'QVQLQQSGAELARPGASVKMSCKASGYTFTRYTMHWVKQRPGQGLEWIGYINPSRGYTNYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYCARYYDDHYCLDYWGQGTTLTVSS' chain = Chain(seq, scheme='imgt') # Access CDR sequences print(f"CDR1: {chain.cdr1_seq}") # GYTFTRYT print(f"CDR2: {chain.cdr2_seq}") # INPSRGYT print(f"CDR3: {chain.cdr3_seq}") # ARYYDDHYCLDY # Access framework sequences print(f"FR1: {chain.fr1_seq}") print(f"FR2: {chain.fr2_seq}") print(f"FR3: {chain.fr3_seq}") print(f"FR4: {chain.fr4_seq}") # Get all regions as a dictionary for region_name, region_dict in chain.regions.items(): seq = ''.join(region_dict.values()) print(f"{region_name}: {seq}") # FR1: QVQLQQSGAELARPGASVKMSCKAS # CDR1: GYTFTRYT # FR2: MHWVKQRPGQGLEWI # CDR2: GYINPSRGYT # FR3: NYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYC # CDR3: ARYYDDHYCLDY # FR4: WGQGTTLTVSS ``` -------------------------------- ### Access and Slice Alignment Data Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Shows how to access raw alignment data for numeric indexing and how to perform slicing using either schema-based numbering or raw Python-style indexing. ```python >>> alignment.raw[0] >>> chain['1':'10'] >>> chain.raw[0:10] ``` -------------------------------- ### Class Methods for Data Export Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Static methods for exporting multiple chains to various file formats like CSV, DataFrame, and FASTA. ```APIDOC ## Class Methods for Data Export ### Description Provides class methods to export lists of `Chain` objects into different formats, including ANARCI-compatible CSV, Pandas DataFrames, and FASTA files. ### Export to ANARCI CSV ```python # Save multiple chains to ANARCI-like CSV from typing import List from abnumber import Chain # Assume chains is a list of Chain objects # chains: List[Chain] # path_to_csv = "/path/to/output.csv" # Chain.to_anarci_csv(chains, path_to_csv) ``` **Parameters:** * **chains** (List[Chain]) - A list of `Chain` objects to export. * **path** (str) - The file path to save the CSV file. ### Export to Pandas DataFrame ```python # Produce a Pandas dataframe with aligned chain sequences in the columns import pandas as pd from typing import List from abnumber import Chain # Assume chains is a list of Chain objects # chains: List[Chain] # df = Chain.to_dataframe(chains) ``` **Parameters:** * **chains** (List[Chain]) - A list of `Chain` objects to convert. **Note:** The DataFrame will contain only positions (columns) present in the provided chains. ### Export to FASTA ```python # Save multiple chains to FASTA format from typing import List from abnumber import Chain # Assume chains is a list of Chain objects # chains: List[Chain] # path_to_fasta = "/path/to/output.fasta" # Chain.to_fasta(chains, path_to_fasta, description='My Antibody Chains') ``` **Parameters:** * **chains** (List[Chain]) - A list of `Chain` objects to export. * **path_or_fd** (str) - The file path or file descriptor to save the FASTA file. * **keep_tail** (bool) - Whether to include the constant region tail. Defaults to False. * **description** (str) - A description to prepend to each FASTA entry. Defaults to ''. ``` -------------------------------- ### Chain Properties and Accessors Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Demonstrates how to access raw sequence data, regions, sequence, species, germline genes, and tail sequence of a protein chain. ```APIDOC ## Chain Properties and Accessors ### Description Access various properties of a `Chain` object, including raw sequence data, defined regions, aligned sequence, species information, germline gene assignments, and the constant region tail. ### Accessing Raw Sequence ```python # Access raw representation of the chain for unaligned numeric indexing and slicing # Numbering of chain.raw starts at 0, end is exclusive (Python style) chain.raw[0:10] ``` ### Accessing Regions ```python # Access a dictionary of region dictionaries # Region is an uppercase string, one of: "FR1", "CDR1", "FR2", "CDR2", "FR3", "CDR3", "FR4" regions_dict = chain.regions ``` ### Accessing Aligned Sequence ```python # Access unaligned string representation of the variable chain sequence aligned_sequence = chain.seq ``` ### Accessing Species Information ```python # Access species as identified by ANARCI species = chain.species ``` ### Accessing V Gene Germline ```python # Access V gene germline as identified by ANARCI (if assign_germline is True) v_gene = chain.v_gene ``` ### Accessing Constant Region Tail ```python # Access constant region sequence constant_tail = chain.tail ``` ``` -------------------------------- ### Graft CDR Regions Source: https://github.com/prihoda/abnumber/blob/master/examples/AbNumber_getting_started.ipynb Shows how to graft CDR regions from one chain onto another using the graft_cdrs_onto method. ```python chain.graft_cdrs_onto(chain2).print() chain2.graft_cdrs_onto(chain).print() ``` -------------------------------- ### Exporting Chains to Pandas DataFrame Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Demonstrates the `to_dataframe` class method for converting a list of `Chain` objects into a Pandas DataFrame, with aligned sequences as columns. ```python >>> # Assuming 'chains' is a list of Chain objects: >>> # import pandas as pd >>> # df = Chain.to_dataframe(chains) >>> # print(df) ``` -------------------------------- ### Chain Methods Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Details on methods for renumbering, slicing, and converting chain objects. ```APIDOC ## Chain Methods ### Description Provides methods for manipulating and transforming `Chain` objects, including renumbering, slicing with optional sequence replacement, and converting to other formats. ### Renumbering a Chain ```python # Return a copy of this chain aligned using a different numbering scheme or CDR definition new_chain = chain.renumber(scheme='imgt', cdr_definition='chothia', allowed_species=['human', 'mouse']) ``` **Parameters:** * **scheme** (str) - Change numbering scheme: One of `imgt`, `chothia`, `kabat`, `aho`. * **cdr_definition** (str) - Change CDR definition scheme: One of `imgt`, `chothia`, `kabat`, `north`. * **allowed_species** (list[str]) - `None` to allow all species, or one or more of: `'human', 'mouse','rat','rabbit','rhesus','pig','alpaca'`. * **use_anarcii** (bool) - Use ANARCII (2.0) for numbering, otherwise use ANARCI (1.0). * **anarcii_args** (dict) - Keyword arguments for Anarcii(). ### Slicing a Chain ```python # Create a slice of this chain, optionally with a replacement sequence sliced_chain = chain.slice(start='10', stop='20', replace_seq='ABCDEFGHIJ') # Direct slicing using string or Position objects sliced_chain_direct = chain['111':'112A'] # Direct slicing using raw accessor sliced_chain_raw = chain.raw[10:20] ``` **Parameters:** * **replace_seq** (str) - Optional replacement sequence, needs to be the same length. * **start** (str | int | [Position](#abnumber.Position)) - Optional slice start position (inclusive). * **stop** (str | int | [Position](#abnumber.Position)) - Optional slice stop position (inclusive). * **stop_inclusive** (bool) - Include stop position in slice. Defaults to True. * **allow_raw** (bool) - Allow unaligned numeric indexing from 0 to length of sequence - 1. Defaults to False. ### Converting to BioPython SeqRecord ```python # Create BioPython SeqRecord object from this Chain seq_record = chain.to_seq_record() ``` ``` -------------------------------- ### Formatting Antibody Sequences Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Shows how to format a Chain object into wide or tall string representations for visualization. ```python chain = Chain('QVQLVQSGAEVKKPGASVKVSCKASGYTFT', scheme='imgt') wide_format = chain.format(method='wide', numbering=True) tall_format = chain.format_tall(columns=10) ``` -------------------------------- ### AbNumber Chain Object Indexing and Slicing Source: https://github.com/prihoda/abnumber/blob/master/README.md Demonstrates how to access individual amino acids or subsequences using indexing and slicing with scheme numbering. ```APIDOC ## AbNumber Chain Object Indexing and Slicing ### Description This section explains how to use scheme-based numbering to access specific amino acids or subsequences from a `Chain` object using indexing and slicing. ### Method N/A (Python Class Indexing/Slicing) ### Endpoint N/A (Python Class Indexing/Slicing) ### Parameters N/A ### Request Example ```python from abnumber import Chain seq = 'QVQLQQSGAELARPGASVKMSCKASGYTFTRYTMHWVKQRPGQGLEWIGYINPSRGYTNYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYCARYYDDHYCLDYWGQGTTLTVSSAKTTAPSVYPLA' chain = Chain(seq, scheme='imgt') # Access a single amino acid print(chain['5']) # Slice a subsequence for pos, aa in chain['H2':'H5']: print(pos, aa) ``` ### Response #### Success Response (200) - **Indexed Amino Acid** (string) - The amino acid at the specified position. - **Sliced Subsequence** (iterator) - An iterator yielding position and amino acid pairs for the specified range. #### Response Example ``` Q H2 V H3 Q H4 L H5 Q ``` ``` -------------------------------- ### DataFrame Export and Import for Antibody Sequences (Python) Source: https://context7.com/prihoda/abnumber/llms.txt Demonstrates converting antibody chains to pandas DataFrames for analysis and exporting/importing aligned sequences in ANARCI-style CSV format using AbNumber. ```python from abnumber import Chain chains = [ Chain('QVQLQQSGAELARPGASVKMSCKASGYTFTRYTMHWVKQRPGQGLEWIGYINPSRGYTNYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYCARYYDDHYCLDYWGQGTTLTVSS', scheme='imgt', name='antibody1'), Chain('QVQLVQSGAELDRPGATVKMSCKASGYTTTRYTMHWVKQRPGQGLDWIGYINPSDRSYTNYNQKFKDKATLTTDKSSSTAYMQKTSLTSEDSAVYYCARYYDDYLDRWGQGTTLTVSS', scheme='imgt', name='antibody2') ] # Convert to DataFrame with aligned positions as columns df = Chain.to_dataframe(chains) print(df) # chain_type species H1 H2 H3 ... # antibody1 H None Q V Q # antibody2 H None Q V Q # Save to ANARCI-style CSV Chain.to_anarci_csv(chains, 'aligned_sequences.csv') # Read back from CSV chains_loaded = Chain.from_anarci_csv('aligned_sequences.csv', scheme='imgt') ``` -------------------------------- ### Accessing Raw Chain Sequence Data Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Demonstrates how to access the raw, unaligned sequence of a chain and how numbering differs between the standard chain representation and its raw form. It shows indexing and slicing behavior for both. ```python >>> # String numbering is based on schema numbering >>> chain['1'] 'QVQLQQSGAE' >>> # Numbering of ``chain.raw`` starts at 0 >>> chain.raw[0] 'QVQLQQSGAE' >>> # Slicing with string is based on schema numbering, the end is inclusive >>> chain['1':'10'] 'QVQLQQSGAE' >>> # Slicing with ``chain.raw`` starts at 0, the end is exclusive (Python style) >>> chain.raw[0:10] 'QVQLQQSGAE' ``` -------------------------------- ### AbNumber Chain Object Printing and Numbering Source: https://github.com/prihoda/abnumber/blob/master/README.md Illustrates how to print the antibody sequence with numbering and highlight CDR regions. ```APIDOC ## AbNumber Chain Object Printing and Numbering ### Description This section demonstrates how to print the antibody sequence with detailed numbering and visual highlighting of CDR regions. ### Method N/A (Python Class Method) ### Endpoint N/A (Python Class Method) ### Parameters N/A ### Request Example ```python from abnumber import Chain seq = 'QVQLQQSGAELARPGASVKMSCKASGYTFTRYTMHWVKQRPGQGLEWIGYINPSRGYTNYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYCARYYDDHYCLDYWGQGTTLTVSSAKTTAPSVYPLA' chain = Chain(seq, scheme='imgt') chain.print(numbering=True) ``` ### Response #### Success Response (200) - **Output** (string) - A formatted string displaying the antibody sequence with numbering and CDR highlighting. #### Response Example ``` 0 1 2 3 4 5 6 7 8 9 10 11 12 12345678912345678901234567890567890123456789012345678923456789012456789012345678901234567890123456789023456789012345678 QVQLQQSGAELARPGASVKMSCKASGYTFTRYTMHWVKQRPGQGLEWIGYINPSRGYTNYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYCARYYDDHYCLDYWGQGTTLTVSS ^^^^^^^^ ^^^^^^^^ ^^^^^^^^^^^^ ``` ``` -------------------------------- ### POST /alignment/slice Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Create a sub-section of an alignment based on position indices or schema-based numbering. ```APIDOC ## POST /alignment/slice ### Description Creates a new sliced Alignment object based on provided start and stop markers. ### Method POST ### Parameters #### Request Body - **start** (string/int) - Optional - Slice start position. - **stop** (string/int) - Optional - Slice stop position. - **stop_inclusive** (boolean) - Optional - Whether to include the stop position. - **allow_raw** (boolean) - Optional - Allow unaligned numeric indexing from 0. ``` -------------------------------- ### FASTA File I/O Source: https://context7.com/prihoda/abnumber/llms.txt Read and write antibody sequences from/to FASTA files with automatic numbering. Supports reading as a generator or pandas Series, and writing with or without the constant region. ```APIDOC ## FASTA File I/O ### Description Read and write antibody sequences from/to FASTA files with automatic numbering. ### Code Examples ```python from abnumber import Chain # Read chains from FASTA file chains = Chain.from_fasta('antibodies.fasta', scheme='imgt') for chain in chains: print(f"{chain.name}: {chain.cdr3_seq}") # Read as generator (memory efficient for large files) for chain in Chain.from_fasta('large_file.fasta', scheme='imgt', as_generator=True): print(f"{chain.name}: {chain.chain_type}") # Read as pandas Series chains_series = Chain.from_fasta('antibodies.fasta', scheme='imgt', as_series=True) print(chains_series) # Write chains to FASTA file chains = [ Chain(seq1, scheme='imgt', name='heavy1'), Chain(seq2, scheme='imgt', name='heavy2') ] Chain.to_fasta(chains, 'output.fasta') # Include constant region (tail) in output Chain.to_fasta(chains, 'output_with_tail.fasta', keep_tail=True) ``` ``` -------------------------------- ### Iterating and Printing Chain Data Source: https://github.com/prihoda/abnumber/blob/master/examples/AbNumber_getting_started.ipynb Shows how to iterate over chain residues and print structural representations of specific sequence segments. ```python chain['111A':'112A'].print_tall() for pos, aa in chain['111A':'112A']: print(pos, aa) for pos, aa in chain.raw[:10]: print(pos, aa) ``` -------------------------------- ### Accessing and Slicing Antibody Chains Source: https://github.com/prihoda/abnumber/blob/master/examples/AbNumber_getting_started.ipynb Demonstrates how to access specific residues by position and slice sequences using both standard indexing and raw indices. ```python chain['112'] chain.raw[112] chain[:'30'] chain['120':] chain.raw[114:] chain.raw[-10:] ``` -------------------------------- ### AbNumber Chain Object Iteration Source: https://github.com/prihoda/abnumber/blob/master/README.md Shows how to iterate through the `Chain` object to access each position and amino acid. ```APIDOC ## AbNumber Chain Object Iteration ### Description This section illustrates how to iterate over a `Chain` object to access each amino acid position and its corresponding residue. ### Method N/A (Python Class Iteration) ### Endpoint N/A (Python Class Iteration) ### Parameters N/A ### Request Example ```python from abnumber import Chain seq = 'QVQLQQSGAELARPGASVKMSCKASGYTFTRYTMHWVKQRPGQGLEWIGYINPSRGYTNYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYCARYYDDHYCLDYWGQGTTLTVSSAKTTAPSVYPLA' chain = Chain(seq, scheme='imgt') for pos, aa in chain: print(pos, aa) ``` ### Response #### Success Response (200) - **pos** (string) - The position identifier (e.g., 'H1', 'L2'). - **aa** (string) - The amino acid at the specified position. #### Response Example ``` H1 Q H2 V H3 Q H4 L H5 Q ``` ``` -------------------------------- ### Parsing Multi-Domain Antibody Sequences (ScFv) with AbNumber Source: https://context7.com/prihoda/abnumber/llms.txt Utilize the `Chain.multiple_domains()` method to parse antibody sequences containing multiple domains, such as Single-Chain variable fragments (ScFvs). This function separates and analyzes each domain individually, providing details for each. ```python from abnumber import Chain # ScFv sequence containing VH and VL domains scfv_seq = 'QVQLQQSGAELARPGASVKMSCKASGYTFTRYTMHWVKQRPGQGLEWIGYINPSRGYTNYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYCARYYDDHYCLDYWGQGTTLTVSSGGGGSGGGGSGGGGSQSVLTQPPSVSVSPGQTASITCSGDKLGDKYACWYQQKPGQSPVLVIYQDSKRPSGIPERFSGSNSGNTATLTISGTQAMDEADYYCQAWDSSTAWGQGTKVEIK' # Parse all domains domains = Chain.multiple_domains(scfv_seq, scheme='imgt') for i, chain in enumerate(domains): print(f"Domain {i+1}: {chain.chain_type} chain") print(f" CDR3: {chain.cdr3_seq}") ``` -------------------------------- ### Iterate and Slice Antibody Chain Source: https://github.com/prihoda/abnumber/blob/master/README.md Shows how to iterate over chain positions and perform indexing or slicing using scheme-specific numbering. ```python for pos, aa in chain: print(pos, aa) # Indexing print(chain['5']) # Slicing for pos, aa in chain['H2':'H5']: print(pos, aa) ``` -------------------------------- ### Initialize and Number Antibody Chain Source: https://github.com/prihoda/abnumber/blob/master/examples/AbNumber_getting_started.ipynb Initializes a Chain object with a sequence and a numbering scheme. This allows for printing the numbered sequence and accessing specific regions. ```python from abnumber import Chain import pandas as pd pd.options.display.max_columns = 200 seq = 'EVQLQQSGAELARPGASVKMSCKASGYTFTRYTMHWVKQRPGQGLEWIGYINPSRGYTNYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYCARYYSEDDERGHYCLDYWGQGTTLTVSSAKTTAPSVYPLA' chain = Chain(seq, scheme='imgt') chain.print(numbering=True) ``` -------------------------------- ### Print Chain Representation (Python) Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Provides methods to print the string representation of a Chain object. `print()` (defaulting to 'wide' method) and `print_wide()` display the sequence with CDR regions highlighted using '^'. `print_tall()` displays the sequence in a tall format, listing each residue and its corresponding region (e.g., FR1, H1). Both methods support customization through additional keyword arguments. ```python def print(self, method='wide', **kwargs): """Print string representation using Chain.format()""" pass ``` ```python def print_tall(self, columns=5): """Print string representation using Chain.format_tall()""" pass ``` ```python def print_wide(self, numbering=False): """Print string representation using Chain.format_wide()""" pass ``` -------------------------------- ### Aligning Two Antibody Chains Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md Shows how to align two antibody chains using the `align` method. The resulting alignment object can be sliced and iterated over to compare positions and amino acids. ```python >>> from abnumber import Chain >>> >>> seq1 = 'QVQLQQSGAELARPGASVKMSCKASGYTFTRYTMHWVKQRPGQGLEWIGYINPSRGYTNYNQKFKDKATLTTDKSSSTAYMQLSSLTSEDSAVYYCARYYDDHYCLDYWGQGTTLTVSSAKTTAP' >>> chain1 = Chain(seq1, scheme='imgt') >>> >>> seq2 = 'QVQLVQSGAELDRPGATVKMSCKASGYTTTRYTMHWVKQRPGQGLDWIGYINPSDRSYTNYNQKFKDKATLTTDKSSSTAYMQKTSLTSEDSAVYYCARYYDDYLDRWGQGTTLTVSSAKTTAP' >>> chain2 = Chain(seq2, scheme='imgt') >>> alignment = chain1.align(chain2) >>> >>> # Iterating through the alignment: >>> for pos, (aa, bb) in alignment[:'5']: >>> print(pos, aa, bb) >>> # Output: >>> # H1 Q Q >>> # H2 V V >>> # H3 Q Q >>> # H4 L L >>> # H5 Q V ``` -------------------------------- ### Format Sequence Numbering Schemes Source: https://github.com/prihoda/abnumber/blob/master/examples/AbNumber_getting_started.ipynb Iterates through various numbering schemes and CDR definitions to format and display sequence alignments. ```python from IPython.display import display, HTML for chain_seq in EXAMPLES: for scheme, cdr_definition in [('imgt', 'imgt'), ('chothia','chothia'), ('kabat','kabat'), ('chothia','north'), ('aho','north')]: chain = Chain(chain_seq, scheme=scheme, cdr_definition=cdr_definition) scheme_label = scheme + ('-'+cdr_definition if cdr_definition != scheme else '') display(HTML(f'

{chain.chain_type} {scheme_label}

')) print(chain.format(numbering=True)) ``` -------------------------------- ### Parse Multi-Domain Sequence (Python) Source: https://github.com/prihoda/abnumber/blob/master/docs/source/index.md A class method that parses an unaligned multi-domain sequence string into a list of individual Chain objects. It requires a numbering scheme and optionally accepts a CDR definition scheme, a sequence name, and parameters for germline assignment (including allowed species and ANARCI version). It returns a tuple containing a dictionary of Chain objects and a dictionary of any errors encountered during parsing. ```python classmethod multiple_domains(cls, sequence: str, scheme: str, cdr_definition=None, name=None, assign_germline=False, allowed_species=None, use_anarcii=False) -> Tuple[Dict[str, Chain], Dict[str, str]]: """Parse multi-domain sequence into a list of Chain objects""" pass ``` -------------------------------- ### Extract Sequence Attributes Source: https://github.com/prihoda/abnumber/blob/master/examples/AbNumber_getting_started.ipynb Demonstrates how to access the processed sequence, the tail region, and the CDR3 sequence from a Chain object. ```python print(chain.seq) print(chain.tail) print(chain.cdr3_seq) ```