@@ -29,6 +29,21 @@ def _load_json_file(self, filename: str) -> List[Dict[str, Any]]:
2929 logger .error (f"Error parsing JSON from { file_path } : { e } " )
3030 return []
3131
32+ def _build_assembly_link (self , accession : str ) -> Dict [str , str ]:
33+ """Build a single assembly link dict."""
34+ url_accession = accession .replace ("." , "_" )
35+ return {
36+ "assemblyAccession" : accession ,
37+ "relativePath" : f"/data/assemblies/{ url_accession } " ,
38+ }
39+
40+ def _build_organism_link (self , taxonomy_id : int ) -> Dict [str , Any ]:
41+ """Build a single organism link dict."""
42+ return {
43+ "ncbiTaxonomyId" : taxonomy_id ,
44+ "relativePath" : f"/data/organisms/{ taxonomy_id } " ,
45+ }
46+
3247 def get_assemblies_links (self ) -> Dict [str , Any ]:
3348 """Get all assembly links in v1 format."""
3449 assemblies = self ._load_json_file ("assemblies.json" )
@@ -38,14 +53,7 @@ def get_assemblies_links(self) -> Dict[str, Any]:
3853 accession = assembly .get ("accession" )
3954 if not accession :
4055 continue
41-
42- url_accession = accession .replace ("." , "_" )
43- links .append (
44- {
45- "assemblyAccession" : accession ,
46- "relativePath" : f"/data/assemblies/{ url_accession } " ,
47- }
48- )
56+ links .append (self ._build_assembly_link (accession ))
4957
5058 logger .info (f"Generated { len (links )} assembly links" )
5159 return {
@@ -57,13 +65,8 @@ def get_assembly_link(self, accession: str) -> Optional[Dict[str, str]]:
5765 assemblies = self ._load_json_file ("assemblies.json" )
5866
5967 for assembly in assemblies :
60- assembly_accession = assembly .get ("accession" )
61- if assembly_accession == accession :
62- url_accession = accession .replace ("." , "_" )
63- return {
64- "assemblyAccession" : accession ,
65- "relativePath" : f"/data/assemblies/{ url_accession } " ,
66- }
68+ if assembly .get ("accession" ) == accession :
69+ return self ._build_assembly_link (accession )
6770
6871 return None
6972
@@ -76,13 +79,7 @@ def get_organisms_links(self) -> Dict[str, Any]:
7679 taxonomy_id = org .get ("ncbiTaxonomyId" )
7780 if not taxonomy_id :
7881 continue
79-
80- links .append (
81- {
82- "ncbiTaxonomyId" : int (taxonomy_id ),
83- "relativePath" : f"/data/organisms/{ taxonomy_id } " ,
84- }
85- )
82+ links .append (self ._build_organism_link (int (taxonomy_id )))
8683
8784 logger .info (f"Generated { len (links )} organism links" )
8885 return {
@@ -95,11 +92,7 @@ def get_organism_link(self, taxon_id: int) -> Optional[Dict[str, Any]]:
9592
9693 for org in organisms :
9794 taxonomy_id = org .get ("ncbiTaxonomyId" )
98- # Handle both string and int taxonomy IDs from JSON
9995 if taxonomy_id is not None and int (taxonomy_id ) == taxon_id :
100- return {
101- "ncbiTaxonomyId" : int (taxonomy_id ),
102- "relativePath" : f"/data/organisms/{ taxonomy_id } " ,
103- }
96+ return self ._build_organism_link (taxon_id )
10497
10598 return None
0 commit comments