-
Notifications
You must be signed in to change notification settings - Fork 2
/
great3D
103 lines (88 loc) · 4.07 KB
/
great3D
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
"""Program to compute and visualise a 3D-transcriptome map.
Take a 3D gene positions file and a gene expression matrix, compute spatial correlation and visualise an interactive 3D graph of the spatial gene expression correlation
"""
import argparse
import pandas as pd
import dash
from dash import dcc
from dash import html
# Import package specific py_modules
import great_3d.genome_3D_integration as grtGI
import great_3d.transcriptome_3d as gtr3d
# Command line arguments parsing
parser = argparse.ArgumentParser(description="3D transcription map, main program")
# Declare command line arguments
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("-s", "--gene-starts",
type=argparse.FileType("r"),
help="Path to the file containing genes, chromosome names and start site genomic coordinates",
dest="geneStarts",
metavar="genes_starts")
group.add_argument("-c", "--gene-3Dcoords",
type=argparse.FileType("r"),
help="Path to the file containing the 3D coordinates of genes",
dest="genePos",
metavar="genes_positions")
parser.add_argument("-e", "--geneExpression-file",
type=argparse.FileType("r"),
required=True,
help="Path to the file containing the gene expression",
dest="geneExpr",
metavar="gene_expression_table")
parser.add_argument("-g", "--genome-coordinates",
type=argparse.FileType("r"),
required=True,
help="Path to the file containing the genome coordinates in 3D",
dest="genome",
metavar="genome_coords")
parser.add_argument("-u", "--user-genes",
type=argparse.FileType("r"),
help="Path to the file with the user genes of interest",
default=None,
dest="userGenes",
metavar="genes_interest")
parser.add_argument("-n", "--nb-genes",
help="Number of neighbouring genes. (DEFAULT = 10)",
type=int,
default=10,
dest="nGenes",
metavar="noGenes")
parser.add_argument("-r", "--correlation-method",
help="Define correlation method. (DEFAULT = 'pearson')",
type=str,
default="pearson",
dest="mCorr",
metavar="correlation_method")
parser.add_argument("-t", "--title",
help="Title for the 3D plotly praph. (DEFAULT = '')",
type=str,
default="",
dest="title",
metavar="title")
# Generate the options-arguments object
args = parser.parse_args()
# Calculate the gene 3D coordinates
if args.genePos:
genePos = pd.read_table(args.genePos)
elif args.geneStarts:
genePos = grtGI.compute_gene_coordinates(args.geneStarts, args.genome)
# Calculate the distance matrix
distanceMatrix = gtr3d.calculate_distance(genePos)
# Populate the dictionary of sorted distances.
sortedDict = gtr3d.sorting_distances(distanceMatrix)
# Compute a dictionnary of the sum of correlations between each gene and its neighbours.
sum_Corr = gtr3d.sum_correlation(sortedDict, args.geneExpr, args.nGenes, args.mCorr)
# Load and visualise genome
traceGenome = gtr3d.generate_genome_3D(args.genome, genePos, sum_Corr, args.userGenes)
# 3D visualization with Plotly
fig = gtr3d.visualise_3D_plotly(traceGenome)
# Simple Dash
# TODO Enrich the Dash application with, controls (radio buttons, sliders, etc.), input files and progress bars!!!
app = dash.Dash(__name__)
app.layout = html.Div(children=[html.H1(children='GREAT 3D transcriptome map'),
html.Div(children=args.title),
dcc.Graph(id='dash_GREAT', figure=fig)])
if __name__ == '__main__':
# app.run_server(host="0.0.0.0", port="8050")
app.run_server(debug = True)