Example #1
0
    def setUp(self):
        args = []
        opts = {'dumpfile': settings.MEDIA_ROOT + 'test_db_dump.xml', 'verbosity': 0}
        cmd = 'migrate_db'
        call_command(cmd, *args, **opts)

        blast_type = 'local'
        voucher_code = 'CP100-10'
        gene_code = 'COI'
        self.blast = BLAST(blast_type, voucher_code, gene_code)
        self.seq_file = ''
Example #2
0
 def test_create_blast_db_unmasked(self):
     blast_type = 'local'
     voucher_code = 'CP100-10'
     gene_code = 'COI'
     blast = BLAST(blast_type, voucher_code, gene_code, mask=False)
     blast.save_seqs_to_file()
     blast.create_blast_db()
     files = glob.glob(
         os.path.join(settings.BASE_DIR,
                      '..',
                      'core',
                      'db',
                      'COI_seqs.fas.n*')
     )
     self.assertTrue(len(files) > 0)
     self.remove_blast_data_files()
Example #3
0
    def setUp(self):
        args = []
        opts = {'dumpfile': 'test_db_dump.xml', 'verbosity': 0}
        cmd = 'migrate_db'
        call_command(cmd, *args, **opts)

        blast_type = 'local'
        voucher_code = 'CP100-10'
        gene_code = 'COI'
        self.blast = BLAST(blast_type, voucher_code, gene_code)
        self.seq_file = ''
Example #4
0
 def test_create_blast_db_unmasked(self):
     blast_type = 'local'
     voucher_code = 'CP100-10'
     gene_code = 'COI'
     blast = BLAST(blast_type, voucher_code, gene_code, mask=False)
     blast.save_seqs_to_file()
     blast.create_blast_db()
     files = glob.glob(
         os.path.join(settings.BASE_DIR, '..', 'core', 'db',
                      'COI_seqs.fas.n*'))
     self.assertTrue(len(files) > 0)
     self.remove_blast_data_files()
Example #5
0
def index(request, voucher_code, gene_code):
    version, stats = get_version_stats()
    username = get_username(request)

    blast = BLAST('local', voucher_code, gene_code)
    blast.save_seqs_to_file()

    if not blast.is_blast_db_up_to_date():
        blast.create_blast_db()

    blast.save_query_to_file()
    blast.do_blast()
    result = blast.parse_blast_output()
    blast.delete_query_output_files()
    return render(request, 'blast_local/index.html',
                  {
                      'username': username,
                      'result': result,
                      'version': version,
                      'stats': stats,
                  },
                  )
Example #6
0
def index(request: HttpRequest, voucher_code: str,
          gene_code: str) -> HttpResponse:
    """Runs a local blast for voucher code and gene code

    Show results to user in a table
    """
    blast = BLAST('local', voucher_code, gene_code)
    blast.save_seqs_to_file()

    if not blast.is_blast_db_up_to_date():
        try:
            blast.create_blast_db()
        except CalledProcessError:
            log.warning("there are no sequences for gene %s", gene_code)

    was_sequence_saved = blast.save_query_to_file()
    if was_sequence_saved:
        blast.do_blast()
        result = blast.parse_blast_output()
        blast.delete_query_output_files()
    else:
        result = {
            "error": "Query sequence has no valid codons, only question marks",
        }
    context = get_context(request)
    context["result"] = result
    return render(request, 'blast_local/index.html', context)
Example #7
0
class BlastLocalTest(TestCase):
    def setUp(self):
        args = []
        opts = {'dumpfile': settings.MEDIA_ROOT + 'test_db_dump.xml', 'verbosity': 0}
        cmd = 'migrate_db'
        call_command(cmd, *args, **opts)

        blast_type = 'local'
        voucher_code = 'CP100-10'
        gene_code = 'COI'
        self.blast = BLAST(blast_type, voucher_code, gene_code)
        self.seq_file = ''

    def remove_blast_data_files(self):
        path = os.path.join(settings.MEDIA_ROOT,
                            'db',
                            '*',
                            )
        for file in glob.glob(path):
            if not file.endswith('py') and os.path.isfile(file):
                os.remove(file)

    def test_have_blast_db(self):
        self.remove_blast_data_files()
        result = self.blast.have_blast_db()
        self.assertEqual(False, result)

    def test_have_blast_db_true(self):
        self.blast.save_seqs_to_file()
        self.blast.create_blast_db()

        result = self.blast.have_blast_db()
        self.assertEqual(True, result)
        self.remove_blast_data_files()

    def test_save_seqs_to_file(self):
        self.blast.save_seqs_to_file()
        self.seq_file = os.path.join(settings.MEDIA_ROOT,
                                     'db',
                                     'COI_seqs.fas',
                                     )
        result = os.path.isfile(self.seq_file)
        self.assertTrue(result)
        self.remove_blast_data_files()

    def test_create_blast_db(self):
        blast_type = 'local'
        voucher_code = 'CP100-10'
        gene_code = 'COI'
        blast = BLAST(blast_type, voucher_code, gene_code, mask=True)
        blast.save_seqs_to_file()
        blast.create_blast_db()
        files = glob.glob(
            os.path.join(settings.MEDIA_ROOT,
                         'db',
                         'COI_seqs.fas.n*')
        )
        self.assertTrue(len(files) > 0)
        self.remove_blast_data_files()

    def test_create_blast_db_unmasked(self):
        blast_type = 'local'
        voucher_code = 'CP100-10'
        gene_code = 'COI'
        blast = BLAST(blast_type, voucher_code, gene_code, mask=False)
        blast.save_seqs_to_file()
        blast.create_blast_db()
        files = glob.glob(
            os.path.join(settings.MEDIA_ROOT,
                         'db',
                         'COI_seqs.fas.n*')
        )
        self.assertTrue(len(files) > 0)
        self.remove_blast_data_files()

    def test_is_blast_db_up_to_date(self):
        self.blast.save_seqs_to_file()
        self.blast.create_blast_db()
        result = self.blast.is_blast_db_up_to_date()
        self.assertTrue(result)
        self.remove_blast_data_files()

    def test_is_blast_db_up_to_date_false(self):
        self.blast.save_seqs_to_file()
        self.blast.create_blast_db()

        b = Vouchers.objects.get(code='CP100-10')

        tomorrow = datetime.datetime.now() + datetime.timedelta(days=1)
        Sequences.objects.filter(code=b, gene_code='COI').update(
            time_edited=tomorrow
        )
        result = self.blast.is_blast_db_up_to_date()
        self.assertFalse(result)
        self.remove_blast_data_files()

    def test_is_blast_db_up_to_date_false2(self):
        self.blast.save_seqs_to_file()
        result = self.blast.is_blast_db_up_to_date()
        self.assertFalse(result)
        self.remove_blast_data_files()

    def test_do_blast(self):
        self.blast.save_seqs_to_file()
        self.blast.create_blast_db()
        self.blast.save_query_to_file()
        result = self.blast.do_blast()
        self.assertTrue(os.path.isfile(result))
        self.remove_blast_data_files()

    def test_parse_blast_output(self):
        self.blast.save_seqs_to_file()
        self.blast.create_blast_db()
        self.blast.save_query_to_file()
        self.blast.do_blast()
        result = self.blast.parse_blast_output()
        self.assertTrue(611 in [i['query_length'] for i in result])
        self.remove_blast_data_files()

    def test_strip_question_marks(self):
        seq = '?G?A??????TTTTATTTTTGG???????????????????????????????????????????CGAA??GAATTAGGTAACCCAGGATCTTTAATTGGAGATGATCAAATTTATAATACTATTGTAACTGCTCATGCATTTATTATAATTTTTTTTATAGTTATACCTATTATAATTGGAGGATTTGGTAATTGATTAATTCCTTTAATACTTGGAGCTCCTGATATAGCTTTCCCTCGAATAAATAATATAAGATTTTGACTTCTCCCCCCCTCTTTAATTTTATTAATTTCTAGAAGAATTGTAGAAACTGGGGCCGGAACAGGCTGAACAGTATACCCTCCTTTATCTTCAAATATTGCTCATGGGGGAGCTTCTGTAGATTTAGCTATTTTTTCTTTACATTTAGCAGGTATTTCCTCTATTTTAGGAGCAATTAATTTTATTACAACTATTATTAATATACGAATTAGTAATATATCATTTGATCAAATACCTTTATTTGTTTGATCAGTAGGAATTACAGCTTTATTATTACTTTTATCTTTACCTGTATTAGCTGGAGCTATTACCATATTATTAACGGATCGAAATTTAAATACTTCATTTTTTGACCCTGCTGGAGGAGGAGATCCCATTCTTTATCAACATCTATTTTGATTTTTTGG'
        expected = 'GNANNNNNNTTTTATTTTTGGNNNNNNNNN'
        result = self.blast.strip_question_marks(seq)
        self.assertTrue(result.startswith(expected))

        seq = '?GGAAGAATTAGGTAACCCAGGATCTTTAATTGGAGATGATCAAATTTATAATACTATTGTAACTGCTCATGCATTTATTATAATTTTTTTTATAGTTATACCTATTATAATTGGAGGATTTGGTAATTGATTAATTCCTTTAATACTTGGAGCTCCTGATATAGCTTTCCCTCGAATAAATAATATAAGATTTTGACTTCTCCCCCCCTCTTTAATTTTATTAATTTCTAGAAGAATTGTAGAAACTGGGGCCGGAACAGGCTGAACAGTATACCCTCCTTTATCTTCAAATATTGCTCATGGGGGAGCTTCTGTAGATTTAGCTATTTTTTCTTTACATTTAGCAGGTATTTCCTCTATTTTAGGAGCAATTAATTTTATTACAACTATTATTAATATACGAATTAGTAATATATCATTTGATCAAATACCTTTATTTGTTTGATCAGTAGGAATTACAGCTTTATTATTACTTTTATCTTTACCTGTATTAGCTGGAGCTATTACCATATTATTAACGGATCGAAATTTAAATACTTCATTTTTTGACCCTGCTGGAGGAGGAGATCCCATTCTTTATCAACATCTATTTTGATTTTTTGG'
        expected = 'GGAAGAATTAGGTAACCCAGGATCTTTAATTGGAGATGATCAAATTTATAATACTATTGTAACTGCTCATGCATTTATTATAATTTTTTTTATAGTTATACCTATTATAATTGGAGGATTTGGTAATTGATTAATTCCTTTAATACTTGGAGCTCCTGATATAGCTTTCCCTCGAATAAATAATATAAGATTTTGACTTCTCCCCCCCTCTTTAATTTTATTAATTTCTAGAAGAATTGTAGAAACTGGGGCCGGAACAGGCTGAACAGTATACCCTCCTTTATCTTCAAATATTGCTCATGGGGGAGCTTCTGTAGATTTAGCTATTTTTTCTTTACATTTAGCAGGTATTTCCTCTATTTTAGGAGCAATTAATTTTATTACAACTATTATTAATATACGAATTAGTAATATATCATTTGATCAAATACCTTTATTTGTTTGATCAGTAGGAATTACAGCTTTATTATTACTTTTATCTTTACCTGTATTAGCTGGAGCTATTACCATATTATTAACGGATCGAAATTTAAATACTTCATTTTTTGACCCTGCTGGAGGAGGAGATCCCATTCTTTATCAACATCTATTTTGATTTTTTGG'
        result = self.blast.strip_question_marks(seq)
        self.assertEqual(expected, result)
Example #8
0
def index(request: HttpRequest, voucher_code: str, gene_code: str) -> HttpResponse:
    """Runs a local blast for voucher code and gene code

    Show results to user in a table
    """
    blast = BLAST('local', voucher_code, gene_code)
    blast.save_seqs_to_file()

    if not blast.is_blast_db_up_to_date():
        try:
            blast.create_blast_db()
        except CalledProcessError:
            log.warning("there are no sequences for gene %s", gene_code)

    was_sequence_saved = blast.save_query_to_file()
    if was_sequence_saved:
        blast.do_blast()
        result = blast.parse_blast_output()
        blast.delete_query_output_files()
    else:
        result = {
            "error": "Query sequence has no valid codons, only question marks",
        }
    context = get_context(request)
    context["result"] = result
    return render(request, 'blast_local/index.html', context)
Example #9
0
class BlastLocalTest(TestCase):
    def setUp(self):
        args = []
        opts = {'dumpfile': 'test_db_dump.xml', 'verbosity': 0}
        cmd = 'migrate_db'
        call_command(cmd, *args, **opts)

        blast_type = 'local'
        voucher_code = 'CP100-10'
        gene_code = 'COI'
        self.blast = BLAST(blast_type, voucher_code, gene_code)
        self.seq_file = ''

    def remove_blast_data_files(self):
        path = os.path.join(settings.BASE_DIR,
                            '..',
                            'core',
                            'db',
                            '*',
                            )
        for file in glob.glob(path):
            if not file.endswith('py') and os.path.isfile(file):
                os.remove(file)

    def test_have_blast_db(self):
        self.remove_blast_data_files()
        result = self.blast.have_blast_db()
        self.assertEqual(False, result)

    def test_have_blast_db_true(self):
        self.blast.save_seqs_to_file()
        self.blast.create_blast_db()

        result = self.blast.have_blast_db()
        self.assertEqual(True, result)
        self.remove_blast_data_files()

    def test_save_seqs_to_file(self):
        self.blast.save_seqs_to_file()
        self.seq_file = os.path.join(settings.BASE_DIR,
                                     '..',
                                     'core',
                                     'db',
                                     'COI_seqs.fas',
                                     )
        result = os.path.isfile(self.seq_file)
        self.assertTrue(result)
        self.remove_blast_data_files()

    def test_create_blast_db(self):
        blast_type = 'local'
        voucher_code = 'CP100-10'
        gene_code = 'COI'
        blast = BLAST(blast_type, voucher_code, gene_code, mask=True)
        blast.save_seqs_to_file()
        blast.create_blast_db()
        files = glob.glob(
            os.path.join(settings.BASE_DIR,
                         '..',
                         'core',
                         'db',
                         'COI_seqs.fas.n*')
        )
        self.assertTrue(len(files) > 0)
        self.remove_blast_data_files()

    def test_create_blast_db_unmasked(self):
        blast_type = 'local'
        voucher_code = 'CP100-10'
        gene_code = 'COI'
        blast = BLAST(blast_type, voucher_code, gene_code, mask=False)
        blast.save_seqs_to_file()
        blast.create_blast_db()
        files = glob.glob(
            os.path.join(settings.BASE_DIR,
                         '..',
                         'core',
                         'db',
                         'COI_seqs.fas.n*')
        )
        self.assertTrue(len(files) > 0)
        self.remove_blast_data_files()

    def test_is_blast_db_up_to_date(self):
        self.blast.save_seqs_to_file()
        self.blast.create_blast_db()
        result = self.blast.is_blast_db_up_to_date()
        self.assertTrue(result)
        self.remove_blast_data_files()

    def test_is_blast_db_up_to_date_false(self):
        self.blast.save_seqs_to_file()
        self.blast.create_blast_db()

        b = Vouchers.objects.get(code='CP100-10')

        tomorrow = datetime.datetime.now() + datetime.timedelta(days=1)
        Sequences.objects.filter(code=b, gene_code='COI').update(
            time_edited=tomorrow
        )
        result = self.blast.is_blast_db_up_to_date()
        self.assertFalse(result)
        self.remove_blast_data_files()

    def test_is_blast_db_up_to_date_false2(self):
        self.blast.save_seqs_to_file()
        result = self.blast.is_blast_db_up_to_date()
        self.assertFalse(result)
        self.remove_blast_data_files()

    def test_do_blast(self):
        self.blast.save_seqs_to_file()
        self.blast.create_blast_db()
        self.blast.save_query_to_file()
        result = self.blast.do_blast()
        self.assertTrue(os.path.isfile(result))
        self.remove_blast_data_files()

    def test_parse_blast_output(self):
        self.blast.save_seqs_to_file()
        self.blast.create_blast_db()
        self.blast.save_query_to_file()
        self.blast.do_blast()
        result = self.blast.parse_blast_output()
        self.assertTrue(611 in [i['query_length'] for i in result])
        self.remove_blast_data_files()

    def test_strip_question_marks(self):
        seq = '?G?A??????TTTTATTTTTGG???????????????????????????????????????????CGAA??GAATTAGGTAACCCAGGATCTTTAATTGGAGATGATCAAATTTATAATACTATTGTAACTGCTCATGCATTTATTATAATTTTTTTTATAGTTATACCTATTATAATTGGAGGATTTGGTAATTGATTAATTCCTTTAATACTTGGAGCTCCTGATATAGCTTTCCCTCGAATAAATAATATAAGATTTTGACTTCTCCCCCCCTCTTTAATTTTATTAATTTCTAGAAGAATTGTAGAAACTGGGGCCGGAACAGGCTGAACAGTATACCCTCCTTTATCTTCAAATATTGCTCATGGGGGAGCTTCTGTAGATTTAGCTATTTTTTCTTTACATTTAGCAGGTATTTCCTCTATTTTAGGAGCAATTAATTTTATTACAACTATTATTAATATACGAATTAGTAATATATCATTTGATCAAATACCTTTATTTGTTTGATCAGTAGGAATTACAGCTTTATTATTACTTTTATCTTTACCTGTATTAGCTGGAGCTATTACCATATTATTAACGGATCGAAATTTAAATACTTCATTTTTTGACCCTGCTGGAGGAGGAGATCCCATTCTTTATCAACATCTATTTTGATTTTTTGG'
        expected = 'GNANNNNNNTTTTATTTTTGGNNNNNNNNN'
        result = self.blast.strip_question_marks(seq)
        self.assertTrue(result.startswith(expected))

        seq = '?GGAAGAATTAGGTAACCCAGGATCTTTAATTGGAGATGATCAAATTTATAATACTATTGTAACTGCTCATGCATTTATTATAATTTTTTTTATAGTTATACCTATTATAATTGGAGGATTTGGTAATTGATTAATTCCTTTAATACTTGGAGCTCCTGATATAGCTTTCCCTCGAATAAATAATATAAGATTTTGACTTCTCCCCCCCTCTTTAATTTTATTAATTTCTAGAAGAATTGTAGAAACTGGGGCCGGAACAGGCTGAACAGTATACCCTCCTTTATCTTCAAATATTGCTCATGGGGGAGCTTCTGTAGATTTAGCTATTTTTTCTTTACATTTAGCAGGTATTTCCTCTATTTTAGGAGCAATTAATTTTATTACAACTATTATTAATATACGAATTAGTAATATATCATTTGATCAAATACCTTTATTTGTTTGATCAGTAGGAATTACAGCTTTATTATTACTTTTATCTTTACCTGTATTAGCTGGAGCTATTACCATATTATTAACGGATCGAAATTTAAATACTTCATTTTTTGACCCTGCTGGAGGAGGAGATCCCATTCTTTATCAACATCTATTTTGATTTTTTGG'
        expected = 'GGAAGAATTAGGTAACCCAGGATCTTTAATTGGAGATGATCAAATTTATAATACTATTGTAACTGCTCATGCATTTATTATAATTTTTTTTATAGTTATACCTATTATAATTGGAGGATTTGGTAATTGATTAATTCCTTTAATACTTGGAGCTCCTGATATAGCTTTCCCTCGAATAAATAATATAAGATTTTGACTTCTCCCCCCCTCTTTAATTTTATTAATTTCTAGAAGAATTGTAGAAACTGGGGCCGGAACAGGCTGAACAGTATACCCTCCTTTATCTTCAAATATTGCTCATGGGGGAGCTTCTGTAGATTTAGCTATTTTTTCTTTACATTTAGCAGGTATTTCCTCTATTTTAGGAGCAATTAATTTTATTACAACTATTATTAATATACGAATTAGTAATATATCATTTGATCAAATACCTTTATTTGTTTGATCAGTAGGAATTACAGCTTTATTATTACTTTTATCTTTACCTGTATTAGCTGGAGCTATTACCATATTATTAACGGATCGAAATTTAAATACTTCATTTTTTGACCCTGCTGGAGGAGGAGATCCCATTCTTTATCAACATCTATTTTGATTTTTTGG'
        result = self.blast.strip_question_marks(seq)
        self.assertEqual(expected, result)