Skip to content

Commit

Permalink
Merge pull request #139 from brinkmanlab/dev-merge
Browse files Browse the repository at this point in the history
Merge dev and cluster-vis
  • Loading branch information
innovate-invent authored Jan 31, 2020
2 parents e84be45 + 5d67f37 commit 508339c
Show file tree
Hide file tree
Showing 30 changed files with 2,419 additions and 655 deletions.
437 changes: 267 additions & 170 deletions IslandCompare/analysis/components.py

Large diffs are not rendered by default.

93 changes: 60 additions & 33 deletions IslandCompare/analysis/integration_tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.test import TestCase, override_settings
from genomes.models import Genome
from genomes.models import Genome, GenomicIsland
from analysis.models import Analysis
from django.contrib.auth.models import User
from django.core.files import File
from analysis.components import ParsnpPipelineComponent, MauvePipelineComponent, \
Expand Down Expand Up @@ -155,10 +156,12 @@ def setUp(self):
self.test_genome_1 = Genome.objects.create(name=self.test_genome_1_name,
owner=self.test_user,
gbk=self.test_genome_1_gbk)
self.test_genome_1.save()

self.test_genome_2 = Genome.objects.create(name=self.test_genome_2_name,
owner=self.test_user,
gbk=self.test_genome_2_gbk)
self.test_genome_2.save()

def test_sigihmm_analysis(self):
report = {
Expand All @@ -175,8 +178,8 @@ def test_sigihmm_analysis(self):
component.analysis(report)
component.cleanup()

self.assertTrue("sigi_gis" in report)
self.assertEqual(2, len(report["sigi_gis"]))
self.assertTrue(self.test_genome_1.genomicisland_set.filter(method="sigi").exists())
self.assertTrue(self.test_genome_2.genomicisland_set.filter(method="sigi").exists())

def tearDown(self):
for genome in Genome.objects.all():
Expand All @@ -202,10 +205,12 @@ def setUp(self):
self.test_genome_1 = Genome.objects.create(name=self.test_genome_1_name,
owner=self.test_user,
gbk=self.test_genome_1_gbk)
self.test_genome_1.save()

self.test_genome_2 = Genome.objects.create(name=self.test_genome_2_name,
owner=self.test_user,
gbk=self.test_genome_2_gbk)
self.test_genome_2.save()

def test_islandpath_analysis(self):
report = {
Expand All @@ -222,10 +227,8 @@ def test_islandpath_analysis(self):
component.analysis(report)
component.cleanup()

self.assertTrue("islandpath_gis" in report)
self.assertEqual(2, len(report["islandpath_gis"]))
self.assertTrue(self.test_genome_1.id in report["islandpath_gis"])
self.assertTrue(self.test_genome_2.id in report["islandpath_gis"])
self.assertTrue(self.test_genome_1.genomicisland_set.filter(method="islandpath").exists())
self.assertTrue(self.test_genome_2.genomicisland_set.filter(method="islandpath").exists())

def tearDown(self):
for genome in Genome.objects.all():
Expand Down Expand Up @@ -284,6 +287,8 @@ class MashMCLTestCase(TestCase):
test_username = "username"
test_user = None

test_cluster_analysis = None

test_genome_1 = None
test_genome_1_name = "genome_1"
test_genome_1_gbk = File(open("../TestFiles/AE009952.gbk"))
Expand All @@ -292,32 +297,62 @@ class MashMCLTestCase(TestCase):
test_genome_2_name = "genome_2"
test_genome_2_gbk = File(open("../TestFiles/BX936398.gbk"))

test_gi_1 = None
test_gi_2 = None

report = None

def setUp(self):
self.test_user = User(username=self.test_username)
self.test_user.save()

self.test_cluster_analysis = Analysis(
celery_task_id="1",
name="test_cluster_analysis",
owner=self.test_user
)
self.test_cluster_analysis.save()

self.test_genome_1 = Genome.objects.create(name=self.test_genome_1_name,
owner=self.test_user,
gbk=self.test_genome_1_gbk)
self.test_genome_1.save()

self.test_genome_2 = Genome.objects.create(name=self.test_genome_2_name,
owner=self.test_user,
gbk=self.test_genome_2_gbk)

def test_generate_gi_fna(self):
component = MashMclClusterPipelineComponent()

report = {
"analysis": 1,
"available_dependencies": ["merge_gis", "gbk_paths"],
self.test_genome_2.save()

self.test_cluster_analysis.genomes.add(self.test_genome_1)
self.test_cluster_analysis.genomes.add(self.test_genome_2)
self.test_cluster_analysis.save()

self.test_gi_1 = GenomicIsland(
method="merge",
start=0,
end=1000,
genome=self.test_genome_1
).save()
self.test_gi_2 = GenomicIsland(
method="merge",
start=0,
end=1000,
genome=self.test_genome_2
).save()

self.report = {
"analysis": self.test_cluster_analysis.id,
"available_dependencies": ["gbk_paths"],
"gbk_paths": {self.test_genome_1.id: self.test_genome_1.gbk.path,
self.test_genome_2.id: self.test_genome_2.gbk.path},
"merge_gis": {self.test_genome_1.id: [[0, 1000]],
self.test_genome_2.id: [[0, 1000]]}
"pipeline_components": "merge"
}

component.setup(report)
component.create_gi_fasta_files(report)
def test_generate_gi_fna(self):
component = MashMclClusterPipelineComponent()

component.setup(self.report)
component.create_gi_fasta_files(self.report)

self.assertTrue(os.path.exists(component.temp_dir_path + "/fna/1/0"))
self.assertTrue(os.path.exists(component.temp_dir_path + "/fna/2/0"))
Expand All @@ -327,25 +362,18 @@ def test_generate_gi_fna(self):
def test_analysis(self):
component = MashMclClusterPipelineComponent()

report = {
"analysis": 1,
"available_dependencies": ["merge_gis", "gbk_paths"],
"gbk_paths": {self.test_genome_1.id: self.test_genome_1.gbk.path,
self.test_genome_2.id: self.test_genome_2.gbk.path},
"merge_gis": {self.test_genome_1.id: [[0, 1000]],
self.test_genome_2.id: [[0, 1000]]}
}

component.setup(report)
component.analysis(report)
component.setup(self.report)
component.analysis(self.report)
component.cleanup()

self.assertTrue("cluster_gis" in report)
self.assertEqual(0, report["cluster_gis"]['numberClusters'])
self.assertTrue("numberClusters" in self.report)
self.assertTrue(Analysis.objects.get(id=self.report["analysis"]).clusters != "")

def tearDown(self):
for genome in Genome.objects.all():
genome.delete()
for analysis in Analysis.objects.all():
analysis.delete()


class RGIComponentIntegrationTestCase(TestCase):
Expand All @@ -364,15 +392,14 @@ def setUp(self):
owner=self.test_user,
gbk=self.test_genome_1_gbk)

@skip("Complete writing tests when component is defined and implemented")
def test_rgi_component(self):
report = {
"analysis": 1,
"available_dependencies": ["gbk_paths"],
"gbk_paths": {self.test_genome_1.id: self.test_genome_1.gbk.path},
}

component = RGIPipelineComponent()#mock.MagicMock(RGIPipelineComponent)
component = RGIPipelineComponent()
component.setup(report)
component.analysis(report)
component.cleanup()
Expand Down
25 changes: 25 additions & 0 deletions IslandCompare/analysis/migrations/0002_auto_20170718_1718.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-07-18 17:18
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('analysis', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='analysis',
name='celery_task_id',
field=models.CharField(max_length=765),
),
migrations.AlterField(
model_name='analysiscomponent',
name='celery_task_id',
field=models.CharField(max_length=765),
),
]
20 changes: 20 additions & 0 deletions IslandCompare/analysis/migrations/0003_analysis_clusters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.5 on 2017-07-31 17:44
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('analysis', '0002_auto_20170718_1718'),
]

operations = [
migrations.AddField(
model_name='analysis',
name='clusters',
field=models.TextField(blank=True),
),
]
3 changes: 1 addition & 2 deletions IslandCompare/analysis/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from genomes.models import Genome
from django.utils import timezone

# Create your models here.


class Analysis(models.Model):
id = models.AutoField(primary_key=True)
Expand All @@ -15,6 +13,7 @@ class Analysis(models.Model):
start_time = models.DateTimeField(null=True)
complete_time = models.DateTimeField(null=True)
owner = models.ForeignKey(User)
clusters = models.TextField(blank=True)

class Meta:
unique_together = ('name', 'owner')
Expand Down
7 changes: 6 additions & 1 deletion IslandCompare/analysis/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class Pipeline(object):
"""A list of available dependencies"""
analysis = None
"""The analysis"""
failed_components = None
"""A list of failed components"""

def __init__(self):
"""
Expand All @@ -141,6 +143,7 @@ def __init__(self):
self.pipeline_components = []
self.available_dependencies = []
self.analysis = None
self.failed_components = {}

def create_database_entry(self, name, genomes, owner):
"""
Expand Down Expand Up @@ -188,7 +191,8 @@ def serialize(pipeline):
'analysis': pipeline.analysis.id,
'available_dependencies': pipeline.available_dependencies,
'pipeline_components': serialized_pipeline_components,
'component_param': serialized_pipeline_param
'component_param': serialized_pipeline_param,
'failed_components': pipeline.failed_components
}
return serialized_dict

Expand All @@ -208,5 +212,6 @@ def deserialize(serialized_dict, pipeline_component_factory):
)
pipeline.available_dependencies = serialized_dict['available_dependencies']
pipeline.analysis = Analysis.objects.get(id=serialized_dict['analysis'])
pipeline.failed_components = serialized_dict['failed_components']

return pipeline
Loading

0 comments on commit 508339c

Please sign in to comment.