Exemplo n.º 1
0
def mkStartStopPlot(names, metaData, outPrefix):
    """metaData={name:({'S':metaStartSense,'AS':metaStartAS},{'S':metaStopSense,'AS':metaStopAS})}.
    Will plot sense above x=0, antisense below x=0, Start plot on left and Stop plot on right"""
    start = pyx.graph.graphxy(
        width=8,
        height=8,
        x=pyx.graph.axis.linear(min=-200,
                                max=200,
                                title='Position Relative to Start Codon'),
        y=pyx.graph.axis.linear(title='Normalized Read Density'))
    stop = pyx.graph.graphxy(width=8,
                             height=8,
                             xpos=start.width * 1.1,
                             key=pyx.graph.key.key(pos='tr'),
                             x=pyx.graph.axis.linear(
                                 min=-200,
                                 max=200,
                                 title='Position Relative to Stop Codon'),
                             y=pyx.graph.axis.linkedaxis(start.axes["y"]))

    for ii in range(len(names)):
        name = names[ii]
        metaStartSense = processMeta(metaData[name][0]['S'])
        start.plot(pyx.graph.data.points(metaStartSense, x=1, y=2),
                   [pyx.graph.style.line([common.colors(ii)])])
        metaStartAS = processMeta(metaData[name][0]['AS'], flip=1)
        start.plot(pyx.graph.data.points(metaStartAS, x=1, y=2),
                   [pyx.graph.style.line([common.colors(ii)])])

        metaStopSense = processMeta(metaData[name][1]['S'])
        stop.plot(pyx.graph.data.points(metaStopSense, x=1, y=2, title=name),
                  [pyx.graph.style.line([common.colors(ii)])])
        metaStopAS = processMeta(metaData[name][1]['AS'], flip=1)
        stop.plot(pyx.graph.data.points(metaStopAS, x=1, y=2, title=name),
                  [pyx.graph.style.line([common.colors(ii)])])

    c = pyx.canvas.canvas()
    c.insert(start)
    c.insert(stop)
    c.writePDFfile(outPrefix)
Exemplo n.º 2
0
async def original_writeups(link):
    """Get all the information about events along with
       link to original writeups

    :link: A URL to the tasks of a CTF

    :return: Information about the all the task along with URL
             to original writeups in tabulated form
    """
    spinner = Halo(text=colors("Grabing writeups", "32"),
                   spinner='moon',
                   color='green')
    spinner.start()

    info = []
    headers = ['S.no', 'Name', 'Points', 'tags', 'URL']
    soup = await make_soup(link)
    trs = soup.findAll('tr')

    # For getting tasks links
    for ind, tr in enumerate(trs[1:]):
        rated = {}
        gen = tr.text.split('\n')

        # Check if writeup exists or not
        if gen[-1] == str(0):
            tags = ','.join(gen[3:-2])
            info.append([ind, gen[0], gen[1], tags, "No writeups"])
            continue

        url = ROOT_URL + tr.find('a').get('href')
        soup = await make_soup(url)
        trs1 = soup.findAll('tr')

        # For getting "all" the writeups of one task
        for tr1 in trs1[1:]:
            para = soup.findAll('p')
            name = soup.find('h2').text
            point = para[0].text.split(':')[-1].strip()
            tags = para[1].text.split(':')[-1].split('\xa0')
            tags = ', '.join(i for i in tags[:-1])
            rated[tr1.find('a').get('href')] = tr1.find('div').text

        # Get writeup link which has the max rating.
        Link = await original_writeup_link(max(rated, key=rated.get))

        info.append([ind, name, point, tags, Link])

    table = tabulate(info, headers, tablefmt="fancy_grid")

    spinner.succeed("Voila!!")
    return table
Exemplo n.º 3
0
async def get_url(name):
    """Get URL of the specific event

    :name: Name of the CTF entered by user

    :return: A url of to the tasks of the CTF
            eg: https://ctftime.org/event/683/tasks/
    """

    spinner = Halo(text="Finding the URL", spinner="moon", color="red")
    spinner.start()
    past_ctfs = await past_events()
    ctfs = get_event(past_ctfs, name)

    if not ctfs:
        spinner.fail(colors("No CTF found", "32"))
        return

    if len(ctfs) != 1:
        spinner.stop()
        tables = [i["name"] for i in ctfs]
        question = [
            inquirer.List("choice",
                          message="Choose one from below?",
                          choices=tables)
        ]
        answer = inquirer.prompt(question)

        # Compare answer with name of CTF to get a link
        choice = list(filter(lambda ctf: ctf["name"] == answer["choice"],
                             ctfs))
        url = ROOT_URL + choice[0]["link"] + "/tasks/"
        return url

    spinner.succeed("Got it")
    return ROOT_URL + ctfs[0]["link"] + "/tasks/"