### Example Usage: FASTQ with Legacy Plotting Source: https://github.com/wdecoster/nanoplot/blob/master/README.md An example demonstrating FASTQ processing with specific thread count, plot types, and legacy plotting enabled for hex plots. ```bash NanoPlot -t 2 --fastq reads1.fastq.gz reads2.fastq.gz --maxlength 40000 --plots dot --legacy hex ``` -------------------------------- ### Run NanoPlot with various input formats Source: https://context7.com/wdecoster/nanoplot/llms.txt Command-line examples for processing different sequencing data file types. ```bash # Standard FASTQ files (supports gzip, bzip2, bgzip compression) NanoPlot --fastq sample.fastq.gz -o output # FASTA files NanoPlot --fasta assembly.fasta -o output # Rich FASTQ with channel/time info (albacore, MinKNOW, guppy) NanoPlot --fastq_rich basecalled.fastq -o output # Minimal FASTQ extraction (faster parsing) NanoPlot --fastq_minimal basecalled.fastq -o output # Sequencing summary files (gzip, bz2, zip, xz compression supported) NanoPlot --summary sequencing_summary.txt -o output # Sorted BAM files NanoPlot --bam aligned_sorted.bam -o output # Unmapped BAM files NanoPlot --ubam unmapped.bam -o output # CRAM files NanoPlot --cram aligned.cram -o output # Previously stored pickle data NanoPlot --pickle NanoPlot-data.pickle -o output # Arrow/Feather files NanoPlot --feather data.feather -o output # Multiple files of the same type NanoPlot --fastq sample1.fastq.gz sample2.fastq.gz sample3.fastq.gz -o output ``` -------------------------------- ### Example Usage: BAM with Downsampling and Output Source: https://github.com/wdecoster/nanoplot/blob/master/README.md Processes BAM files with multiple threads, custom color, downsampling, and specifies an output directory for plots. ```bash NanoPlot -t 12 --color yellow --bam alignment1.bam alignment2.bam alignment3.bam --downsample 10000 -o bamplots_downsampled ``` -------------------------------- ### NanoPlot Command Line Interface Source: https://context7.com/wdecoster/nanoplot/llms.txt The main entry point for NanoPlot, providing comprehensive options for input data sources, filtering, and visualization customization. ```APIDOC ## NanoPlot Command Line Interface ### Description The main entry point for NanoPlot, providing comprehensive options for input data sources, filtering, and visualization customization. ### Usage Examples **Basic usage with FASTQ files:** ```bash NanoPlot --fastq reads.fastq.gz -o output_directory ``` **Process sequencing summary file with log-transformed lengths:** ```bash NanoPlot --summary sequencing_summary.txt --loglength -o summary-plots-log-transformed ``` **Multi-threaded processing of multiple FASTQ files with length filtering:** ```bash NanoPlot -t 2 --fastq reads1.fastq.gz reads2.fastq.gz --maxlength 40000 --plots kde dot ``` **BAM file analysis with downsampling and custom color:** ```bash NanoPlot --color yellow --bam alignment1.bam alignment2.bam alignment3.bam --downsample 10000 -o bamplots ``` **Full analysis with filtering options:** ```bash NanoPlot --summary sequencing_summary.txt \ --minlength 500 \ --maxlength 50000 \ --minqual 7 \ --drop_outliers \ --loglength \ --N50 \ --title "My Sequencing Run" \ -o output_dir ``` **Process barcoded samples:** ```bash NanoPlot --summary sequencing_summary.txt --barcoded -o barcoded_output ``` **Use aligned read lengths from BAM files:** ```bash NanoPlot --bam aligned.bam --alength -o aligned_output ``` **Generate legacy plots with hex binning:** ```bash NanoPlot --fastq reads.fastq.gz --plots kde dot --legacy hex -o legacy_output ``` **Custom output formats and DPI settings:** ```bash NanoPlot --fastq reads.fastq.gz -f png svg pdf --dpi 300 -o high_quality_output ``` **Store extracted data for future use:** ```bash NanoPlot --fastq reads.fastq.gz --store --raw -o stored_data ``` ``` -------------------------------- ### Initialize Plotly Visualization Source: https://github.com/wdecoster/nanoplot/blob/master/scripts/agm_tests/WeightedLogTransformed_HistogramReadlength.html Configures the Plotly environment and initializes a bar chart with specific data and layout templates. ```javascript window.PlotlyConfig = {MathJaxConfig: 'local'}; window.PLOTLYENV=window.PLOTLYENV || {}; if (document.getElementById("93f45ef8-a392-4147-90de-050d15d2e02f")) { Plotly.newPlot( "93f45ef8-a392-4147-90de-050d15d2e02f", [{"hoverinfo":"y+text","hovertext":["268","287","308","330","354","380","407","437","468","502","538","577","619","664","712","763","818","877","940","1008","1081","1159","1243","1333","1429","1532","1643","1761","1889","2025","2171","2328","2496","2676","2870","3077","3299","3537","3793","4067","4360","4675","5013","5375","5763","6179","6625","7104","7617","8167","8757","9389","10067","10794","11574","12410","13306","14267","15297","16402","17586","18856","20218","21678","23243","24922","26722","28652","30721","32939","35318"],"marker":{"color":"#4CB391"},"x":{"dtype":"f8","bdata":"bp+I6f9sA0BcHTmnBKsDQEqb6WQJ6QNAOBmaIg4nBEAml0rgEmUEQBQV+50XowRAApOrWxzhBEDwEFwZIR8FQN6ODNclXQVAzAy9lCqbBUC5im1SL9kFQKcIHhA0FwZAlYbOzThVBkCDBH+LPZMGQHGCL0lC0QZAXwDgBkcPB0BNfpDES00HQDv8QIJQiwdAKXrxP1XJB0AX+KH9WQcIQAV2UrteRQhA8\u002fMCeWODCEDhcbM2aMEIQM\u002fvY\u002fRs\u002fwhAvW0UsnE9CUCq68RvdnsJQJhpdS17uQlAhucl63\u002f3CUB0ZdaohDUKQGLjhmaJcwpAUGE3JI6xCkA+3+fhku8KQCxdmJ+XLQtAGttIXZxrC0AIWfkaoakLQPbWqdil5wtA5FRalqolDEDS0gpUr2MMQMBQuxG0oQxArs5rz7jfDECcTByNvR0NQIrKzErCWw1AeEh9CMeZDUBmxi3Gy9cNQFRE3oPQFQ5AQsKOQdVTDkAwQD\u002f\u002f2ZEOQB6+77zezw5ADDygeuMND0D6uVA46EsPQOc3AfbsiQ9A1bWxs\u002fHHD0DiGbE4+wIQQNhYiZf9IRBA0Jdh9v9AEEDG1jlVAmAQQL4VErQEfxBAtFTqEgeeEECsk8JxCb0QQKLSmtAL3BBAmRFzLw77EECQUEuOEBoRQIePI+0SORFAfs77SxVYEUB1DdSqF3cRQGxMrAkalhFAY4uEaBy1EUBaylzHHtQRQFEJNSYh8xFASEgNhSMSEkA\u002fh+XjJTESQA=="},"y":{"dtype":"f8","bdata":"poFHbyalpEDJdLhPCcKkQD6BaltolqVAj6wUbWBspUDHqjEoGt+mQAUqbhsjCaZAfqDZs4Prp0ANu9mTgGumQMc7ktJ+RqdAPy0CzwhQp0CNfL6c1oKnQDgnCQgnV6lALbUONoMvqEAphn9RklOpQDiigFkVM6lA4lf8QNbYqEAw030YPP2oQB8MuSE7z6pA6VDJW7AeqkCFMEnuLrGrQNA+Rl5qAatAMdEQC+twqUB6MhtjpkSqQG2X7bW7FatAV23qFn9hq0CgzkcXBzypQDRuVy1RQKlAOTtBtr6Iq0B659sBpOCqQBcKuf\u002fTm6lADUZvvZSFqkABZFnciTypQDouWuW0SKlABU81RePUp0ARzGR0uy2oQF902ZdD36ZA58LwZUonpUBNoprWkl+kQDwCNfMbRaNA5y5VoI3boUAuC1HagE6gQGNmgyixzZ1AWYT9QhCrnECICbg8fnSXQPKjpPRLspdAd5QAkEuGkkDSy+lPxP6KQOO\u002f0rhkI4dACktn06HfgUDfr8CiNXZ9QB3jWmJ4bXFAY4bzXkfAZUBAtkqDgO1YQN62En9RH1pABvYgxw0yUUAsbmknxWVVQPwqC7YBkERAyhgF2PjYSECW7A6KmNA0QDdUhuQuLylA2EBJjPZfOUDzSkmGswoxQG7RlX73IiFAnJG\u002fdxNVIUAHUolsK1kRQAAAAAAAAAAAhK5cyeKdIUAAAAAAAAAAAAAAAAAAAAAAb1iWm2kFEkA\u002fh+XjJTESQA=="},"type":"bar"}], {"template":{"data":{"histogram2dcontour":[{"type":"histogram2dcontour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"choropleth":[{"type":"choropleth","colorbar":{"outlinewidth":0,"ticks":""}}],"histogram2d":[{"type":"histogram2d","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmap":[{"type":"heatmap","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"contourcarpet":[{"type":"contourcarpet","colorbar":{"outlinewidth":0,"ticks":""}}],"contour":[{"type":"contour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"surface":[{"type":"surface","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"mesh3d":[{"type":"mesh3d","colorbar":{"outlinewidth":0,"ticks":""}}],"scatter":[{"fillpattern":{"fillmode":"overlay","size":10,"solidity":0.2},"type":"scatter"}],"parcoords":[{"type":"parcoords","line":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolargl":[{"type":"scatterpolargl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"bar":[{"error_ ``` -------------------------------- ### Write Statistical Summaries with nanomath Source: https://context7.com/wdecoster/nanoplot/llms.txt Export statistical data to files using the write_stats utility function. ```python import pandas as pd import numpy as np from nanomath import write_stats ``` -------------------------------- ### NanoPlot Command Line Interface Usage Source: https://context7.com/wdecoster/nanoplot/llms.txt Execute various quality control and visualization tasks using the NanoPlot CLI. Options include input file formats, filtering, multi-threading, and output customization. ```bash # Basic usage with FASTQ files NanoPlot --fastq reads.fastq.gz -o output_directory # Process sequencing summary file with log-transformed lengths NanoPlot --summary sequencing_summary.txt --loglength -o summary-plots-log-transformed # Multi-threaded processing of multiple FASTQ files with length filtering NanoPlot -t 2 --fastq reads1.fastq.gz reads2.fastq.gz --maxlength 40000 --plots kde dot # BAM file analysis with downsampling and custom color NanoPlot --color yellow --bam alignment1.bam alignment2.bam alignment3.bam --downsample 10000 -o bamplots # Full analysis with filtering options NanoPlot --summary sequencing_summary.txt \ --minlength 500 \ --maxlength 50000 \ --minqual 7 \ --drop_outliers \ --loglength \ --N50 \ --title "My Sequencing Run" \ -o output_dir # Process barcoded samples NanoPlot --summary sequencing_summary.txt --barcoded -o barcoded_output # Use aligned read lengths from BAM files NanoPlot --bam aligned.bam --alength -o aligned_output # Generate legacy plots with hex binning NanoPlot --fastq reads.fastq.gz --plots kde dot --legacy hex -o legacy_output # Custom output formats and DPI settings NanoPlot --fastq reads.fastq.gz -f png svg pdf --dpi 300 -o high_quality_output # Store extracted data for future use NanoPlot --fastq reads.fastq.gz --store --raw -o stored_data ``` -------------------------------- ### FASTQ Data Plotting with Options Source: https://github.com/wdecoster/nanoplot/blob/master/README.md Processes FASTQ files with specified threads, maximum length, and plot types. Supports 'dot' and 'hex' plots. ```bash NanoPlot -t 2 --fastq reads1.fastq.gz reads2.fastq.gz --maxlength 40000 --plots hex dot ``` -------------------------------- ### Basic Summary Plotting Source: https://github.com/wdecoster/nanoplot/blob/master/README.md Generates summary plots from a sequencing summary file. Use --loglength for log-transformed read length histograms. ```bash NanoPlot --summary sequencing_summary.txt --loglength -o summary-plots-log-transformed ``` -------------------------------- ### Generate Read Length Distribution Plots Source: https://context7.com/wdecoster/nanoplot/llms.txt Create various read length distribution plots, including weighted and non-weighted histograms, and their log-transformed versions. Requires `nanomath.get_N50`. ```python import numpy as np import nanoplotter from nanomath import get_N50 # Sample read length data lengths = np.random.lognormal(8, 1.2, 10000).astype('uint64') n50 = get_N50(np.sort(lengths)) settings = { 'format': ['png'], 'no_static': False, 'dpi': 300 } # Generate length distribution plots plots = nanoplotter.length_plots( array=lengths, name='Read length', path='output/', n50=n50, color='#4CB391', title='Sequencing Run Length Distribution', settings=settings ) ``` -------------------------------- ### Customize NanoPlot colors and colormaps Source: https://context7.com/wdecoster/nanoplot/llms.txt Command-line options for setting plot colors and listing available colormaps. ```bash # Use named color NanoPlot --fastq reads.fastq.gz --color teal -o output # Use hex color code NanoPlot --fastq reads.fastq.gz --color "#FF6B6B" -o output # Custom colormap for heatmaps NanoPlot --summary summary.txt --colormap Viridis -o output # List available colors NanoPlot --listcolors # List available colormaps (Greens, Blues, Viridis, Cividis, etc.) NanoPlot --listcolormaps ``` -------------------------------- ### Initialize Plotly Bar Chart Source: https://github.com/wdecoster/nanoplot/blob/master/scripts/agm_tests/Non_weightedHistogramReadlength.html Configures the Plotly environment and renders a bar chart into a specified HTML element. Ensure the target element ID exists in the DOM before execution. ```javascript window.PlotlyConfig = {MathJaxConfig: 'local'}; window.PLOTLYENV=window.PLOTLYENV || {}; if (document.getElementById("9bc95e55-35fa-4b75-bf1d-bd21cc5a0fd2")) { Plotly.newPlot( "9bc95e55-35fa-4b75-bf1d-bd21cc5a0fd2", [{"marker":{"color":"#4CB391"},"x":{"dtype":"f8","bdata":"6sn47VI\u002fh0DqyfjtUleTQOAu9WT8DptA6sn47VJjoUBl\u002fHapJz+lQOAu9WT8GqlAWmFzINH2rEDqyfjtUmmwQCjjt0s9V7JAZfx2qSdFtECiFTYHEjO2QOAu9WT8ILhAHUi0wuYOukBaYXMg0fy7QJh6Mn676r1A1ZPx26XYv0CJVtgcSOPAQCjjt0s92sFAxm+XejLRwkBl\u002fHapJ8jDQASJVtgcv8RAohU2BxK2xUBBohU2B63GQOAu9WT8o8dAfrvUk\u002fGayEAdSLTC5pHJQLzUk\u002fHbiMpAWmFzINF\u002fy0D57VJPxnbMQJh6Mn67bc1ANgcSrbBkzkDVk\u002fHbpVvPQDqQaIVNKdBAiVbYHMik0EDYHEi0QiDRQCjjt0u9m9FAd6kn4zcX0kDGb5d6spLSQBY2BxItDtNAZfx2qaeJ00C0wuZAIgXUQASJVticgNRAU0\u002fGbxf81ECiFTYHknfVQPLbpZ4M89VAQaIVNodu1kCQaIXNAerWQOAu9WR8ZddAL\u002fVk\u002fPbg10B+u9STcVzYQM6BRCvs19hAHUi0wmZT2UBsDiRa4c7ZQLzUk\u002fFbStpAC5sDidbF2kBaYXMgUUHbQKon47fLvNtA+e1ST0Y43EBItMLmwLPcQJh6Mn47L91A50CiFbaq3UA2BxKtMCbeQIbNgUSrod5A1ZPx2yUd30AkWmFzoJjfQDqQaIUNCuBAYXMg0cpH4ECJVtgciIXgQLE5kGhFw+BA2BxItAIB4UAAAAAAwD7hQA=="},"y":{"dtype":"i2","bdata":"b0RfIA4Ujw5UCtYHzQWVBDsDmgIoAnYB+ADIAIIAcAA6AC8AEwARABQAEQAHAA8ABQAGAAcABQAHAAIAAQABAAIAAgADAAEAAgABAAIAAAAAAAAAAQACAAAAAAAAAAAAAAAAAAEAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAABAA=="},"type":"bar"}], {"template":{"data":{"histogram2dcontour":[{"type":"histogram2dcontour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"choropleth":[{"type":"choropleth","colorbar":{"outlinewidth":0,"ticks":""}}],"histogram2d":[{"type":"histogram2d","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"heatmap":[{"type":"heatmap","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"contourcarpet":[{"type":"contourcarpet","colorbar":{"outlinewidth":0,"ticks":""}}],"contour":[{"type":"contour","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"surface":[{"type":"surface","colorbar":{"outlinewidth":0,"ticks":""},"colorscale":[[0.0,"#0d0887"],[0.1111111111111111,"#46039f"],[0.2222222222222222,"#7201a8"],[0.3333333333333333,"#9c179e"],[0.4444444444444444,"#bd3786"],[0.5555555555555556,"#d8576b"],[0.6666666666666666,"#ed7953"],[0.7777777777777778,"#fb9f3a"],[0.8888888888888888,"#fdca26"],[1.0,"#f0f921"]]}],"mesh3d":[{"type":"mesh3d","colorbar":{"outlinewidth":0,"ticks":""}}],"scatter":[{"fillpattern":{"fillmode":"overlay","size":10,"solidity":0.2},"type":"scatter"}],"parcoords":[{"type":"parcoords","line":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolargl":[{"type":"scatterpolargl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"bar":[{"error_x":{"color":"#2a3f5f"},"error_y":{"color":"#2a3f5f"},"marker":{"line":{"color":"#E5ECF6","width":0.5},"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"bar"}],"scattergeo":[{"type":"scattergeo","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterpolar":[{"type":"scatterpolar","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"histogram":[{"marker":{"pattern":{"fillmode":"overlay","size":10,"solidity":0.2}},"type":"histogram"}],"scattergl":[{"type":"scattergl","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatter3d":[{"type":"scatter3d","line":{"colorbar":{"outlinewidth":0,"ticks":""}},"marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattermap":[{"type":"scattermap","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattermapbox":[{"type":"scattermapbox","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scatterternary":[{"type":"scatterternary","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"scattercarpet":[{"type":"scattercarpet","marker":{"colorbar":{"outlinewidth":0,"ticks":""}}}],"carpet":[{"aaxis":{"endlinecol ``` -------------------------------- ### Compute Sequencing Statistics with nanomath.Stats Source: https://context7.com/wdecoster/nanoplot/llms.txt Calculate comprehensive sequencing metrics from a pandas DataFrame containing read lengths, quality scores, and channel IDs. ```python import pandas as pd import numpy as np from nanomath import Stats # Create sample DataFrame with sequencing data df = pd.DataFrame({ 'lengths': np.random.lognormal(8, 1, 1000).astype(int), 'quals': np.random.normal(15, 3, 1000), 'channelIDs': np.random.randint(1, 512, 1000) }) # Calculate statistics stats = Stats(df) print(f"Number of reads: {stats.number_of_reads}") print(f"Total bases: {stats.number_of_bases}") print(f"Mean read length: {stats.mean_read_length:.1f}") print(f"Median read length: {stats.median_read_length:.1f}") print(f"Read length N50: {stats.n50}") print(f"Mean quality: {stats.mean_qual:.2f}") print(f"Active channels: {stats.active_channels}") # Export as dictionary for TSV output stats_dict = stats.to_dict() ``` -------------------------------- ### Create Flowcell Activity Heatmap Source: https://context7.com/wdecoster/nanoplot/llms.txt Visualize flowcell activity by generating a heatmap of reads per channel. Automatically detects flowcell type (Flongle, MinION, PromethION). ```python import numpy as np from nanoplotter.spatial_heatmap import spatial_heatmap # Sample channel data (MinION has channels 1-512) channel_ids = np.random.choice(range(1, 513), size=50000, replace=True) settings = { 'format': ['png'], 'no_static': False, 'dpi': 300 } # Generate flowcell activity heatmap plots = spatial_heatmap( array=channel_ids, path='output/ActivityMap_ReadsPerChannel', colormap='Greens', settings=settings, title='Flowcell Channel Activity' ) ``` -------------------------------- ### Create Scatter Plots with Marginal Histograms Source: https://context7.com/wdecoster/nanoplot/llms.txt Generate bivariate scatter plots with optional KDE and dot plot styles. Supports log transformation for one axis. Ensure output directory exists. ```python import pandas as pd import numpy as np import nanoplotter # Sample data df = pd.DataFrame({ 'lengths': np.random.lognormal(8, 1, 5000).astype(int), 'quals': np.random.normal(15, 3, 5000) }) settings = { 'format': ['png'], 'no_static': False, 'dpi': 300 } # Create scatter plots (KDE and dot) plots = nanoplotter.scatter( x=df['lengths'], y=df['quals'], legacy={}, names=['Read lengths', 'Average read quality'], path='output/LengthvsQualityScatterPlot', plots={'kde': 1, 'dot': 1, 'hex': 0, 'pauvre': 0}, color='#4CB391', colormap='Greens', settings=settings, title='Read Length vs Quality' ) # Create log-transformed scatter plot log_plots = nanoplotter.scatter( x=np.log10(df['lengths']), y=df['quals'], legacy={}, names=['Read lengths', 'Average read quality'], path='output/LogLengthvsQualityScatterPlot', plots={'kde': 1, 'dot': 1, 'hex': 0, 'pauvre': 0}, color='#4CB391', colormap='Greens', settings=settings, log=True, title='Log Read Length vs Quality' ) ``` -------------------------------- ### Calculate Average Quality with nanomath Source: https://context7.com/wdecoster/nanoplot/llms.txt Compute the average Phred quality score for a list of reads, with an optional parameter to round the result to the nearest integer. ```python from nanomath import ave_qual # Calculate average quality from integer Phred scores quality_scores = [20, 25, 30, 28, 22, 35, 18, 27, 31, 24] avg_quality = ave_qual(quality_scores) print(f"Average quality: {avg_quality:.2f}") # Output: Average quality: 24.87 # Round to nearest integer avg_quality_rounded = ave_qual(quality_scores, qround=True) print(f"Rounded average quality: {avg_quality_rounded}") # Output: Rounded average quality: 25 ``` -------------------------------- ### Generate Time-Based Analysis Plots Source: https://context7.com/wdecoster/nanoplot/llms.txt Create plots for time-series sequencing data, including cumulative yield, reads over time, and violin plots of length/quality over time. Requires both `df` and `subsampled_df`. ```python import pandas as pd import numpy as np from datetime import timedelta from nanoplotter.timeplots import time_plots # Create sample time-series data n_reads = 5000 df = pd.DataFrame({ 'lengths': np.random.lognormal(8, 1, n_reads).astype(int), 'quals': np.random.normal(15, 3, n_reads), 'channelIDs': np.random.randint(1, 512, n_reads), 'start_time': [timedelta(hours=np.random.uniform(0, 48)) for _ in range(n_reads)] }) # Subsample for violin plots subsampled_df = df.sample(min(10000, len(df))) settings = { 'format': ['png'], 'no_static': False, 'dpi': 300 } # Generate all time-based plots plots = time_plots( df=df, subsampled_df=subsampled_df, path='output/', settings=settings, title='48-Hour Sequencing Run', color='#4CB391', log_length=False ) ``` -------------------------------- ### Calculate N50 with nanomath Source: https://context7.com/wdecoster/nanoplot/llms.txt Compute the N50 metric from a sorted array of read lengths using the get_N50 function. ```python import numpy as np from nanomath import get_N50 # Calculate N50 from read lengths read_lengths = np.array([1000, 2000, 3000, 5000, 8000, 10000, 15000, 20000]) sorted_lengths = np.sort(read_lengths) n50_value = get_N50(sorted_lengths) print(f"N50: {n50_value} bp") # Output: N50: 10000 bp ``` -------------------------------- ### nanomath.write_stats Source: https://context7.com/wdecoster/nanoplot/llms.txt Write statistical summaries to a file, supporting both TSV format and legacy human-readable format. ```APIDOC ## nanomath.write_stats ### Description Write statistical summaries to a file, supporting both TSV format and legacy human-readable format. ### Method ```python write_stats(stats_dict: dict, output_file: str, output_format: str = 'tsv') ``` ### Parameters #### Path Parameters - **stats_dict** (dict) - Required - A dictionary containing the statistics to write. - **output_file** (str) - Required - The path to the output file. - **output_format** (str) - Optional - The format of the output file ('tsv' or 'human'). Defaults to 'tsv'. ### Request Example ```python import pandas as pd import numpy as np from nanomath import Stats, write_stats # Create sample DataFrame with sequencing data df = pd.DataFrame({ 'lengths': np.random.lognormal(8, 1, 1000).astype(int), 'quals': np.random.normal(15, 3, 1000), 'channelIDs': np.random.randint(1, 512, 1000) }) # Calculate statistics stats = Stats(df) stats_dict = stats.to_dict() # Write statistics to a TSV file write_stats(stats_dict, 'stats.tsv', output_format='tsv') # Write statistics to a human-readable file write_stats(stats_dict, 'stats.txt', output_format='human') ``` ``` -------------------------------- ### Create dynamic histogram with nanoplotter Source: https://context7.com/wdecoster/nanoplot/llms.txt Generates a dynamic histogram from a pandas Series of data. ```python plot = nanoplotter.dynamic_histogram( array=pd.Series(percent_identity), name='percent identity', path='output/PercentIdentityHistogram', settings=settings, title='Read Percent Identity Distribution', color='#4CB391' ) ``` -------------------------------- ### Manage plots with Plot class Source: https://context7.com/wdecoster/nanoplot/llms.txt Handles plot object creation, figure attachment, and export to HTML or static images. ```python from nanoplotter.plot import Plot import plotly.express as px import numpy as np # Create a plot object my_plot = Plot( path='output/custom_plot.html', title='Custom Scatter Plot' ) # Generate plotly figure x_data = np.random.lognormal(8, 1, 1000) y_data = np.random.normal(15, 3, 1000) fig = px.scatter(x=x_data, y=y_data) fig.update_layout( xaxis_title='Read Length', yaxis_title='Quality Score', title=my_plot.title ) # Attach figure and generate HTML my_plot.fig = fig my_plot.html = fig.to_html(full_html=False, include_plotlyjs='cdn') # Save with settings settings = { 'format': ['png', 'svg'], 'no_static': False, 'dpi': 300 } my_plot.save(settings) # Encode for HTML report embedding html_snippet = my_plot.encode() ``` -------------------------------- ### BAM Data Plotting with Downsampling Source: https://github.com/wdecoster/nanoplot/blob/master/README.md Analyzes BAM files with specified color and downsampling. Downsampling is applied after data collection and may not significantly speed up processing for smaller datasets. ```bash NanoPlot --color yellow --bam alignment1.bam alignment2.bam alignment3.bam --downsample 10000 ```