Commit 5c6f2630 authored by MARIJON Pierre's avatar MARIJON Pierre

Add instruction in Readme to generate html knot report

parent 7fc484d9
include *.md
include knot/*.rules
include knot/config.yaml
recursive-include knot/extremity_search *
recursive-include knot/filter_tig *
recursive-include knot/path_search *
recursive-include knot/analysis *
recursive-include knot/analysis/template *
......@@ -7,6 +7,8 @@ Give an assembly and a set of reads to KNOT, it will output an information-rich
- [Input](#input)
- [Output](#output)
- [Usage](#usage)
* [Run knot](#run-knot)
* [Generate html report on knot result](generate-html-report-on-knot-result)
- [Installation](#installation)
* [Install with conda](#install-with-conda)
* [Install without conda](#install-without-conda)
......@@ -53,6 +55,8 @@ Assume that
- contigs are stored in `contigs.fasta`
- contig graph is stored in `contigs.gfa`
### Run knot
Then run KNOT as:
```
......@@ -94,6 +98,17 @@ optional arguments:
In addition, snakemake parameters can be add after `--`.
### Generate html report on knot result
You can generate a html report `knot_report.html` on knot information generate previously with this command:
```
knot.analysis -i {output prefix give to knot previously} -c -p -o knot_report.html
```
If `-c` is present, knot.analysis run a path classification, based on path length and composition see [manuscript](#citation) for more details.
If `-p` is present, knot.analysis run a hamilton path search, see [manuscript](#citation) for more details.
## Installation
### Install with conda
......
......@@ -5,6 +5,7 @@ import os
import csv
import sys
import argparse
import subprocess
from jinja2 import FileSystemLoader
from jinja2 import Environment
......@@ -18,29 +19,33 @@ def main(args=None):
parser = argparse.ArgumentParser(prog="knot.analysis.generate_report")
parser.add_argument("-a", "--aag", type=argparse.FileType('r'), help="AAG filepath")
parser.add_argument("-C", "--contig", type=argparse.FileType('r'), help="contig filepath", required=True)
parser.add_argument("-c", "--classification", type=argparse.FileType('r'), help="path classification filepath", required=True)
parser.add_argument("-p", "--hamilton-path", type=argparse.FileType('r'), help="hamilton path filepath")
parser.add_argument("-o", "--output", type=argparse.FileType('wb'), help="path where report was write")
parser.add_argument("-i", "--input_prefix", type=str, help="prefix of knot output", required=True)
parser.add_argument("-o", "--output", type=argparse.FileType('wb'), help="path where report was write", required=True)
parser.add_argument("-c", "--classification", help="Add path classification in report", action="store_true")
parser.add_argument("-p", "--hamilton-path", help="Add hamilton path in report", action="store_true")
args = vars(parser.parse_args(args))
template_path = os.path.dirname(__file__) + os.sep + "template" + os.sep
env = Environment(loader=FileSystemLoader(template_path))
template = env.get_template('report.jinja2.html')
param = dict()
contig_info(param, args["contig"])
classification_info(param, args["classification"])
contig_info(param, open(args["input_prefix"] + "knot/contigs.fasta"))
if args["classification"]:
run_classification(args["input_prefix"] + "AAG.csv", args["input_prefix"])
classification_info(param, open(args["input_prefix"]+"classification.csv"))
if args["hamilton_path"] is not None:
hamilton_info(param, args["hamilton_path"])
if args["hamilton_path"]:
run_hamilton(args["input_prefix"] + "AAG.csv", args["input_prefix"])
hamilton_info(param, open(args["input_prefix"]+"hamilton_path.csv"))
full_aag_info(param, args["aag"])
args["aag"].seek(0)
build_AAG_representation(param, args["aag"])
full_aag_info(param, open(args["input_prefix"]+"AAG.csv"))
build_AAG_representation(param, open(args["input_prefix"]+"AAG.csv"))
args["output"].write(template.render(param).encode("utf-8"))
......@@ -52,6 +57,9 @@ def contig_info(param, contig_file):
param["tig_info"] = tig2len
def run_classification(aag_path, prefix_output):
subprocess.run(["knot.analysis.classifications", "-i", aag_path, "-o", prefix_output+"_classification.csv"])
def classification_info(param, classification_file):
ext2type = dict()
......@@ -60,6 +68,9 @@ def classification_info(param, classification_file):
param["classification_info"] = ext2type
def run_hamilton(aag_path, prefix_output):
subprocess.run(["knot.analysis.hamilton_path", "-i", aag_path, "-o", prefix_output+"_hamilton_path.csv"])
def hamilton_info(param, hamilton_file):
hamilton_path = list()
......@@ -103,8 +114,8 @@ def build_AAG_representation(param, aag_file):
for tig in tig_set:
nodes += "{{ id: '{}_begin', label: '{}_begin' }},\n".format(tig, tig)
nodes += "{{ id: '{}_end', label: '{}_end' }},\n".format(tig, tig)
nodes += "{{ id: '{}_begin', label: 'begin' }},\n".format(tig, tig)
nodes += "{{ id: '{}_end', label: 'end' }},\n".format(tig, tig)
for tig in tig_set:
e1 = tig + "_begin"
......
......@@ -85,6 +85,9 @@ def AAG2graph(AAG_path):
else:
nb_base = int(row["nb_base"])
if nb_base < 0:
nb_base = 0
if key in paths and paths[key] < nb_base:
continue
......
<h1>Hamiltonian path</h1>
<h2>Table of path with weight</h2>
<table class="dataframe", border=1>
<tr>
<th>path</th>
......@@ -12,3 +13,47 @@
</tr>
{% endfor %}
</table>
<h2>Evolution of weight</h2>
<div id="hamilton_curve"></div>
<script type="text/javascript">
var container = document.getElementById('hamilton_curve')
var items = [
{% for _, weight in hamilton_info %}
{x: {{loop.index}}, y: {{weight}}},
{% endfor %}
]
var dataset = new vis.DataSet(items);
var options = {
format: {
minorLabels: {
millisecond: 'x',
second: 'x',
minute: 'x',
hour: 'x',
weekday: 'x',
day: 'x',
month: 'x',
year: 'x'
},
majorLabels: {
millisecond: '',
second: '',
minute: '',
hour: '',
weekday: '',
day: '',
month: '',
year: ''
}
},
timeAxis: {scale: 'millisecond', step: 10},
};
var graph2d = new vis.Graph2d(container, dataset, options);
</script>
......@@ -13,7 +13,9 @@
{% include 'contig_report.jinja2.html' %}
{% if classification_info is defined %}
{% include 'path_classification.jinja2.html' %}
{% endif %}
{% include 'aag.jinja2.html' %}
......
......@@ -45,7 +45,7 @@ setup(
'knot.extremity_search = knot.extremity_search.__main__:main',
'knot.analysis.classifications = knot.analysis.classifications:main',
'knot.analysis.hamilton_path = knot.analysis.hamilton_path:main',
'knot.analysis.generation_report = knot.analysis.generation_report:main'
'knot.analysis = knot.analysis.generation_report:main'
]
}
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment