예제 #1
0
    def setUp(self):
        import os
        import tempfile
        from edge import import_gff

        data = """##gff-version 3
chrI\tTest\tchromosome\t1\t160\t.\t.\t.\tID=i1;Name=f1
chrI\tTest\tcds\t30\t80\t.\t-\t.\tID=i2;Name=f2
chrI\tTest\trbs\t20\t28\t.\t+\t.\tID=i3
chrII\tTest\tgene\t40\t60\t.\t-\t.\tID=f4;gene=g4
chrII\tTest\tgene\t20\t80\t.\t+\t.\tID=i5;Name=f5
###
##FASTA
>chrI
CCACACCACACCCACACACCCACACACCACACCACACACCACACCACACCCACACACACACATCCTAACACTACCCTAAC
ACAGCCCTAATCTAACCCTGGCCAACCTGTCTCTCAACTTACCCTCCATTACCCTGCCTCCACTCGTTACCCTGTCCCAT
>chrII
CCACACCACACCCACACACCCACACACCACACCACACACCACACCACACCCACACACACACATCCTAACACTACCCTAAC
ACAGCCCTAATCTAACCCTGGCCAACCTGTCTCTCAACTTACCCTCCATTACCCTGCCTCCACTCGTTACCCTGTCCCAT
"""
        with tempfile.NamedTemporaryFile(mode='w+', delete=False) as f:
            f.write(data)
            f.close()
            import_gff('TestGenome', f.name)
            self.genome = Genome.objects.get(name='TestGenome')
            os.unlink(f.name)
        self.assertItemsEqual([f.name for f in self.genome.fragments.all()], ['chrI', 'chrII'])
예제 #2
0
    def test_import_gff_procedure_creates_genome_and_annotations(self):
        from edge import import_gff

        data = """##gff-version 3
chrI\tTest\tchromosome\t1\t160\t.\t.\t.\tID=i1;Name=f1
chrI\tTest\tcds\t30\t80\t.\t-\t.\tID=i2;Name=f2
chrI\tTest\trbs\t20\t28\t.\t+\t.\tID=i3
chrII\tTest\tgene\t40\t60\t.\t-\t.\tID=f4;gene=g4
chrII\tTest\tgene\t20\t80\t.\t+\t.\tID=i5;Name=f5
###
##FASTA
>chrI
CCACACCACACCCACACACCCACACACCACACCACACACCACACCACACCCACACACACACATCCTAACACTACCCTAAC
ACAGCCCTAATCTAACCCTGGCCAACCTGTCTCTCAACTTACCCTCCATTACCCTGCCTCCACTCGTTACCCTGTCCCAT
>chrII
CCACACCACACCCACACACCCACACACCACACCACACACCACACCACACCCACACACACACATCCTAACACTACCCTAAC
ACAGCCCTAATCTAACCCTGGCCAACCTGTCTCTCAACTTACCCTCCATTACCCTGCCTCCACTCGTTACCCTGTCCCAT
"""

        with tempfile.NamedTemporaryFile(mode='w+', delete=False) as f:
            f.write(data)
            f.close()

            self.assertEquals(
                Genome.objects.filter(name='TestGenome').count(), 0)
            import_gff('TestGenome', f.name)
            self.assertEquals(
                Genome.objects.filter(name='TestGenome').count(), 1)

            # import again with same name does not work
            self.assertRaises(Exception, import_gff, 'TestGenome', f.name)

            # can import again with different name
            self.assertEquals(
                Genome.objects.filter(name='TestGenome2').count(), 0)
            import_gff('TestGenome2', f.name)
            self.assertEquals(
                Genome.objects.filter(name='TestGenome2').count(), 1)

            genome = Genome.objects.get(name='TestGenome')

            os.unlink(f.name)

        # created one fragment for each sequence in GFF file
        self.assertItemsEqual([f.name for f in genome.fragments.all()],
                              ['chrI', 'chrII'])
        chrI = [
            f.indexed_fragment() for f in genome.fragments.all()
            if f.name == 'chrI'
        ][0]
        self.assertEquals(len(chrI.sequence), 160)
        self.assertEquals(len(chrI.annotations()), 2)
        chrII = [
            f.indexed_fragment() for f in genome.fragments.all()
            if f.name == 'chrII'
        ][0]
        self.assertEquals(len(chrII.sequence), 160)
        self.assertEquals(len(chrII.annotations()), 2)
예제 #3
0
    def test_import_gff_procedure_creates_genome_and_annotations(self):
        from edge import import_gff

        data = """##gff-version 3
chrI\tTest\tchromosome\t1\t160\t.\t.\t.\tID=i1;Name=f1
chrI\tTest\tcds\t30\t80\t.\t-\t.\tID=i2;Name=f2
chrI\tTest\trbs\t20\t28\t.\t+\t.\tID=i3
chrII\tTest\tgene\t40\t60\t.\t-\t.\tID=f4;gene=g4
chrII\tTest\tgene\t20\t80\t.\t+\t.\tID=i5;Name=f5
###
##FASTA
>chrI
CCACACCACACCCACACACCCACACACCACACCACACACCACACCACACCCACACACACACATCCTAACACTACCCTAAC
ACAGCCCTAATCTAACCCTGGCCAACCTGTCTCTCAACTTACCCTCCATTACCCTGCCTCCACTCGTTACCCTGTCCCAT
>chrII
CCACACCACACCCACACACCCACACACCACACCACACACCACACCACACCCACACACACACATCCTAACACTACCCTAAC
ACAGCCCTAATCTAACCCTGGCCAACCTGTCTCTCAACTTACCCTCCATTACCCTGCCTCCACTCGTTACCCTGTCCCAT
"""

        with tempfile.NamedTemporaryFile(mode='w+', delete=False) as f:
            f.write(data)
            f.close()

            self.assertEquals(Genome.objects.filter(name='TestGenome').count(), 0)
            import_gff('TestGenome', f.name)
            self.assertEquals(Genome.objects.filter(name='TestGenome').count(), 1)

            # import again with same name does not work
            self.assertRaises(Exception, import_gff, 'TestGenome', f.name)

            # can import again with different name
            self.assertEquals(Genome.objects.filter(name='TestGenome2').count(), 0)
            import_gff('TestGenome2', f.name)
            self.assertEquals(Genome.objects.filter(name='TestGenome2').count(), 1)

            genome = Genome.objects.get(name='TestGenome')

            os.unlink(f.name)

        # created one fragment for each sequence in GFF file
        self.assertItemsEqual([f.name for f in genome.fragments.all()], ['chrI', 'chrII'])
        chrI = [f.indexed_fragment() for f in genome.fragments.all() if f.name == 'chrI'][0]
        self.assertEquals(len(chrI.sequence), 160)
        self.assertEquals(len(chrI.annotations()), 2)
        chrII = [f.indexed_fragment() for f in genome.fragments.all() if f.name == 'chrII'][0]
        self.assertEquals(len(chrII.sequence), 160)
        self.assertEquals(len(chrII.annotations()), 2)
예제 #4
0
def genome_import(request):
    res = {
      'imported_genomes': [],
    }

    for name in request.FILES:
        with tempfile.NamedTemporaryFile(mode='rw+b', delete=False) as gff:
            for chuck in request.FILES.get(name).chunks():
                gff.write(chuck)
        g = import_gff(name, gff.name)
        os.unlink(gff.name)

        blastdb_task = build_genome_blastdb.delay(g.id)

        res['imported_genomes'].append({
            'id': g.id,
            'name': g.name,
            'blastdb_task_id': blastdb_task.id,
        })

    return JsonResponse(res)
예제 #5
0
def genome_import(request):
    res = {
        "imported_genomes": [],
    }

    for name in request.FILES:
        with tempfile.NamedTemporaryFile(mode="w+b", delete=False) as gff:
            for chuck in request.FILES.get(name).chunks():
                gff.write(chuck)
        g = import_gff(name, gff.name)
        os.unlink(gff.name)

        blastdb_task = build_genome_blastdb.delay(g.id)

        res["imported_genomes"].append({
            "id": g.id,
            "name": g.name,
            "blastdb_task_id": blastdb_task.id,
        })

    return JsonResponse(res)
예제 #6
0
# flake8: noqa
import django

django.setup()

import sys
from edge import import_gff

import_gff(sys.argv[1], sys.argv[2])
예제 #7
0
 def handle(self, *args, **options):
     if len(args) != 2:
         raise Exception("Expecting two arguments: name of genome and GFF file")
     import_gff(args[0], args[1])
예제 #8
0
파일: import_gff.py 프로젝트: Chris7/edge
 def handle(self, *args, **options):
     if len(args) != 2:
         raise Exception('Expecting two arguments: name of genome and GFF file')
     import_gff(args[0], args[1])