-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
308 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[bumpversion] | ||
current_version = 0.1.0 | ||
commit = True | ||
tag = True | ||
|
||
[bumpversion:file:README.md] | ||
|
||
[bumpversion:file:dna_mutator/version.py] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: build | ||
|
||
on: [push, workflow_dispatch] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.9 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.9' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pytest pytest-cov | ||
- name: Test pip installation | ||
run: | | ||
pip install -e . | ||
- name: Test with pytest | ||
run: | | ||
python -m pytest --cov dna_mutator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Edinburgh Genome Foundry | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,41 @@ | ||
# Mutator | ||
<p align="center"> | ||
<img alt="EGF logo" title="EGF" src="images/egf.png" width="120"> | ||
</p> | ||
|
||
# DNA Mutator | ||
|
||
![version](https://img.shields.io/badge/current_version-0.1.0-blue) | ||
[![build](https://github.com/Edinburgh-Genome-Foundry/dna_mutator/actions/workflows/build.yml/badge.svg)](https://github.com/Edinburgh-Genome-Foundry/dna_mutator/actions/workflows/build.yml) | ||
|
||
Create variants of DNA sequences. | ||
|
||
This repository is based on the software code of a dissertation project (B237870) for the MSc Bioinformatics program at the University of Edinburgh. | ||
|
||
## Install | ||
|
||
```bash | ||
pip install git+https://github.com/Edinburgh-Genome-Foundry/mutator.git | ||
``` | ||
|
||
## Usage | ||
|
||
```python | ||
import dna_mutator as mutator | ||
record = mutator.Mutator.read_genbank("EGF.gb") | ||
mut = mutator.Mutator(record) | ||
mut.DelN() | ||
mut.write_all_records("variants") | ||
``` | ||
|
||
## Versioning | ||
|
||
DNA Mutator uses the [semantic versioning](https://semver.org) scheme. | ||
|
||
## License = MIT | ||
|
||
DNA Mutator is free/libre and open-source software, which means the users have the freedom to run, study, change and distribute the software. | ||
|
||
DNA Mutator was written at the [Edinburgh Genome Foundry](https://edinburgh-genome-foundry.github.io/) | ||
by [B237870](https://github.com/B237870-2024) and [Peter Vegh](https://github.com/veghp). | ||
|
||
Copyright 2024 Edinburgh Genome Foundry, University of Edinburgh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import os | ||
import random | ||
|
||
import pandas | ||
|
||
from Bio import SeqIO | ||
from Bio.Seq import Seq, MutableSeq | ||
from Bio.SeqRecord import SeqRecord | ||
from Bio.SeqFeature import SeqFeature, FeatureLocation | ||
|
||
|
||
class Mutator: | ||
"""Class to generate simulations of structural and single nucleotide variants. | ||
**Parameters** | ||
**reference** | ||
> A `SeqRecord` instance. | ||
**library_size** | ||
> Library size (`int`). | ||
""" | ||
|
||
def __init__(self, reference, library_size=10): | ||
self.reference = reference | ||
self.library_size = library_size | ||
self.variant_records = [] | ||
|
||
def write_sample_sheet(self, csv_file): | ||
"""Create a sample sheet (for use with Sequeduct)""" | ||
barcode_dir = [ | ||
"barcode" + ("{0:02d}".format(i + 1)) | ||
for i in range(len(self.variant_records)) | ||
] | ||
|
||
variants = [variant_record.id for variant_record in self.variant_records] | ||
df_variants = pandas.DataFrame({"Sample": variants, "Barcode_dir": barcode_dir}) | ||
df_variants.to_csv(csv_file, index=False) | ||
|
||
@staticmethod | ||
def subtract_bases(seq, pos, n): | ||
"""Substract N bases from a sequence | ||
**Parameters** | ||
**seq** | ||
> `Seq` instance. | ||
**pos** | ||
> Location of change (`int`). | ||
**n** | ||
> Number of bases to subtract (`int`). | ||
""" | ||
modified_sequence = MutableSeq(seq) | ||
deleted_sequence = modified_sequence[pos : pos + n] | ||
del modified_sequence[pos : pos + n] | ||
|
||
return ( | ||
modified_sequence, | ||
pos, | ||
deleted_sequence, | ||
) | ||
|
||
@staticmethod | ||
def get_random_pos(record, n=1): | ||
"""Get n different random positions in a record""" | ||
positions = random.sample(range(0, len(record)), n) | ||
|
||
return positions | ||
|
||
@staticmethod | ||
def read_genbank(genbank, use_file_name_as_id=True): | ||
"""Get the reference sequence and features from input file | ||
**Parameters** | ||
**genbank** | ||
> Path to Genbank file (`str`). | ||
**use_file_name_as_id** | ||
> Replace record id and name with the filename (`bool`). | ||
""" | ||
record = SeqIO.read(genbank, "genbank") | ||
if use_file_name_as_id: | ||
record.name = os.path.splitext(os.path.basename(genbank))[0] | ||
record.id = record.name | ||
|
||
return record | ||
|
||
@staticmethod | ||
def write_genbank(record, file_name): | ||
"""Write SeqRecord to a Genbank file""" | ||
SeqIO.write(record, file_name, "gb") | ||
|
||
def write_all_records(self, dir_name): | ||
"""Write original record and all variants into a directory""" | ||
extension = ".gb" # standard file ext for GenBank files | ||
os.mkdir(dir_name) | ||
# ORIGINAL REFERENCE RECORD | ||
ref_path = os.path.join(dir_name, self.reference.id + extension) | ||
self.write_genbank(self.reference, ref_path) | ||
# VARIANTS | ||
for variant in self.variant_records: | ||
variant_path = os.path.join(dir_name, variant.id) | ||
self.write_genbank(variant, variant_path + extension) | ||
|
||
def DelN(self, bases=1): | ||
"""Simulate N base deletion""" | ||
positions = self.get_random_pos(self.reference, n=self.library_size) | ||
for i in range(self.library_size): | ||
position = positions[i] | ||
modified_sequence, position, deleted_sequence = self.subtract_bases( | ||
self.reference.seq, position, bases | ||
) | ||
if len(deleted_sequence) == 1: # show the letter if there's only one | ||
suffix = str(deleted_sequence) | ||
else: | ||
suffix = str(len(deleted_sequence)) | ||
# We append the original name according to nomenclature: | ||
variant_name = self.reference.id + "_" + str(position) + "D" + suffix | ||
variant_record = SeqRecord( | ||
Seq(modified_sequence), | ||
id=variant_name, | ||
name=variant_name, | ||
annotations={"molecule_type": "DNA", "topology": "circular"}, | ||
) | ||
label = "@mutator(del)" | ||
description = ( | ||
"Deletion in position " | ||
+ str(position) | ||
+ " of " | ||
+ str(bases) | ||
+ " bases (" | ||
+ str(deleted_sequence) | ||
+ ")" | ||
) | ||
feature = SeqFeature( | ||
FeatureLocation(position, position), | ||
type="misc_feature", | ||
id="@mutator", | ||
qualifiers={"label": label, "note": description}, | ||
) | ||
variant_record.features.append(feature) | ||
|
||
self.variant_records.append(variant_record) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .Mutator import Mutator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = "0.1.0" |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
DNA Mutator | ||
============================= | ||
|
||
Creating variants of DNA sequences | ||
|
||
|
||
**Install:** | ||
|
||
.. code:: bash | ||
pip install dna_mutator | ||
**Web documentation:** | ||
|
||
`<https://edinburgh-genome-foundry.github.io/dna_mutator/>`_ | ||
|
||
|
||
**Github page:** | ||
|
||
`<https://github.com/Edinburgh-Genome-Foundry/dna_mutator>`_ | ||
|
||
|
||
**License:** MIT, Copyright 2024 Edinburgh Genome Foundry, University of Edinburgh | ||
|
||
|
||
More biology software | ||
--------------------- | ||
|
||
.. image:: https://raw.githubusercontent.com/Edinburgh-Genome-Foundry/Edinburgh-Genome-Foundry.github.io/master/static/imgs/logos/egf-codon-horizontal.png | ||
:target: https://edinburgh-genome-foundry.github.io/ | ||
|
||
DNA Mutator is part of the `EGF Codons <https://edinburgh-genome-foundry.github.io/>`_ synthetic biology software suite for DNA design, manufacturing and validation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from setuptools import setup, find_packages | ||
|
||
version = {} | ||
with open("dna_mutator/version.py") as fp: | ||
exec(fp.read(), version) | ||
|
||
setup( | ||
name="dna_mutator", | ||
version=version["__version__"], | ||
author="B237870", | ||
author_email="egf-software@ed.ac.uk", | ||
description="Create variants of DNA sequences", | ||
long_description=open("pypi-readme.rst").read(), | ||
long_description_content_type="text/x-rst", | ||
license="MIT", | ||
keywords="biology dna", | ||
packages=find_packages(exclude="docs"), | ||
include_package_data=True, | ||
install_requires=["biopython"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import pytest | ||
|
||
import dna_mutator | ||
|
||
|
||
def test_Mutator(): | ||
pass |