### Install scikit-bio from source Source: https://scikit.bio/install.html Install scikit-bio by downloading the repository, extracting it, and running pip install. This is for the development version and may not be stable. ```bash pip install . ``` -------------------------------- ### Tests __init__.py Example Source: https://scikit.bio/devdoc/new_module.html A minimal __init__.py file for the tests directory within a scikit-bio module. This file is necessary for test discovery and execution after installation. ```python # ---------------------------------------------------------------------------- # Copyright (c) 2013--, scikit-bio development team. # # Distributed under the terms of the Modified BSD License. # # The full license is to the file LICENSE.txt, distributed with this software. # ---------------------------------------------------------------------------- ``` -------------------------------- ### Install scikit-bio from a wheel file Source: https://scikit.bio/install.html Install scikit-bio using a pre-compiled wheel file. Download the appropriate file for your platform first. ```bash pip install your_wheel_file.whl ``` -------------------------------- ### Sample Metadata File Example Source: https://scikit.bio/docs/latest/generated/skbio.io.format.sample_metadata.html An example of a sample metadata file in TSV format. This format is compatible with QIIME 2 metadata. ```text id col1 col2 col3 #q2:types categorical categorical categorical id1 1 a foo id2 2 b bar id3 3 c 42 ``` -------------------------------- ### Install Dependencies with Pip Source: https://scikit.bio/contribute.html Install all project dependencies using pip from the requirement files within the activated virtual environment. ```bash pip install -r ci/requirements.txt -r ci/requirements.test.txt -r ci/requirements.lint.txt -r ci/requirements.doc.txt ``` -------------------------------- ### Get All Tip Names from a Tree Source: https://scikit.bio/docs/latest/generated/skbio.tree.TreeNode.subset.html This example shows how to obtain a sorted list of all tip names present in the entire tree by calling the subset method on the root node without any arguments. This is useful for understanding the full set of taxa in the tree. ```python >>> sorted(tree.subset()) ['a', 'b', 'c', 'f', 'g'] ``` -------------------------------- ### Get bipartition for a clade with less than half taxa Source: https://scikit.bio/docs/latest/generated/skbio.tree.TreeNode.bipart.html This example shows how to get the bipartition for a clade ('X') that contains less than half of the total taxa in the tree. The result is sorted for consistent output. ```python >>> sorted(tree.find('X').bipart()) ['b', 'c'] ``` -------------------------------- ### Perform preorder traversal on a TreeNode Source: https://scikit.bio/docs/latest/generated/skbio.tree.TreeNode.preorder.html This example shows how to iterate through a TreeNode using the preorder traversal method and print the name of each visited node. The traversal starts from the root. ```python >>> for node in tree.preorder(): ... print(node.name) g c a b f d e ``` -------------------------------- ### Doctest Example Usage Source: https://scikit.bio/devdoc/doc_guide.html Examples should be written in doctest format for automatic testing. This example shows how to run 'example_function1'. ```python Examples -------- Run the ``example_function1`` function: >>> from skbio.example import example_function1 >>> example_function1("hello", "world") hello world! ``` -------------------------------- ### Install Documentation Dependencies Source: https://scikit.bio/devdoc/doc_guide.html Installs necessary Sphinx and extensions for building scikit-bio documentation using conda. ```bash conda install -c conda-forge --file ci/requirements.doc.txt ``` -------------------------------- ### Example PHYLIP File Content Source: https://scikit.bio/docs/latest/generated/skbio.io.format.phylip.html This is an example of a PHYLIP-formatted file, showing the header with sequence count and length, followed by aligned sequences. ```plaintext 5 42 Turkey AAGCTNGGGC ATTTCAGGGT GAGCCCGGGC AATACAGGGT AT Salmo gairAAGCCTTGGC AGTGCAGGGT GAGCCGTGGC CGGGCACGGT AT H. SapiensACCGGTTGGC CGTTCAGGGT ACAGGTTGGC CGTTCAGGGT AA Chimp AAACCCTTGC CGTTACGCTT AAACCGAGGC CGGGACACTC AT Gorilla AAACCCTTGC CGGTACGCTT AAACCATTGC CGGTACGCTT AA ``` -------------------------------- ### Write and Read BIOM Table Source: https://scikit.bio/docs/latest/generated/skbio.io.format.biom.html Demonstrates writing an existing scikit-bio Table to a BytesIO object and then reading it back into a scikit-bio Table. This example requires the `biom` library to be installed. ```python import io, skbio f = io.BytesIO() skbio.table.example_table.write(f) roundtrip = skbio.read(f, into=skbio.Table) roundtrip ``` -------------------------------- ### Ordination Results Format Example Source: https://scikit.bio/docs/latest/generated/skbio.io.format.ordination.html This example demonstrates the structure of an ordination results file, including Eigvals, Proportion explained, Species, Site, Biplot, and Site constraints attributes with their respective data. ```text Eigvals4 0.360.180.070.08 Proportion explained4 0.460.230.100.10 Species94 Species00.110.28-0.20-0.00 Species10.140.300.39-0.14 Species2-1.010.09-0.19-0.10 Species3-1.030.100.220.22 Species41.050.53-0.430.22 Species50.990.570.67-0.38 Species60.25-0.17-0.200.43 Species70.14-0.85-0.010.05 Species80.41-0.700.21-0.69 Site104 Site00.71-3.080.21-1.24 Site10.58-3.00-0.942.69 Site20.76-3.152.13-3.11 Site31.111.07-1.870.66 Site4-0.97-0.06-0.69-0.61 Site51.040.45-0.630.28 Site6-0.95-0.080.13-0.42 Site70.94-0.100.52-0.00 Site8-1.140.490.471.17 Site91.031.032.74-1.28 Biplot33 -0.160.630.76 -0.990.06-0.04 0.18-0.970.03 Site constraints104 Site00.69-3.08-0.32-1.24 Site10.66-3.060.232.69 Site20.63-3.040.78-3.11 Site31.100.50-1.550.66 Site4-0.970.06-1.12-0.61 Site51.050.53-0.430.28 Site6-1.020.10-0.00-0.42 Site70.990.570.67-0.00 Site8-1.080.131.111.17 Site90.940.611.79-1.28 ``` -------------------------------- ### FASTQ File Example Source: https://scikit.bio/docs/latest/generated/skbio.io.format.fastq.html An example of a FASTQ-formatted file containing two DNA sequences and their quality scores. Each record consists of a header line, sequence data, a quality header line, and quality scores. ```plaintext @seq1 description 1 AACACCAAACTTCTCCACCACGTGAGCTACAAAAG + ````Y^T]`]c^cabcacc`^Lb^ccYT\T\Y\WF @seq2 description 2 TATGTATATATAACATATACATATATACATACATA + ]KZ[PY]_[YY^```ac^\\`bT``c`\aT``bbb ``` -------------------------------- ### Install scikit-bio development version Source: https://scikit.bio/ Installs the development version of scikit-bio directly from its GitHub repository using Pip. ```bash pip install git+https://github.com/scikit-bio/scikit-bio.git ``` -------------------------------- ### Install Pre-commit Hooks Source: https://scikit.bio/contribute.html Install pre-commit hooks to automatically run code quality checks before each commit, ensuring code consistency and adherence to standards. ```bash pre-commit install ``` -------------------------------- ### Install scikit-bio from Source Source: https://scikit.bio/contribute.html Install scikit-bio in editable mode from the source code. This ensures that changes made to the source code are immediately reflected without reinstallation. ```bash pip install --no-deps -e . ``` -------------------------------- ### Example lsmat File Content Source: https://scikit.bio/docs/latest/generated/skbio.io.format.lsmat.html This example shows the structure of a labeled square matrix file with two objects, 'a' and 'b', and their corresponding distance values. The delimiter used is '', which can be a tab or comma. ```text ab a0.01.0 b1.00.0 ``` -------------------------------- ### Example Stockholm File Source: https://scikit.bio/docs/latest/generated/skbio.io.format.stockholm.html This is an example of a complete Stockholm file, showcasing the header, metadata (GF lines), multiple sequence alignment, and footer. ```stockholm # STOCKHOLM 1.0 #=GF ID UPSK #=GF SE Predicted; Infernal #=GF SS Published; PMID 9223489 #=GF RN [1] #=GF RM 9223489 #=GF RT The role of the pseudoknot at the 3' end of turnip yellow mosaic #=GF RT virus RNA in minus-strand synthesis by the viral RNA-dependent RNA #=GF RT polymerase. #=GF RA Deiman BA, Kortlever RM, Pleij CW; #=GF RL J Virol 1997;71:5990-5996. AF035635.1/619-641 UGAGUUCUCGAUCUCUAAAAUCG M24804.1/82-104 UGAGUUCUCUAUCUCUAAAAUCG J04373.1/6212-6234 UAAGUUCUCGAUCUUUAAAAUCG M24803.1/1-23 UAAGUUCUCGAUCUCUAAAAUCG #=GC SS_cons .AAA....<<<>>> // ``` -------------------------------- ### Test scikit-bio Installation Source: https://scikit.bio/contribute.html Run all unit tests to verify that the scikit-bio installation is successful and all functionalities work correctly. The output should only show passes and warnings. ```bash make test ``` -------------------------------- ### Navigate to Project Directory Source: https://scikit.bio/contribute.html Enter the cloned scikit-bio directory to begin setting up the development environment. ```bash cd scikit-bio ``` -------------------------------- ### Iterate Over Samples Starting with 'Z' Source: https://scikit.bio/docs/latest/generated/skbio.table.Table.iter.html Iterates over samples in a BIOM table and filters for those whose IDs start with 'Z'. This example assumes a table has been created and imported. ```python [(values, id, metadata) for values, id, metadata in table.iter() if id[0]=='Z'] ``` -------------------------------- ### Activate Conda Environment Source: https://scikit.bio/contribute.html Activate the newly created Conda environment 'skbio-dev' to start using the installed dependencies. ```bash conda activate skbio-dev ``` -------------------------------- ### Module __init__.py Example Source: https://scikit.bio/devdoc/new_module.html This is a basic __init__.py file for a scikit-bio module. It includes documentation strings and imports a TestRunner for testing purposes. ```python """ A module (:mod:`skbio.module`) ============================== .. currentmodule:: skbio.module Documentation for this module. """ # ---------------------------------------------------------------------------- # Copyright (c) 2013--, scikit-bio development team. # # Distributed under the terms of the Modified BSD License. # # The full license is to the file LICENSE.txt, distributed with this software. # ---------------------------------------------------------------------------- from skbio.util import TestRunner test = TestRunner(__file__).test ``` -------------------------------- ### Get ancestors of a TreeNode Source: https://scikit.bio/docs/latest/generated/skbio.tree.TreeNode.ancestors.html This snippet shows how to retrieve the ancestors of a specific TreeNode. The `include_self` parameter controls whether the starting node is included in the result. ```python >>> tip = tree.find('a') >>> [node.name for node in tip.ancestors()] ['c', 'g'] ``` ```python >>> [node.name for node in tip.ancestors(include_self=True)] ['a', 'c', 'g'] ``` -------------------------------- ### Get data for a sample ID Source: https://scikit.bio/docs/latest/generated/skbio.table.Table.data.html Retrieves the data associated with a specific sample ID. Ensure the 'biom' library is imported and an example table is available. ```python from biom import example_table example_table.data('S1', axis='sample') ``` -------------------------------- ### Sequence Initialization and Comparison Source: https://scikit.bio/docs/latest/generated/skbio.sequence.Sequence.html Demonstrates how to create Sequence objects and compare them for equality based on their characters and metadata. ```APIDOC ## Sequence Initialization and Comparison ### Description This section shows how to initialize `Sequence` objects and compare them for equality. Two sequences are considered equal if they are of the same type, have identical underlying character sequences, and possess matching metadata and positional metadata. If any of these attributes differ, the sequences are not equal. ### Examples **Creating and comparing equal sequences:** ```python from skbio import Sequence s = Sequence('ACGT') t = Sequence('ACGT') print(s == t) print(t == s) ``` **Comparing sequences with different characters:** ```python u = Sequence('ACGA') print(u == t) ``` **Comparing sequences with different metadata:** ```python v = Sequence('ACGA', metadata={'id': 'abc'}, positional_metadata={'quality':[1, 5, 3, 3]}) print(u == v) ``` ``` -------------------------------- ### Get minimum nonzero value over samples Source: https://scikit.bio/docs/latest/generated/skbio.table.Table.min.html Use `Table.min(axis='sample')` to find the minimum nonzero value for each sample. Requires the `biom` library to be installed for `example_table`. ```python >>> from biom import example_table >>> print(example_table.min(axis='sample')) [ 3. 1. 2.] ``` -------------------------------- ### Import example_table Source: https://scikit.bio/docs/latest/generated/skbio.table.Table.iter_pairwise.html Import the example_table from the biom library to use in subsequent examples. ```python from biom import example_table ``` -------------------------------- ### Get bipartition for a clade with more than half taxa Source: https://scikit.bio/docs/latest/generated/skbio.tree.TreeNode.bipart.html This example demonstrates retrieving the bipartition for a clade ('Z') that contains more than half of the total taxa. The output represents the remaining taxa. ```python >>> sorted(tree.find('Z').bipart()) ['e', 'f', 'g'] ``` -------------------------------- ### Create a sample Table object Source: https://scikit.bio/docs/latest/generated/skbio.table.Table.reduce.html Initializes a Table object with specified data, observation IDs, sample IDs, and metadata. ```python data = np.asarray([[0, 0, 1], [1, 3, 42]]) table = Table(data, ['O1', 'O2'], ['S1', 'S2', 'S3'], [{'foo': 'bar'}, {'x': 'y'}], None) ``` -------------------------------- ### Create a biom.table.Table Source: https://scikit.bio/docs/latest/generated/skbio.table.Table.collapse.html Demonstrates how to create a `Table` object with data, observation IDs, sample IDs, observation metadata, and sample metadata. ```python import numpy as np from biom.table import Table dt_rich = Table( np.array([[5, 6, 7], [8, 9, 10], [11, 12, 13]]), ['1', '2', '3'], ['a', 'b', 'c'], [{'taxonomy': ['k__a', 'p__b']}, {'taxonomy': ['k__a', 'p__c']}, {'taxonomy': ['k__a', 'p__c']}], [{'barcode': 'aatt'}, {'barcode': 'ttgg'}, {'barcode': 'aatt'}]) print(dt_rich) ``` -------------------------------- ### Create and Partition a BIOM Table Source: https://scikit.bio/docs/latest/generated/skbio.table.Table.partition.html Demonstrates how to create a BIOM table with observation and sample metadata, define a partitioning function based on metadata, and then partition the table. The output shows how to access the yielded bins and tables. ```python import numpy as np from biom.table import Table from biom.util import unzip ``` ```python data = np.asarray([[0, 0, 1], [1, 3, 42]]) table = Table(data, ['O1', 'O2'], ['S1', 'S2', 'S3'], [{'full_genome_available': True}, {'full_genome_available': False}], [{'sample_type': 'a'}, {'sample_type': 'a'}, {'sample_type': 'b'}]) ``` ```python f = lambda id_, md: md['sample_type'] ``` ```python bins, tables = table.partition(f) print(bins[1]) # Constructed from biom file #OTU ID S1 S2 #O1 0.0 0.0 #O2 1.0 3.0 print(tables[1]) # Constructed from biom file #OTU ID S3 #O1 1.0 #O2 42.0 ``` -------------------------------- ### Create Sample Data Matrix Source: https://scikit.bio/docs/latest/diversity.html Initializes a list of lists for sample data and a list of sample IDs. ```python data = [[23, 64, 14, 0, 0, 3, 1], [0, 3, 35, 42, 0, 12, 1], [0, 5, 5, 0, 40, 40, 0], [44, 35, 9, 0, 1, 0, 0], [0, 2, 8, 0, 35, 45, 1], [0, 0, 25, 35, 0, 19, 0]] ids = list('ABCDEF') ``` -------------------------------- ### Use paired_subsamples to get matched sample IDs Source: https://scikit.bio/docs/latest/generated/skbio.stats.power.paired_subsamples.html This example shows how to use the paired_subsamples function to identify samples that can be matched based on specified control categories. It highlights how missing values in control categories can affect matching when strict_match is True. ```python from skbio.stats.power import paired_subsamples ids = paired_subsamples(meta, 'HOUSING', ['SEX', 'AGE', 'ABX']) print(np.hstack(ids)) ``` -------------------------------- ### Build HTML Documentation Locally Source: https://scikit.bio/contribute.html This command builds the entire HTML documentation package locally. The generated documentation can be found at `doc/build/html/index.html` and examined in a web browser. ```bash make doc ``` -------------------------------- ### Sequence Initialization Source: https://scikit.bio/docs/latest/generated/skbio.sequence.Sequence.html Demonstrates how to initialize a Sequence object with and without metadata. ```APIDOC ## Sequence Initialization ### Description Initializes a generic sequence object with optional metadata. ### Method `__init__` ### Parameters - **sequence** (str, Sequence, or 1D np.ndarray) - The sequence data. - **metadata** (dict, optional) - Arbitrary metadata for the entire sequence. - **positional_metadata** (pd.DataFrame consumable, optional) - Arbitrary per-character metadata. - **interval_metadata** (IntervalMetadata) - Metadata for intervals within the sequence. - **lowercase** (bool or str, optional) - Controls conversion of lowercase characters to uppercase. ### Request Example ```python from skbio import Sequence from skbio.metadata import IntervalMetadata # Create a sequence without metadata seq1 = Sequence('GGUCGUGAAGGA') # Create a sequence with metadata metadata = {'authors': ['Alice'], 'desc':'seq desc', 'id':'seq-id'} positional_metadata = {'exons': [True, True, False, True], 'quality': [3, 3, 4, 10]} interval_metadata = IntervalMetadata(4) interval = interval_metadata.add([(1, 3)], metadata={'gene': 'sagA'}) seq2 = Sequence('ACGT', metadata=metadata, positional_metadata=positional_metadata, interval_metadata=interval_metadata) ``` ### Response #### Success Response (200) - **Sequence object** - The initialized sequence object. #### Response Example ```python # For seq1 Sequence --------------- Stats: length: 12 --------------- 0 GGUCGUGAAG GA # For seq2 Sequence ----------------------------- Metadata: 'authors': 'desc': 'seq desc' 'id': 'seq-id' Positional metadata: 'exons': 'quality': Interval metadata: 1 interval feature Stats: length: 4 ----------------------------- 0 ACGT ``` ``` -------------------------------- ### Create Sample Metadata DataFrame Source: https://scikit.bio/docs/latest/diversity.html Creates a pandas DataFrame to store sample metadata, including 'body_site' and 'subject', indexed by sample IDs. ```python import pandas as pd sample_md = pd.DataFrame([ ['gut', 's1'], ['skin', 's1'], ['tongue', 's1'], ['gut', 's2'], ['tongue', 's2'], ['skin', 's2']], index=['A', 'B', 'C', 'D', 'E', 'F'], columns=['body_site', 'subject']) sample_md ``` -------------------------------- ### Translate RNA to Protein (Require Start Codon) Source: https://scikit.bio/docs/latest/generated/skbio.sequence.GeneticCode.translate.html Translates an RNA sequence into a protein sequence, requiring the translation to start at the first start codon. Methionine (M) is used as the first amino acid if an alternative start codon is encountered. ```python >>> sgc.translate(rna, start='require') Protein -------------------------- Stats: length: 5 has gaps: False has degenerates: False has definites: True has stops: True -------------------------- 0 MPL*E ``` -------------------------------- ### Install scikit-bio with Conda Source: https://scikit.bio/install.html Use this command to install the latest release of scikit-bio from the conda-forge channel. ```bash conda install -c conda-forge scikit-bio ``` -------------------------------- ### Iterate Over Tree Tips Source: https://scikit.bio/docs/latest/generated/skbio.tree.TreeNode.tips.html Shows how to use the .tips() method to iterate over the leaf nodes (tips) of a tree and print their names. Ensure the tree is initialized and visualized first. ```python >>> for node in tree.tips(): ... print(node.name) ... a b d e ``` -------------------------------- ### Create and visualize a tree Source: https://scikit.bio/docs/latest/generated/skbio.tree.TreeNode.bifurcate.html This example demonstrates how to create a TreeNode from a string representation and visualize its structure using ascii_art. This is a prerequisite for applying tree modification methods. ```python >>> from skbio import TreeNode >>> tree = TreeNode.read(["((a,b,g,h)c,(d,e)f)root;"]) >>> print(tree.ascii_art()) /-a | |--b /c------- | |--g | -root----| | | /-h \f------- \-e ``` -------------------------------- ### Access AlignPath Starts Source: https://scikit.bio/docs/latest/generated/skbio.alignment.AlignPath.html Retrieves the start positions of each sequence within the alignment. These are 0-based indices. ```python path.starts ``` -------------------------------- ### Add Doctest Example for GC Content Function Source: https://scikit.bio/contribute.html This snippet demonstrates how to add an example usage to the docstring of the `gc_content` function. Doctests are automatically executed as part of the test suite to ensure example code and output match. ```python def gc_content(seq): """Calculate the GC content of a nucleotide sequence. ... Examples -------- >>> from skbio.sequence.nucl import gc_content >>> gc_content("ACGT") 0.5 """ ... ``` -------------------------------- ### Example GS Metadata Source: https://scikit.bio/docs/latest/generated/skbio.io.format.stockholm.html Provides an example of sequence-specific global feature (GS) metadata in a Stockholm file. ```plaintext #=GS O83071/259-312 AC O83071 ``` -------------------------------- ### RNA Sequence Initialization Source: https://scikit.bio/docs/latest/generated/skbio.sequence.RNA.html Demonstrates how to initialize an RNA sequence object with various parameters. ```APIDOC ## RNA Sequence Initialization ### Description Initializes an RNA sequence object with the provided sequence data and optional metadata. ### Method `RNA(sequence, metadata=None, positional_metadata=None, interval_metadata=None, lowercase=False, validate=True)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **sequence** (str, Sequence, or 1D np.ndarray) - Required - Characters representing the RNA sequence itself. - **metadata** (dict) - Optional - Arbitrary metadata which applies to the entire sequence. - **positional_metadata** (Pandas DataFrame consumable) - Optional - Arbitrary per-character metadata. - **interval_metadata** (IntervalMetadata) - Optional - Arbitrary metadata which applies to intervals within a sequence. - **lowercase** (bool or str) - Optional - If `True`, lowercase characters are converted to uppercase. If a str, it's a key for positional metadata. - **validate** (bool) - Optional - If `True`, validation is performed to ensure valid IUPAC RNA characters. ### Request Example ```python from skbio import RNA # Basic initialization rna_seq = RNA('ACCGAAU') # With metadata and lowercase conversion rna_seq_meta = RNA('AcCGaaU', metadata={'id': 'seq1'}, lowercase=True) ``` ### Response #### Success Response (200) An `RNA` object representing the initialized sequence. #### Response Example ``` RNA -------------------------- Stats: length: 7 has gaps: False has degenerates: False has definites: True GC-content: 42.86% -------------------------- 0 ACCGAAU ``` ``` -------------------------------- ### Install scikit-bio using Pip Source: https://scikit.bio/ Installs the scikit-bio package using the Pip package manager from PyPI. ```bash pip install scikit-bio ``` -------------------------------- ### Initialize StringIO and read taxdump file Source: https://scikit.bio/docs/latest/generated/skbio.io.format.taxdump.html Initializes a StringIO object with sample taxdump data and imports necessary libraries for reading the file. ```python >>> from io import StringIO >>> import skbio.io >>> import pandas as pd >>> fs = '\n'.join([ ... '1\t|\t1\t|\tno rank\t|', ... '2\t|\t131567\t|\tsuperkingdom\t|', ... '6\t|\t335928\t|\tgenus\t|' ... ]) >>> fh = StringIO(fs) ``` -------------------------------- ### Get Complement of DNA Sequence Source: https://scikit.bio/docs/latest/generated/skbio.sequence.NucleotideMixin.complement.html Demonstrates how to get the complement of a DNA sequence. Positional metadata is preserved. ```python >>> from skbio import DNA >>> seq = DNA('TTCATT', positional_metadata={'quality':range(6)}) >>> seq DNA ----------------------------- Positional metadata: 'quality': Stats: length: 6 has gaps: False has degenerates: False has definites: True GC-content: 16.67% ----------------------------- 0 TTCATT >>> seq.complement() DNA ----------------------------- Positional metadata: 'quality': Stats: length: 6 has gaps: False has degenerates: False has definites: True GC-content: 16.67% ----------------------------- 0 AAGTAA ``` -------------------------------- ### Get MSA shape Source: https://scikit.bio/docs/latest/generated/skbio.alignment.TabularMSA.html Accessing the shape property of a TabularMSA object to get the number of sequences and positions. ```python >>> from skbio import DNA, TabularMSA >>> msa = TabularMSA([DNA('ACG'), DNA('AC-')]) >>> msa.shape Shape(sequence=2, position=3) >>> msa.shape == (2, 3) True ``` -------------------------------- ### Create and Visualize a TreeNode Source: https://scikit.bio/docs/latest/generated/skbio.tree.TreeNode.tips.html Demonstrates how to create a TreeNode from a string representation and visualize it using ascii_art. This is a prerequisite for using methods like .tips(). ```python >>> from skbio import TreeNode >>> tree = TreeNode.read(["((a,b)c,(d,e)f);"]) >>> print(tree.ascii_art()) /-a /c-------| | \-b --------- | /-d \f-------| \-e ``` -------------------------------- ### Verify scikit-bio installation Source: https://scikit.bio/install.html Check if scikit-bio is installed correctly by importing it and printing its version in a Python shell or script. ```python import skbio print(skbio.__version__) ``` -------------------------------- ### Install scikit-bio on Arch Linux Source: https://scikit.bio/install.html Install scikit-bio from the Arch User Repository (AUR) on Arch Linux or Manjaro. ```bash yay -S python-scikit-bio ``` -------------------------------- ### Create and Query a BIOM Table Source: https://scikit.bio/docs/latest/generated/skbio.table.Table.get_value_by_ids.html Demonstrates creating a BIOM table with sample data and then retrieving a specific value using observation and sample IDs. Ensure numpy and biom.table are imported. ```python import numpy as np from biom.table import Table ``` ```python data = np.asarray([[0, 0, 1], [1, 3, 42]]) table = Table(data, ['O1', 'O2'], ['S1', 'S2', 'Z3']) ``` ```python print(table.get_value_by_ids('O2', 'Z3')) ``` -------------------------------- ### Create a BIOM Table Source: https://scikit.bio/docs/latest/generated/skbio.table.Table.metadata.html Demonstrates how to create a BIOM table with specific dimensions, observation IDs, sample IDs, observation metadata, and no sample metadata. ```python import numpy as np from biom.table import Table data = np.asarray([[0, 0, 1], [1, 3, 42]]) table = Table(data, ['O1', 'O2'], ['S1', 'S2', 'S3'], [{'foo': 'bar'}, {'x': 'y'}], None) ``` -------------------------------- ### Install scikit-bio using Conda Source: https://scikit.bio/ Installs the scikit-bio package using the Conda package manager from the conda-forge channel. ```bash conda install -c conda-forge scikit-bio ``` -------------------------------- ### Create and Compare Sequence Objects Source: https://scikit.bio/docs/latest/generated/skbio.sequence.Sequence.html Demonstrates creating Sequence objects with identical and different character sequences, and how equality is determined based on sequence characters and metadata. ```python >>> from skbio import Sequence >>> s = Sequence('ACGT') >>> t = Sequence('ACGT') >>> s == t True >>> t == s True ``` ```python >>> u = Sequence('ACGA') >>> u == t False ``` ```python >>> v = Sequence('ACGA', metadata={'id': 'abc'}, ... positional_metadata={'quality':[1, 5, 3, 3]}) >>> _ = v.interval_metadata.add([(0, 1)]) >>> u == v False ``` -------------------------------- ### Access AlignPath Ranges Source: https://scikit.bio/docs/latest/generated/skbio.alignment.AlignPath.html Retrieves the start and stop positions for each sequence in the alignment as a list of [start, stop] pairs. ```python path.ranges ``` -------------------------------- ### Get k-mer counts from a Sequence Source: https://scikit.bio/docs/latest/generated/skbio.sequence.Sequence.kmer_frequencies.html Use `kmer_frequencies` with `overlap=False` to get counts of non-overlapping k-mers. Requires `skbio.Sequence`. ```python >>> from skbio import Sequence >>> s = Sequence('ACACATTTATTA') >>> freqs = s.kmer_frequencies(3, overlap=False) >>> freqs {'ACA': 1, 'CAT': 1, 'TTA': 2} ``` -------------------------------- ### Install scikit-bio-binaries with Conda Source: https://scikit.bio/install.html Install the scikit-bio-binaries package using Conda to significantly increase the performance of select scikit-bio functions. ```bash conda install -c conda-forge scikit-bio-binaries ``` -------------------------------- ### Create and Inspect a BIOM Table Source: https://scikit.bio/docs/latest/generated/skbio.table.Table.ids.html Demonstrates how to create a BIOM table and retrieve its observation and sample IDs. Ensure 'numpy' and 'biom.table' are imported. ```python import numpy as np from biom.table import Table ``` ```python data = np.asarray([[0, 0, 1], [1, 3, 42]]) table = Table(data, ['O1', 'O2'], ['S1', 'S2', 'S3']) ``` ```python print(table.ids(axis='observation')) ``` ```python print(table.ids()) ```