def test_annotation(self): annotation = Annotation("COG0001") self.session.add(annotation) self.session.commit() assert Annotation.query.first() is annotation #Test the many to many relationship reference_assembly = ReferenceAssembly("version 1") gene = Gene("gene1", reference_assembly) gene2 = Gene("gene2", reference_assembly) gene3 = Gene("gene3", reference_assembly) annotation2 = Annotation("COG0002", description="This cog is really really good") # Test having multiple genes to one annotation annotation_source = AnnotationSource("Cog", "v1.0", "rpsblast", "e_value=0.000001") gene_annotation1 = GeneAnnotation(annotation_source = annotation_source, e_value=0.0000001) gene_annotation2 = GeneAnnotation(annotation_source = annotation_source) gene_annotation1.gene = gene gene_annotation2.gene = gene2 gene_annotation1.annotation = annotation gene_annotation2.annotation = annotation self.session.add(annotation) self.session.add(gene3) self.session.add(gene_annotation1) self.session.add(gene_annotation2) self.session.commit() annotation_01 = Annotation.query.filter_by(type_identifier="COG0001").first() assert len(annotation_01.genes) == 2 assert gene in annotation_01.genes assert gene2 in annotation_01.genes assert annotation in Gene.query.filter_by(name="gene1").first().annotations assert annotation in Gene.query.filter_by(name="gene2").first().annotations assert len(Gene.query.filter_by(name="gene3").first().annotations) == 0 # Genes for annotation method genes_for_annotation = Annotation.genes_per_annotation([annotation.id]) assert len(genes_for_annotation) == 2 assert (gene, annotation) in genes_for_annotation assert (gene2, annotation) in genes_for_annotation # Add the second annotation self.session.add(annotation2) self.session.commit() q = Annotation.query.filter(Annotation.description.contains("good")) annotation_02 = q.all() assert len(annotation_02) == 1 assert annotation_02[0] == annotation2 # Test having multiple annotations to one gene gene_annotation3 = GeneAnnotation(annotation2, gene, annotation_source, e_value = 1e-14) self.session.add(gene_annotation3) self.session.commit() assert len(Gene.query.filter_by(name="gene1").first().annotations) == 2 assert annotation in Gene.query.filter_by(name="gene1").first().annotations assert annotation2 in Gene.query.filter_by(name="gene1").first().annotations assert gene_annotation1.e_value > gene_annotation3.e_value assert gene.e_value_for(annotation) > gene.e_value_for(annotation2) # gene -> annotation # gene2 -> annotation # gene -> annotation2 # Genes for annotation method genes_for_annotation = Annotation.genes_per_annotation([annotation.id]) assert len(genes_for_annotation) == 2 assert (gene, annotation) in genes_for_annotation assert (gene2, annotation) in genes_for_annotation genes_for_annotation = Annotation.genes_per_annotation([annotation2.id]) assert len(genes_for_annotation) == 1 assert (gene, annotation2) in genes_for_annotation genes_for_annotation = Annotation.genes_per_annotation([annotation.id, annotation2.id]) assert len(genes_for_annotation) == 3 assert (gene, annotation) in genes_for_annotation assert (gene, annotation2) in genes_for_annotation assert (gene2, annotation) in genes_for_annotation annotation3 = Annotation("COG0003", description=("This cog is really really good. I assure you, " "really quite good. Among its capabilities I have to mention that its utterly suitable for " "testing the description string, including the short description.")) assert len(annotation3.description) > 103 assert annotation3.short_description[-3:] == "..." assert len(annotation3.short_description) == 103 assert annotation3.description[:100] == annotation3.short_description[:100]