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

Solve some bugs #266

Merged
merged 10 commits into from
Jul 16, 2020
14 changes: 11 additions & 3 deletions pygenometracks/readBed.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ def get_bed_interval(self, bed_line, is_first_line=False):
Processes each bed line from a bed file, casts the values and returns
a namedtuple object

>>> bed_line="chr1\t0\t1000\tgene_1\t0.5\t-\t0\t1000\t0\t3\t10,20,100\t20,200,700"
>>> bed_line="chr1\t0\t1000\tgene_1\t0.5\t-\t0\t1000\t0\t3\t10,20,300\t0,200,700"
>>> with open('/tmp/test.bed', 'w') as fh:
... foo = fh.write(bed_line)
>>> bed_f = ReadBed(open('/tmp/test.bed','r'))
>>> bed = bed_f.get_bed_interval(bed_line)
>>> bed.chromosome
'chr1'
>>> bed.block_starts
[20, 200, 700]
[0, 200, 700]

>>> bed_line="chr2\t0\t1000\tgene_1\t0.5\t-\n"
>>> with open('/tmp/test.bed', 'w') as fh:
Expand Down Expand Up @@ -270,7 +270,7 @@ def get_bed_interval(self, bed_line, is_first_line=False):
f"#{self.line_number}, "
f"the block field {r} is not "
f"valid.\nError message: {detail}"
"\nNo block will be used.\n")
"\nOne block will be used.\n")
line_values = line_values[:9]
line_values.append(1)
line_values.append([line_values[2] - line_values[1]])
Expand Down Expand Up @@ -359,3 +359,11 @@ def check_bed12(line_values, line_number, bed_line):
" 12th field of a bed12 should contains relative start" \
" positions of blocks and the 11th field should contains" \
" the length of each block."
assert min(block_relative_starts) == 0, \
f"The blocks relative_starts of line\n{bed_line}\n" \
"does not contain 0. BED blocks must span chromStart" \
" to chromEnd."
assert max([bstart + bsize for bstart, bsize in zip(block_relative_starts, block_sizes)]) == line_values[2] - line_values[1], \
f"The blocks described in line\n{bed_line}\n" \
"does not cover chromEnd. BED blocks must span chromStart" \
" to chromEnd."
4 changes: 2 additions & 2 deletions pygenometracks/tracks/GenomeTrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,10 @@ def process_color(self, param, colormap_possible=False,
elif self.properties[param][0] == '(':
try:
custom_color = eval(self.properties[param])
except ValueError:
except (SyntaxError, NameError) as e:
self.log.warning(f"*WARNING*: '{param}' for section"
f" {self.properties[param]}"
" is not valid. "
f" raised an error:\n{e}\n"
f"{self.properties['section_name']} has "
"been set to "
f"{default_value}.\n")
Expand Down
8 changes: 8 additions & 0 deletions pygenometracks/tracks/ScaleBarTrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ class ScaleBarTrack(GenomeTrack):
# The color can only be a color

def plot(self, ax, chrom_region, start_region, end_region):
# Get the center from the properties
x_center = self.properties['x_center']
if x_center is None:
# Else put it in the middle
x_center = (end_region + start_region) / 2
# Get the size form the properties
size = self.properties['size']
if size is None:
# We put the size that is less than half the plotted region
Expand All @@ -72,6 +75,11 @@ def plot(self, ax, chrom_region, start_region, end_region):
else:
first_char = 1
size = first_char * 10**(len(str(half_plotted_region)) - 1)
# We only plot if it will be visible
if x_center - size / 2 > end_region or x_center + size / 2 < start_region:
return

# We adjust the unit to make it pretty
if size < 1e3:
size_label = f"{size} bases"
elif size < 1e6:
Expand Down
18 changes: 13 additions & 5 deletions pygenometracks/tracksClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,17 @@ def parse_tracks(self, tracks_file, plot_regions=None):
raise InputError(f"The section {section_name} is supposed to be a vline"
" but there is no file.")
track_options['file'] = parser.get(section_name, 'file')
if len(all_keywords) > 2:
extra_keywords = [k for k in all_keywords
if k not in ['file', 'type']]
if 'line_width' in all_keywords:
try:
track_options['line_width'] = float(parser.get(section_name, 'line_width'))
except ValueError:
raise InputError(f"In section {section_name}, line_width "
f"was set to {parser.get(section_name, 'line_width')}"
" whereas we should have a float "
"value.")
extra_keywords = [k for k in all_keywords
if k not in ['file', 'type', 'line_width']]
if len(extra_keywords) > 0:
log.warn("These parameters were specified but will not"
f" be used {' '.join(extra_keywords)}.\n")
self.vlines_properties = \
Expand Down Expand Up @@ -628,7 +636,7 @@ class SpacerTrack(GenomeTrack):
POSSIBLE_PROPERTIES = {}
BOOLEAN_PROPERTIES = []
STRING_PROPERTIES = ['overlay_previous',
'title']
'title', 'file_type']
FLOAT_PROPERTIES = {'height': [0, np.inf]}
INTEGER_PROPERTIES = {}

Expand All @@ -649,7 +657,7 @@ class XAxisTrack(GenomeTrack):
POSSIBLE_PROPERTIES = {'where': ['top', 'bottom']}
BOOLEAN_PROPERTIES = []
STRING_PROPERTIES = ['overlay_previous',
'title', 'where']
'title', 'where', 'file_type']
FLOAT_PROPERTIES = {'fontsize': [0, np.inf],
'height': [0, np.inf]}
INTEGER_PROPERTIES = {}
Expand Down
2 changes: 1 addition & 1 deletion pygenometracks/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def transform(score_list, transform, log_pseudocount, file):
else:
return(np.log1p(score_list))
elif transform == '-log':
if np.nanmax(score_list) <= - log_pseudocount:
lldelisle marked this conversation as resolved.
Show resolved Hide resolved
if np.nanmin(score_list) <= - log_pseudocount:
msg = ("\n*ERROR*\ncoverage contains values smaller or equal to"
f" - {log_pseudocount}.\n"
f"- log( {log_pseudocount} + <values>) transformation can "
Expand Down