### Install Unicycler from Source Source: https://github.com/rrwick/unicycler/blob/main/README.md Clones the Unicycler repository and installs it using setup.py. May require sudo for permissions or --user for local installation. ```bash git clone https://github.com/rrwick/Unicycler.git cd Unicycler python3 setup.py install ``` ```bash python3 setup.py install --user ``` ```bash python3 setup.py install --prefix=$HOME/.local ``` ```bash python3 setup.py install --makeargs "CXX=icpc" ``` -------------------------------- ### Install Unicycler with Pip Source: https://github.com/rrwick/unicycler/blob/main/README.md Installs Unicycler using pip, either from a local path or directly from GitHub. ```bash pip3 install path/to/Unicycler ``` ```bash pip3 install git+https://github.com/rrwick/Unicycler.git ``` -------------------------------- ### Build Unicycler from Source without Installation Source: https://github.com/rrwick/unicycler/blob/main/README.md Compiles Unicycler code from source without copying executables. Use the provided runner script for execution. ```bash git clone https://github.com/rrwick/Unicycler.git cd Unicycler make ``` -------------------------------- ### Extract and Convert Reads to FASTA Source: https://github.com/rrwick/unicycler/wiki/Read-extraction Uses zgrep to extract matching read headers and sequences, then uses sed to convert FASTQ headers (starting with '@') to FASTA headers (starting with '>'). ```bash zgrep -A 1 --no-group-separator -E $(...) long_reads.fastq.gz | sed 's|^@|>|' ``` -------------------------------- ### Get Best SPAdes Graph Source: https://context7.com/rrwick/unicycler/llms.txt Utilize the get_best_spades_graph function to run SPAdes short-read assembly with automatic k-mer optimization, returning the optimal assembly graph. ```python from unicycler.spades_func import get_best_spades_graph, get_kmer_range ``` -------------------------------- ### Get Basic Graph Statistics Source: https://context7.com/rrwick/unicycler/llms.txt Retrieve key statistics from the AssemblyGraph, including total length, total length without overlaps, number of dead ends, and median read depth. ```python # Get basic graph statistics total_length = graph.get_total_length() total_length_no_overlaps = graph.get_total_length_no_overlaps() dead_ends = graph.total_dead_end_count() median_depth = graph.get_median_read_depth() ``` -------------------------------- ### Adding ML tags for manual multiplicity Source: https://github.com/rrwick/unicycler/wiki/Multiplicity-mistake Manually assign multiplicity tags (ML) in the GFA file to guide Unicycler's assembly process. This example shows how to set ML to '2' for contigs identified as 2x repeats. ```text S 52 TTTTT...TCGAT LN:i:21445 dp:f:3.253 LB:z:3.253 CL:z:forestgreen ML:i:2 ``` ```text S 66 CGCAA...CGTCA LN:i:10064 dp:f:3.219 LB:z:3.219 CL:z:forestgreen ML:i:2 ``` -------------------------------- ### Get Connected Components Source: https://context7.com/rrwick/unicycler/llms.txt Extract connected components from the assembly graph. Each component is a list of segment numbers. ```python # Get connected components components = graph.get_connected_components() # Returns: [[1, 2, 3], [4, 5]] # segment numbers grouped by component ``` -------------------------------- ### Get Single-Copy Segments Source: https://context7.com/rrwick/unicycler/llms.txt Retrieve a list of segments that appear to be single-copy within the assembly graph, useful for scaffolding purposes. ```python # Get single-copy segments (useful for scaffolding) single_copy_segments = graph.get_single_copy_segments() ``` -------------------------------- ### Get Path Sequence Source: https://context7.com/rrwick/unicycler/llms.txt Reconstruct the DNA sequence for a given path through the assembly graph. Paths are defined by a list of signed segment numbers. ```python # Get path sequence through the graph path = [1, 2, -3, 4] # signed segment numbers (negative = reverse complement) sequence = graph.get_path_sequence(path) ``` -------------------------------- ### Get Completed Circular Replicons Source: https://context7.com/rrwick/unicycler/llms.txt Identify and retrieve the segment numbers that form complete circular replicons within the assembly graph. ```python # Get completed circular replicons circular_segs = graph.completed_circular_replicons() # Returns list of segment numbers that form complete circles ``` -------------------------------- ### Parse GFA Output and Get Statistics Source: https://context7.com/rrwick/unicycler/llms.txt Programmatically parses the final GFA output file to retrieve assembly statistics like N50, longest contig, and total segments. Also checks the completion status of connected components. ```python from unicycler.assembly_graph import AssemblyGraph final_graph = AssemblyGraph('output_dir/assembly.gfa', overlap=0) # Get assembly statistics n50, shortest, q1, median, q3, longest = final_graph.get_contig_stats() print(f"N50: {n50} bp") print(f"Longest contig: {longest} bp") print(f"Total segments: {len(final_graph.segments)}") # Check completion status components = final_graph.get_connected_components() for i, comp in enumerate(components): status = "complete" if final_graph.is_component_complete(comp) else "incomplete" length = sum(final_graph.segments[x].get_length() for x in comp) print(f"Component {i+1}: {length} bp, {status}") ``` -------------------------------- ### Extract Aligned Long Reads (macOS) Source: https://github.com/rrwick/unicycler/wiki/Read-extraction This alternative command is designed for macOS, which may have different command-line tool behaviors. You might need to install GNU grep via Homebrew. It achieves the same goal of extracting relevant long reads. ```bash gunzip -c long_reads.fastq.gz | grep -A 1 --no-group-separator -E $(minimap2 -x map10k -c -t 8 sequence.fasta long_reads.fastq.gz | awk '{if ($2 >= 2000 && $11 >= 1000 && $10/$11 >= 0.85) print $1;}' | sort | uniq | tr '\n' '|' | sed 's/.$//') | sed 's|^@|>|' > reads.fasta ``` -------------------------------- ### Configure Path Length Ratios Source: https://context7.com/rrwick/unicycler/llms.txt Sets the minimum and maximum relative path length ratios for assembly graph path finding. ```python min_path_length_ratio = settings.MIN_RELATIVE_PATH_LENGTH # 0.9 max_path_length_ratio = settings.MAX_RELATIVE_PATH_LENGTH # 1.1 ``` -------------------------------- ### Assembly Graph Visualization Source: https://github.com/rrwick/unicycler/blob/main/README.md Illustrates the difference between simple contigs and a more complex assembly graph structure. ```text Just contigs: Assembly graph: TCGAAACTTGACGCGAGTCGC CTTGTTTA TGCTACTGCTTGATGATGCGG / \ TGTCCATT TCGAAACTTGACGCGAGTCGC TGCTACTGCTTGATGATGCGG CTTGTTTA \ / TGTCCATT ``` -------------------------------- ### Create Miniasm String Graph Source: https://context7.com/rrwick/unicycler/llms.txt Generates a string graph for hybrid assembly by aligning long reads to a SPAdes graph and polishing with Racon. ```python from unicycler.miniasm_assembly import make_miniasm_string_graph # Create miniasm string graph for hybrid assembly string_graph = make_miniasm_string_graph( graph=short_read_graph, # AssemblyGraph from SPAdes (None for long-read-only) read_dict=read_dictionary, # Dict of read_name -> Read objects long_read_filename='long_reads.fastq.gz', scoring_scheme=scoring_scheme, # AlignmentScoringScheme object read_nicknames=nickname_dict, # Dict mapping read names to short IDs counter=itertools.count(start=1), # Counter for output file numbering args=args, # Parsed command-line arguments anchor_segments=anchor_list, # List of single-copy segments to bridge existing_long_read_assembly=None # Path to pre-made assembly or None ) # Returns: StringGraph object with polished unitigs ``` -------------------------------- ### Run Hybrid Assembly Source: https://context7.com/rrwick/unicycler/llms.txt Combine short and long reads for optimal hybrid assembly. Use -1 and -2 for short reads, -l for long reads, and -o for the output directory. ```bash # Hybrid assembly (best results - both short and long reads) unicycler -1 short_reads_1.fastq.gz -2 short_reads_2.fastq.gz -l long_reads.fastq.gz -o output_dir ``` -------------------------------- ### Run Unicycler in Bold Mode Source: https://github.com/rrwick/unicycler/wiki/Insufficient-long-read-depth Use this command to run Unicycler in 'bold' mode, which may improve assembly completeness at the cost of increased misassembly risk. Ensure you have short and long read FASTQ files. ```bash unicycler-runner.py -1 short_1.fastq.gz -2 short_2.fastq.gz -l long.fastq.gz -o assembly --mode bold ``` -------------------------------- ### Miniasm Assembly Pipeline Source: https://context7.com/rrwick/unicycler/llms.txt Creates a string graph for hybrid assembly using miniasm and Racon polishing, integrating long reads with short-read contigs. ```APIDOC ## Miniasm Assembly Pipeline ### Description Creates a string graph for hybrid assembly using miniasm and Racon polishing, integrating long reads with short-read contigs. ### Method `make_miniasm_string_graph` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **graph** (AssemblyGraph) - Optional - AssemblyGraph from SPAdes. If None, performs long-read-only assembly. - **read_dict** (dict) - Required - A dictionary mapping read names to Read objects. - **long_read_filename** (str) - Required - Filename for the long reads. - **scoring_scheme** (AlignmentScoringScheme) - Required - An AlignmentScoringScheme object. - **read_nicknames** (dict) - Optional - A dictionary mapping read names to short IDs. - **counter** (itertools.count) - Optional - A counter for output file numbering. - **args** (object) - Optional - Parsed command-line arguments. - **anchor_segments** (list) - Optional - A list of single-copy segments to bridge. - **existing_long_read_assembly** (str) - Optional - Path to a pre-made long-read assembly, or None. ### Request Example ```python string_graph = make_miniasm_string_graph( graph=short_read_graph, read_dict=read_dictionary, long_read_filename='long_reads.fastq.gz', scoring_scheme=scoring_scheme, read_nicknames=nickname_dict, anchor_segments=anchor_list, args=args ) ``` ### Response #### Success Response (200) - **StringGraph object** - A StringGraph object representing the polished unitigs. ``` -------------------------------- ### Run Hybrid Assembly with Custom Options Source: https://context7.com/rrwick/unicycler/llms.txt Configure Unicycler for hybrid assembly with advanced options. This includes setting the assembly mode, number of threads, verbosity, minimum FASTA length, and number of assemblies to keep. ```bash # Hybrid assembly with custom options unicycler \ -1 short_reads_1.fastq.gz \ -2 short_reads_2.fastq.gz \ -l long_reads.fastq.gz \ -o output_dir \ --mode bold \ --threads 16 \ --verbosity 2 \ --min_fasta_length 500 \ --keep 2 ``` -------------------------------- ### Run Illumina-only Assembly Source: https://context7.com/rrwick/unicycler/llms.txt Execute Unicycler for assembly using only paired-end Illumina short reads. Specify input files with -1 and -2, and the output directory with -o. ```bash # Illumina-only assembly (paired-end reads) unicycler -1 short_reads_1.fastq.gz -2 short_reads_2.fastq.gz -o output_dir ``` -------------------------------- ### Optimize K-mer Range and Run SPAdes Source: https://context7.com/rrwick/unicycler/llms.txt Functions to determine the optimal k-mer range for assembly and execute the SPAdes assembler to generate an assembly graph. ```python kmer_range = get_kmer_range( given_kmers=None, # None for automatic, or list like [21, 51, 71] reads_1_filename='R1.fastq.gz', reads_2_filename='R2.fastq.gz', unpaired_reads_filename=None, spades_dir='/path/to/spades_work', kmer_count=8, # Number of k-mer steps min_kmer_frac=0.2, # Min k-mer as fraction of read length max_kmer_frac=0.95, # Max k-mer as fraction of read length spades_path='spades.py' ) # Returns: [27, 47, 63, 77, 89, 99, 107, 117] ``` ```python best_graph = get_best_spades_graph( short1='reads_1.fastq.gz', short2='reads_2.fastq.gz', short_unpaired=None, out_dir='/path/to/output', read_depth_filter=0.25, # Filter contigs below this fraction of chromosomal depth verbosity=1, spades_path='spades.py', threads=8, keep=1, # File retention level (0-3) kmer_count=8, min_k_frac=0.2, max_k_frac=0.95, kmers=None, # Specific k-mers or None for auto expected_linear_seqs=0, largest_component=False, # Keep only largest component? spades_graph_prefix='/path/to/graphs/spades', spades_options=None, # Additional SPAdes options spades_version='3.15.0' ) # Returns: AssemblyGraph object with optimal k-mer assembly ``` -------------------------------- ### Run Build Test Source: https://github.com/rrwick/unicycler/blob/main/test/README.md Perform build tests for Unicycler, which include running the `Makefile` with various compilers and executing `unicycler_align` to ensure its functionality. Results are presented in a table. Compilers earlier than GCC 4.9.1 and Clang 3.5 are expected to fail. ```bash python3 test/build_test.py ``` -------------------------------- ### Configure SPAdes temporary directory in Unicycler Source: https://github.com/rrwick/unicycler/wiki/FAQs Use the --spades_options flag to specify a local temporary directory when running Unicycler in a virtual machine to avoid file system errors. ```bash unicycler -1 reads_1.fastq.gz -2 reads_2.fastq.gz -o outdir --spades_options "--tmp-dir /tmp" ``` -------------------------------- ### SPAdes Graph Generation Source: https://context7.com/rrwick/unicycler/llms.txt Runs SPAdes to generate the best assembly graph, optionally filtering contigs and using specific k-mers. ```APIDOC ## Run SPAdes and get best assembly graph ### Description Runs SPAdes to generate the best assembly graph, optionally filtering contigs and using specific k-mers. ### Method `get_best_spades_graph` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **short1** (str) - Required - Filename for the first set of paired-end reads. - **short2** (str) - Required - Filename for the second set of paired-end reads. - **short_unpaired** (str) - Optional - Filename for unpaired short reads. - **out_dir** (str) - Required - Output directory for SPAdes results. - **read_depth_filter** (float) - Optional - Filter contigs below this fraction of chromosomal depth. - **verbosity** (int) - Optional - Verbosity level for SPAdes output. - **spades_path** (str) - Optional - Path to the SPAdes executable. - **threads** (int) - Optional - Number of threads to use for SPAdes. - **keep** (int) - Optional - File retention level (0-3). - **kmer_count** (int) - Optional - Number of k-mer steps to consider. - **min_k_frac** (float) - Optional - Minimum k-mer size as a fraction of read length. - **max_k_frac** (float) - Optional - Maximum k-mer size as a fraction of read length. - **kmers** (list) - Optional - Specific k-mers to use, or None for automatic selection. - **expected_linear_seqs** (int) - Optional - Expected number of linear sequences. - **largest_component** (bool) - Optional - If True, keep only the largest connected component. - **spades_graph_prefix** (str) - Optional - Prefix for SPAdes graph output files. - **spades_options** (str) - Optional - Additional command-line options for SPAdes. - **spades_version** (str) - Optional - Version of SPAdes to use. ### Request Example ```python best_graph = get_best_spades_graph( short1='reads_1.fastq.gz', short2='reads_2.fastq.gz', out_dir='/path/to/output', threads=8, kmer_count=8, min_k_frac=0.2, max_k_frac=0.95 ) ``` ### Response #### Success Response (200) - **AssemblyGraph object** - An object representing the best assembly graph generated by SPAdes. ``` -------------------------------- ### Run Random Sequence Assembly Test Source: https://github.com/rrwick/unicycler/blob/main/test/README.md Initiate tests that generate random sequences, create fake reads, and assemble them using Unicycler. This test runs indefinitely and requires manual interruption (Ctrl-C). ```bash python3 test/random_sequence_assembly_test.py ``` -------------------------------- ### Load Assembly Graph from GFA Source: https://context7.com/rrwick/unicycler/llms.txt Initialize an AssemblyGraph object by loading data from a GFA file. Specify the overlap parameter, and optionally custom insert size parameters. ```python from unicycler.assembly_graph import AssemblyGraph # Load an assembly graph from a GFA file graph = AssemblyGraph('assembly_graph.gfa', overlap=77) # Load with custom insert size parameters graph = AssemblyGraph('assembly_graph.gfa', overlap=77, insert_size_mean=350, insert_size_deviation=75) ``` -------------------------------- ### Run Unicycler Unit Tests Source: https://github.com/rrwick/unicycler/blob/main/test/README.md Execute all unit tests for Unicycler. These tests verify individual functions within the codebase and are designed to be fast. ```bash python3 -m unittest ``` -------------------------------- ### Run Assembly with Unpaired Short Reads Source: https://context7.com/rrwick/unicycler/llms.txt Assemble genomes using unpaired short reads and long reads. Use -s for unpaired short reads and -l for long reads, specifying the output directory with -o. ```bash # Assembly with unpaired short reads unicycler -s unpaired_reads.fastq.gz -l long_reads.fastq.gz -o output_dir ``` -------------------------------- ### Prepare Read Names for Grep (macOS variant) Source: https://github.com/rrwick/unicycler/wiki/Read-extraction Sorts and uniquely identifies read names, then formats them into a pipe-delimited string using 'tr' and 'sed' for compatibility with macOS grep. ```bash sort | uniq | tr '\n' '|' | sed 's/.$//' ``` -------------------------------- ### Apply Assembly Bridges Source: https://context7.com/rrwick/unicycler/llms.txt Creates and applies bridges between single-copy segments using evidence from SPAdes, long reads, and miniasm assemblies. ```python from unicycler.bridge_long_read import create_long_read_bridges from unicycler.bridge_spades_contig import create_spades_contig_bridges from unicycler.bridge_miniasm import create_miniasm_bridges # Create bridges from SPAdes contig paths spades_bridges = create_spades_contig_bridges( graph=assembly_graph, anchor_segments=single_copy_segments ) # Create bridges from long read alignments long_read_bridges = create_long_read_bridges( graph=assembly_graph, read_dict=read_dictionary, read_names=read_name_list, anchor_segments=single_copy_segments, verbosity=1, min_scaled_score=85.0, threads=8, scoring_scheme=scoring_scheme, min_alignment_length=1000, expected_linear_seqs=False, min_bridge_qual=10.0 ) # Create bridges from miniasm assembly miniasm_bridges = create_miniasm_bridges( graph=assembly_graph, string_graph=miniasm_string_graph, anchor_segments=single_copy_segments, scoring_scheme=scoring_scheme, verbosity=1, min_bridge_qual=10.0 ) # Combine all bridges all_bridges = spades_bridges + long_read_bridges + miniasm_bridges # Apply bridges to graph (sorted by quality, highest first) seg_nums_used = graph.apply_bridges( bridges=all_bridges, verbosity=1, min_bridge_qual=10.0 # Reject bridges below this quality ) ``` -------------------------------- ### Miniasm+Racon Assembly Options Source: https://github.com/rrwick/unicycler/blob/main/README.md Options for controlling the use of miniasm and Racon for long-read bridging. ```APIDOC ## Miniasm+Racon Assembly Options ### Description These options control the use of miniasm and Racon to produce long-read bridges. ### Parameters #### Query Parameters - **--no_miniasm** - Optional - Skip miniasm+Racon bridging (default: use miniasm and Racon to produce long-read bridges) - **--racon_path** (string) - Optional - Path to the Racon executable (default: racon) - **--existing_long_read_assembly** (string) - Optional - A pre-prepared long-read assembly for the sample in GFA or FASTA format. If this option is used, Unicycler will skip the miniasm/Racon steps and instead use the given assembly (default: perform long-read assembly using miniasm/Racon) ``` -------------------------------- ### SPAdes Assembly Options Source: https://github.com/rrwick/unicycler/blob/main/README.md Options that control the SPAdes assembler's behavior during the initial assembly phase. ```APIDOC ## SPAdes Assembly Options ### Description These options configure the SPAdes assembler used by Unicycler. ### Parameters #### Query Parameters - **--min_kmer_frac** (float) - Optional - Lowest k-mer size for SPAdes assembly, expressed as a fraction of the read length (default: 0.2) - **--max_kmer_frac** (float) - Optional - Highest k-mer size for SPAdes assembly, expressed as a fraction of the read length (default: 0.95) - **--kmers** (string) - Optional - Exact k-mers to use for SPAdes assembly, comma-separated (example: 21,51,71, default: automatic) - **--kmer_count** (integer) - Optional - Number of k-mer steps to use in SPAdes assembly (default: 8) - **--depth_filter** (float) - Optional - Filter out contigs lower than this fraction of the chromosomal depth, if doing so does not result in graph dead ends (default: 0.25) - **--largest_component** - Optional - Only keep the largest connected component of the assembly graph (default: keep all connected components) - **--spades_options** (string) - Optional - Additional options to be given to SPAdes (example: "--phred-offset 33", default: no additional options) ``` -------------------------------- ### Run Long-read-only Assembly Source: https://context7.com/rrwick/unicycler/llms.txt Perform assembly using only long reads (PacBio or Nanopore). Provide the long-read file using the -l flag and specify the output directory with -o. ```bash # Long-read-only assembly (PacBio or Nanopore) unicycler -l long_reads.fastq.gz -o output_dir ``` -------------------------------- ### Assembly Rotation Options Source: https://github.com/rrwick/unicycler/blob/main/README.md Options for rotating completed circular sequences. ```APIDOC ## Assembly Rotation Options ### Description These options control the rotation of completed circular sequence near the end of the Unicycler pipeline. ### Parameters #### Query Parameters - **--no_rotate** - Optional - Do not rotate completed replicons to start at a standard gene (default: completed replicons are rotated) - **--start_genes** (string) - Optional - FASTA file of genes for start point of rotated replicons (default: start_genes.fasta) - **--start_gene_id** (float) - Optional - The minimum required BLAST percent identity for a start gene search (default: 90.0) - **--start_gene_cov** (float) - Optional - The minimum required BLAST percent coverage for a start gene search (default: 95.0) - **--makeblastdb_path** (string) - Optional - Path to the makeblastdb executable (default: makeblastdb) - **--tblastn_path** (string) - Optional - Path to the tblastn executable (default: tblastn) ``` -------------------------------- ### Extract and Convert Reads to FASTA (macOS variant) Source: https://github.com/rrwick/unicycler/wiki/Read-extraction Uses grep to extract matching read headers and sequences, then uses sed to convert FASTQ headers to FASTA headers. This variant is for unzipped files or when using 'gunzip -c'. ```bash gunzip -c long_reads.fastq.gz | grep -A 1 --no-group-separator -E $(...) | sed 's|^@|>|' ``` -------------------------------- ### Use Existing Long-Read Assembly for Bridging Source: https://context7.com/rrwick/unicycler/llms.txt Utilize a pre-existing long-read assembly graph (GFA format) to aid in bridging short reads. Specify the existing assembly with --existing_long_read_assembly. ```bash # Using existing long-read assembly for bridging unicycler -1 R1.fq.gz -2 R2.fq.gz -l long.fq.gz -o out \ --existing_long_read_assembly my_long_read_assembly.gfa ``` -------------------------------- ### Configure Assembly Mode Settings Source: https://context7.com/rrwick/unicycler/llms.txt Access Unicycler's configuration constants for different assembly modes (conservative, normal, bold) to adjust bridge quality thresholds and other parameters. These settings affect accuracy and completeness. ```python from unicycler import settings # Bridge quality thresholds by mode # Conservative: most accurate, fewer completed replicons conservative_threshold = settings.CONSERVATIVE_MIN_BRIDGE_QUAL # 25.0 # Normal: balanced accuracy and completeness normal_threshold = settings.NORMAL_MIN_BRIDGE_QUAL # 10.0 # Bold: most completed replicons, higher misassembly risk bold_threshold = settings.BOLD_MIN_BRIDGE_QUAL # 1.0 # Other key settings max_threads_default = settings.MAX_AUTO_THREAD_COUNT # 8 min_alignment_length = settings.MIN_LONG_READ_ALIGNMENT_LENGTH # 50 racon_loops_hybrid = settings.RACON_POLISH_LOOP_COUNT_HYBRID # 2 racon_loops_long_only = settings.RACON_POLISH_LOOP_COUNT_LONG_ONLY # 4 ``` -------------------------------- ### Specify Expected Linear Sequences Source: https://context7.com/rrwick/unicycler/llms.txt Configure Unicycler to expect linear sequences, which is useful for organisms with linear chromosomes. Use the --linear_seqs flag. ```bash # Expected linear sequences (e.g., for organisms with linear chromosomes) unicycler -1 R1.fq.gz -2 R2.fq.gz -l long.fq.gz -o out --linear_seqs 1 ``` -------------------------------- ### Minimap2 Alignment Command Source: https://github.com/rrwick/unicycler/wiki/Read-extraction This command performs the initial alignment of long reads to a reference sequence using minimap2. The '-c' flag enables base-by-base alignment for identity calculation, and '-x map-ont' is a preset for Nanopore reads. ```bash minimap2 -x map-ont -c -t 8 sequence.fasta long_reads.fastq.gz ``` -------------------------------- ### Unicycler Output Directory Structure Source: https://context7.com/rrwick/unicycler/llms.txt Default output directory structure for Unicycler with `--keep 1`. The final assembly is always saved in GFA and FASTA formats. ```bash # Output directory structure (--keep 1, default): output_dir/ ├── assembly.gfa # Final assembly in GFA v1 format ├── assembly.fasta # Final assembly in FASTA format ├── unicycler.log # Detailed log of the assembly process ├── 001_spades_graph_k*.gfa # SPAdes graphs at each k-mer ├── 002_depth_filter.gfa # Graph after depth filtering ├── 003_overlaps_removed.gfa # Overlap-free graph ├── 004_long_read_assembly.gfa # Miniasm+Racon assembly (hybrid only) ├── 005_bridges_applied.gfa # Graph after bridging └── 006_final_clean.gfa # Cleaned graph before rotation ``` -------------------------------- ### K-mer Range Calculation Source: https://context7.com/rrwick/unicycler/llms.txt Calculates an optimal range of k-mer sizes for SPAdes based on read lengths and other parameters. ```APIDOC ## Get optimal k-mer range based on read lengths ### Description Calculates an optimal range of k-mer sizes for SPAdes based on read lengths and other parameters. ### Method `get_kmer_range` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **given_kmers** (list) - Optional - None for automatic, or list like [21, 51, 71] - **reads_1_filename** (str) - Required - Filename for the first set of paired-end reads. - **reads_2_filename** (str) - Required - Filename for the second set of paired-end reads. - **unpaired_reads_filename** (str) - Optional - Filename for unpaired reads. - **spades_dir** (str) - Optional - Directory for SPAdes working files. - **kmer_count** (int) - Optional - Number of k-mer steps to consider. - **min_kmer_frac** (float) - Optional - Minimum k-mer size as a fraction of read length. - **max_kmer_frac** (float) - Optional - Maximum k-mer size as a fraction of read length. - **spades_path** (str) - Optional - Path to the SPAdes executable. ### Request Example ```python kmer_range = get_kmer_range( reads_1_filename='R1.fastq.gz', reads_2_filename='R2.fastq.gz', kmer_count=8, min_kmer_frac=0.2, max_kmer_frac=0.95 ) ``` ### Response #### Success Response (200) - **kmer_range** (list) - A list of integers representing the optimal k-mer sizes. ``` -------------------------------- ### Run Conservative Mode Assembly Source: https://context7.com/rrwick/unicycler/llms.txt Execute Unicycler in conservative mode for the lowest misassembly rate, potentially resulting in smaller contigs. Requires short and long reads. ```bash # Conservative mode (lowest misassembly rate, smaller contigs) unicycler -1 R1.fq.gz -2 R2.fq.gz -l long.fq.gz -o out --mode conservative ``` -------------------------------- ### Graph Cleaning Options Source: https://github.com/rrwick/unicycler/blob/main/README.md Options for removing small sequences from the assembly graph. ```APIDOC ## Graph Cleaning Options ### Description These options control the removal of small leftover sequences after bridging is complete. ### Parameters #### Query Parameters - **--min_component_size** (integer) - Optional - Graph components smaller than this size (bp) will be removed from the final graph (default: 1000) - **--min_dead_end_size** (integer) - Optional - Graph dead ends smaller than this size (bp) will be removed from the final graph (default: 1000) ``` -------------------------------- ### Perform Illumina-only assembly Source: https://github.com/rrwick/unicycler/blob/main/sample_data/README.md Uses paired-end short reads to generate an assembly without long-read data. ```bash unicycler -1 short_reads_1.fastq.gz -2 short_reads_2.fastq.gz -o output_dir ``` -------------------------------- ### Sort reads by position and convert to FASTA Source: https://github.com/rrwick/unicycler/wiki/Read-extraction Aligns reads to a reference, filters for primary alignments, sorts by reference and position, and converts the resulting SAM output to FASTA format. ```bash minimap2 -a -x map10k -t 4 assembly.fasta reads.fasta | samtools view -F 258 -F 2048 | sort -u -k1,1 | sort -k3,3 -k4,4n | awk '{print ">"$1"\n"$10}' > reads_sorted.fasta ``` -------------------------------- ### Bridge Application Source: https://context7.com/rrwick/unicycler/llms.txt Creates and applies bridges between single-copy segments using evidence from long reads, SPAdes paths, and miniasm assemblies. ```APIDOC ## Bridge Application ### Description Creates and applies bridges between single-copy segments using evidence from long reads, SPAdes paths, and miniasm assemblies. ### Method `create_spades_contig_bridges`, `create_long_read_bridges`, `create_miniasm_bridges`, `graph.apply_bridges` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters for `create_spades_contig_bridges`: - **graph** (AssemblyGraph) - Required - The assembly graph. - **anchor_segments** (list) - Required - A list of single-copy segments. ### Parameters for `create_long_read_bridges`: - **graph** (AssemblyGraph) - Required - The assembly graph. - **read_dict** (dict) - Required - A dictionary mapping read names to Read objects. - **read_names** (list) - Required - A list of read names. - **anchor_segments** (list) - Required - A list of single-copy segments. - **verbosity** (int) - Optional - Verbosity level. - **min_scaled_score** (float) - Optional - Minimum scaled score for bridges. - **threads** (int) - Optional - Number of threads to use. - **scoring_scheme** (AlignmentScoringScheme) - Required - An AlignmentScoringScheme object. - **min_alignment_length** (int) - Optional - Minimum alignment length. - **expected_linear_seqs** (bool) - Optional - Whether to expect linear sequences. - **min_bridge_qual** (float) - Optional - Minimum bridge quality. ### Parameters for `create_miniasm_bridges`: - **graph** (AssemblyGraph) - Required - The assembly graph. - **string_graph** (StringGraph) - Required - The StringGraph from miniasm. - **anchor_segments** (list) - Required - A list of single-copy segments. - **scoring_scheme** (AlignmentScoringScheme) - Required - An AlignmentScoringScheme object. - **verbosity** (int) - Optional - Verbosity level. - **min_bridge_qual** (float) - Optional - Minimum bridge quality. ### Parameters for `graph.apply_bridges`: - **bridges** (list) - Required - A list of bridges to apply. - **verbosity** (int) - Optional - Verbosity level. - **min_bridge_qual** (float) - Optional - Minimum bridge quality to consider. ### Request Example ```python spades_bridges = create_spades_contig_bridges(graph=assembly_graph, anchor_segments=single_copy_segments) long_read_bridges = create_long_read_bridges(graph=assembly_graph, read_dict=read_dictionary, read_names=read_name_list, anchor_segments=single_copy_segments, scoring_scheme=scoring_scheme) miniasm_bridges = create_miniasm_bridges(graph=assembly_graph, string_graph=miniasm_string_graph, anchor_segments=single_copy_segments, scoring_scheme=scoring_scheme) all_bridges = spades_bridges + long_read_bridges + miniasm_bridges seg_nums_used = graph.apply_bridges(bridges=all_bridges, verbosity=1, min_bridge_qual=10.0) ``` ### Response #### Success Response (200) - **spades_bridges** (list) - Bridges created from SPAdes contig paths. - **long_read_bridges** (list) - Bridges created from long read alignments. - **miniasm_bridges** (list) - Bridges created from miniasm assembly. - **all_bridges** (list) - Combined list of all bridges. - **seg_nums_used** (int) - The number of segments used after applying bridges. ``` -------------------------------- ### Save Assembly Graph Source: https://context7.com/rrwick/unicycler/llms.txt Save the current assembly graph to different file formats (GFA or FASTA). Options are available to include additional information like copy depth and segment type. ```python # Save graph to different formats graph.save_to_gfa('output.gfa') graph.save_to_fasta('output.fasta', min_length=500) graph.save_to_gfa('output_with_info.gfa', save_copy_depth_info=True, save_seg_type_info=True) ``` -------------------------------- ### Merge Simple Paths Source: https://context7.com/rrwick/unicycler/llms.txt Simplify the assembly graph by merging segments that form simple, unbranching paths. The bridging mode can be specified. ```python # Merge simple paths (segments in unbranching paths) graph.merge_all_possible(anchor_segments=None, bridging_mode=1) ``` -------------------------------- ### Perform hybrid assembly Source: https://github.com/rrwick/unicycler/blob/main/sample_data/README.md Combines short reads with long reads to improve assembly resolution. High-depth long reads are recommended for complex genomes. ```bash unicycler -1 short_reads_1.fastq.gz -2 short_reads_2.fastq.gz -l long_reads_low_depth.fastq.gz -o output_dir ``` ```bash unicycler -1 short_reads_1.fastq.gz -2 short_reads_2.fastq.gz -l long_reads_high_depth.fastq.gz -o output_dir ``` -------------------------------- ### Unicycler Hybrid Assembly Source: https://github.com/rrwick/unicycler/blob/main/README.md Performs genome assembly using both short Illumina and long reads for improved accuracy and completeness. ```bash unicycler -1 short_reads_1.fastq.gz -2 short_reads_2.fastq.gz -l long_reads.fastq.gz -o output_dir ``` -------------------------------- ### Check if Component is Complete Source: https://context7.com/rrwick/unicycler/llms.txt Determine if a given connected component in the assembly graph represents a complete circular replicon. ```python # Check if a component is complete (circular replicon) for component in components: if graph.is_component_complete(component): print(f"Component {component} is a complete circular replicon") ``` -------------------------------- ### Prepare Read Names for Grep Source: https://github.com/rrwick/unicycler/wiki/Read-extraction Sorts and uniquely identifies read names, then formats them into a pipe-delimited string suitable for use as an extended regular expression in grep. ```bash sort | uniq | paste -s -d '|' ``` -------------------------------- ### Load and Process Long Reads Source: https://context7.com/rrwick/unicycler/llms.txt Loads long reads from FASTQ/FASTA files and creates short nicknames for reads, which are used in miniasm. Access read information like sequence and qualities. ```python from unicycler.read_ref import load_long_reads, get_read_nickname_dict # Load long reads from file read_dict, read_names, long_read_filename = load_long_reads( filename='long_reads.fastq.gz', output_dir='/path/to/output' # For decompressed temp files ) # read_dict: {read_name: Read object with sequence, qualities, alignments} # read_names: ordered list of read names # long_read_filename: path to (possibly decompressed) reads file # Create short nicknames for reads (used in miniasm) nicknames = get_read_nickname_dict(read_names) # Returns: {'very_long_read_name_1': 'R001', 'another_read': 'R002', ...} # Access read information for name in read_names: read = read_dict[name] sequence = read.sequence qualities = read.qualities alignments = read.alignments # List after alignment step ``` -------------------------------- ### Repeat Orientations Source: https://github.com/rrwick/unicycler/wiki/Multiplicity-mistake Illustrates the two possible orientations for a sequence located between two inverted repeats. This is a conceptual representation, not executable code. ```text option 1: start -> repeat -> middle -> taeper -> end option 2: start -> repeat -> elddim -> taeper -> end ``` -------------------------------- ### Unicycler Long-read-only Assembly Source: https://github.com/rrwick/unicycler/blob/main/README.md Performs genome assembly using only long reads (e.g., PacBio or Oxford Nanopore). ```bash unicycler -l long_reads.fastq.gz -o output_dir ``` -------------------------------- ### Perform long-read-only assembly Source: https://github.com/rrwick/unicycler/blob/main/sample_data/README.md Uses high-depth long reads to generate an assembly without short-read data. ```bash unicycler -l long_reads_high_depth.fastq.gz -o output_dir ``` -------------------------------- ### Extract Aligned Long Reads (Linux/Unix) Source: https://github.com/rrwick/unicycler/wiki/Read-extraction Use this command to extract long reads that align to a specified sequence with given thresholds for read length, alignment length, and identity. Ensure your reads are gzipped; otherwise, use 'grep' instead of 'zgrep'. ```bash zgrep -A 1 --no-group-separator -E $(minimap2 -x map-ont -c -t 8 sequence.fasta long_reads.fastq.gz | awk '{if ($2 >= 2000 && $11 >= 1000 && $10/$11 >= 0.85) print $1;}' | sort | uniq | paste -s -d '|') long_reads.fastq.gz | sed 's|^@|>|' > reads.fasta ``` -------------------------------- ### Long-read Alignment and Bridging Options Source: https://github.com/rrwick/unicycler/blob/main/README.md Options for controlling long-read alignment to generate bridges. ```APIDOC ## Long-read Alignment and Bridging Options ### Description These options control the use of long-read alignment to produce long-read bridges. ### Parameters #### Query Parameters - **--no_simple_bridges** - Optional - Skip simple long-read bridging (default: use simple long-read bridging) - **--no_long_read_alignment** - Optional - Skip long-read-alignment-based bridging (default: use long-read alignments to produce bridges) - **--contamination** (string) - Optional - FASTA file of known contamination in long reads - **--scores** (string) - Optional - Comma-delimited string of alignment scores: match, mismatch, gap open, gap extend (default: 3,-6,-5,-2) - **--low_score** (float) - Optional - Score threshold - alignments below this are considered poor (default: set threshold automatically) ``` -------------------------------- ### Configure Alignment Scoring Scheme Source: https://context7.com/rrwick/unicycler/llms.txt Defines scoring parameters for sequence alignment, including match, mismatch, and gap penalties. ```python from unicycler.alignment import AlignmentScoringScheme # Create scoring scheme from comma-separated string # Format: match, mismatch, gap_open, gap_extend scoring_scheme = AlignmentScoringScheme('3,-6,-5,-2') # Access individual scores match_score = scoring_scheme.match # 3 mismatch_score = scoring_scheme.mismatch # -6 gap_open = scoring_scheme.gap_open # -5 gap_extend = scoring_scheme.gap_extend # -2 ``` -------------------------------- ### Run Overlap Removal Test Source: https://github.com/rrwick/unicycler/blob/main/test/README.md Execute tests focused on Unicycler's overlap removal functionality. This involves generating sequences with repeats, creating fake reads, assembling them with SPAdes, and then applying the `AssemblyGraph.remove_all_overlaps` function. This test also runs indefinitely. ```bash python3 test/overlap_removal_test.py ``` -------------------------------- ### Awk Filtering for Alignment Quality Source: https://github.com/rrwick/unicycler/wiki/Read-extraction Filters the PAF output from minimap2, selecting read names where alignment length ($2) is at least 2000, alignment span ($11) is at least 1000, and alignment identity ($10/$11) is at least 0.85. ```awk awk '{if ($2 >= 2000 && $11 >= 1000 && $10/$11 >= 0.85) print $1;}' ``` -------------------------------- ### Renumber Segments by Length Source: https://context7.com/rrwick/unicycler/llms.txt Reorder the segment identifiers in the assembly graph based on their length, assigning the longest segment the identifier 1. ```python # Renumber segments by length (longest = 1) graph.renumber_segments() ``` -------------------------------- ### Alignment Scoring Scheme Source: https://context7.com/rrwick/unicycler/llms.txt Configuration for sequence alignment scoring parameters used in the assembly and bridging pipeline. ```APIDOC ## Alignment Scoring Scheme ### Description Configuration for sequence alignment scoring parameters used throughout the assembly and bridging pipeline. ### Method `AlignmentScoringScheme` constructor ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **scoring_string** (str) - Required - A comma-separated string in the format: `match,mismatch,gap_open,gap_extend`. ### Request Example ```python from unicycler.alignment import AlignmentScoringScheme scoring_scheme = AlignmentScoringScheme('3,-6,-5,-2') ``` ### Response #### Success Response (200) - **scoring_scheme** (AlignmentScoringScheme) - An AlignmentScoringScheme object. ### Accessing Scores: - **match** (int) - The score for a match. - **mismatch** (int) - The score for a mismatch. - **gap_open** (int) - The penalty for opening a gap. - **gap_extend** (int) - The penalty for extending a gap. ``` -------------------------------- ### Determine Segment Copy Depth Source: https://context7.com/rrwick/unicycler/llms.txt Analyzes graph connectivity and read depth to assign copy numbers to segments. Use `get_single_copy_segments()` to retrieve segments with a copy number of 1. ```python from unicycler.assembly_graph_copy_depth import determine_copy_depth # Analyze graph and assign copy depths to segments determine_copy_depth(graph) # After running, segments have copy depth information: # graph.copy_depths = {segment_number: [depth1, depth2, ...]} # Single-copy segments have exactly one depth value # Get single-copy segments (copy number = 1) single_copy = graph.get_single_copy_segments() # Get copy number for specific segment copy_num = graph.get_copy_number(segment) # Returns 0, 1, 2, 3, etc. # Check if segment is single-copy is_single = graph.is_seg_num_single_copy(segment_number) # Get segments without assigned copy depth no_depth = graph.get_no_copy_depth_segments() # Copy depth visualization colors (for Bandage) # 1 copy: green, 2 copies: gold, 3 copies: orange, 4+ copies: red ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.