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()
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()
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()
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)
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)
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)
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 = []
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
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()
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
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
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/')
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()
def test_get_voucher_codes(self): expected = 3 result = get_voucher_codes(self.cleaned_data) self.assertEqual(expected, len(result))
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))
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))