2

I'm trying to draw suffix trees in latex for a report. Since I'm programming trees I just print them in qtree format from my code so that I don't have to bother making them manually.

For small trees this works great. (The usual "banana" example incoming)

\documentclass{article}
\usepackage{graphics}
\usepackage{qtree}

\begin{document}
    \begin{center}
        \Tree[.  [.\$ ]
        [.banana\$ ]
        [.a [.n [.a [.na\$ ]
        [.\$ ]
        ]  ] [.\$ ]
        ] [.n [.a [.na\$ ]
        [.\$ ]
        ]  ]  ]
    \end{center}
\end{document}

Suffix tree for $banana$

But if I want to draw a bigger tree, like "idontknowsomethingbig" I use the same process:

\documentclass{article}
\usepackage{graphics}
\usepackage{qtree}

\begin{document}
    \begin{center}
        \Tree[.  [.\$idontknowsomethingbig\$ ]
        [.i [.dontknowsomethingbig\$ ]
        [.ngbig\$ ]
        [.g\$ ]
        ] [.dontknowsomethingbig\$ ]
        [.o [.ntknowsomethingbig\$ ]
        [.wsomethingbig\$ ]
        [.methingbig\$ ]
        ] [.n [.tknowsomethingbig\$ ]
        [.owsomethingbig\$ ]
        [.gbig\$ ]
        ] [.t [.knowsomethingbig\$ ]
        [.hingbig\$ ]
        ] [.knowsomethingbig\$ ]
        [.wsomethingbig\$ ]
        [.somethingbig\$ ]
        [.methingbig\$ ]
        [.ethingbig\$ ]
        [.hingbig\$ ]
        [.g [.big\$ ]
        [.\$ ]
        ] [.big\$ ]
        ]
    \end{center}
\end{document}

All I get is this

broken tree

Depending on the input I may get the last branch or just a word like in this case.

My guess is the code is syntactically correct and that the problem lies in it being to big and latex getting confused by it. But afaik it could be anything.

MJ Galram
  • 275
  • 2
  • 7

1 Answers1

2

The problem as the comments explained is that qtree can't handle more than 14 branches. The solution was to simply use forest instead. With it I can now draw bigger trees such as this one:

Big random genome tree

Which comes from:

\documentclass[border=1mm]{standalone}
\usepackage{graphics}
\usepackage{forest}


\begin{document}

        \begin{forest}
            for tree={
                calign=center,
                grow'=east,
                parent anchor=east, child anchor=west,
                text height=1.4ex, text depth=0.2ex 
            }
            [.  [.\$GATTACATAGCTGATGCTAGCTATATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.G [.A [.T [.TACATAGCTGATGCTAGCTATATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.G [.C [.TAGCTATATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.GCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            ]  ] [.AGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.CTGS\$ ]
            ]  ] [.C [.T [.GATGCTAGCTATATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.A [.G [.C [.T [.A [.TATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.GTCGTAGCTATGATCTGS\$ ]
            ]  ]  ] [.TCGTAGCTATGATCTGS\$ ]
            ] [.T [.ATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.GATCTGS\$ ]
            ]  ] [.CGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            ] [.G [.CTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.ATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            ]  ] [.T [.C [.G [.ATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.TAGCTATGATCTGS\$ ]
            ]  ] [.AGCTATGATCTGS\$ ]
            ] [.S\$ ]
            ] [.A [.T [.TACATAGCTGATGCTAGCTATATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.A [.G [.C [.T [.GATGCTAGCTATATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.AGCTAGTCGTAGCTATGATCTGS\$ ]
            ]  ]  ] [.TCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            ] [.G [.C [.TAGCTATATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.GCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            ] [.ATCTGS\$ ]
            ] [.C [.GTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.TGS\$ ]
            ]  ] [.CATAGCTGATGCTAGCTATATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.G [.C [.T [.GATGCTAGCTATATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.A [.T [.ATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.GATCTGS\$ ]
            ] [.G [.CTAGTCGTAGCTATGATCTGS\$ ]
            [.TCGTAGCTATGATCTGS\$ ]
            ]  ]  ]  ] [.TCGTAGCTATGATCTGS\$ ]
            ]  ] [.T [.TACATAGCTGATGCTAGCTATATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.A [.CATAGCTGATGCTAGCTATATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.G [.C [.T [.GATGCTAGCTATATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.A [.T [.ATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.GATCTGS\$ ]
            ] [.G [.CTAGTCGTAGCTATGATCTGS\$ ]
            [.TCGTAGCTATGATCTGS\$ ]
            ]  ]  ]  ] [.TCGTAGCTATGATCTGS\$ ]
            ] [.T [.ATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.CGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.GATCTGS\$ ]
            ]  ] [.G [.A [.T [.GCTAGCTATATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.CTGS\$ ]
            ]  ] [.C [.TAGCTATATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.GCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            ] [.S\$ ]
            ] [.C [.G [.T [.CGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.AGCTATGATCTGS\$ ]
            ] [.ATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.CGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            ] [.TGS\$ ]
            ]  ] [.C [.ATAGCTGATGCTAGCTATATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.T [.G [.ATGCTAGCTATATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.S\$ ]
            ] [.A [.G [.C [.T [.A [.TATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.GTCGTAGCTATGATCTGS\$ ]
            ]  ]  ] [.TCGTAGCTATGATCTGS\$ ]
            ] [.T [.ATCGTCGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.GATCTGS\$ ]
            ]  ] [.CGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            ] [.G [.T [.CGATGCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.AGCTATGATCTGS\$ ]
            ] [.A [.T [.GCGCTCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.AGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            ]  ] [.C [.TCGCGATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            [.GATAGCTAGCTAGTCGTAGCTATGATCTGS\$ ]
            ]  ]  ] [.S\$ ]
            ] 
        \end{forest}  


\end{document}

The syntax in forest differs from qtree so every node has an extra '.' character in this example. Keep this in mind if you are using this answer as an example on how to build trees using forest :)

MJ Galram
  • 275
  • 2
  • 7
  • Or tikz-qtree which would let you keep qtree's syntax. Can you include the code for that output in your answer? As it is, it is of limited use to anybody else with the same problem. – cfr Jan 22 '17 at 14:56
  • I've also tried tikz-qtree but the syntax didn't work. Actually, forests seem to have the same syntax at least for what I intend to use them – MJ Galram Jan 22 '17 at 16:19
  • @MJGalram The forest syntax doesn't use the ., so all your node labels have . in them. If this is what you want, then that's fine, but otherwise you may want to remove them. – Alan Munn Jan 22 '17 at 16:35
  • @AlanMunn Yeah, I noticed, but that's an easy thing to fix in the final code. For the example it's good enough. – MJ Galram Jan 22 '17 at 18:14
  • @AlanMunn That's not the only difference, is it? Isn't the bracket structure different as well? – cfr Jan 22 '17 at 19:54
  • @cfr Yes, there are other differences: terminals node must be bracketed in forest and tikz-qtree requires spaces before closing brackets (except after other close brackets). – Alan Munn Jan 22 '17 at 20:39