From 7f87c3267be036523a9970a95becbe971d2bd872 Mon Sep 17 00:00:00 2001 From: Owen Bodley Date: Sat, 26 Jul 2025 20:37:43 +0200 Subject: [PATCH] feat: add 2 new examples which show 2 ways to fetch the number of correct sequences in documents --- examples/fetch_status_chart.py | 20 ++++++++ examples/run_extract_job.py | 2 +- .../run_report_job_to_summarize_documents.py | 46 +++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 examples/fetch_status_chart.py create mode 100644 examples/run_report_job_to_summarize_documents.py diff --git a/examples/fetch_status_chart.py b/examples/fetch_status_chart.py new file mode 100644 index 0000000..047fed0 --- /dev/null +++ b/examples/fetch_status_chart.py @@ -0,0 +1,20 @@ +from pipebio.pipebio_client import PipebioClient + +client = PipebioClient(url='https://app.pipebio.com') + +# Set document id to get the status chart for. +# NOTE: This document must be annotated or you will not get a good result back. +document_id = 'ent_TozXnaXkMVhEjFm9' + +result = client.session.get(f'sequences/charts/StatusPieChart?documentId={document_id}') + +data = result.json() + +# Below are some examples of how to interact with the data returned from the StatusPieChart endpoint. +correct_count = data['status']['CORRECT'] +assert correct_count == 131 + +incorrect_count = data['status']['INCORRECT'] +assert incorrect_count == 6 + +assert data['total'] == correct_count + incorrect_count \ No newline at end of file diff --git a/examples/run_extract_job.py b/examples/run_extract_job.py index 78e448d..918185e 100644 --- a/examples/run_extract_job.py +++ b/examples/run_extract_job.py @@ -20,7 +20,7 @@ # Run an extract job and put the results in the new_folder we just created. job_id = client.jobs.create( shareable_id=shareable_id, - name='Extract job from API', + name='Extract job from SDK', job_type=JobType.ExtractJob, # Either hard code input entity ids or get these from the output_entity_ids from a previous job. input_entity_ids=[document_id], diff --git a/examples/run_report_job_to_summarize_documents.py b/examples/run_report_job_to_summarize_documents.py new file mode 100644 index 0000000..1c11ad0 --- /dev/null +++ b/examples/run_report_job_to_summarize_documents.py @@ -0,0 +1,46 @@ +import os +from pipebio.pipebio_client import PipebioClient +from pipebio.models.job_type import JobType + +client = PipebioClient(url='https://app.pipebio.com') +shareable_id = os.environ['TARGET_SHAREABLE_ID'] +folder_id = os.environ['TARGET_FOLDER_ID'] + +document_id = 'ent_PbyAluxijmJfNXph' + +# Summarise 1 or more documents using a summary job. +job_id = client.jobs.create( + shareable_id=shareable_id, + name='Summary job from SDK', + job_type=JobType.SummaryJob, + # Include 1 or more document ids here to summarize in one go. + input_entity_ids=[document_id], + params={ + "targetFolderId": folder_id + }, + poll_jobs=True +) + +# Fetch the job. +job = client.jobs.get(job_id) + +# Get the id of the report that was created. +output_id = next(e['id'] for e in job['outputEntities']) + +# Fetch the summary report we just created. +response = client.session.get(f'entities/{output_id}/attachments/Report') +result = response.json() +annotation_summary = next(item for item in result['data']['items'] if item['title'].startswith('Analysis results for')) + +# Print the results. +# e.g: +# Id: SRR11974622 +# Total reads: 1059733 +# Correct annotated: 320376 +# Correct annotated percent: 30.2317659259455 +for row in annotation_summary['data']['rows']: + for col in annotation_summary['data']['columns']: + header = col['headerName'] + field = col['field'] + value = row[field] + print(f'{header}: {value}')