%pylab inline
from sequana import GenomeCov, sequana_data
rcParams['figure.figsize'] = (10,6)

"""
Explanation: Coverage characterization using GenomeCov class (sequana.bedtools module)
<center>http://sequana.readthedocs.org</center>
Author: Thomas Cokelaer 2016-2018
Illustrative example of the Coverage module with interactive widget to see effect of the running median window length
First, let us import the functions of interest (sequana_data is optional and used to import some data from sequana)
End of explanation
"""


gc = GenomeCov(sequana_data("virus.bed", "data"), low_threshold=-2.5, high_threshold=2.5)

"""
Explanation: Read a Coverage file in BED format
End of explanation
"""


chrom = gc[0]

"""
Explanation: Select one chromosome (there is only one in this case)
End of explanation
"""


N = 4001
chrom.running_median(N, circular=True)
chrom.compute_zscore()
chrom.plot_coverage()

"""
Explanation: Compute the running median and plot the results
End of explanation
"""


from ipywidgets import interact, interactive, fixed
import ipywidgets as widgets

def f(N):
    chrom.running_median(N, circular=True)
    chrom.compute_zscore()
    chrom.plot_coverage()
    ylim([1000,5500])
    plt.show()
    # plt.show is to fix issue reported in :
    # https://stackoverflow.com/questions/44329068/jupyter-notebook-interactive-plot-with-widgets

interact(f, N=widgets.IntSlider(min=501,max=8001, step=200))

"""
Explanation: Interactive view of the effects of the running window
End of explanation
"""


chrom.running_median(4101)

chrom.compute_zscore()

chrom.get_rois().get_low_rois()

"""
Explanation: Region of interests
End of explanation
"""


print(chrom)

chrom.get_centralness()

print(chrom.get_stats())

"""
Explanation: Some statistics
End of explanation
"""


filename = sequana_data("JB409847.bed")
reference = sequana_data("JB409847.fasta")

gc = GenomeCov(filename)
gc.compute_gc_content(reference)

chrom = gc[0]
chrom.get_gc_correlation()

chrom.plot_gc_vs_coverage(cmap="BrBG", Nlevels=0, bins=[80,50])

"""
Explanation: GC correlation
End of explanation
"""


