Skip to content

Commit

Permalink
Merge pull request #671 from populationgenomics/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
milo-hyben authored Jan 30, 2024
2 parents c8ce4e2 + 6134af9 commit 1634b3c
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 3 deletions.
9 changes: 9 additions & 0 deletions scripts/parse_existing_cohort.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def __init__(
batch_number,
include_participant_column,
allow_missing_files,
sequencing_type,
):
if include_participant_column:
participant_column = Columns.PARTICIPANT_COLUMN
Expand All @@ -131,6 +132,7 @@ def __init__(
assay_meta_map=Columns.sequence_meta_map(),
batch_number=batch_number,
allow_extra_files_in_search_path=True,
default_sequencing_type=sequencing_type,
)

def _get_dict_reader(self, file_pointer, delimiter: str):
Expand Down Expand Up @@ -210,6 +212,11 @@ def get_existing_external_sequence_ids(self, participant_map: dict[str, dict]):
'--project',
help='The metamist project to import manifest into',
)
@click.option(
'--sequencing-type',
type=click.Choice(['genome', 'exome']),
help='Sequencing type: genome or exome',
)
@click.option('--search-location', 'search_locations', multiple=True)
@click.option(
'--confirm', is_flag=True, help='Confirm with user input before updating server'
Expand All @@ -236,6 +243,7 @@ async def main(
dry_run=False,
include_participant_column=False,
allow_missing_files=False,
sequencing_type: str = 'genome',
):
"""Run script from CLI arguments"""

Expand All @@ -245,6 +253,7 @@ async def main(
batch_number=batch_number,
include_participant_column=include_participant_column,
allow_missing_files=allow_missing_files,
sequencing_type=sequencing_type,
)

for manifest_path in manifests:
Expand Down
119 changes: 119 additions & 0 deletions test/test_parse_existing_cohort.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ async def test_single_row(
search_locations=[],
project=self.project_name,
allow_missing_files=False,
sequencing_type='genome',
)

parser.filename_map = {
Expand Down Expand Up @@ -116,6 +117,7 @@ async def test_no_header(self):
search_locations=[],
project=self.project_name,
allow_missing_files=False,
sequencing_type='genome',
)

parser.filename_map = {
Expand Down Expand Up @@ -217,6 +219,7 @@ async def test_existing_row(
search_locations=[],
project=self.project_name,
allow_missing_files=False,
sequencing_type='genome',
)

parser.filename_map = {
Expand Down Expand Up @@ -248,6 +251,7 @@ async def test_get_read_filenames_no_reads_fail(self):
search_locations=[],
project=self.project_name,
allow_missing_files=False,
sequencing_type='genome',
)
parser.filename_map = {}

Expand All @@ -268,6 +272,7 @@ async def test_get_read_filenames_no_reads_pass(self):
search_locations=[],
project=self.project_name,
allow_missing_files=True,
sequencing_type='genome',
)
parser.filename_map = {}

Expand All @@ -280,3 +285,117 @@ async def test_get_read_filenames_no_reads_pass(self):
self.assertIn('No read files found for ', cm.output[0])

self.assertEqual(len(read_filenames), 0)

@run_as_sync
async def test_genome_sequencing_type(self):
"""Test that the sequencing type is set correctly when the --sequencing-type flag is set to 'genome''"""

# Test with 'genome'
parser = ExistingCohortParser(
include_participant_column=False,
batch_number='M01',
search_locations=[],
project=self.project_name,
allow_missing_files=True,
sequencing_type='genome',
)
self.assertEqual(parser.default_sequencing_type, 'genome')

@run_as_sync
async def test_exome_sequencing_type(self):
"""Test that the sequencing type is set correctly when the --sequencing-type flag is set to 'exome'"""

# Test with 'exome'
parser = ExistingCohortParser(
include_participant_column=False,
batch_number='M01',
search_locations=[],
project=self.project_name,
allow_missing_files=True,
sequencing_type='exome',
)
self.assertEqual(parser.default_sequencing_type, 'exome')

@run_as_sync
@patch('metamist.parser.generic_parser.query_async')
@patch('metamist.parser.cloudhelper.CloudHelper.datetime_added')
@patch('metamist.parser.cloudhelper.CloudHelper.file_exists')
@patch('metamist.parser.cloudhelper.CloudHelper.file_size')
async def test_sequencing_type_in_assay_meta(
self,
mock_filesize,
mock_fileexists,
mock_datetime_added,
mock_graphql_query,
):
"""Test that the sequencing type is set correctly when the --sequencing-type flag is set to 'genome' or 'exome'"""

mock_graphql_query.side_effect = self.run_graphql_query_async

mock_filesize.return_value = 111
mock_fileexists.return_value = False
mock_datetime_added.return_value = datetime.fromisoformat('2022-02-02T22:22:22')

rows = [
'HEADER',
'""',
'Application\tExternal ID\tSample Concentration (ng/ul)\tVolume (uL)\tSex\tSample/Name\tReference Genome\tParticipant ID\t',
'App\tEXTID1234\t100\t100\tFemale\t220405_FLUIDX1234\thg38\tPID123',
]

for sequencing_type in ['genome', 'exome']:
with self.subTest(sequencing_type=sequencing_type):
parser = ExistingCohortParser(
include_participant_column=False,
batch_number='M01',
search_locations=[],
project=self.project_name,
allow_missing_files=False,
sequencing_type=sequencing_type,
)
parser.filename_map = {
'HG3F_2_220405_FLUIDX1234_Homo-sapiens_AAC-TAT_R_220208_VB_BLAH_M002_R1.fastq': '/path/to/HG3F_2_220405_FLUIDX1234_Homo-sapiens_AAC-TAT_R_220208_VB_BLAH_M002_R1.fastq',
'HG3F_2_220405_FLUIDX1234_Homo-sapiens_AAC-TAT_R_220208_VB_BLAH_M002_R2.fastq': '/path/to/HG3F_2_220405_FLUIDX1234_Homo-sapiens_AAC-TAT_R_220208_VB_BLAH_M002_R2.fastq',
}

file_contents = '\n'.join(rows)
participants: list[ParsedParticipant]
_, participants = await parser.parse_manifest(
StringIO(file_contents), delimiter='\t', dry_run=True
)

sample_to_add = participants[0].samples[0]
expected_sequence_dict = {
'reference_genome': 'hg38',
'platform': 'App',
'concentration': '100',
'volume': '100',
'fluid_x_tube_id': '220405_FLUIDX1234',
'reads_type': 'fastq',
'reads': [
{
'location': '/path/to/HG3F_2_220405_FLUIDX1234_Homo-sapiens_AAC-TAT_R_220208_VB_BLAH_M002_R1.fastq',
'basename': 'HG3F_2_220405_FLUIDX1234_Homo-sapiens_AAC-TAT_R_220208_VB_BLAH_M002_R1.fastq',
'class': 'File',
'checksum': None,
'size': 111,
'datetime_added': '2022-02-02T22:22:22',
},
{
'location': '/path/to/HG3F_2_220405_FLUIDX1234_Homo-sapiens_AAC-TAT_R_220208_VB_BLAH_M002_R2.fastq',
'basename': 'HG3F_2_220405_FLUIDX1234_Homo-sapiens_AAC-TAT_R_220208_VB_BLAH_M002_R2.fastq',
'class': 'File',
'checksum': None,
'size': 111,
'datetime_added': '2022-02-02T22:22:22',
},
],
'sequencing_platform': 'illumina',
'sequencing_technology': 'short-read',
'sequencing_type': f'{sequencing_type}',
'batch': 'M01',
}
assay = sample_to_add.sequencing_groups[0].assays[0]
self.maxDiff = None
self.assertDictEqual(expected_sequence_dict, assay.meta)
return
2 changes: 1 addition & 1 deletion web/src/pages/billing/BillingInvoiceMonthCost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const BillingCurrentCost = () => {
const year = invoiceMonth.substring(0, 4)
const month = invoiceMonth.substring(4, 6)
let nextYear = year
let nextMonth = (parseInt(month, 10) + 1).toString()
let nextMonth = (parseInt(month, 10) + 1).toString().padStart(2, '0')
if (month === '12') {
nextYear = (parseInt(year, 10) + 1).toString()
nextMonth = '01'
Expand Down
5 changes: 3 additions & 2 deletions web/src/shared/components/Graphs/DonutChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@ export const DonutChart: React.FC<IDonutChartProps> = ({ data, maxSlices, colors
const margin = 15
const radius = Math.min(width, height) / 2 - margin

// keep order of the slices
// keep order of the slices, declare custom sort function to keep order of slices as passed in
// by default pie function starts from index 1 and sorts by value
const pieFnc = pie()
.value((d) => d.value)
.sort((a) => {
if (typeof a === 'object' && a.type === 'inc') {
return 1
}
return -1
return 0 // works both on Safari and Firefox, any other value will break one of them
})
const data_ready = pieFnc(data)
const innerRadius = radius / 1.75 // inner radius of pie, in pixels (non-zero for donut)
Expand Down

0 comments on commit 1634b3c

Please sign in to comment.