예제 #1
0
파일: utils.py 프로젝트: carlosp420/VoSeq
    def __init__(self, cleaned_data):
        self.cleaned_data = cleaned_data
        self.translations = None
        self.degen_translations = None
        self.clean_translations()

        self.errors = []
        self.seq_objs = []
        self.minimum_number_of_genes = cleaned_data["number_genes"]
        self.aminoacids = cleaned_data["aminoacids"]

        try:
            self.codon_positions = clean_positions(cleaned_data["positions"])
        except exceptions.InadequateCodonPositions as e:
            self.codon_positions = None
            self.errors = [e]

        self.file_format = cleaned_data["file_format"]
        self.partition_by_positions = cleaned_data["partition_by_positions"]
        self.voucher_codes = get_voucher_codes(cleaned_data)
        self.gene_codes = get_gene_codes(cleaned_data)
        self.gene_codes_and_lengths = None
        self.taxon_names = cleaned_data["taxon_names"]
        self.voucher_codes_metadata = dict()
        self.gene_codes_metadata = self.get_gene_codes_metadata()
        self.warnings = []
        self.outgroup = cleaned_data["outgroup"]
        self.dataset_file = None
        self.aa_dataset_file = None
        self.charset_block = None
        self.dataset_str = self.create_dataset()
예제 #2
0
파일: views.py 프로젝트: Lakeshed/VoSeq
 def __init__(self, cleaned_data):
     self.cleaned_data = self.populate_cleaned_data_form(cleaned_data)
     self.voucher_codes = get_voucher_codes(cleaned_data)
     self.gene_codes = get_gene_codes(cleaned_data)
     self.fasta_datasets = self.get_fasta_datasets()
     self.genes_type = self.get_genes_type()
     self.stats = self.get_stats_from_datasets()
예제 #3
0
파일: utils.py 프로젝트: danmcelroy/VoSeq
    def __init__(self, cleaned_data):
        # skip sequences with accession numbers and building GenBank Fasta file
        self.sequences_skipped = []
        self.cleaned_data = cleaned_data
        self.translations = None
        self.degen_translations = None
        self.clean_translations()

        self.errors = []
        self.seq_objs = []
        self.minimum_number_of_genes = cleaned_data['number_genes']
        self.aminoacids = cleaned_data['aminoacids']

        try:
            self.codon_positions = clean_positions(cleaned_data['positions'])
        except exceptions.InadequateCodonPositions as e:
            self.codon_positions = None
            self.errors = [e]

        self.file_format = cleaned_data['file_format']
        self.partition_by_positions = cleaned_data['partition_by_positions']
        self.voucher_codes = get_voucher_codes(cleaned_data)
        self.gene_codes = get_gene_codes(cleaned_data)
        self.gene_codes_and_lengths = None
        self.taxon_names = cleaned_data['taxon_names']
        self.voucher_codes_metadata = dict()
        self.gene_codes_metadata = self.get_gene_codes_metadata()
        self.warnings = []
        self.outgroup = cleaned_data['outgroup']
        self.dataset_file = None
        self.aa_dataset_file = None
        self.charset_block = None
        self.dataset_str = self.create_dataset()
예제 #4
0
 def test_get_voucher_codes_order(self):
     """Voucher codes should not be sorted. Same order as input from author
     should be kept."""
     self.cleaned_data["voucher_codes"] = "CP100-10\r\nCP100-11\r\nCP100-12\r\nCP100-13\r\nCP100-11"
     expected = ("CP100-10", "CP100-11", "CP100-12", "CP100-13")
     result = get_voucher_codes(self.cleaned_data)
     self.assertEqual(expected, result)
예제 #5
0
파일: utils.py 프로젝트: carlosp420/VoSeq
    def __init__(self, cleaned_data):
        # skip sequences with accession numbers and building GenBank Fasta file
        self.sequences_skipped = []
        self.cleaned_data = cleaned_data
        self.translations = None
        self.degen_translations = None
        self.clean_translations()

        self.errors = []
        self.seq_objs = []
        self.minimum_number_of_genes = cleaned_data['number_genes']
        self.aminoacids = cleaned_data['aminoacids']

        try:
            self.codon_positions = clean_positions(cleaned_data['positions'])
        except exceptions.InadequateCodonPositions as e:
            self.codon_positions = None
            self.errors = [e]

        self.file_format = cleaned_data['file_format']
        self.partition_by_positions = cleaned_data['partition_by_positions']
        self.voucher_codes = get_voucher_codes(cleaned_data)
        self.gene_codes = get_gene_codes(cleaned_data)
        self.gene_codes_and_lengths = None
        self.taxon_names = cleaned_data['taxon_names']
        self.voucher_codes_metadata = dict()
        self.gene_codes_metadata = self.get_gene_codes_metadata()
        self.warnings = []
        self.outgroup = cleaned_data['outgroup']
        self.dataset_file = None
        self.aa_dataset_file = None
        self.charset_block = None
        self.dataset_str = self.create_dataset()
예제 #6
0
 def __init__(self, cleaned_data):
     self.cleaned_data = self.populate_cleaned_data_form(cleaned_data)
     self.voucher_codes = get_voucher_codes(cleaned_data)
     self.gene_codes = get_gene_codes(cleaned_data)
     self.fasta_datasets = self.get_fasta_datasets()
     self.genes_type = self.get_genes_type()
     self.stats = self.get_stats_from_datasets()
예제 #7
0
 def test_get_voucher_codes_order(self):
     """Voucher codes should not be sorted. Same order as input from author
     should be kept."""
     self.cleaned_data['voucher_codes'] = 'CP100-10\r\nCP100-11\r\nCP100-12\r\nCP100-13\r\nCP100-11'
     expected = ('CP100-10', 'CP100-11', 'CP100-12', 'CP100-13')
     result = get_voucher_codes(self.cleaned_data)
     self.assertEqual(expected, result)
예제 #8
0
 def test_get_voucher_codes_order(self):
     """Voucher codes should not be sorted. Same order as input from author
     should be kept."""
     self.cleaned_data[
         'voucher_codes'] = 'CP100-10\r\nCP100-11\r\nCP100-12\r\nCP100-13\r\nCP100-11'
     expected = ('CP100-10', 'CP100-11', 'CP100-12', 'CP100-13')
     result = get_voucher_codes(self.cleaned_data)
     self.assertEqual(expected, result)
예제 #9
0
파일: utils.py 프로젝트: Lakeshed/VoSeq
 def __init__(self, cleaned_data):
     self.cleaned_data = cleaned_data
     self.gene_info_to_display = self.get_gene_info_to_display()
     self.voucher_codes = get_voucher_codes(cleaned_data)
     self.gene_codes = get_gene_codes(cleaned_data)
     self.voucher_info_values = self.get_voucher_info_values()
     self.voucher_info = self.get_voucher_info()
     self.sequences_info = self.get_sequence_info()
     self.warnings = []
예제 #10
0
 def __init__(self, cleaned_data):
     self.cleaned_data = cleaned_data
     self.gene_info_to_display = self.get_gene_info_to_display()
     self.voucher_codes = get_voucher_codes(cleaned_data)
     self.gene_codes = get_gene_codes(cleaned_data)
     self.voucher_info_values = self.get_voucher_info_values()
     self.voucher_info = self.get_voucher_info()
     self.sequences_info = self.get_sequence_info()
     self.warnings = []
예제 #11
0
    def create_dataset(self):
        if not self.codon_positions:
            return ''

        error_msg = None
        if self.degen_translations is not None and self.codon_positions != [
                'ALL'
        ]:
            error_msg = 'Cannot degenerate codons if you have not selected all codon positions'
            self.errors.append(error_msg)
        elif self.degen_translations is not None and self.partition_by_positions != 'by gene':
            error_msg = 'Cannot degenerate codons if they go to different partitions'
            self.errors.append(error_msg)

        if error_msg:
            return ''

        self.voucher_codes = get_voucher_codes(self.cleaned_data)
        self.gene_codes = get_gene_codes(self.cleaned_data)
        self.create_seq_objs()

        if self.file_format in [
                'NEXUS', 'GenBankFASTA', 'FASTA', 'MEGA', 'TNT', 'PHYLIP'
        ]:
            try:
                dataset = Dataset(
                    self.seq_objs,
                    format=self.file_format,
                    partitioning=self.partition_by_positions,
                    codon_positions=self.codon_positions[0],
                    aminoacids=self.aminoacids,
                    degenerate=self.degen_translations,
                    outgroup=self.outgroup,
                )
            except (MissingParameterError, ValueError,
                    TranslationErrorMixedGappedSeq) as e:
                self.errors.append(e)
                dataset = None
            except NexusError as e:
                self.errors.append(e.__str__())
                dataset = None

            if not dataset:
                return ""

            self.warnings += dataset.warnings
            dataset_handler = DatasetHandler(dataset.dataset_str,
                                             self.file_format)
            self.dataset_file = dataset_handler.dataset_file

            if self.file_format == 'PHYLIP':
                self.charset_block = dataset.extra_dataset_str

            return dataset.dataset_str
예제 #12
0
 def __init__(self, cleaned_data):
     print(">>>>>>_init", cleaned_data)
     self.errors = []
     self.seq_objs = dict()
     self.codon_positions = cleaned_data['positions']
     self.partition_by_positions = cleaned_data['partition_by_positions']
     self.cleaned_data = cleaned_data
     self.voucher_codes = get_voucher_codes(cleaned_data)
     self.gene_codes = get_gene_codes(cleaned_data)
     self.reading_frames = self.get_reading_frames()
     self.taxon_names = cleaned_data['taxon_names']
     self.dataset_str = self.create_dataset()
예제 #13
0
파일: utils.py 프로젝트: carlosp420/VoSeq
    def create_dataset(self):
        if not self.codon_positions:
            return ""

        if self.degen_translations is not None and self.codon_positions != ["ALL"]:
            msg = "Cannot degenerate codons if you have not selected all codon positions"
            self.errors.append(msg)
            return ""
        elif self.degen_translations is not None and self.partition_by_positions != "by gene":
            msg = "Cannot degenerate codons if they go to different partitions"
            self.errors.append(msg)
            return ""

        self.voucher_codes = get_voucher_codes(self.cleaned_data)
        self.gene_codes = get_gene_codes(self.cleaned_data)
        self.create_seq_objs()

        if self.file_format in ["NEXUS", "GenBankFASTA", "FASTA", "MEGA", "TNT", "PHYLIP"]:
            try:
                dataset = Dataset(
                    self.seq_objs,
                    format=self.file_format,
                    partitioning=self.partition_by_positions,
                    codon_positions=self.codon_positions[0],
                    aminoacids=self.aminoacids,
                    degenerate=self.degen_translations,
                    outgroup=self.outgroup,
                )
            except MissingParameterError as e:
                self.errors.append(e)
                return ""
            except ValueError as e:
                self.errors.append(e)
                return ""
            except TranslationErrorMixedGappedSeq as e:
                self.errors.append(e)
                return ""
            except NexusError as e:
                self.errors.append(e.__str__())
                return ""

            self.warnings += dataset.warnings
            dataset_handler = DatasetHandler(dataset.dataset_str, self.file_format)
            self.dataset_file = dataset_handler.dataset_file

            if self.file_format == "PHYLIP":
                self.charset_block = dataset.extra_dataset_str

            return dataset.dataset_str
예제 #14
0
파일: utils.py 프로젝트: carlosp420/VoSeq
    def create_dataset(self):
        if not self.codon_positions:
            return ''

        error_msg = None
        if self.degen_translations is not None and self.codon_positions != ['ALL']:
            error_msg = 'Cannot degenerate codons if you have not selected all codon positions'
            self.errors.append(error_msg)
        elif self.degen_translations is not None and self.partition_by_positions != 'by gene':
            error_msg = 'Cannot degenerate codons if they go to different partitions'
            self.errors.append(error_msg)

        if error_msg:
            return ''

        self.voucher_codes = get_voucher_codes(self.cleaned_data)
        self.gene_codes = get_gene_codes(self.cleaned_data)
        self.create_seq_objs()

        if self.file_format in ['NEXUS', 'GenBankFASTA', 'FASTA', 'MEGA', 'TNT', 'PHYLIP']:
            try:
                dataset = Dataset(
                    self.seq_objs,
                    format=self.file_format,
                    partitioning=self.partition_by_positions,
                    codon_positions=self.codon_positions[0],
                    aminoacids=self.aminoacids,
                    degenerate=self.degen_translations,
                    outgroup=self.outgroup,
                )
            except (MissingParameterError, ValueError, TranslationErrorMixedGappedSeq) as e:
                self.errors.append(e)
                dataset = None
            except NexusError as e:
                self.errors.append(e.__str__())
                dataset = None

            if not dataset:
                return ""

            self.warnings += dataset.warnings
            dataset_handler = DatasetHandler(dataset.dataset_str, self.file_format)
            self.dataset_file = dataset_handler.dataset_file

            if self.file_format == 'PHYLIP':
                self.charset_block = dataset.extra_dataset_str

            return dataset.dataset_str
예제 #15
0
def results(request):
    version, stats = get_version_stats()

    if request.method == 'POST':
        form = GenBankFastaForm(request.POST)

        if form.is_valid():
            cleaned_data = form.cleaned_data

            voucher_codes = get_voucher_codes(cleaned_data)
            gene_codes = get_gene_codes(cleaned_data)

            res = utils.Results(voucher_codes, gene_codes)
            res.get_datasets()
            items_with_accession = res.items_with_accession
            fasta = res.fasta
            protein = res.protein
            fasta_file = re.search('(fasta_[a-z0-9]+\.fasta)', res.fasta_file).groups()[0]
            protein_file = re.search('(prot_[a-z0-9]+\.fasta)', res.protein_file).groups()[0]

            return render(request, 'genbank_fasta/results.html',
                          {
                              'items_with_accession': items_with_accession,
                              'fasta': fasta,
                              'fasta_file': fasta_file,
                              'protein': protein,
                              'protein_file': protein_file,
                              'version': version,
                              'stats': stats,
                          },
                          )
        else:
            return render(request, 'genbank_fasta/index.html',
                          {
                              'form': form,
                              'version': version,
                              'stats': stats,
                          },
                          )

    return HttpResponseRedirect('/genbank_fasta/')
예제 #16
0
 def create_dataset(self):
     self.voucher_codes = get_voucher_codes(self.cleaned_data)
     self.gene_codes = get_gene_codes(self.cleaned_data)
     self.create_seq_objs()
     return self.from_seq_objs_to_fasta()
예제 #17
0
 def test_get_voucher_codes(self):
     expected = 3
     result = get_voucher_codes(self.cleaned_data)
     self.assertEqual(expected, len(result))
예제 #18
0
 def test_get_voucher_codes_dropped(self):
     self.cleaned_data["voucher_codes"] = "CP100-10\r\n--CP100-11\r\nCP100-12"
     expected = 2
     result = get_voucher_codes(self.cleaned_data)
     self.assertEqual(expected, len(result))
예제 #19
0
 def test_get_voucher_codes(self):
     expected = 3
     result = get_voucher_codes(self.cleaned_data)
     self.assertEqual(expected, len(result))
예제 #20
0
 def test_get_voucher_codes_dropped(self):
     self.cleaned_data[
         'voucher_codes'] = 'CP100-10\r\n--CP100-11\r\nCP100-12'
     expected = 2
     result = get_voucher_codes(self.cleaned_data)
     self.assertEqual(expected, len(result))