Skip to content

Commit e648ea8

Browse files
committed
Now only shows alignment block + option to show total block
1 parent 739a2d7 commit e648ea8

File tree

4 files changed

+96
-33
lines changed

4 files changed

+96
-33
lines changed

SADisplay/include/main.h

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,34 @@ bool checkExtension(const std::string& filePath, const std::string& ext);
5656

5757

5858
/**
59-
* \brief Function that reads a .SPT (SPLITTED PAF)
60-
* \param filepath const std::string& a reference to the string containing the filepath
59+
* \brief Function that outputs a .SVG from a contig vector
60+
* \param ctgList std::vector<Contig>& a reference to the vector containing all contigs to represent
61+
* \param chrLength int integer length of the chromosome to display
62+
* \param offset int space between contigs
63+
* \param zoom int zoom parameter, contigs smaller than this value won't be represented
64+
* \param col1 svg::Color SVG::Color object
65+
* \param col2 svg::Color SVG::Color object
66+
* \param col3 svg::Color SVG::Color object
67+
* \param Yoffset int up and down offset (if 0 sticks to border)
68+
* \param showLinks bool bool to decide whether we show links were alignment starts and stops
69+
* \param showInfo bool bool to decide whether we show contigs relative length
70+
* \param onlyAligned bool bool to decide whether we show only alignment blocks
71+
* \param targetName std::string string containing the target name of chromosome (in QUERY option of minimap2)
72+
* \param SVGFilePath std::string path to which svg is outputted
6173
**/
62-
void buildGraph(std::vector<Contig> ctgList, int chrLength, int offset, int zoom, svg::Color col1, svg::Color col2, svg::Color col3, int Yoffset, bool showLinks, bool showInfo, std::string targetName, std::string SVGFilePath);
74+
void buildGraph(std::vector<Contig>& ctgList, int& chrLength, int& offset, int& zoom, svg::Color& col1, svg::Color& col2, svg::Color& col3, int& Yoffset, bool& showLinks, bool& showInfo, bool& total, std::string& targetName, std::string& SVGFilePath);
6375

6476
/**
65-
* \brief Function that reads a .SPT (SPLITTED PAF)
66-
* \param filepath const std::string& a reference to the string containing the filepath
77+
* \brief Function that pus args into a SVG::Color object
78+
* \param char* character array containing rgb 0-255 values ";" separated
6779
**/
6880
svg::Color getColorFromArg(char *arg);
6981

7082
/**
71-
* \brief Function that reads a .SPT (SPLITTED PAF)
72-
* \param filepath const std::string& a reference to the string containing the filepath
73-
* \param chrLength int& a reference to the variable containing the target length
74-
* \param chrLength std::string& a reference to the variable containing the target name
83+
* \brief Function that reads a .DB
84+
* \param filepath const std::string& a reference to the string containing the filepath
85+
* \param chrLength int& a reference to the variable containing the target length
86+
* \param targetName std::string& a reference to the variable containing the target name
7587
* \return a list of Contig objects
7688
**/
7789
std::vector<Contig> readDB(std::string &dbFilePath, std::string &targetName, int * chrLength);

SADisplay/src/main.cpp

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using namespace svg;
55
// FUNCTIONS
66
int main(int argc, char* argv[]) {
77
// Check the number of parameters
8-
if (argc != 2 && argc != 11) {
8+
if (argc != 2 && argc != 12) {
99
std::cout << "WARNING: Bad argument number!" << std::endl;
1010
// Tell the user how to run the program
1111
printHelp();
@@ -65,6 +65,12 @@ int main(int argc, char* argv[]) {
6565
std::string targetName(argv[10]); //Target Name
6666
//std::cout << "Target name:\t\t" << targetName << std::endl; // DEBUG
6767

68+
bool total(false); // Show only aligned blocks (not the total block)
69+
//std::cout << std::string(argv[9]) << std::endl; // DEBUG
70+
if (std::string(argv[11]) != "n") {
71+
total = true;
72+
}
73+
6874
std::cout << "OK" << std::endl;
6975

7076
// SELECTING FROM DATABASE AND CREATING THE CONTIGLIST
@@ -76,7 +82,7 @@ int main(int argc, char* argv[]) {
7682

7783
std::cout << "Creating .svg figure...\t\t\t"; // Setting a string with SVGFilePath
7884
std::string SVGFilePath(dbFilePath.substr(0, dbFilePath.find_last_of("\\/")+1) + targetName + ".svg");
79-
buildGraph(ctgList, chrLength, offset, zoomFactor, c1, c2, c3, yoffset, showLinks, showInfo, targetName, SVGFilePath);
85+
buildGraph(ctgList, chrLength, offset, zoomFactor, c1, c2, c3, yoffset, showLinks, showInfo, total, targetName, SVGFilePath);
8086
std::cout << "OK" << std::endl;
8187
std::cout << "Output path:\n" << SVGFilePath << std::endl;
8288
return 0;
@@ -213,7 +219,7 @@ std::vector<Contig> readDB(std::string &dbFilePath, std::string &targetName, int
213219
return ctgList;
214220
}
215221

216-
void buildGraph(std::vector<Contig> ctgList, int chrLength, int offset, int zoom, svg::Color col1, svg::Color col2, svg::Color col3, int Yoffset, bool showLinks, bool showInfo, std::string targetName, std::string SVGFilePath) {
222+
void buildGraph(std::vector<Contig>& ctgList, int& chrLength, int& offset, int& zoom, svg::Color& col1, svg::Color& col2, svg::Color& col3, int& Yoffset, bool& showLinks, bool& showInfo, bool& total, std::string& targetName, std::string& SVGFilePath) {
217223
int lstSize(ctgList.size());
218224

219225
// Initializes row lists
@@ -247,7 +253,7 @@ void buildGraph(std::vector<Contig> ctgList, int chrLength, int offset, int zoom
247253
if (plus) { // Loops through PLUS ROW LIST
248254
for (int j(0); j < plusRowLst.size(); j++) {
249255

250-
if (!(plusRowLst[j].inSpan(ctgSpan1, ctgSpan2, offset))) { // Checks if contig is in span (+ 10 bp of sep min)
256+
if (!(plusRowLst[j].inSpan(ctgSpan1, ctgSpan2, offset))) { // Checks if contig is in span (+ offset of sep min)
251257
plusRowLst[j].addSpan(ctgSpan1, ctgSpan2); // Adds a soan to current row
252258
ctgList[i].setRow(j); // Sets the row nb to current contig
253259
//std::cout << "Added to row: " << j << std::endl;
@@ -312,13 +318,13 @@ void buildGraph(std::vector<Contig> ctgList, int chrLength, int offset, int zoom
312318

313319
for (int i(0); i < lstSize; i++) { // FOR EACH CTG IN LIST
314320
Contig contig(ctgList[i]);
315-
bool plus(contig.getRelStrand());
316-
int rowNb(contig.getRow() + 1); // Rows are not 0 indexed below (easier compute)
317-
int tStart(contig.getChrStart()/zoom);
318-
int tEnd(contig.getChrEnd()/zoom);
319-
int qStart(contig.getStart()/zoom);
320-
int qEnd(contig.getEnd()/zoom);
321-
int qLength(contig.getLength()/zoom);
321+
bool plus(contig.getRelStrand()); // RELATIVE STRAND WHERE BLOCK WAS FOUND
322+
int rowNb(contig.getRow() + 1); // Rows are not 0 indexed below (easier compute)
323+
int tStart(contig.getChrStart()/zoom); // START ON CHROMOSOME
324+
int tEnd(contig.getChrEnd()/zoom); // END ON CHROMOSOME
325+
int qStart(contig.getStart()/zoom); // START ON QUERY (where fisrt link should point)
326+
int qEnd(contig.getEnd()/zoom); // END ON QUERY (where second link should point)
327+
int qLength(contig.getLength()/zoom); // TOTAL LENGTH OF CONTIG (ALIGNED LENGTH = chrend - chrstart)
322328

323329
// BUILDS THE STRAND INFO STRING
324330
std::stringstream ss;
@@ -339,11 +345,13 @@ void buildGraph(std::vector<Contig> ctgList, int chrLength, int offset, int zoom
339345
// END DEBUG
340346

341347
// BLOCKS
342-
// Y position : Y offset + (T start - Q start)
348+
// Y position : Y offset + (T start - Q start) (Y offset + position on chromosome - start position on contig)
343349
int blockYPosition(Yoffset + (tStart - qStart) ); // Y position of the block to draw (same on + & - sides of chr)
344-
350+
// THIS Y POSITION SHOULD BE tstart if option TOTAL is set
345351
// LINKS
346-
// up link 1 (ctg) y position : blockYPosition + Q start
352+
// up link 1 (ctg) y position : blockYPosition + Q start <--> Y offset + tStart
353+
// since blockYPosition = Yoffset + tStart - qStart
354+
// THEN uplink1Y = Yoffset + tStart - qStart + qStart <=> upLink1Y = Yoffset + tStart
347355
int upLink1Y(blockYPosition + qStart);
348356
// down link 1 (ctg) y position : blockYPosition + Q end
349357
int downLink1Y(blockYPosition + qEnd);
@@ -363,13 +371,24 @@ void buildGraph(std::vector<Contig> ctgList, int chrLength, int offset, int zoom
363371
// LINKS ON CHROMOSOME X POSITION = X POSITION OF THE CHROMOSOME + 20 -> 30*(nM+1)
364372
int linksOnChromosomeXPosition(30*(nM+1));
365373

366-
doc << Rectangle(Point(blockXPosition, blockYPosition), 20, qLength, idString, col2);
367-
if (showInfo && qLength != 0) {
368-
doc << Text(Point(blockXPosition+25, blockYPosition-2), toString(qLength), Color::Black, Font(10, "Verdana"));
374+
if (total) {
375+
doc << Rectangle(Point(blockXPosition, blockYPosition), 20, qLength, idString, col2);
376+
if (showInfo && qLength != 0) {
377+
doc << Text(Point(blockXPosition+25, blockYPosition-2), toString(qLength), Color::Black, Font(10, "Verdana"));
378+
}
379+
} else {
380+
int onlyAlignedYPosition(Yoffset + tStart);
381+
int onlyAlignedLength(tEnd - tStart);
382+
//std::cout << "ys: " << onlyAlignedYPosition << "\tyL: " << onlyAlignedLength << std::endl;
383+
doc << Rectangle(Point(blockXPosition, onlyAlignedYPosition), 20, onlyAlignedLength, idString, col2);
384+
if (showInfo && qLength != 0) {
385+
doc << Text(Point(blockXPosition+25, onlyAlignedYPosition-2), toString(qLength), Color::Black, Font(10, "Verdana"));
386+
}
369387
}
370388

371389
// SHOW THE LINKS
372-
if (showLinks && qLength != 0) {
390+
int alignedLength(tEnd - tStart);
391+
if (showLinks && qLength != 0 && alignedLength > 1) {
373392
Point upCtg(blockXPosition, upLink1Y);
374393
Point upChr(linksOnChromosomeXPosition, upLink2Y);
375394
Point downCtg(blockXPosition, downLink1Y);
@@ -392,13 +411,24 @@ void buildGraph(std::vector<Contig> ctgList, int chrLength, int offset, int zoom
392411
// LINKS ON CHROMOSOME X POSITION = X POSITION OF THE CHROMOSOME -> 30*nM+10
393412
int linksOnChromosomeXPosition(30*nM+10);
394413

395-
doc << Rectangle(Point(blockXPosition, blockYPosition), 20, qLength, idString, col3);
396-
if (showInfo && qLength != 0) {
397-
doc << Text(Point(blockXPosition-15, blockYPosition-2), toString(qLength), Color::Black, Font(10, "Verdana"));
414+
415+
if (total) {
416+
doc << Rectangle(Point(blockXPosition, blockYPosition), 20, qLength, idString, col3);
417+
if (showInfo && qLength != 0) {
418+
doc << Text(Point(blockXPosition-15, blockYPosition-2), toString(qLength), Color::Black, Font(10, "Verdana"));
419+
}
420+
} else {
421+
int onlyAlignedYPosition(Yoffset + tStart);
422+
int onlyAlignedLength(tEnd - tStart);
423+
doc << Rectangle(Point(blockXPosition, onlyAlignedYPosition), 20, onlyAlignedLength, idString, col3);
424+
if (showInfo && qLength != 0) {
425+
doc << Text(Point(blockXPosition-15, onlyAlignedYPosition-2), toString(qLength), Color::Black, Font(10, "Verdana"));
426+
}
398427
}
399428

400429
// SHOW THE LINKS
401-
if (showLinks && qLength != 0) {
430+
int alignedLength(tEnd - tStart);
431+
if (showLinks && qLength != 0 && alignedLength > 1) {
402432
Point upCtg(linksOnContigXPosition, upLink1Y);
403433
Point upChr(linksOnChromosomeXPosition, upLink2Y);
404434
Point downCtg(linksOnContigXPosition, downLink1Y);

install.sh

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/bin/bash
22
#To avoid permission issue: chmod +x install.sh
3+
#To avoid cmake ABI issues: sudo install.sh
34
#1. Install SARead
45
cd ./SARead
56
mkdir tmp

python/SAVi.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@
1212
import datetime
1313
import subprocess
1414
import sqlite3
15+
import inspect
1516

1617
class MainSAVi(wx.Frame) :
1718
"""This is a frame inherited object setting up the main frame of SAVi"""
1819
def __init__(self, parent, title) :
1920
"""Class builder"""
21+
22+
# CHANGE WORKING DIR TO SAVI DIRECTORY
23+
SAViPath = os.path.abspath(inspect.stack()[0][1])
24+
dirSAViPath = os.path.dirname(os.path.abspath(inspect.stack()[0][1]))
25+
os.chdir(dirSAViPath)
26+
2027
"""
2128
The super function is versatile:
2229
1. super() is called on a class to get a single inheritance to refer to the parent class without naming it
@@ -27,7 +34,6 @@ def __init__(self, parent, title) :
2734
Formerly in py2:
2835
super(SubClass, self).method(args) #It is still valid in python3
2936
"""
30-
3137
super().__init__(parent, title=title, size=(1400,800))
3238

3339
self.Centre()
@@ -198,6 +204,7 @@ def init_UI(self) :
198204
self.minTxt = wx.StaticText(self, label="- strand color", style=wx.ALIGN_LEFT)
199205
self.showInfoTxt = wx.StaticText(self, label="Show block informations", style=wx.ALIGN_LEFT)
200206
self.showLinksTxt = wx.StaticText(self, label="Show links on chromosome", style=wx.ALIGN_LEFT)
207+
self.showQueryTxt = wx.StaticText(self, label="Show total query blocks", style=wx.ALIGN_LEFT)
201208

202209
# INPUT
203210
self.queryInput = wx.TextCtrl(self)
@@ -227,6 +234,8 @@ def init_UI(self) :
227234
self.showInfoBox.Enable(False)
228235
self.showLinksBox = wx.CheckBox(self)
229236
self.showLinksBox.Enable(False)
237+
self.showQueryBox = wx.CheckBox(self)
238+
self.showQueryBox.Enable(False)
230239

231240
# OUTPUT
232241
self.logout = wx.TextCtrl(self, value="Outputs are printed here\n", style = wx.TE_READONLY | wx.TE_MULTILINE) # Sets self as parent
@@ -241,6 +250,7 @@ def init_UI(self) :
241250
self.HSub6 = wx.BoxSizer(wx.HORIZONTAL) # - col
242251
self.HSub7 = wx.BoxSizer(wx.HORIZONTAL) # show info
243252
self.HSub8 = wx.BoxSizer(wx.HORIZONTAL) # show links
253+
self.HSub9 = wx.BoxSizer(wx.HORIZONTAL) # show only alignment block
244254

245255
# COLOR INFO
246256
self.colChromPanel = wx.Panel(self)
@@ -262,6 +272,7 @@ def init_UI(self) :
262272
self.VBoxLeft.Add(self.HSub6, flag=wx.EXPAND|wx.ALL)
263273
self.VBoxLeft.Add(self.HSub7, flag=wx.EXPAND|wx.ALL)
264274
self.VBoxLeft.Add(self.HSub8, flag=wx.EXPAND|wx.ALL)
275+
self.VBoxLeft.Add(self.HSub9, flag=wx.EXPAND|wx.ALL)
265276
self.VBoxLeft.Add((-1,5), flag=wx.EXPAND)
266277
self.VBoxLeft.Add(self.displayButton, flag=wx.EXPAND|wx.ALL, border=2)
267278
self.VBoxLeft.Add(self.logout, flag=wx.CENTER|wx.EXPAND, border=2, proportion=1)
@@ -275,6 +286,7 @@ def init_UI(self) :
275286
self.HSub6.Add(self.minTxt, flag=wx.CENTER|wx.EAST, proportion=3)
276287
self.HSub7.Add(self.showInfoTxt, flag=wx.CENTER|wx.EAST, proportion=1)
277288
self.HSub8.Add(self.showLinksTxt, flag=wx.CENTER|wx.EAST, proportion=1)
289+
self.HSub9.Add(self.showQueryTxt, flag=wx.CENTER|wx.EAST, proportion=1)
278290

279291
self.HSub0.Add(self.queryInput, border=1, proportion=1)
280292
self.HSub1.Add(self.sepInput, border=1, proportion=1)
@@ -285,6 +297,7 @@ def init_UI(self) :
285297
self.HSub6.Add(self.minInput, border=1, proportion=2)
286298
self.HSub7.Add(self.showInfoBox, border=1, proportion=1)
287299
self.HSub8.Add(self.showLinksBox, border=1, proportion=1)
300+
self.HSub9.Add(self.showQueryBox, border=1, proportion=1)
288301

289302
self.HSub4.Add(self.colChromPanel, border=1, proportion=1, flag=wx.EXPAND|wx.ALL|wx.CENTER)
290303
self.HSub5.Add(self.colPlusPanel, border=1, proportion=1, flag=wx.EXPAND|wx.ALL|wx.CENTER)
@@ -400,6 +413,7 @@ def _reset(self, id) : # OK DONE
400413
self.minInput.Enable(False) # Disables - strand color input
401414
self.showInfoBox.Enable(False) # Disables show info tick
402415
self.showLinksBox.Enable(False) # Disables show links tick
416+
self.showQueryBox.Enable(False) # Disables show links tick
403417
self.displayButton.Enable(False) # Disables SADisplay command start
404418

405419
# ENABLES WIDGETS
@@ -442,6 +456,7 @@ def _display(self, id) :
442456
DISPLAY = True # Sets a DISPLAY bool
443457
showinfo = bool(self.showInfoBox.GetValue()) # Gets the value of show info
444458
showlinks = bool(self.showLinksBox.GetValue()) # Gets the value of show links
459+
showtotal = bool(self.showQueryBox.GetValue()) # Gets the value of show only aligned blocks
445460
try :
446461
qname = str(self.queryInput.GetValue()) # Gets the value of query input
447462
if not self.check_input_value_type(qname, "string") : # Checks the value type
@@ -526,7 +541,11 @@ def _display(self, id) :
526541
if not showlinks :
527542
links = "n"
528543

529-
cmd = "../SADisplay/SADisplay {} {} {} {} {} {} {} {} {} {}".format(self.rename_spac(self.currentDB), sep, zoom, yoff, links, chrcolstr, pluscolstr, minuscolstr, info, qname)
544+
total = "y"
545+
if not showtotal :
546+
total = "n"
547+
548+
cmd = "../SADisplay/SADisplay {} {} {} {} {} {} {} {} {} {} {}".format(self.rename_spac(self.currentDB), sep, zoom, yoff, links, chrcolstr, pluscolstr, minuscolstr, info, qname, total)
530549
self.logout.AppendText("Command used:\n${}\n".format(cmd)) # Logs the cmd
531550
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) # Starts SADisplay
532551
self.logout.SetDefaultStyle(wx.TextAttr(colText=wx.RED)) # Sets the text to red
@@ -596,6 +615,7 @@ def _load_db(self, path) :
596615
self.minInput.Enable(True) # Enables - strand color input
597616
self.showInfoBox.Enable(True) # Enables show info tick
598617
self.showLinksBox.Enable(True) # Enables show links tick
618+
self.showQueryBox.Enable(True) # Enables show links tick
599619
self.displayButton.Enable(True) # Enables SADisplay command start
600620

601621
def _pick_color(self, event) :

0 commit comments

Comments
 (0)