Skip to content

Commit

Permalink
restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
gamcil committed Sep 3, 2020
1 parent 09a501d commit 6319e94
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 11 deletions.
Empty file added clinker/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
6 changes: 5 additions & 1 deletion cli.py → clinker/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ def run(args):
clusters = []
print("Parsing GenBank files")
for file in args.files:
print(file)
records = [record for record in SeqIO.parse(file, "genbank")]
cluster = Cluster.from_seqrecords(*records, mode=args.mode)
print(cluster.name, cluster.loci)
clusters.append(cluster)

# Scan genes for smCOGs if protein mode specified
Expand All @@ -38,9 +40,11 @@ def run(args):
print("Aligning your clusters")
aligner = globaligner.align_clusters(*clusters)

print(aligner)

# Generate the SVG
print("Generating the figure")
figure = visualise.Figure(aligner=aligner, width=args.width).render("maximize")
figure = visualise.Figure(aligner=aligner, width=args.width).render("added")

# Write output files
with open(args.output, "w") as svg:
Expand Down
31 changes: 22 additions & 9 deletions globaligner.py → clinker/globaligner.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def get_cluster(self, cluster):
raise KeyError("No cluster with this name could be retrieved") from exc

# TODO: check for number of genes vs pure identity score
def compute_display_order(self, order="maximize"):
def compute_display_order(self, order="first_as_seed"):
""" Return sorted cluster name list based on specified order scheme.
Arguments:
Expand Down Expand Up @@ -221,9 +221,13 @@ def compute_display_order(self, order="maximize"):
for permutation in permutations(self._clusters.keys()):
score = 0
for i in range(1, total_clusters):
score += self.get_alignment(
permutation[i - 1], permutation[i]
).score
try:
score += self.get_alignment(
permutation[i - 1], permutation[i]
).score
except ValueError:
# no links
continue
if score > best_score:
best_score = score
best_permutation = permutation
Expand All @@ -245,12 +249,19 @@ def compute_display_order(self, order="maximize"):
continue

# Grab alignment between last added cluster and next
alignment = self.get_alignment(permutation[-1], target)
if alignment.score > max_score:
max_score = alignment.score
max_cluster = target
try:
alignment = self.get_alignment(permutation[-1], target)
except KeyError:
continue
try:
if alignment.score > max_score:
max_score = alignment.score
max_cluster = target
except ValueError:
continue

permutation.append(max_cluster)
if max_cluster:
permutation.append(max_cluster)

return permutation

Expand Down Expand Up @@ -301,6 +312,8 @@ def find_gene(self, gene_name):
@property
def score(self):
"""Calculate 'score' of this alignment by summing identities."""
if not self.links:
raise ValueError("Alignment has no links")
return sum(link.identity + link.similarity for link in self.links) / len(
self.links
)
Expand Down
10 changes: 9 additions & 1 deletion visualise.py → clinker/visualise.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ def render(self, order):
genes = ""

for count, cluster_name in enumerate(display_order): # cluster names
cluster = self.aligner.get_cluster(cluster_name)
print(count, cluster_name)

try:
cluster = self.aligner.get_cluster(cluster_name)
except:
continue

cluster_maps.append(
cluster.map_cluster(
locus_spacing=self.locus_spacing, scale_factor=scale_factor
Expand All @@ -105,6 +111,8 @@ def render(self, order):
lower = previous_cluster.genes[index]
upper = previous_cluster.genes[previous_total - index - 1]

print(lower, upper)

if first and last:
break

Expand Down
39 changes: 39 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import re

from pathlib import Path
from setuptools import setup, find_packages

with open("README.md") as readme:
long_description = readme.read()


def get_version():
"""Get version number from __init__.py"""
version_file = Path(__file__).resolve().parent / "synthaser" / "__init__.py"
version_match = re.search(
r"^__version__ = ['\"]([^'\"]*)['\"]", version_file.read_text(), re.M
)
if version_match:
return version_match.group(1)
raise RuntimeError("Failed to find version string")


setup(
name="clinker",
author="Cameron Gilchrist",
version=get_version(),
description="",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/gamcil/clinker",
packages=find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
install_requires=["genome2json"],
python_requires=">=3.6",
entry_points={"console_scripts": ["synthaser=clinker.main:main"]},
include_package_data=True,
)

0 comments on commit 6319e94

Please sign in to comment.