Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proviral_landscape_plot: handle HIVIntact error codes #24

Open
wants to merge 9 commits into
base: proviral-landscape-plot
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,56 @@
'Premature Stop': "#CC6677",
'Chimera': "#AA4499",
'Scrambled': "#882255",
'Large Insertion': "#DDCC77",
'Frameshift': "#DDAA77",
'Divergence': "#661100",
}

# colors are chosen from Paul Tol's muted color scheme, which is color-blind safe
# if another defect color is needed, this one is recommended: #DDCC77
HIGHLIGHT_COLORS = {'Defect Region': "black",
'Inverted Region': "#AFAFAF",
}

DEFECT_TYPE = {'LargeDeletion': 'Large Deletion',
'LongDeletion': 'Large Deletion',
'InternalInversion': 'Inversion',
'ScramblePlus': 'Scrambled',
'ScrambleMinus': 'Scrambled',
'ScrambleCheck': 'Scrambled',
'Scramble': 'Scrambled',
'Hypermut': 'Hypermutated',
'APOBECHypermutation': 'Hypermutated',
'Intact': 'Intact',
'Inferred_Intact': 'Intact',
'PrematureStop_OR_AAtooLong_OR_AAtooShort': 'Premature Stop',
'PrematureStop_OR_AAtooLong_OR_AAtooShort_GagNoATG': 'Premature Stop',
'Inferred_PrematureStopORInframeDEL': 'Premature Stop',
'Inferred_PrematureStopORInframeDEL_GagNoATGandFailed': 'Premature Stop',
'Inferred_PrematureStopORInframeDEL_GagNoATG': 'Premature Stop',
'InternalStop': "Premature Stop",
'MutatedStopCodon': "Premature Stop",
'MutatedStartCodon': "Premature Stop",
'SequenceDivergence': "Divergence",
'Deletion': "Premature Stop",
'Insertion': "Large Insertion",
'Frameshift': "Frameshift",
'5DEFECT': "5' Defect",
'5DFECT_IntoGag': "5' Defect", # this is a typo in HIVSeqinR
'5DEFECT_GagNoATGGagPassed': "5' Defect",
'5DEFECT_GagNoATGGagFailed': "5' Defect",
'Inferred_Intact_GagNoATG': "5' Defect",
'Inferred_Intact_NoGag': "5' Defect",
'Intact_GagNoATG': "5' Defect",
'MajorSpliceDonorSiteMutated': "5' Defect",
'PackagingSignalDeletion': "5' Defect",
'PackagingSignalNotComplete': "5' Defect",
'RevResponseElementDeletion': "5' Defect",
'NonHIV': 'Chimera',
'AlignmentFailed': 'Chimera',
'UnknownNucleotide': 'Chimera',
}

# There are some defects where we don't care about the alignment and just want to plot lines:
LINE_DEFECTS = ['Hypermutated', 'Intact', 'Premature Stop']
DEFECT_ORDER = {'Intact': 10,
Expand All @@ -51,9 +73,12 @@
'Large Deletion': 40,
'Inversion': 50,
'Premature Stop': 60,
'Large Insertion': 63,
'Frameshift': 67,
'Scrambled': 70,
'Chimera': 80,
}

START_POS = 638
END_POS = 9632
LEFT_PRIMER_END = 666
Expand Down Expand Up @@ -159,12 +184,13 @@ def add_sidebar(self, sidebar_x, sidebar_ystart, fontsize, drawing):
except KeyError:
print(f"No color defined for defect {defect}")
continue

# percentage sidebar
sidebar_height = self.defect_percentages[defect] / 100 * (self.lineheight + 1) * self.num_samples
sidebar_label = f'{round(self.defect_percentages[defect], 1)}%'
sidebar_ystart -= sidebar_height
sidebar_label_y = fontsize / 4 + sidebar_ystart + 0.5 * sidebar_height
if self.defect_percentages[defect] < 3:
if self.defect_percentages[defect] < 0.1:
# skip very small percentages
pending_percentages.append((self.defect_percentages[defect], sidebar_height, color))
else:
Expand Down Expand Up @@ -235,12 +261,14 @@ def __init__(self, figure, tot_samples):
self.figure = figure
self.curr_multitrack = []
self.tot_samples = tot_samples
self.lineheight = 500 / self.tot_samples
self.lineheight = 500 / self.tot_samples if self.tot_samples > 0 else 0
if self.lineheight > 5:
self.lineheight = 5
self.xaxisheight = 0

def add_line(self, samp_name, xstart, xend, defect_type, highlight):
highlight = None

is_first = False
if defect_type not in DEFECT_TO_COLOR.keys():
print(f"Unknown defect: {defect_type}")
Expand Down Expand Up @@ -294,7 +322,8 @@ def make_gene_track(self, xstart, xend, defect_type, highlight=False):

def draw_current_multitrack(self):
# draw line and reset multitrack
self.figure.add(Multitrack(self.curr_multitrack), gap=1)
if self.curr_multitrack:
self.figure.add(Multitrack(self.curr_multitrack), gap=1)
self.curr_multitrack = []

def add_xaxis(self):
Expand Down