|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from uniprot.scripts.extract_subset import parse_de_sections, parse_organism |
| 4 | +from uniprot.scripts.export_model_metadata import ( |
| 5 | + ManifestRow, |
| 6 | + ModelMetadataRow, |
| 7 | + build_record, |
| 8 | +) |
| 9 | + |
| 10 | + |
| 11 | +def test_parse_de_sections_preserves_square_brackets_in_names() -> None: |
| 12 | + lines = [ |
| 13 | + "DE RecName: Full=Acyl-[acyl-carrier-protein]--UDP-N-acetylglucosamine O-acyltransferase;", |
| 14 | + ] |
| 15 | + |
| 16 | + full_names, short_names = parse_de_sections(lines) |
| 17 | + |
| 18 | + assert full_names == [ |
| 19 | + "Acyl-[acyl-carrier-protein]--UDP-N-acetylglucosamine O-acyltransferase" |
| 20 | + ] |
| 21 | + assert short_names == [] |
| 22 | + |
| 23 | + |
| 24 | +def test_parse_de_sections_preserves_semicolons_inside_names() -> None: |
| 25 | + lines = [ |
| 26 | + "DE RecName: Full=nitrite reductase (cytochrome; ammonia-forming) {ECO:0000256|ARBA:ARBA00011887};", |
| 27 | + ] |
| 28 | + |
| 29 | + full_names, short_names = parse_de_sections(lines) |
| 30 | + |
| 31 | + assert full_names == ["nitrite reductase (cytochrome; ammonia-forming)"] |
| 32 | + assert short_names == [] |
| 33 | + |
| 34 | + |
| 35 | +def test_parse_de_sections_uses_submitted_names_as_full_name_fallback() -> None: |
| 36 | + lines = [ |
| 37 | + "DE SubName: Full=Methyl-coenzyme M reductase alpha {ECO:0000313|EMBL:ABW73421.1};", |
| 38 | + "DE Flags: Fragment;", |
| 39 | + ] |
| 40 | + |
| 41 | + full_names, short_names = parse_de_sections(lines) |
| 42 | + |
| 43 | + assert full_names == ["Methyl-coenzyme M reductase alpha"] |
| 44 | + assert short_names == [] |
| 45 | + |
| 46 | + |
| 47 | +def test_parse_de_sections_keeps_recommended_names_before_submitted_names() -> None: |
| 48 | + lines = [ |
| 49 | + "DE RecName: Full=Curated recommended name;", |
| 50 | + "DE SubName: Full=Submitted fallback name {ECO:0000313|EMBL:ABC123.1};", |
| 51 | + ] |
| 52 | + |
| 53 | + full_names, short_names = parse_de_sections(lines) |
| 54 | + |
| 55 | + assert full_names == ["Curated recommended name", "Submitted fallback name"] |
| 56 | + assert short_names == [] |
| 57 | + |
| 58 | + |
| 59 | +def test_parse_organism_preserves_parenthetical_text_in_scientific_name() -> None: |
| 60 | + organism, common_names, synonyms = parse_organism("Escherichia coli (strain K12).") |
| 61 | + |
| 62 | + assert organism == "Escherichia coli (strain K12)" |
| 63 | + assert common_names == ["strain K12"] |
| 64 | + assert synonyms == [] |
| 65 | + |
| 66 | + |
| 67 | +def test_build_record_adds_model_level_complex_fields() -> None: |
| 68 | + config = { |
| 69 | + "latestVersion": 1, |
| 70 | + "allVersions": [1], |
| 71 | + "providerId": "AF-TEST", |
| 72 | + "entityType": "protein", |
| 73 | + } |
| 74 | + manifest_rows = [ |
| 75 | + ManifestRow( |
| 76 | + model_entity_id="AF-0000000000000001", |
| 77 | + entity_id="1", |
| 78 | + chain_id="A", |
| 79 | + uniprot_ac="P11111", |
| 80 | + sequence_start=None, |
| 81 | + sequence_end=None, |
| 82 | + is_fragment=False, |
| 83 | + is_isoform=False, |
| 84 | + entity_type="protein", |
| 85 | + average_plddt=90.0, |
| 86 | + fraction_plddt_very_low=0.0, |
| 87 | + fraction_plddt_low=0.0, |
| 88 | + fraction_plddt_confident=0.2, |
| 89 | + fraction_plddt_very_high=0.8, |
| 90 | + ), |
| 91 | + ManifestRow( |
| 92 | + model_entity_id="AF-0000000000000001", |
| 93 | + entity_id="2", |
| 94 | + chain_id="B", |
| 95 | + uniprot_ac="Q22222", |
| 96 | + sequence_start=None, |
| 97 | + sequence_end=None, |
| 98 | + is_fragment=False, |
| 99 | + is_isoform=False, |
| 100 | + entity_type="protein", |
| 101 | + average_plddt=88.0, |
| 102 | + fraction_plddt_very_low=0.0, |
| 103 | + fraction_plddt_low=0.1, |
| 104 | + fraction_plddt_confident=0.2, |
| 105 | + fraction_plddt_very_high=0.7, |
| 106 | + ), |
| 107 | + ] |
| 108 | + entry_map = { |
| 109 | + "P11111": { |
| 110 | + "primary_ac": "P11111", |
| 111 | + "entry_name": "PROT1_TEST", |
| 112 | + "protein_full_names": ["Protein one"], |
| 113 | + "protein_short_names": None, |
| 114 | + "gene_names": "GENE1", |
| 115 | + "gene_synonyms": None, |
| 116 | + "gene_ordered_locus_names": None, |
| 117 | + "gene_orf_names": None, |
| 118 | + "organism": "Organismus exampleus", |
| 119 | + "organism_common_names": None, |
| 120 | + "organism_synonyms": None, |
| 121 | + "taxid": 1111, |
| 122 | + "sequence_version_date": "2024-01-01", |
| 123 | + "sequence": "ACDE", |
| 124 | + "is_uniprot_reference_proteome": True, |
| 125 | + "reviewed": True, |
| 126 | + }, |
| 127 | + "Q22222": { |
| 128 | + "primary_ac": "Q22222", |
| 129 | + "entry_name": "PROT2_TEST", |
| 130 | + "protein_full_names": ["Protein two"], |
| 131 | + "protein_short_names": None, |
| 132 | + "gene_names": "GENE2", |
| 133 | + "gene_synonyms": None, |
| 134 | + "gene_ordered_locus_names": None, |
| 135 | + "gene_orf_names": None, |
| 136 | + "organism": "Organismus exampleus", |
| 137 | + "organism_common_names": None, |
| 138 | + "organism_synonyms": None, |
| 139 | + "taxid": 1111, |
| 140 | + "sequence_version_date": "2024-01-01", |
| 141 | + "sequence": "FGHI", |
| 142 | + "is_uniprot_reference_proteome": True, |
| 143 | + "reviewed": True, |
| 144 | + }, |
| 145 | + } |
| 146 | + model_metadata = { |
| 147 | + "AF-0000000000000001": ModelMetadataRow( |
| 148 | + iptm=0.91, |
| 149 | + average_plddt=89.3, |
| 150 | + complex_name=None, |
| 151 | + is_am_data=False, |
| 152 | + ) |
| 153 | + } |
| 154 | + |
| 155 | + record = build_record( |
| 156 | + "AF-0000000000000001", |
| 157 | + config, |
| 158 | + manifest_rows, |
| 159 | + entry_map, |
| 160 | + model_metadata, |
| 161 | + ) |
| 162 | + |
| 163 | + assert record["assemblyType"] == "Hetero" |
| 164 | + assert record["oligomericState"] == "dimer" |
| 165 | + assert record["oligomericStateDescription"] == "Heterodimer" |
| 166 | + assert record["complexComposition"] == ["P11111_1", "Q22222_1"] |
0 commit comments