Skip to content

Commit

Permalink
fixed gender output in statistics file
Browse files Browse the repository at this point in the history
  • Loading branch information
Lennart authored and Lennart committed Jan 15, 2021
1 parent 8d9d1cd commit ea07cf0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
45 changes: 22 additions & 23 deletions wisecondorX/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,37 +152,36 @@ def tool_test(args):
sample = scale_sample(sample, int(
sample_file['binsize'].item()), int(ref_file['binsize']))

gender = predict_gender(sample, ref_file['trained_cutoff'])
if not ref_file['is_nipt']:
actual_gender = predict_gender(sample, ref_file['trained_cutoff'])
if args.gender:
actual_gender = args.gender
sample = gender_correct(sample, actual_gender)
gender = args.gender
sample = gender_correct(sample, gender)
ref_gender = gender
else:
actual_gender = 'F'

if args.gender:
actual_gender = args.gender

ref_gender = actual_gender
if args.gender:
gender = args.gender
ref_gender = 'F'

logging.info('Normalizing autosomes ...')

results_r, results_z, results_w, ref_sizes, m_lr, m_z = normalize(
args, sample, ref_file, 'A')

if not ref_file['has_male'] and actual_gender == 'M':
logging.warning('This sample is male, whilst the reference is created with fewer than 5 males. '
'The female gonosomal reference will be used for X predictions. Note that these might '
'not be accurate. If the latter is desired, create a new reference and include more '
'male samples.')
ref_gender = 'F'

elif not ref_file['has_female'] and actual_gender == 'F':
logging.warning('This sample is female, whilst the reference is created with fewer than 5 females. '
'The male gonosomal reference will be used for XY predictions. Note that these might '
'not be accurate. If the latter is desired, create a new reference and include more '
'female samples.')
ref_gender = 'M'
if not ref_file['is_nipt']:
if not ref_file['has_male'] and gender == 'M':
logging.warning('This sample is male, whilst the reference is created with fewer than 5 males. '
'The female gonosomal reference will be used for X predictions. Note that these might '
'not be accurate. If the latter is desired, create a new reference and include more '
'male samples.')
ref_gender = 'F'

elif not ref_file['has_female'] and gender == 'F':
logging.warning('This sample is female, whilst the reference is created with fewer than 5 females. '
'The male gonosomal reference will be used for XY predictions. Note that these might '
'not be accurate. If the latter is desired, create a new reference and include more '
'female samples.')
ref_gender = 'M'

logging.info('Normalizing gonosomes ...')

Expand All @@ -198,7 +197,7 @@ def tool_test(args):
'binsize': int(ref_file['binsize']),
'n_reads': n_reads,
'ref_gender': ref_gender,
'actual_gender': actual_gender,
'gender': gender,
'mask': ref_file['mask.{}'.format(ref_gender)],
'bins_per_chr': ref_file['bins_per_chr.{}'.format(ref_gender)],
'masked_bins_per_chr': ref_file['masked_bins_per_chr.{}'.format(ref_gender)],
Expand Down
6 changes: 3 additions & 3 deletions wisecondorX/predict_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def _generate_segments_and_aberrations_bed(rem_input, results):
int(segment[2] * rem_input['binsize']),
segment[4], segment[3]]
segments_file.write('{}\n'.format('\t'.join([str(x) for x in row])))
ploidy = 2

if (chr_name == 'X' or chr_name == 'Y') and rem_input['actual_gender'] == 'M':
ploidy = 2
if (chr_name == 'X' or chr_name == 'Y') and rem_input['ref_gender'] == 'M':
ploidy = 1
if rem_input['args'].beta is not None:
if float(segment[4]) > __get_aberration_cutoff(rem_input['args'].beta, ploidy)[1]:
Expand Down Expand Up @@ -146,7 +146,7 @@ def _generate_chr_statistics_file(rem_input, results):
stats_file.write('\t'.join([str(x) for x in row]) + '\n')

stats_file.write('Gender based on --yfrac (or manually overridden by --gender): {}\n'
.format(str(rem_input['actual_gender'])))
.format(str(rem_input['gender'])))

stats_file.write('Number of reads: {}\n'
.format(str(rem_input['n_reads'])))
Expand Down

0 comments on commit ea07cf0

Please sign in to comment.