diff --git a/funannotate2/name_cleaner.py b/funannotate2/name_cleaner.py index bba40f8..53af275 100644 --- a/funannotate2/name_cleaner.py +++ b/funannotate2/name_cleaner.py @@ -381,15 +381,16 @@ def process_annotation(self, annotation, gene_id=None): del result["name"] # Process product if present - if "product" in result and "name" in result: + if "product" in result: products = result["product"] - names = result["name"] + names = result.get("name", []) + name = names[0] if (isinstance(names, list) and names) else None - if isinstance(products, list) and products and isinstance(names, list) and names: + if isinstance(products, list) and products: # If we have a curated product, it's already set above - if not self.get_curated_product(names[0]): + if not name or not self.get_curated_product(name): # Clean the product - cleaned_product = self.clean_product(products[0], names[0]) + cleaned_product = self.clean_product(products[0], name) result["product"] = [cleaned_product] return result diff --git a/funannotate2/search.py b/funannotate2/search.py index b2f5425..0891771 100755 --- a/funannotate2/search.py +++ b/funannotate2/search.py @@ -735,9 +735,12 @@ def add2dict(adict, gene, key, value): def swissprot_valid_gene(name): + if not name: + return False if ( - number_present(name) - and len(name) > 2 + len(name) > 2 + and not name.startswith("orf") + and not name[0].isdigit() and not morethanXnumbers(name, 3) and "." not in name ): diff --git a/tests/unit/test_search_comprehensive.py b/tests/unit/test_search_comprehensive.py index 1a70136..d564342 100644 --- a/tests/unit/test_search_comprehensive.py +++ b/tests/unit/test_search_comprehensive.py @@ -343,8 +343,11 @@ def test_swissprot2tsv(self, mock_json_dump): assert "seq1" in result assert "db_xref" in result["seq1"] assert result["seq1"]["db_xref"] == ["UniProtKB/Swiss-Prot:P12345"] - assert "note" in result["seq1"] - assert "80.0% identical to TEST_HUMAN Test protein" in result["seq1"]["note"][0] + assert "name" in result["seq1"] + assert result["seq1"]["name"] == ["TEST"] + assert "product" in result["seq1"] + assert result["seq1"]["product"] == ["Test protein"] + assert "note" not in result["seq1"] assert mock_json_dump.call_count == 1 @patch("funannotate2.search.os.path.isdir")