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

fix bugs #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pyrcos/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
__version__ = "0.0.1"
from pyrcos import objects,utils
__version__ = "0.0.1"

47 changes: 30 additions & 17 deletions pyrcos/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ def from_file(self, path):
rows.append(KaryotypeChromosome.parse(line))
else:
rows.append(KaryotypeBand.parse(line))
if hasattr(self,'rows') and type(self.rows) is list:
self.rows.extend(rows)
else:
self.rows=rows


class Circos(CircosObject):
Expand Down Expand Up @@ -218,13 +222,20 @@ def __init__(self, file=None, color=None, radius=None, bezier_radius=0.1, bezier

class Rules(object):
def __init__(self, rules=None):
if isinstance(rules, Rules):
if rules is None:
rules=[]
elif isinstance(rules, Rules):
rules = rules.rules
self.rules = [] if rules is None else rules
elif isinstance(rules, Rule):
rules = [ rules ]
self.rules = rules

def __len__(self):
return len(self.rules)

def __getitem__(self, item):
return self.rules[item]


class Rule(CircosObject):
__template__ = "rule.config.template"
Expand Down Expand Up @@ -468,7 +479,7 @@ def thickness(self, thickness):

class Scatter(Plot):
def __init__(self, file, r0, r1, backgrounds=None, axes=None, rules=None, color=None,
glyph=None, glyph_size=None, stroke_color=None, stroke_thickness=None, orientation=None):
glyph=None, glyph_size=None, stroke_color=None, stroke_thickness=None, orientation=None, **kwds):
super(Scatter, self).__init__("scatter", file, r0, r1,
backgrounds=backgrounds,
axes=axes,
Expand All @@ -478,7 +489,7 @@ def __init__(self, file, r0, r1, backgrounds=None, axes=None, rules=None, color=
glyph_size=glyph_size,
stroke_color=stroke_color,
stroke_thickness=stroke_thickness,
orientation=orientation)
orientation=orientation, **kwds)

@property
def glyph(self):
Expand Down Expand Up @@ -628,9 +639,9 @@ def __init__(self, ticks, show_label=True):
ticks = ticks.ticks
elif isinstance(ticks, Tick):
ticks = [ticks]
self.ticks = ticks
self.ticks = ticks
self.show_label = show_label

self.thickness = '3p'
def __len__(self):
return len(self.ticks)

Expand All @@ -642,23 +653,25 @@ class Tick(CircosObject):
__template__ = "tick.config.template"

def __init__(self, size=None, spacing=None, color=None, show_label=True, label_size=None,
format=None, grid=False, grid_color=None, grid_thickness=None, radii=None, radius=None):
format=None, grid=False, grid_color=None, grid_thickness=None, radii=None, radius=None, **kwds):
super(Tick, self).__init__()

self.size = size
self.spacing = spacing
self.color = color
self.show_label = show_label
self.label_size = label_size
self.format = format
self.grid = grid
self.grid_color = grid_color
self.size = size
self.spacing = spacing
self.color = color
self.show_label = show_label
self.label_size = label_size
self.format = format
self.grid = grid
self.grid_color = grid_color
self.grid_thickness = grid_thickness
self.radii = radii if radii is not None else []
self.attributes = kwds
self.radii = radii if radii is not None else []
if radii is None and radius is not None:
self.radii.append(radius)



class Highlights(object):
def __init__(self, highlights=None):
if highlights is None:
Expand All @@ -684,4 +697,4 @@ def __init__(self, file, r0, r1, color=None, init_counter=None, **kwargs):
CircosObjectWithinRadius.__init__(self, r0, r1)
self.attributes = kwargs
self.attributes['fill_color'] = color
self.attributes['init_counter'] = init_counter
self.attributes['init_counter'] = init_counter
12 changes: 6 additions & 6 deletions pyrcos/templates/axis.config.template
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ y0 = {{ y0 }}
y1 = {{ y1 }}
{% if spacing is not none %}
spacing = {{ spacing }}
{ %endif} %}
{% endif %}
{% if position is not none %}
position = {{ position }}
{ %endif} %}
{% endif %}
{% if position_skip is not none %}
position_skip = {{ position_skip }}
{ %endif} %}
{% endif %}
{% if color is not none %}
color = {{ color }}
{ %endif} %}
{% endif %}
{% if thickness is not none %}
thickness = {{ thickness }}
{ %endif} %}
</axis>
{% endif %}
</axis>
8 changes: 6 additions & 2 deletions pyrcos/templates/circos.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ karyotype = {{ karyotypes|join(',', attribute='filename')}}
{% endif %}

{% if ticks|length > 0 %}
<ticks>
show_ticks = True
show_tick_labels = {{ ticks.show_label }}
<ticks>
multiplier = 1/1u
thickness = {{ ticks.thickness }}
tick_separation = 2p
label_separation = 5p
{% for tick in ticks %}
{{ tick.configuration }}
{% endfor %}
Expand Down Expand Up @@ -46,4 +50,4 @@ radius* = {{ radius }}p

{% for k, v in attributes.iteritems() %}
{{ k }} = {{ v }}
{% endfor %}
{% endfor %}
6 changes: 3 additions & 3 deletions pyrcos/templates/rule.config.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ color = {{ color }}
show = {{ "yes" if show else "no" }}
flow = {{ flow }}
{% if radius1 is not none %}
radius1 = radius1
radius1 = {{ radius1 }} #check?
{% endif %}
{% if radius2 is not none %}
radius2 = radius2
radius2 = {{ radius2 }}
{% endif %}
</rule>
</rule>
10 changes: 8 additions & 2 deletions pyrcos/templates/tick.config.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ grid = {{ "yes" if grid else "no" }}
grid_color = {{ grid_color }}
grid_thickness = {{ grid_thickness }}

#other attributes
{% for k, v in attributes.iteritems() %}
{{ k }} = {{ v }}
{% endfor %}


{% for radius in radii %}
radius = {{ radius }}r {% endif %}
</tick>
radius = {{ radius }} {% endfor %}
</tick>
18 changes: 18 additions & 0 deletions pyrcos/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


def seq_records_to_karyotype(records, color_map={}):
records=list(records)
assert all([isinstance(r, SeqRecord) for r in records])
chrs = []
for i, record in enumerate(records):
Expand All @@ -29,4 +30,21 @@ def seq_record_to_tiles(records, feature_types=["gene"]):
track["start"] = np.array(track["start"], dtype=int)
track["end"] = np.array(track["end"], dtype=int)

yield track

def seq_record_to_texts(records, feature_types=["gene"]):
for record in records:
track = DataFrame(columns=["chromosome", "start", "end", "value", "options"])
i = 0
for feature in record.features:
if feature.type in feature_types:
track.loc[i] = (record.id, int(feature.location.start+1),
int(feature.location.end),
feature.qualifiers.get(feature.qualifiers.keys()[0], ['unidentified'] )[0], "")
i += 1

track["start"] = np.array(track["start"], dtype=int)
track["end"] = np.array(track["end"], dtype=int)
track['value']=track['value'].str.replace(' ','_')
track['value']=np.where(track['value'].str.len()>8, track['value'].str[:8]+'...', track['value'] )
yield track