@@ -5,7 +5,7 @@ using namespace svg;
55// FUNCTIONS
66int 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);
0 commit comments