!curl https://raw.githubusercontent.com/Serulab/Py4Bio/master/samples/samples.tar.bz2 -o samples.tar.bz2
!mkdir samples
!tar xvfj samples.tar.bz2 -C samples

"""
Explanation: Python for Bioinformatics

This Jupyter notebook is intented to be used alongside the book Python for Bioinformatics
Note: Before opening the file, this file should be accesible from this Jupyter notebook. In order to do so, the following commands will download these files from Github and extract them into a directory called samples.
Chapter 14: Graphics in Python
USING BOKEH
End of explanation
"""


from bokeh.plotting import figure, output_file, show

p = figure(width=400, height=400)
p.circle(2, 3, radius=.5, alpha=0.5)
output_file("out.html")
show(p)

"""
Explanation: Listing 14.1: basiccircle.py: A circle made with Bokeh
End of explanation
"""


from bokeh.plotting import figure, output_file, show

p = figure(width=500, height=500)
x = [1, 1, 2, 2]
y = [1, 2, 1, 2]
p.circle(x, y, radius=.35, alpha=0.5, color='red')
output_file("out.html")
show(p)

"""
Explanation: Listing 14.2: fourcircles.py: 4 circles made with Bokeh
End of explanation
"""


from bokeh.plotting import figure, output_file, show

x = [1, 2, 3, 4, 5, 6, 7, 8]
y = [.7, 1.4, 2.1, 3, 3.85, 4.55, 5.8, 6.45]

p = figure(title='Mean wt increased vs. time',
           x_axis_label='Time in days',
           y_axis_label='% Mean WT increased')
p.circle(x, y, legend='Subject 1', size=10)
output_file('test.html')
show(p)

"""
Explanation: Listing 14.3: plot1.py: A minimal plot
End of explanation
"""



from bokeh.plotting import figure, output_file, show

x = [1, 2, 3, 4, 5, 6, 7, 8]
y = [.7, 1.4, 2.1, 3, 3.85, 4.55, 5.8, 6.45]
z = [.5, 1.1, 1.9, 2.5, 3.1, 3.9, 4.85, 5.2]

p = figure(title='Mean wt increased vs. time',
           x_axis_label='Time in days',
           y_axis_label='% Mean WT increased')
p.circle(x, y, legend='Subject 1', size=10)
p.circle(x, z, legend='Subject 2', size=10, line_color='red',
         fill_color='white')
p.legend.location = 'top_left'
output_file('test.html')
show(p)

"""
Explanation: Listing 14.4: plot2.py: Two data series plot
End of explanation
"""


from bokeh.charts import Scatter, output_file, show
from pandas import DataFrame

df = DataFrame.from_csv('samples/fishdata.csv')

scatter = Scatter(df, x='PC1', y='PC2', color='feeds',
        marker='species', title=
        'Metabolic variations based on 1H NMR profiling of fishes',
        xlabel='Principal Component 1: 35.8%',
        ylabel='Principal Component 2: 15.1%')
scatter.legend.background_fill_alpha = 0.3
output_file('scatter.html')
show(scatter)

"""
Explanation: Listing 14.5: fishpc.py: Scatter plot
End of explanation
"""


from bokeh.charts import HeatMap, bins, output_file, show
import pandas as pd

DATA_FILE = 'samples/GSM188012.CEL'
dtype = {'x': int, 'y': int, 'lux': float}
dataset = pd.read_csv(DATA_FILE, sep='\t', dtype=dtype)
hm = HeatMap(dataset, x=bins('x'), y=bins('y'), values='lux',
             title='Expression', stat='mean')
output_file("heatmap7.html", title="heatmap.py example")
show(hm)

"""
Explanation: Listing 14.6: heatmap.py: Plot a gene expression file
End of explanation
"""


from bokeh.charts import output_file, Chord
from bokeh.io import show
import pandas as pd
data = pd.read_csv('samples/test3.csv')
chord_from_df = Chord(data, source='name_x', target='name_y',
                      value='value')
output_file('chord.html')
show(chord_from_df)

"""
Explanation: Listing 14.7: chord.py: A Chord diagram
End of explanation
"""


