def tab0(f, clones, clone2hits, group2keywords, options):
    for clone in clones:
        vs, js, ds, sample2size = getCloneInfo(clone)
        if clone in clone2hits:
            hits = clone2hits[clone]
            hitsWithKeyword = []  # list of hits that have at least 1 keyword
            for hit in hits:
                for g, kw in group2keywords.iteritems():
                    if g == "b27" or g == "pathogen":
                        continue
                    if checkKeywords(hit[0], kw):
                        hitsWithKeyword.append(hit)
                        break
            if len(hitsWithKeyword) == 0:  # no hit with keyword
                continue

            seq = hits[0][2]
            samples = sorted([iseqlib.properName(s) for s in sample2size.keys()])
            numrow = max([len(samples), len(hitsWithKeyword)])

            f.write(
                "\\multirow{%d}{*}{%s} & \\multirow{%d}{*}{%s} & \\multirow{%d}{*}{%s} & "
                % (numrow, vs, numrow, seq, numrow, js)
            )  # Write V, CDR3, J
            # f.write("%s & %d & %s & %s & %s \\\\\n " %( samples[0], sample2size[iseqlib.properName2name(samples[0])], hitsWithKeyword[0][4], hitsWithKeyword[0][3], hitsWithKeyword[0][0] )) #first row
            f.write(
                "%s & %d & %s & %s & %s \\\\\n "
                % (
                    samples[0],
                    sample2size[iseqlib.properName2name(samples[0])],
                    hitsWithKeyword[0][4],
                    hitsWithKeyword[0][3],
                    parsePaperInfo(hitsWithKeyword[0][0]),
                )
            )
            for i in xrange(1, numrow):
                f.write("\\cline{4-8}\n")
                f.write(" & & & ")
                if i < len(samples):
                    s = samples[i]
                    f.write(" %s & %d &" % (s, sample2size[iseqlib.properName2name(s)]))
                else:
                    f.write(" & & ")
                if i < len(hitsWithKeyword):
                    h = hitsWithKeyword[i]
                    # f.write( "%s & %s & %s \\\\\n" %(h[4], h[3], h[0]) )
                    f.write("%s & %s & %s \\\\\n" % (h[4], h[3], parsePaperInfo(h[0])))
                else:
                    f.write(" & & \\\\\n")
            f.write("\\hline\n")
def tab(f, clones, clone2hits, group2keywords, options, samples):
    for clone in clones:
        vs, js, ds, sample2size = getCloneInfo(clone)
        if clone in clone2hits:
            hits = clone2hits[clone]
            hitsWithKeyword = []  # list of hits that have at least 1 keyword
            for hit in hits:
                for g, kw in group2keywords.iteritems():
                    if g == "b27" or g == "pathogen":
                        continue
                    if checkKeywords(hit[0], kw):
                        hitsWithKeyword.append(hit)
                        break
            if len(hitsWithKeyword) == 0:  # no hit with keyword
                continue

            seq = hits[0][2]
            numrow = len(hitsWithKeyword)

            # First line
            f.write(
                "\\multirow{%d}{*}{%s} & \\multirow{%d}{*}{%s} & \\multirow{%d}{*}{%s} & "
                % (numrow, vs, numrow, seq, numrow, js)
            )  # Write V, CDR3, J
            for s in samples:
                name = iseqlib.properName2name(s)
                if name in sample2size:
                    count = sample2size[name]
                    f.write("\\multirow{%d}{*}{%d} & " % (numrow, count))
                else:
                    f.write("\\multirow{%d}{*}{} & " % (numrow))
            f.write(
                "%s & %s & %s \\\\\n "
                % (hitsWithKeyword[0][4], hitsWithKeyword[0][3], parsePaperInfo(hitsWithKeyword[0][0]))
            )

            # Other hits:
            for i in xrange(1, numrow):
                f.write("\\cline{%d-%d}\n" % (3 + len(samples) + 1, 3 + len(samples) + 3))
                f.write(" &" * (3 + len(samples)))
                h = hitsWithKeyword[i]
                f.write("%s & %s & %s \\\\\n" % (h[4], h[3], parsePaperInfo(h[0])))
            f.write("\\hline\n")
def tab(f, clones, clone2hits, group2keywords, options, samples):
    for clone in clones:
        vs, js, ds, sample2size = getCloneInfo(clone)
        if clone in clone2hits:
            hits = clone2hits[clone]
            hitsWithKeyword = [] #list of hits that have at least 1 keyword
            for hit in hits:
                if checkKeywords(hit.title, group2keywords['mice']) or (options.abstract and checkKeywords(hit.abstract, group2keywords['mice'])): #mice studies, ignore
                    continue
                for g, kw in group2keywords.iteritems():
                    if g == 'b27' or g == 'pathogen':
                        continue
                    if checkKeywords(hit.title, kw) or (options.abstract and checkKeywords(hit.abstract, kw)):
                        hitsWithKeyword.append(hit)
                        break
            if len(hitsWithKeyword) == 0: #no hit with keyword
                continue
            
            seq = hits[0].qAln
            numrow = len(hitsWithKeyword)
            
            #First line
            f.write("\\multirow{%d}{*}{%s} & \\multirow{%d}{*}{%s} & \\multirow{%d}{*}{%s} & " %(numrow, vs, numrow, seq, numrow, js) ) #Write V, CDR3, J
            for s in samples:
                name = iseqlib.properName2name(s)
                if name in sample2size:
                    count = sample2size[name]
                    f.write("\\multirow{%d}{*}{%d} & " % (numrow, count))
                else:
                    f.write("\\multirow{%d}{*}{} & " % (numrow))
            f.write("%s & %s & %s \\\\\n " %( hitsWithKeyword[0].tAln, hitsWithKeyword[0].match, parsePaperInfo(hitsWithKeyword[0].title) ))
            
            #Other hits:
            for i in xrange(1, numrow):
                f.write("\\cline{%d-%d}\n" %(3 + len(samples) + 1, 3 + len(samples) + 3))
                f.write(" &"*( 3 + len(samples) ) )
                h = hitsWithKeyword[i]
                f.write( "%s & %s & %s \\\\\n" %(h.tAln, h.match, parsePaperInfo(h.title)) )
            f.write("\\hline\n")