Skip to content

Commit

Permalink
add metagenome json file && cover the missing line
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiangs18 committed Sep 5, 2024
1 parent 788c7ee commit 65467ea
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 14 deletions.
1 change: 1 addition & 0 deletions lib/GenomeFileUtil/core/GenomeInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def _update_metagenome(self, genome):
"""Checks for missing required fields and fixes breaking changes"""
if 'molecule_type' not in genome:
genome['molecule_type'] = 'Unknown'
return genome

def _update_genome(self, genome):
"""Checks for missing required fields and fixes breaking changes"""
Expand Down
53 changes: 53 additions & 0 deletions test/data/metagenomes/toy/metagenome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"contig_ids": [
"Ga0065724_100001"
],
"contig_lengths": [
538871
],
"dna_size": 538871,
"domain": "Eukaryota",
"environment": null,
"external_source_origination_date": null,
"feature_counts": {
"CDS": 20,
"gene": 20,
"non_coding_features": 0,
"protein_encoding_gene": 20
},
"features_handle_ref": "KBH_736245",
"gc_content": 0.64469,
"genetic_code": 1,
"genome_type": "Metagenome",
"gff_handle_ref": "KBH_736244",
"id": "MyMetagenome",
"md5": "e2ccbd5a9bed0148015bd6b784e3c1c3",
"molecule_type": "SingleLetterAlphabet",
"notes": null,
"num_contigs": 1,
"num_features": 40,
"ontologies_present": {},
"ontology_events": [
{
"id": "GO",
"method": "GenomeFileUtils Genbank uploader from annotations",
"method_version": "0.11.7",
"ontology_ref": "KBaseOntology/gene_ontology",
"timestamp": "2024_09_05_06_45_31"
}
],
"original_source_file_name": null,
"protein_handle_ref": "KBH_736243",
"publications": [],
"scientific_name": "Arabidopsis thaliana",
"source": "GFF",
"source_id": "unknown",
"suspect": 1,
"taxon_assignments": {
"ncbi": "3702"
},
"taxonomy": "cellular organisms; Eukaryota; Viridiplantae; Streptophyta; Streptophytina; Embryophyta; Tracheophyta; Euphyllophyta; Spermatophyta; Magnoliopsida; Mesangiospermae; eudicotyledons; Gunneridae; Pentapetalae; rosids; malvids; Brassicales; Brassicaceae; Camelineae; Arabidopsis",
"warnings": [
"SUSPECT: This genome has 20 genes that needed to be spoofed for existing parentless CDS."
]
}
50 changes: 36 additions & 14 deletions test/problematic_tests/save_genome_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
from GenomeFileUtil.core.GenomeInterface import GenomeInterface
from installed_clients.WorkspaceClient import Workspace as workspaceService

KBASE_GENOME = "KBaseGenomes.Genome"
KBASE_METAGENOME = "KBaseMetagenomes.AnnotatedMetagenomeAssembly"


class SaveGenomeTest(unittest.TestCase):

Expand Down Expand Up @@ -115,17 +118,36 @@ def delete_shock_node(cls, node_id):

@classmethod
def prepare_data(cls):
assembly_file_path = os.path.join(cls.scratch,
'e_coli_assembly.fasta')

assembly_file_path = os.path.join(cls.scratch,'e_coli_assembly.fasta')
meta_file_path = os.path.join(cls.scratch,'metagenome.fa')

shutil.copy('data/e_coli/e_coli_assembly.fasta', assembly_file_path)
shutil.copy('data/metagenomes/toy/metagenome.fa', meta_file_path)

au = AssemblyUtil(os.environ['SDK_CALLBACK_URL'])
assembly_ref = au.save_assembly_from_fasta({
'workspace_name': cls.wsName,
'assembly_name': 'e_coli.assembly',
'file': {'path': assembly_file_path}
})

assembly_refs = au.save_assemblies_from_fastas(
{
'workspace_id': cls.wsID,
'inputs': [
{
'assembly_name': 'e_coli.assembly',
'file': assembly_file_path
},
{
'assembly_name': 'metagenome.assembly',
'file': meta_file_path
}
]
}
)["results"]

cls.test_genome_data = json.load(open('data/e_coli/e_coli.json'))
cls.test_genome_data['assembly_ref'] = assembly_ref
cls.test_genome_data['assembly_ref'] = assembly_refs[0]["upa"]

cls.test_metagenome_data = json.load(open('data/metagenomes/toy/metagenome.json'))
cls.test_metagenome_data['assembly_ref'] = assembly_refs[1]["upa"]

def getWsClient(self):
return self.__class__.wsClient
Expand Down Expand Up @@ -154,12 +176,12 @@ def fail_save_genome(self, params, error, exception=ValueError, contains=False,
else:
self.assertEqual(error, str(context.exception))

def check_save_one_genome_output(self, ret, genome_name):
def check_save_one_genome_output(self, ret, genome_name, data_type=KBASE_GENOME):
self.assertTrue('info' in ret)

genome_info = ret['info']
self.assertEqual(genome_info[1], genome_name)
self.assertEqual(genome_info[2].split('-')[0], 'KBaseGenomes.Genome')
self.assertEqual(genome_info[2].split('-')[0], data_type)
self.assertEqual(genome_info[5], self.user_id)

def test_bad_one_genome_params(self):
Expand Down Expand Up @@ -211,18 +233,18 @@ def test_genomes(self):

def test_genomes_with_upgrade(self):
self.start_test()
genome_name = 'test_genome'
genome_name = 'MyMetagenome'
inputs = [
{
'name': genome_name,
'data': self.test_genome_data,
'workspace_datatype': "KBaseMetagenomes.AnnotatedMetagenomeAssembly",
'data': self.test_metagenome_data,
'workspace_datatype': KBASE_METAGENOME,
'upgrade': True,
}
]
params = {'workspace_id': self.wsID, 'inputs': inputs}
ret = self.genome_interface.save_genome_mass(params)[0]
self.check_save_one_genome_output(ret, genome_name)
self.check_save_one_genome_output(ret, genome_name, data_type=KBASE_METAGENOME)

def test_genomes_with_hidden(self):
self.start_test()
Expand Down

0 comments on commit 65467ea

Please sign in to comment.