{"id":21466718,"url":"https://github.com/edinburgh-genome-foundry/geneblocks","last_synced_at":"2025-07-02T15:32:19.841Z","repository":{"id":57433472,"uuid":"102761944","full_name":"Edinburgh-Genome-Foundry/Geneblocks","owner":"Edinburgh-Genome-Foundry","description":":diamond_shape_with_a_dot_inside: Find common blocks and differences between DNA sequences","archived":false,"fork":false,"pushed_at":"2025-04-07T11:31:22.000Z","size":1575,"stargazers_count":42,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-06-28T02:48:56.596Z","etag":null,"topics":["python","sequence-analysis","synthetic-biology"],"latest_commit_sha":null,"homepage":"https://edinburgh-genome-foundry.github.io/Geneblocks/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Edinburgh-Genome-Foundry.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-09-07T16:42:00.000Z","updated_at":"2025-04-29T12:27:05.000Z","dependencies_parsed_at":"2025-05-19T23:06:31.795Z","dependency_job_id":"2737415b-4716-42a7-9e86-f4cc02d8e8d4","html_url":"https://github.com/Edinburgh-Genome-Foundry/Geneblocks","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/Edinburgh-Genome-Foundry/Geneblocks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Edinburgh-Genome-Foundry%2FGeneblocks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Edinburgh-Genome-Foundry%2FGeneblocks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Edinburgh-Genome-Foundry%2FGeneblocks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Edinburgh-Genome-Foundry%2FGeneblocks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Edinburgh-Genome-Foundry","download_url":"https://codeload.github.com/Edinburgh-Genome-Foundry/Geneblocks/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Edinburgh-Genome-Foundry%2FGeneblocks/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263166021,"owners_count":23424069,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python","sequence-analysis","synthetic-biology"],"created_at":"2024-11-23T08:15:02.025Z","updated_at":"2025-07-02T15:32:19.826Z","avatar_url":"https://github.com/Edinburgh-Genome-Foundry.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":".. raw:: html\n\n    \u003cp align=\"center\"\u003e\n    \u003cimg alt=\"Geneblocks Logo\" title=\"Geneblocks\" src=\"https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/Geneblocks/master/docs/_static/images/title.png\" width=\"450\"\u003e\n    \u003cbr /\u003e\u003cbr /\u003e\n    \u003c/p\u003e\n\nGeneBlocks\n==========\n\n.. image:: https://github.com/Edinburgh-Genome-Foundry/Geneblocks/actions/workflows/build.yml/badge.svg\n    :target: https://github.com/Edinburgh-Genome-Foundry/Geneblocks/actions/workflows/build.yml\n    :alt: GitHub CI build status\n\n.. image:: https://coveralls.io/repos/github/Edinburgh-Genome-Foundry/Geneblocks/badge.svg\n  :target: https://coveralls.io/github/Edinburgh-Genome-Foundry/Geneblocks\n\nGeneBlocks is a Python library for comparing DNA sequences. It can be used to:\n\n- Find common blocks in a group of DNA sequences, to factorize them (e.g. only analyze or synthetize each common block once).\n- Highlight differences between sequences (insertions, deletions, mutations).\n- Transfer Genbank features from one record to another sharing similar subsequences.\n\nAt the Edinburgh Genome Foundry, we use GeneBlocks to optimize sequence assembly, explore sets of non-annotated sequences, or visualize the differences\nbetween different versions of a sequence, and re-annotate records coming from third parties such as DNA manufacturers.\n\n\nLive demos\n----------\n\n`Find common sequence blocks \u003chttps://cuba.genomefoundry.org/find-common-blocks\u003e`_\n\n`Plot sequence diffs \u003chttps://cuba.genomefoundry.org/compare-two-sequences\u003e`_\n\n`Transfer Genbank features between records \u003chttps://cuba.genomefoundry.org/transfer-features\u003e`_\n\n\nInstallation\n------------\n\nThe CommonBlocks feature requires NCBI BLAST+. On Ubuntu, install it with\n\n.. code:: shell\n\n    apt-get install ncbi-blast+\n\n\nYou can install GeneBlocks through PIP:\n\n.. code:: shell\n\n    pip install geneblocks\n\nAlternatively, you can unzip the sources in a folder and type:\n\n.. code:: shell\n\n    python setup.py install\n\n\nUsage\n-----\n\nFinding common blocks in a set of sequences:\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code:: python\n\n    from geneblocks import CommonBlocks\n\n    # Input sequences are in a dictionary as follows:\n    sequences = {'seq1': 'ATTTGCGT', 'seq2': 'ATGCCCGCACG',}  # etc\n\n    common_blocks = CommonBlocks.from_sequences(sequences)\n\n    # PLOT THE BLOCKS\n    axes = common_blocks.plot_common_blocks()\n    axes[0].figure.savefig(\"basic_example.png\", bbox_inches=\"tight\")\n\n    # GET ALL COMMON BLOCKS AS BIOPYTHON RECORDS\n    blocks_records = common_blocks.common_blocks_records()\n\n    # WRITE ALL COMMON BLOCKS INTO A CSV SPREADSHEET\n    common_blocks.common_blocks_to_csv(target_file=\"blocks.csv\")\n\nResult:\n\n.. raw:: html\n   \n   \u003cimg src='https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/GeneBlocks/master/examples/common_blocks.png'\n    width='600px'/\u003e\n\n\nTransferring features between genbank records:\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIn this snippet we assume that we have two genbank records:\n\n- A record of an annotated part, containing an expression module.\n- A record of a plasmid which contains the part but the part was not properly annotated.\n\nWe will use GeneBlocks to automatically detect where the part is located in\nthe plasmid and automatically copy the features from the part record to the\nplasmid record.\n\n.. code:: python\n\n    from geneblocks import CommonBlocks, load_record\n    part = load_record('part.gb', name='insert')\n    plasmid = load_record('part.gb', name='plasmid')\n    blocks = CommonBlocks.from_sequences([part, plasmid])\n    new_records = blocks.copy_features_between_common_blocks(inplace=False)\n    annotated_plasmid = new_records['plasmid'] # Biopython record\n\n\nThe resulting annotated plasmids has annotations from both the original plasmid and the annotated part:\n\n.. raw:: html\n   \n   \u003cimg src='https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/GeneBlocks/master/examples/features_transfer.png'\n    width='600px'/\u003e\n\n\nHighlighting the differences between two sequences:\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code:: python\n\n    seq_1 = load_record(\"sequence1.gb\")\n    seq_2 = load_record(\"sequence2.gb\")\n\n    diff_blocks = DiffBlocks.from_sequences(seq_1, seq_2)\n    ax1, ax2 = diff_blocks.merged().plot(figure_width=8)\n    ax1.figure.savefig(\"diff_blocks.png\")\n\nResult:\n\n.. raw:: html\n   \n     \u003cimg src='https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/GeneBlocks/master/examples/diff_blocks.png'\n      width='700px'/\u003e\n\n\nExample on more complex sequences\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nIn the example below we build two ~50kb \"sister\" sequences with many insertions,\ndeletions, transpositions between them, and even a self-homology. Then we ask\nGeneBlocks to compare the two sequences, in term of common blocks, and in terms\nof modifications brought to the second sequence:\n\n.. code:: python\n\n    from geneblocks import DiffBlocks, CommonBlocks, random_dna_sequence\n    import geneblocks.sequence_modification_utils as smu\n    import matplotlib.pyplot as plt\n\n    # GENERATE 2 \"SISTER\" SEQUENCES FOR THE EXAMPLE\n    seq1 = random_dna_sequence(50000)\n    seq1 = smu.copy(seq1, 25000, 30000, 50000)\n\n    seq2 = seq1\n    seq2 = smu.insert(seq2, 39000, random_dna_sequence(100))\n    seq2 = smu.insert(seq2, 38000, random_dna_sequence(100))\n    seq2 = smu.reverse(seq2, 30000, 35000)\n    seq2 = smu.swap(seq2, (30000, 35000), (45000, 480000))\n    seq2 = smu.delete(seq2, 20000, 2000)\n    seq2 = smu.insert(seq2, 10000, random_dna_sequence(2000))\n    seq2 = smu.insert(seq2, 0, 1000*\"A\")\n\n    # FIND COMMON BLOCKS AND DIFFS\n    common_blocks = CommonBlocks.from_sequences({'seq1': seq1, 'seq2': seq2})\n    diff_blocks = DiffBlocks.from_sequences(seq1, seq2).merged()\n\n    # PLOT EVERYTHING\n    fig, axes = plt.subplots(3, 1, figsize=(15, 8))\n    common_blocks.plot_common_blocks(axes=axes[:-1])\n    diff_blocks.plot(ax=axes[-1], separate_axes=False)\n    axes[-1].set_xlabel(\"Changes in seq2 vs. seq1\")\n    fig.savefig(\"complex_sequences.png\", bbox_inches='tight')\n\n.. raw:: html\n   \n     \u003cimg src='https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/GeneBlocks/master/examples/complex_sequences.png'\n      width='700px'/\u003e\n\n\nLicense = MIT\n-------------\n\nGeneBlocks is an open-source software originally written at the `Edinburgh Genome Foundry\n\u003chttp://www.genomefoundry.org\u003e`_ by `Zulko \u003chttps://github.com/Zulko\u003e`_\nand `released on Github \u003chttps://github.com/Edinburgh-Genome-Foundry/Geneblocks\u003e`_ under the MIT license (Copyright 2017 Edinburgh Genome Foundry, University of Edinburgh).\nEveryone is welcome to contribute!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedinburgh-genome-foundry%2Fgeneblocks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedinburgh-genome-foundry%2Fgeneblocks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedinburgh-genome-foundry%2Fgeneblocks/lists"}