From 0c8e5d97c5725431d003908aea5f460df9303741 Mon Sep 17 00:00:00 2001 From: murphycj2 Date: Mon, 19 Apr 2021 12:52:49 -0400 Subject: [PATCH 1/2] bug when there are no contributing sites --- biometrics/minor_contamination.py | 65 +++++++++++++++++-------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/biometrics/minor_contamination.py b/biometrics/minor_contamination.py index 125e3da..bd02f5c 100644 --- a/biometrics/minor_contamination.py +++ b/biometrics/minor_contamination.py @@ -70,49 +70,53 @@ def plot(self, samples, outdir): # plot VAF of contributing sites plot_data = [] + samples_with_contributing_sites = [] for i, sample_name in enumerate(data['sample_name']): contributing_sites = samples[sample_name].metrics['minor_contamination']['contributing_sites'] + if len(contributing_sites) > 0: + samples_with_contributing_sites.append(sample_name) + for site_id, site_data in contributing_sites.items(): site_data['sample_name'] = sample_name site_data['MAF'] = site_data['minor_allele_freq'] site_data['index'] = i - del site_data['minor_allele_freq'] plot_data.append(site_data) plot_data = pd.DataFrame(plot_data) - plot_data = plot_data[[ - 'sample_name', 'chrom', 'pos', 'ref', 'alt', 'MAF', 'reads_all', 'A', 'C', 'T', 'G', - 'N', 'index']] - plot_data['MAF'] = plot_data['MAF'].map(lambda x: round(x, 5)) - fig = go.Figure() - fig.add_trace( - go.Scatter( - x=plot_data['index'], - y=plot_data['MAF'], - mode='markers', - showlegend=False, - customdata=plot_data.to_numpy(), - hovertemplate='Sample: %{customdata[0]}' + - '
Chrom: %{customdata[1]}' + - '
Pos: %{customdata[2]}' + - '
Ref allele: %{customdata[3]}' + - '
Alt allele: %{customdata[4]}' + - '
MAF: %{customdata[5]}' + - '
Total reads: %{customdata[6]}' + - '
Count A: %{customdata[7]}' + - '
Count C: %{customdata[8]}' + - '
Count T: %{customdata[9]}' + - '
Count G: %{customdata[10]}' + - '
Count N: %{customdata[11]}' + - '')) - - data = data[data['sample_name'].isin(plot_data['sample_name'])] + if len(plot_data) > 0: + plot_data = plot_data[[ + 'sample_name', 'chrom', 'pos', 'ref', 'alt', 'MAF', 'reads_all', 'A', 'C', 'T', 'G', + 'N', 'index']] + plot_data['MAF'] = plot_data['MAF'].map(lambda x: round(x, 5)) + + fig.add_trace( + go.Scatter( + x=plot_data['index'], + y=plot_data['MAF'], + mode='markers', + showlegend=False, + customdata=plot_data.to_numpy(), + hovertemplate='Sample: %{customdata[0]}' + + '
Chrom: %{customdata[1]}' + + '
Pos: %{customdata[2]}' + + '
Ref allele: %{customdata[3]}' + + '
Alt allele: %{customdata[4]}' + + '
MAF: %{customdata[5]}' + + '
Total reads: %{customdata[6]}' + + '
Count A: %{customdata[7]}' + + '
Count C: %{customdata[8]}' + + '
Count T: %{customdata[9]}' + + '
Count G: %{customdata[10]}' + + '
Count N: %{customdata[11]}' + + '')) + + data = data[data['sample_name'].isin(samples_with_contributing_sites)] data['index'] = range(len(data)) for i in data.index: @@ -145,13 +149,14 @@ def plot(self, samples, outdir): mode='markers' )) + if len(plot_data) > 0: + fig.update_layout(yaxis = dict(range=(-0.005, plot_data['MAF'].max()*1.05))) - ticks = plot_data[['sample_name', 'index']].drop_duplicates() + ticks = data[['sample_name', 'index']].drop_duplicates() fig.update_layout( yaxis_title="Minor allele frequency", title_text="Statistics of sites that contribute to minor contamination", - yaxis = dict(range=(-0.005, plot_data['MAF'].max()*1.05)), xaxis = dict( tickmode = 'array', tickvals = ticks['index'], From 567a42b6fd59ff8cfc8b44d229908b03b71a39ef Mon Sep 17 00:00:00 2001 From: murphycj2 Date: Mon, 19 Apr 2021 12:52:51 -0400 Subject: [PATCH 2/2] Update VERSION --- biometrics/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/biometrics/VERSION b/biometrics/VERSION index a45be46..1866a36 100644 --- a/biometrics/VERSION +++ b/biometrics/VERSION @@ -1 +1 @@ -0.2.8 +0.2.9