コード例 #1
0
def drawPieChart(val1):
    #To draw a pie chart
    val2 = 100 - val1
    chart = PieChart3D(250, 100)
    chart.add_data([val1, val2])
    chart.set_pie_labels(['Use', 'Not Use'])
    print '<img src="%s"></img></td>' % chart.get_url()
コード例 #2
0
ファイル: youtweet.py プロジェクト: varun5001/ZIA
def create_chart(tweet_dict):
# Calls to GoogleChart
    chart=PieChart3D(500,200)
    chart.add_data(tweet_dict.values())
    chart.set_colours(['282D8F'])
    chart.set_pie_labels(tweet_dict.keys())
    return chart.get_url()
コード例 #3
0
ファイル: GraphPie.py プロジェクト: cwt1/MAFA
def pie_google(data, output):
    from pygooglechart import PieChart3D
    chart = PieChart3D(750, 400)
    chart.add_data(data[1])
    chart.set_pie_labels(data[0])
    print chart.get_url()
    chart.download(output)
コード例 #4
0
 def post(self):
     value = self.request.get('slider')
      
     rec = getRecords(value,str(self.session.get("cid")))
     table = rec['records']
     sum = rec['sum']
     chart = PieChart3D(325, 100)
     categoryvalues = []
     for x in sum.values():
         if x : categoryvalues.append(x)
     chart.add_data(categoryvalues)
     
     # Assign the labels to the pie data
     categorykey=[]
     for x in sum.keys():
         if sum[x]: categorykey.append(x)
     chart.set_pie_labels(categorykey)
     
     totalSum = 0
     for x in sum.values():
         totalSum = totalSum + x
     
     # Print the chart URL
     pieURL =  chart.get_url()
     self.response.out.write(template.render('templates/analysisview/app.html',{
                                 'pieURL':pieURL,
                                 'descpie':'Relative Spendings',
                                 'desctable':'Category Wise Spendings',
                                 'total':totalSum,
                                 'table':table,
                                 }))       
コード例 #5
0
 def get_piechart_url(self):
     from pygooglechart import PieChart3D
     #import pdb
     #pdb.set_trace()
     answer_set = self.answer_set.all()
     chart = PieChart3D(500, 230)
     chart.add_data([a.votes for a in answer_set])
     chart.set_pie_labels([a.answer for a in answer_set])
     return chart.get_url()
コード例 #6
0
    def get(self):
        time1 = self.request.get('time')
        if time1 == 'today':
            sum = makeDailyPie(str(self.session.get("cid")))
            table = makeDailyTable(str(self.session.get("cid")))
            desctable ='All Spendings'
        if time1 == 'week':
            sum = makeWeekPie(str(self.session.get("cid")))
            table = []
            for x,y in sum.items():
                table.append(userDB(amount = str(y),category = str(x)))
            desctable = 'Category wise Spending'
        if time1 == 'month':
            sum = makeMonthPie(str(self.session.get("cid")))
            table = []
            for x,y in  sum.items():
                table.append(userDB(amount = str(y),category = str(x)))
            desctable = 'Category wise Spending'
        if time1 == 'year':
            sum = makeYearPie(str(self.session.get("cid")))
            table = []
            for x,y in sum.items():
                table.append(userDB(amount = str(y),category = str(x)))
            desctable = 'Category wise Spending'
        # Create a chart object of 250x100 pixels
        chart = PieChart3D(325, 100)

        # Add some data
        categoryvalues = []
        for x in sum.values():
            if x : categoryvalues.append(x)
        chart.add_data(categoryvalues)
        
        # Assign the labels to the pie data
        categorykey=[]
        for x in sum.keys():
            if sum[x]: categorykey.append(x)
        chart.set_pie_labels(categorykey)
        
        totalSum = 0
        for x in sum.values():
            totalSum = totalSum + x
        
        # Print the chart URL
        pieURL =  chart.get_url()
        self.response.out.write(template.render('templates/analysisview/app.html',{
                                    'pieURL':pieURL,
                                    'descpie':'Relative Spendings',
                                    'desctable':desctable,
                                    'total':totalSum,
                                    'table':table,
                                    }))       
コード例 #7
0
ファイル: month_breakdown.py プロジェクト: afh/pdfledger
def hello_world():

    # Create a chart object of 200x100 pixels
    chart = PieChart3D(250, 100)

    # Add some data
    chart.add_data([20, 10])

    # Assign the labels to the pie data
    chart.set_pie_labels(['Hello', 'World'])

    # Download the chart
    chart.download('pie-hello-world.png')
コード例 #8
0
def tipovidomejn_grafik():
    """Вкупно колку домејни има по типови"""

    c2 = conn.cursor()
    tipovi = {
        '.com.mk': 0,
        '.org.mk': 0,
        '.gov.mk': 0,
        '.name.mk': 0,
        '.net.mk': 0,
        '.inf.mk': 0,
        '.edu.mk': 0
    }

    vchera = (datetime.datetime.now() - datetime.timedelta(1)).date()

    # select count(distinct domen) from domaininfo where status = 'Y' //Broj na site domeni
    #
    c2.execute("select count(distinct domejn) from domejni where datum=?",
               (vchera.strftime("%Y-%m-%d"), ))
    vkupno = c2.fetchone()[0]

    ostanati = 0
    for tip, broj in tipovi.iteritems():
        c2.execute(
            "select count(distinct domejn) from domejni where datum=? and domejn like ?",
            (vchera.strftime("%Y-%m-%d"), '%%%s' % tip))
        tipovi[tip] = c2.fetchone()[0]
        ostanati += tipovi[tip]

    tipovi['.mk'] = vkupno - ostanati

    chart = PieChart3D(500, 200)
    chart.add_data([x for x in tipovi.itervalues()])
    chart.set_pie_labels([
        "%s (%s%%)" % (x, round(y * 100.0 / vkupno, 2))
        for x, y in tipovi.iteritems()
    ])

    chart.set_legend(["%s (%s)" % (x, y) for x, y in tipovi.iteritems()])
    chart.set_legend_position('b')
    chart.set_title("Вкупно %s .мк домени од кои:" % vkupno)

    return chart.get_url()
コード例 #9
0
    def buildPieChart3D(self, data, addValueToLabel=False, sortByKeys=False):
        chart = PieChart3D(self.defaultWidth, self.defaultHeight)

        labels = list()
        dataPoints = list()

        keys = sorted(data.keys()) if sortByKeys else data.keys()
        for key in keys:
            value = data[key]
            label = key

            if addValueToLabel: label += ' (' + str(value) + ')'

            labels.append(label)
            dataPoints.append(value)

        chart.add_data(dataPoints)
        chart.set_pie_labels(labels)

        return chart
コード例 #10
0
    def buildTagBuddiesChart(self, data):

        if len(data) > 5:
            data = data[:5]

        bars = list()
        labels = list()

        for value in data:
            bars.append(value[1])
            labels.append(value[0] + ' (' + str(value[1]) + ')')

        chart = PieChart3D(self.defaultWidth, self.defaultHeight)

        chart.add_data(bars)
        chart.set_pie_labels(labels)

        chart.set_title('TOP 5 Tag Buddies')

        return chart
コード例 #11
0
    def buildWallPostersChart(self, data):

        if len(data) > 5:
            data = data[:5]

        values = list()
        keys = list()

        for value in data:
            values.append(value[1])
            keys.append(value[0] + ' (' + str(value[1]) + ')')

        chart = PieChart3D(self.defaultWidth, self.defaultHeight)

        chart.add_data(values)
        chart.set_pie_labels(keys)

        chart.set_title('Top 5 People Posting on Your Wall')

        return chart
コード例 #12
0
    def buildTopRecordsPieChartFromSortedData(self, data, title):

        if len(data) > 5:
            data = data[:5]

        values = list()
        keys = list()

        for value in data:
            values.append(value[1])
            keys.append(
                self.removeNonAscii(value[0]) + ' (' + str(value[1]) + ')')

        chart = PieChart3D(self.defaultWidth, self.defaultHeight)

        chart.add_data(values)
        chart.set_pie_labels(keys)

        chart.set_title(title)

        return chart
コード例 #13
0
ファイル: views.py プロジェクト: tanveerahmad1517/myewb2
def group_membership_breakdown(request, group_slug):
    group = get_object_or_404(BaseGroup, slug=group_slug)

    statusBreakdownChart = PieChart3D(600, 240)
    allusers = group.member_users.all().count()
    regular = group.member_users.filter(
        memberprofile__membership_expiry__gt=date.today()).count()
    associate = group.get_accepted_members().count() - regular
    mlist = allusers - regular - associate

    statusBreakdownChart.add_data([
        mlist +
        1,  # FIXME: the +1 is needed so pygoogle doesn't crash (it doesn't handle zeroes well)
        associate + 1,
        regular + 1
    ])

    statusBreakdownChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    statusBreakdownChart.set_pie_labels(
        ["mailing list members", "associate members", "regular members"])
    return statusBreakdownChart.get_url()
コード例 #14
0
def stacked_vertical():
    total = Totals.get_or_insert('total')
    if len(total.shirts) == 0:
        shirts = sorted(T_Shirts, key=lambda shirt: shirt[0])
        for shirt in shirts:
            total.shirts.append(shirt[0])
            total.votes.append(0)

    votes = []
    shirts = []
    i = 0
    while i < len(total.votes):
        if total.votes[i] != 0:
            votes.append(total.votes[i])
            shirts.append('Design %s' % total.shirts[i])
        i += 1

    if len(votes) == 0:
        return ''

    chart = PieChart3D(650, 300)
    chart.add_data(votes)
    chart.set_pie_labels(shirts)
    return chart.get_url()
コード例 #15
0
ファイル: views.py プロジェクト: tanveerahmad1517/myewb2
def main_dashboard(request):

    today, created = DailyStats.objects.get_or_create(day=date.today())
    if today.users == 0:
        today.users = 1

    # ---- Daily usage ----
    enddate = date.today()
    #startdate = enddate - timedelta(weeks=60)
    startdate = enddate - timedelta(weeks=4)
    averageusage = DailyStats.objects.filter(
        day__range=(startdate, enddate)).order_by('day')
    days = []
    signins = []
    posts = []
    replies = []
    whiteboards = []
    signups = []
    listsignups = []
    listupgrades = []
    deletions = []
    numUsers = []
    numRegularMembers = []
    regupgrades = []
    renewals = []
    regdowngrades = []
    for s in averageusage:
        days.append(s.day.strftime("%B %y"))
        signins.append(s.signins)
        posts.append(s.posts)
        replies.append(s.replies)
        whiteboards.append(s.whiteboardEdits)
        signups.append(s.signups)
        listsignups.append(s.mailinglistsignups)
        listupgrades.append(s.mailinglistupgrades)
        deletions.append(s.deletions)
        numUsers.append(s.users)
        numRegularMembers.append(s.regularmembers)
        regupgrades.append(s.regupgrades)
        renewals.append(s.renewals)
        regdowngrades.append(s.regdowngrades)

    xaxis = []
    #for i in range(0, len(days), 1):    # this will make limited test data look better
    for i in range(0, len(days), len(days) / 8):
        xaxis.append(days[i])

    # ---- Daily usage ----
    dailyUsageChart = SimpleLineChart(600, 450, y_range=(0, max(signins)))
    #chart.add_data(avgsignins)
    dailyUsageChart.add_data(posts)
    dailyUsageChart.add_data(replies)
    dailyUsageChart.add_data(signins)
    dailyUsageChart.add_data(whiteboards)

    dailyUsageChart.set_colours(['ff0000', 'ffff00', '00ff00', '0000ff'])
    dailyUsageChart.set_legend(['posts', 'replies', 'signins', 'whiteboards'])
    dailyUsageChart.set_legend_position('b')

    #yaxis = range(0, max_signins + 1, 2)    # this will make limited test data look better
    yaxis = range(0, max(signins), max(signins) / 10)
    yaxis[0] = ''
    dailyUsageChart.set_axis_labels(Axis.LEFT, yaxis)
    dailyUsageChart.set_axis_labels(Axis.BOTTOM, xaxis)

    dailyUsage = dailyUsageChart.get_url()

    # ---- Account changes ----
    accountChangesChart = SimpleLineChart(600, 450, y_range=(0, 25))
    accountChangesChart.add_data(signups)
    accountChangesChart.add_data(listsignups)
    accountChangesChart.add_data(listupgrades)
    accountChangesChart.add_data(deletions)

    accountChangesChart.set_colours(['ff0000', 'ffff00', '00ff00', '0000ff'])
    accountChangesChart.set_legend(
        ['account signups', 'email signups', 'email upgrades', 'deletions'])
    accountChangesChart.set_legend_position('b')

    #yaxis = range(0, 25, 2)    # this will make limited test data look better
    yaxis = range(0, min(max(listsignups), 10), max(max(listsignups) / 10, 1))
    yaxis[0] = ''
    accountChangesChart.set_axis_labels(Axis.LEFT, yaxis)
    accountChangesChart.set_axis_labels(Axis.BOTTOM, xaxis)

    accountChanges = accountChangesChart.get_url()

    # ---- Membership ----
    membershipChart = SimpleLineChart(600, 450, y_range=(42000, 52000))
    membershipChart.add_data(numUsers)
    membershipChart.add_data(numRegularMembers)

    membershipChart.set_colours(['ff0000', '0000ff'])
    membershipChart.set_legend(['total users', 'regular members'])
    membershipChart.set_legend_position('b')

    yaxis = range(42000, 52000, 1000)
    yaxis[0] = ''
    yaxis2 = range(0, 1500, 50)
    yaxis2[0] = ''
    membershipChart.set_axis_labels(Axis.LEFT, yaxis)
    membershipChart.set_axis_labels(Axis.RIGHT, yaxis2)
    membershipChart.set_axis_labels(Axis.BOTTOM, xaxis)

    membershipChart = membershipChart.get_url()

    # ---- Account changes ----
    membershipChangesChart = SimpleLineChart(600, 450, y_range=(0, 10))
    membershipChangesChart.add_data(regupgrades)
    membershipChangesChart.add_data(renewals)
    membershipChangesChart.add_data(regdowngrades)

    membershipChangesChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    membershipChangesChart.set_legend(
        ['regular upgrades', 'renewals', 'regular downgrades'])
    membershipChangesChart.set_legend_position('b')

    #yaxis = range(0, 25, 2)    # the same.
    yaxis = range(
        0, max(max(regupgrades), max(regdowngrades), max(renewals)),
        max(max(max(regupgrades), max(regdowngrades), max(renewals)) / 10, 1))
    yaxis[0] = ''
    membershipChangesChart.set_axis_labels(Axis.LEFT, yaxis)
    membershipChangesChart.set_axis_labels(Axis.BOTTOM, xaxis)

    membershipChanges = membershipChangesChart.get_url()

    # ---- Status breakdown ----
    statusBreakdownChart = PieChart3D(600, 240)
    mlistmembers = today.users - today.regularmembers - today.associatemembers
    statusBreakdownChart.add_data([
        mlistmembers +
        1,  # FIXME: the +1 is needed so pygoogle doesn't crash (it doesn't handle zeroes well)
        today.associatemembers + 1,
        today.regularmembers + 1
    ])

    statusBreakdownChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    statusBreakdownChart.set_pie_labels(
        ["mailing list members", "associate members", "regular members"])
    statusBreakdown = statusBreakdownChart.get_url()

    # ---- Membership breakdown ----
    chapters = Network.objects.filter(chapter_info__isnull=False,
                                      is_active=True)
    chapternames = []
    chaptermembers = []
    for chapter in chapters:
        chapternames.append(chapter.slug)
        chaptermembers.append(chapter.members.all().count())

    membershipBreakdownChart = StackedHorizontalBarChart(
        500, 500, x_range=(0, max(chaptermembers)))
    membershipBreakdownChart.add_data(chaptermembers)
    yaxis = range(0, max(chaptermembers), 10)
    yaxis[0] = ''
    membershipBreakdownChart.set_axis_labels(Axis.BOTTOM, yaxis)
    membershipBreakdownChart.set_axis_labels(Axis.LEFT, chapternames)
    membershipBreakdownChart.set_bar_width(330 / len(chapternames))
    membershipBreakdown = membershipBreakdownChart.get_url()

    # ---- Province breakdown ----
    profiletype = ContentType.objects.get_for_model(MemberProfile)
    addresses = Address.objects.filter(content_type=profiletype)
    totalprov = Address.objects.filter(
        content_type=profiletype).count() + 1  # FIXME

    provinces = []
    provincecount = []
    provincelist = list(pycountry.subdivisions.get(country_code='CA'))
    for p in provincelist:
        pcode = p.code.split('-')[1]
        provincecount2 = Address.objects.filter(content_type=profiletype,
                                                province=pcode).count()
        if provincecount2 == 0:
            provincecount2 = 1
        provincecount.append(provincecount2)
        provinces.append(pcode + " (%d%%)" %
                         (provincecount2 * 100 / totalprov))
    #provinces = sorted(provinces)

    provinceBreakdownChart = PieChart3D(600, 240)
    provinceBreakdownChart.add_data(provincecount)

    #provinceBreakdownChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    provinceBreakdownChart.set_pie_labels(provinces)
    provinceBreakdown = provinceBreakdownChart.get_url()

    # ---- Gender breakdown ----
    males = MemberProfile.objects.filter(gender='M').count() + 1
    females = MemberProfile.objects.filter(gender='F').count() + 1
    genderunknown = MemberProfile.objects.filter(
        gender__isnull=True).count() + 1  #FIXME
    gendertotal = males + females + genderunknown
    genderBreakdownChart = PieChart3D(600, 240)
    genderBreakdownChart.add_data([males, females, genderunknown])

    genderBreakdownChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    genderBreakdownChart.set_pie_labels([
        'Male (%d%%)' % (males * 100 / gendertotal),
        'Female (%d%%)' % (females * 100 / gendertotal),
        'Unspecified (%d%%)' % (genderunknown * 100 / gendertotal)
    ])
    genderBreakdown = genderBreakdownChart.get_url()

    # ---- Student breakdown ----
    students = User.objects.filter(
        studentrecord__graduation_date__isnull=True).count() + 1
    nonstudents = User.objects.filter(
        workrecord__end_date__isnull=True).count() + 1
    # yeah, i know, not 100% accurate since a student can have a part-time job
    studentBreakdownChart = PieChart3D(600, 240)
    studentBreakdownChart.add_data([students, nonstudents])

    studentBreakdownChart.set_colours(['ff0000', '00ff00'])
    studentBreakdownChart.set_pie_labels(['Students', 'Non-students'])
    studentBreakdown = studentBreakdownChart.get_url()

    # ---- Language breakdown ----
    preferen = MemberProfile.objects.filter(language='E').count() + 1
    preferfr = MemberProfile.objects.filter(language='F').count() + 1
    prefernone = MemberProfile.objects.filter(
        language__isnull=True).count() + 1
    languageBreakdownChart = PieChart3D(600, 240)
    languageBreakdownChart.add_data([preferen, preferfr, prefernone])

    languageBreakdownChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    languageBreakdownChart.set_pie_labels(
        ['english', 'french', 'not specified'])
    languageBreakdown = languageBreakdownChart.get_url()

    # ---- Post breakdown ----
    postspublic = GroupTopic.objects.filter(
        parent_group__visibility='E',
        parent_group__parent__isnull=True).count() + 1
    postsprivate = GroupTopic.objects.filter(
        parent_group__parent__isnull=True).exclude(
            parent_group__visibility='E').count() + 1
    postspublicchapter = GroupTopic.objects.filter(
        parent_group__visibility='E',
        parent_group__parent__isnull=False).count() + 1
    postsprivatechapter = GroupTopic.objects.filter(
        parent_group__parent__isnull=False).exclude(
            parent_group__visibility='E').count() + 1
    postcount = postspublic + postsprivate + postspublicchapter + postsprivatechapter
    postBreakdownChart = PieChart3D(600, 240)
    postBreakdownChart.add_data(
        [postspublic, postspublicchapter, postsprivatechapter, postsprivate])

    #postBreakdownChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    postBreakdownChart.set_pie_labels(
        ['public', 'public chapter', 'private chapter', 'private'])
    postBreakdown = postBreakdownChart.get_url()

    # ---- Login distribution ----
    logincount = []
    malelogins = []
    femalelogins = []
    for i in range(0, 30):
        logincount.append(
            MemberProfile.objects.filter(login_count__gte=i).count())
        malelogins.append(
            MemberProfile.objects.filter(login_count__gte=i,
                                         gender='M').count())
        femalelogins.append(
            MemberProfile.objects.filter(login_count__gte=i,
                                         gender='F').count())

    loginDistribution = SimpleLineChart(600, 450, y_range=(0, 9000))
    loginDistribution.add_data(logincount)
    loginDistribution.add_data(malelogins)
    loginDistribution.add_data(femalelogins)

    loginDistribution.set_colours(['ff0000', '0000ff', '00ff00'])
    loginDistribution.set_legend(['logins', 'male', 'female'])
    loginDistribution.set_legend_position('b')

    yaxis = range(
        0, 9000,
        500)  # that last number should be 25 or 50.  but for testing...
    yaxis[0] = ''
    loginDistribution.set_axis_labels(Axis.LEFT, yaxis)
    loginDistribution.set_axis_labels(Axis.BOTTOM, range(0, 30))

    loginDistribution = loginDistribution.get_url()

    # ---- Login recency ----
    loginrecent = []
    loginrecentdate = []
    thedate = date(date.today().year - 1, date.today().month, 1)
    skip = False
    while thedate.year != date.today().year or thedate.month != date.today(
    ).month:
        if thedate.month == 12:
            enddate = date(year=thedate.year + 1, month=1, day=1)
        else:
            enddate = date(year=thedate.year, month=thedate.month + 1, day=1)
        loginrecent.append(
            MemberProfile.objects.filter(
                previous_login__range=(thedate, enddate)).count())
        if not skip:
            loginrecentdate.append(thedate.strftime("%B %y"))
        else:
            loginrecentdate.append("")
        skip = not skip
        thedate = enddate

    loginRecency = SimpleLineChart(600, 450, y_range=(0, max(loginrecent) + 1))
    loginRecency.add_data(loginrecent)

    yaxis = range(0, max(loginrecent), max(
        max(loginrecent) / 10,
        1))  # that last number should be 25 or 50.  but for testing...
    if len(yaxis) == 0:
        yaxis.append(10)
        yaxis.append(10)
    yaxis[0] = ''
    loginRecency.set_axis_labels(Axis.LEFT, yaxis)
    loginRecency.set_axis_labels(Axis.BOTTOM, loginrecentdate)

    loginRecency = loginRecency.get_url()

    # ---- Age distribution ----
    ages = []
    for age in range(15, 75):
        year = date.today().year - age
        ages.append(
            MemberProfile.objects.filter(date_of_birth__year=year).count())

    ageDistribution = SimpleLineChart(600, 450, y_range=(0, max(ages) + 1))
    ageDistribution.add_data(ages)

    yaxis = range(0, max(ages) + 1, 50)
    yaxis[0] = ''
    ageDistribution.set_axis_labels(Axis.LEFT, yaxis)
    ageDistribution.set_axis_labels(Axis.BOTTOM, range(15, 75, 5))

    ageDistribution = ageDistribution.get_url()

    # ---- Finally! ----
    return render_to_response(
        "stats/dashboard.html", {
            "signins": today.signins,
            "posts": today.posts,
            "replies": today.replies,
            "signups": today.signups,
            "listsignups": today.mailinglistsignups,
            "listupgrades": today.mailinglistupgrades,
            "deletions": today.deletions,
            "regupgrades": today.regupgrades,
            "regdowngrades": today.regdowngrades,
            "renewals": today.renewals,
            "totalusers": today.users,
            "dailyUsage": dailyUsage,
            "accountChanges": accountChanges,
            "membershipChart": membershipChart,
            "membershipChanges": membershipChanges,
            "statusBreakdown": statusBreakdown,
            "mlistmembers": mlistmembers,
            "mlistmemberspercent": mlistmembers * 100 / today.users,
            "associatemembers": today.associatemembers,
            "associatememberspercent":
            today.associatemembers * 100 / today.users,
            "regularmembers": today.regularmembers,
            "regularmemberspercent": today.regularmembers * 100 / today.users,
            "membershipBreakdown": membershipBreakdown,
            "provinceBreakdown": provinceBreakdown,
            "provincecount": totalprov,
            "genderBreakdown": genderBreakdown,
            "studentBreakdown": studentBreakdown,
            "languageBreakdown": languageBreakdown,
            "postBreakdown": postBreakdown,
            "loginDistribution": loginDistribution,
            "loginRecency": loginRecency,
            "ageDistribution": ageDistribution
        },
        context_instance=RequestContext(request))
コード例 #16
0
def python_pie3D():
    chart = PieChart3D(250, 250)
    chart.add_data([100, 200, 250, 500, 900])
    chart.set_pie_labels("Anuj Sid Nikunj Kardam Maru".split())
    print chart.get_url()
    chart.download("hisab.png")
コード例 #17
0
        large_digit = sorted(number, reverse=True)
        small_combained = int(''.join(small_digit))
        large_combained = int(''.join(large_digit))
        kc = large_combained - small_combained
        number = map(lambda x: x, str(kc).zfill(4))
        iter = iter + 1
    fd[x] = iter
for k, v in fd.iteritems():
    print k,
    print 'takes',
    print v,
    print 'iterations to reach 6174'
    gm.append(v)
sm = (Counter(gm).items())
sm = sorted(sm)
print 'Iteration 	Total Count of Numbers'
for i in range(len(sm)):
    xx.append(str(sm[i][0]) + ' iterations')
    yy.append(sm[i][1])
    print sm[i][0],  #printing the no. of iterations
    print '\t\t',
    print sm[i][1]
#creating graph
chart = PieChart3D(500, 200)
chart.add_data(yy)
chart.set_pie_labels(xx)
chart.download('iter_pie_chart.png')
webbrowser.open(
    'iter_pie_chart.png', new=0
)  #Displays the graph in default browser appropriate to the callers environment.
raw_input("Press Enter to continue...")
コード例 #18
0
ファイル: create_summary.py プロジェクト: omsai/metAMOS
def create_summary(first, amosbnk, prefix, ref_asm, utils, img, rund, nLibs,
                   taxa_level, dbdir):
    #if __name__ == "__main__":
    #    if len(sys.argv) < 5:
    #        print "usage: create_report.py <metaphyler tab file> <AMOS bnk> <output prefix> <ref_asm> <Utils dir> <run dir> <# of libs> <taxa level of classifications>"
    #        sys.exit(0)

    html_prefix = prefix
    prefix = prefix.replace("/html/", "")
    MA_dir = prefix
    MA_dir = MA_dir.replace("/Postprocess/out", "")
    mp = open(first, 'r')
    #mp2 = open(sys.argv[1].replace("s12","s3"),'r')

    # set working dir
    os.chdir(html_prefix)

    if not os.path.exists(html_prefix + "asmstats.out"):
        libPath = rund.rsplit(os.sep, 1)[0] + os.sep + rund.rsplit(
            os.sep, 1)[-1].replace("bin", "lib")
        #print "perl -I %s %s/perl/statistics.pl %s > %sasmstats.out"%(libPath,utils,ref_asm,html_prefix)
        run_process(
            _settings, "perl -I %s %s/perl/statistics.pl %s > %sasmstats.out" %
            (libPath, utils, ref_asm, html_prefix), "Postprocess")
    report = open(html_prefix + "asmstats.out", 'r')

    initialStep = "Classify"

    # get metamos version
    version = "1.0"
    summary = open("%s/pipeline.run" % (MA_dir), 'r')
    for line in summary:
        line = line.replace("\n", "")
        if "#" in line:
            continue
        elif "metAMOS Version:" in line:
            version = line.replace("\n", "").split("\t")[-1]
    summary.close()

    steps = []
    steps.append("Preprocess")
    steps.append("Assemble")
    steps.append("MapReads")
    steps.append("Validate")
    #steps.append("MultiAlign")
    steps.append("FindORFS")
    steps.append("FindRepeats")
    steps.append("Scaffold")
    steps.append("FindScaffoldORFS")
    steps.append("Abundance")
    steps.append("Classify")
    steps.append("FunctionalAnnotation")
    steps.append("Propagate")
    steps.append("Bin")
    steps.append("Browse Results")

    step_status = {}
    step_status["Preprocess"] = "OK"
    step_status["Assemble"] = "OK"
    step_status["MapReads"] = "OK"
    step_status["Validate"] = "OK"
    #step_status["MultiAlign"] = "OK"
    step_status["FindORFS"] = "OK"
    step_status["FindRepeats"] = "OK"
    step_status["Scaffold"] = "OK"
    step_status["FindScaffoldORFS"] = "OK"
    step_status["Abundance"] = "FAIL"
    step_status["Classify"] = "FAIL"
    step_status["FunctionalAnnotation"] = "FAIL"
    step_status["Propagate"] = "NONE"
    step_status["Bin"] = "NONE"
    step_status["Browse Results"] = "OK"
    ##get status of each step from Log dir
    for step in steps:
        if step == "Browse Results":
            continue
        stepn = step.lower()
        started = False
        completed = False
        skipped = False
        if os.path.exists("%s/Logs/%s.started" % (MA_dir, stepn)):
            started = True
        if os.path.exists("%s/Logs/%s.ok" % (MA_dir, stepn)):
            completed = True
        if os.path.exists("%s/Logs/%s.skip" % (MA_dir, stepn)):
            skipped = True
        if completed and not skipped:
            step_status[step] = "OK"
        elif skipped:
            step_status[step] = "SKIP"
        elif started and not completed:
            step_status[step] = "FAIL"
        elif not started:
            step_status[step] = "NONE"
        else:
            step_status[step] = "NONE"

    #+male1  /cbcb/project-scratch/sergek/metAMOS/individualAsms/m1_asm      proba   b-      metaphyler=1
    ## call Dan's script, for now on a single sample/run
    cpfile = open("%s/plot.tab" % (html_prefix), 'w')
    cpfile.write("+sample1\t%s\tproba\tb-\tmetaphyler=1\n" % (MA_dir))
    cpfile.close()
    #os.system("python %s/python/create_plots.py %s/plot.tab proba1"%(utils,html_prefix))
    if _havePlots:
        create_plots("%s/plot.tab" % (html_prefix), "%s" % ("proba1"))

    ##update counts
    #count reads
    os.system(
        "cat `ls %s/Preprocess/out/* |egrep 'lib[0-9]*\.fasta$'` | grep -c \">\" > readcount.txt"
        % (MA_dir))
    readcount = open("readcount.txt", 'r').read().replace("\n", "")
    #print readcount
    os.system("rm readcount.txt")
    #count contigs
    os.system(
        "grep -c \">\" %s/Assemble/out/proba.asm.contig > contigcount.txt" %
        (MA_dir))
    contigcount = open("contigcount.txt", 'r').read().replace("\n", "")
    #print contigcount
    os.system("rm contigcount.txt")
    #count scaffolds
    os.system(
        "grep -c \">\" %s/Scaffold/out/proba.scaffolds.final > scafcount.txt" %
        (MA_dir))
    scaffoldcount = open("scafcount.txt", 'r').read().replace("\n", "")
    #print scaffoldcount
    os.system("rm scafcount.txt")
    #count scaffolds
    os.system("grep -c \">\" %s/Scaffold/out/proba.motifs > motifcount.txt" %
              (MA_dir))
    motifcount = open("motifcount.txt", 'r').read().replace("\n", "")
    #print motifcount
    os.system("rm motifcount.txt")
    #count ORFs
    os.system("grep -c \">\" %s/FindORFS/out/proba.fna > orfcount.txt" %
              (MA_dir))
    orfcount = open("orfcount.txt", 'r').read().replace("\n", "")
    #print orfcount
    os.system("rm orfcount.txt")
    ##copy stuff
    for step in steps:
        #        step = step.lower()
        if os.path.exists("%s/javascript/%s.html" % (utils, step)):
            os.system("cp %s/javascript/%s.html %s/" %
                      (utils, step, html_prefix))
    os.system("cp %s/Logs/COMMANDS.log %s/pipeline.commands" %
              (MA_dir, html_prefix))
    os.system("cp %s/pipeline.run %s/pipeline.summary" % (MA_dir, html_prefix))
    os.system("cp %s/javascript/style.css %s/" %
              (utils, html_prefix))  # TEMP: change back to cp
    os.system("cp -r %s/../KronaTools/src %s/../KronaTools/img %s/" %
              (utils, utils, html_prefix))  # TODO: unhack KronaTools path
    #    os.system("cp %s/blocks.jpg %s/"%(img,html_prefix))
    #    os.system("cp %s/blocks_small.jpg %s/"%(img,html_prefix))
    os.system("cp %s/blocks_dark_tiny.png %s/" % (img, html_prefix))
    os.system("cp %s/name.png %s/" % (img, html_prefix))

    # generate dynamic java scripts
    # first classify and propagate
    #os.system("python %s/python/get_classify_stats.py %s/propagate.in.clusters %s/propagate.out.clusters %s/DB/tax_key.tab %s Classify.html Propagate.html %s"%(utils, html_prefix, html_prefix, utils, html_prefix, taxa_level))
    get_classify_stats("%s/propagate.in.clusters" % (html_prefix),
                       "%s/propagate.out.clusters" % (html_prefix),
                       "%s/tax_key.tab" % (dbdir), "%s" % (html_prefix),
                       "Bin.html", "Propagate.html", "%s" % (taxa_level))

    # generate preprocess
    preprocess = markup.page()
    preprocess.init(css="style.css")  #bodyattrs={'style':"margin:0px"})
    preprocess.p()

    nQC = 0
    for i in range(1, nLibs + 1):
        if os.path.exists("%s/lib%d.1.fastqc/fastqc_report.html" %
                          (html_prefix, i)):
            nQC = nQC + 1

    summary = open("%s/pipeline.ini" % (MA_dir), 'r')
    libcnt = 1
    format = None
    mmin = 0
    mmax = 0
    mated = False
    interleaved = False
    innie = False
    linkerType = ""
    libadded = False
    firstLib = True
    headerArray = []
    dataArray = []
    for line in summary:
        line = line.replace("\n", "")
        if "#" in line:
            continue
        elif "asmcontigs:" in line:
            asmc = line.replace("\n", "").split("\t")[-1]
            if len(asmc) <= 2:
                continue
            preprocess.add(
                "<div class=\"datagrid\">Pre-assembled contigs input: %s</div>"
                % (asmc))
            preprocess.br()
        elif "format:" in line:
            if format and not libadded:
                outputLibraryInfo(headerArray, dataArray, firstLib, libcnt,
                                  format, mated, interleaved, mmin, mmax,
                                  nQC > 0)
                libcnt += 1
            libadded = False
            format = line.replace("\n", "").split("\t")[-1]
        elif "mated:" in line:
            mated = str2bool(line.replace("\n", "").split("\t")[-1])
        elif "innie:" in line:
            innie = str2bool(line.replace("\n", "").split("\t")[-1])
        elif "linker:" in line:
            linkerType = line.replace("\n", "").split("\t")[-1]
        elif "interleaved:" in line:
            interleaved = str2bool(line.replace("\n", "").split("\t")[-1])
        elif "f1:" in line:
            data = line.split("\t")

            inf = data[1].split(",")
            mmin = int(inf[1])
            mmax = int(inf[2])
        elif "f2:" in line:
            data = line.split("\t")

            inf = data[1].split(",")
            mmin = int(inf[1])
            mmax = int(inf[2])

        elif "frg" in line:
            data = line.split("\t")
    if format and not libadded:
        outputLibraryInfo(headerArray, dataArray, firstLib, libcnt, format,
                          mated, interleaved, mmin, mmax, nQC > 0)
    preprocess.add(getTable(headerArray, dataArray))
    summary.close()

    if os.path.exists("%s/Postprocess/out/html/kmergenie_report.html" %
                      (MA_dir)):
        preprocess.iframe(id_="KmerGenie",
                          src_="kmergenie_report.html",
                          width="800",
                          height="5000")

    preprocess_out = open("%s/Preprocess.html" % (html_prefix), 'w')
    preprocess_out.write(preprocess.__str__())
    preprocess_out.close()

    validate_out = open("%s/Validate.html" % (html_prefix), 'w')
    validate = markup.page()
    validate.init(css="style.css",
                  bodyattrs={'style': "background-color:#FFFFFF;"})
    headerArray = []
    dataArray = []
    firstScore = True
    bestAsm = ""
    refs = []
    if os.path.exists("%s/Postprocess/out/asm.scores" % (MA_dir)):
        best = open("%s/Postprocess/out/best.asm" % (MA_dir), 'r')
        bestAsm = best.read()
        best.close()
        laps = open("%s/Postprocess/out/asm.scores" % (MA_dir), 'r')
        validate.p()
        validate.add("<div class=\"datagrid\">")
        validate.add("Selected assembler: %s" % (bestAsm))
        ref = open("%s/Postprocess/out/ref.name" % (MA_dir), 'r')
        first = True
        for r in ref.xreadlines():
            refs.append(r)
            if first:
                validate.br()
                first = False
            validate.add("Selected reference: %s" % (r))
        ref.close()
        if os.path.exists("%s/Bin/out/contaminant.true" % (MA_dir)):
            cont = open("%s/Bin/out/contaminant.true" % (MA_dir), 'r')
            contPercent = cont.read().split()
            cont.close()
            validate.br()
            validate.add(
                "<b>Sample may have contaminants, only %s%% contigs/reads >%sbp assigned to %s. Check Classify output</b>"
                % (contPercent[0], contPercent[2], contPercent[1]))
        validate.br()
        for line in laps:
            line = line.replace("\n", "")
            if "#" in line:
                continue
            else:
                res = line.split("\t")
                outputValidate(headerArray, dataArray, firstScore, bestAsm,
                               res)
                firstScore = False
        validate.add(getTable(headerArray, dataArray))
        validate.add("</div>")
        laps.close()

    # when we have quast, we will add our table to their report, otherwise write standalone report
    if os.path.exists(
            "%s/Postprocess/out/html/quast/combined_quast_output/report.html" %
        (MA_dir)):
        os.system(
            "cp %s/Postprocess/out/html/quast/combined_quast_output/report.html %s/Postprocess/out/html/quast/combined_quast_output/~report.html"
            % (MA_dir, MA_dir))
        quastIn = open(
            "%s/Postprocess/out/html/quast/combined_quast_output/~report.html"
            % (MA_dir), 'r')
        quastOut = open(
            "%s/Postprocess/out/html/quast/combined_quast_output/report.html" %
            (MA_dir), 'w')
        skip = False
        output = False
        for line in quastIn.xreadlines():
            if not skip:
                quastOut.write(line.strip().replace("<br>", "") + "\n")
            elif output:
                quastOut.write("margin-left: 50px;\n")
                quastOut.write("padding-top: 10px;\n")
                quastOut.write("background: #ffffff;\n")
                output = False

            if ".content" in line:
                skip = True
                output = True
            elif "clear:" in line:
                quastOut.write(line.strip() + "\n")
                skip = False
                output = False
        quastIn.close()
        quastOut.close()
        validate.iframe(id_="quast",
                        src_="quast/combined_quast_output/report.html",
                        width="800",
                        height="1000")
    validate_out.write(validate.__str__())
    validate_out.close()

    # multialign step
    treeScripts = {}
    treeScripts[
        "http://www.jsphylosvg.com/js/jquery/jquery-1.4.2.min.js"] = "javascript"
    treeScripts[
        "http://www.jsphylosvg.com/js/jquery/jquery.simplemodal.1.4.1.min.js"] = "javascript"
    treeScripts[
        "http://www.jsphylosvg.com/js/raphael/raphael-min.js"] = "javascript"
    treeScripts[
        "http://www.jsphylosvg.com/js/jsphylosvg-min.js?1.29"] = "javascript"
    treeScripts[
        "http://www.jsphylosvg.com/js/unitip/js/unitip.js"] = "javascript"

    treeScript = []
    treeScript.append("<script type=\"text/javascript\">")
    treeScript.append(
        "   var dataObject = { newick: '(M_canettii_CIPT_d:0.059437,(M_canettii_CIPT_e:0.07845,((((M_africanum_GM04118:0.00646,(M_bovis_AF2122_97:0.00269,(M_bovis_BCG_Tokyo_1:0.00013,((M_bovis_BCG_Korea_1:0.0,M_bovis_BCG_Pasteur:0.0):0.00014,M_bovis_BCG_Mexico:0.00013):0.00014):0.00294):0.00514):0.00207,(((MTBC_Beijing_NITR20:0.00914,(MTBC_CCDC5180:0.00102,(MTBC_CCDC5079:0.00423,MTBC_CCDC5079:0.00014):0.00078):0.00016):0.00368,((((MTBC_Erdman_ATCC_35:0.00075,MTBC:0.00123):0.00129,(MTBC_CDC1551:0.00245,MTBC_Haarlem3_NITR2:0.01398):0.00093):0.00065,((((MTBC_CTRI_2:0.001,(MTBC_KZN_4207:0.00014,(MTBC_KZN_605:0.00012,MTBC_KZN_1435:0.00014):0.00012):0.00071):0.00061,(MTBC_RGTB327:0.00462,MTBC_UT205:0.0012):0.00037):0.00014,MTBC_F11:0.00158):0.00109,(MTBC_H37Ra:0.00016,(MTBC_H37Rv:0.00028,MTBC_H37Rv:0.00014):0.00014):0.00281):0.00047):0.00112,MTBC_CAS_NITR204:0.009827):0.00022):0.00247,((MTBC_EAI5:0.0023,MTBC_EAI5_NITR206:0.00933):0.0035,(MTBC_RGTB423:0.00868,spades.45.asm.contig:0.0035):0.00066):0.00289):0.00015):0.07224,(M_canettii_CIPT_a:0.01891,M_canettii_CIPT_b:0.05096):0.03720):0.03909,M_canettii_CIPT_c:0.056869):0.00469):0.02099);' };"
    )
    treeScript.append("   function load() {")
    treeScript.append("      var divVal = $('#svgCanvas').empty();")
    treeScript.append(
        "      var isCircular = $('#circularize-value')[0].value;")
    treeScript.append(
        "      Smits.PhyloCanvas.Render.Parameters.Rectangular.bufferX = 150;")
    treeScript.append(
        "      Smits.PhyloCanvas.Render.Parameters.Circular.bufferRadius = 0.35;"
    )
    treeScript.append(
        "      Smits.PhyloCanvas.Render.Style.line.stroke = 'rgb(0,0,255)';")
    treeScript.append(
        "      Smits.PhyloCanvas.Render.Style.text[\"font-size\"] = 10;")
    treeScript.append("      if (isCircular.toLowerCase() == 'true') {")
    treeScript.append("         phylocanvas = new Smits.PhyloCanvas(")
    treeScript.append("                                         dataObject,")
    treeScript.append("                                         'svgCanvas',")
    treeScript.append(
        "                                          1000, 1000, 'circular'")
    treeScript.append("                                         );")
    treeScript.append("         $('#circularize-value')[0].value = 'false';")
    treeScript.append("      } else {")
    treeScript.append("         phylocanvas = new Smits.PhyloCanvas(")
    treeScript.append("                                         dataObject,")
    treeScript.append("                                         'svgCanvas',")
    treeScript.append("                                          500, 500")
    treeScript.append("                                         );")
    treeScript.append("         $('#circularize-value')[0].value = 'true';")
    treeScript.append("      }")
    treeScript.append("      init();")
    treeScript.append("   }")
    treeScript.append("function snapshot() {")
    treeScript.append("      var svgSource = phylocanvas.getSvgSource();")
    treeScript.append("      if(svgSource) {")
    treeScript.append("         var url = 'data:image/svg+xml,' + svgSource")
    treeScript.append("         window.open(url);")
    treeScript.append("      }")
    treeScript.append("   }")
    treeScript.append("</script>")
    treeBody = {}
    treeBody["onload"] = "load()"

    maStep = markup.page()
    maStep.add("\n".join(treeScript))
    maStep.init(
        css=("http://www.jsphylosvg.com//js/yui/build/cssfonts/fonts-min.css",
             "http://www.jsphylosvg.com/js/unitip/css/unitip.css"),
        script=treeScripts,
        bodyattrs=treeBody)
    maStep.div()
    maStep.add(
        "<input type=\"button\" id=\"download-link\" onclick=\"snapshot()\" value=\"Snapshot\" />"
    )
    maStep.div.close()
    maStep.div()
    maStep.add(
        "<input type=\"button\" id=\"circularize-link\" onclick=\"load()\" value=\"Toggle Circular\" />"
    )
    maStep.add(
        "<input type=\"hidden\" id=\"circularize-value\" value=\"false\">")
    maStep.div.close()
    maStep.div(id_="svgCanvas")
    maStep.div.close()
    maStep_out = open("%s/MultiAlign.html" % (html_prefix), 'w')
    maStep_out.write(maStep.__str__())
    maStep_out.close()

    # todo, need to add report for MapReads including # reads mapped (%), contig coverage histogram, and % reads between contigs and number of links histogram. Also re-estimated insert sizes for each lib
    #mapreads = markup.page()
    #mapreads.init(bodyattrs={'style':"margin:0px"})
    #mapreads.img(src_="hist_ctgcvg.png",height_="100%",width_="100%")
    #mapreads_out = open("%s/MapReads.html"%(html_prefix), 'w')
    #mapreads_out.write(mapreads.__str__())

    ##This will create ScaffoldSizes.png,ContigSizes.png

    ##create code to automatically generate .js files for HTML report
    ## let's start with Abundance
    #abundance_js = open(html_prefix+"abundance.js",'w')

    rdata = []
    for line in report:
        rdata.append(line)

    if not os.path.exists(html_prefix + "covstats.out"):
        run_process(
            _settings, "%s/analyze-read-depth -x 2 %s > %scovstats.out" %
            (rund, amosbnk, html_prefix), "Postprocess")
    ff = open(html_prefix + "covstats.out", 'r')
    covdata = []
    #covdata = ff.readlines()
    #zflag = 0
    for line in ff:
        covdata.append(line)

    if not os.path.exists(html_prefix + "stats.out"):
        if os.path.getsize("%s/Assemble/out/proba.asm.contig" % (MA_dir)) == 0:
            run_process(_settings, "touch %sstats.out" % (html_prefix),
                        "Postprocess")
        else:
            #os.system("%s/astats %s > %sstats.out"%(rund,amosbnk,html_prefix))
            run_process(
                _settings,
                "%s/astats %s > %sstats.out" % (rund, amosbnk, html_prefix),
                "Postprocess")
    dd = open(html_prefix + "stats.out", 'r')
    ddata = dd.readlines()

    ddf = ""
    bflag = 0
    cflag = 0
    rflag = 0
    for line in ddata:
        if "<body>" in line:
            bflag = 1
            ddf += "<table border=\"1\">"
        elif "[Contigs]" in line:
            cflag = 1
            ddf += line
        elif "[Small" in line:
            cflag = 0
        elif "[Big" in line:
            cflag = 0
        elif "[Reads]" in line:
            rflag = 1
            ddf += line
        elif cflag != 0 or rflag != 0:
            if "N50" not in line:
                ddf += line
        else:
            continue
    mp.readline()
    cov = []
    abund = []
    ids = []
    mpd = mp.readlines()
    phylum = False
    for line in mpd:
        if ">phylum" in line:
            phylum = True
        if len(line) < 3:
            continue
        data = line.split("\t")
        if len(data) < 2:
            continue
        if not phylum:
            continue
        ids.append(data[0])
        #cov.append(int(float(data[2])))
        abund.append(100 * float(data[1]))

    # Create a chart object of 200x100 pixels
#    chart2 = StackedVerticalBarChart(600, 300)
    chart2 = PieChart3D(550, 300)

    chart2.set_colours(["0A8C8A", "EBB671", "DE091A"])
    # Add some data
    chart2.add_data(abund)
    #    chart2.add_data(abund2)

    # Assign the labels to the pie data
    chart2.set_pie_labels(ids)
    #    chart2.set_axis_labels(Axis.BOTTOM, ids)

    # Download the chart
    try:
        chart2.download(html_prefix + 'abund.png')
    except:
        print "Warning: could not download abund.png"

    chart = GroupedHorizontalBarChart(600, 500, x_range=(0, 100))
    chart.set_bar_width(30)
    chart.set_colours(("FF0000", "0000FF"))
    #chart.set_colours_within_series(("FF0000","FF7F00","FFFF00","00FF00","0000FF","8B00FF","FFFFFF"))

    #    chart.set_colours(['00ff00', 'ff0000'])
    chart.add_data(abund)
    #chart.add_data(abund2)
    #chart.add_data([1,4,9,16,25])
    #category = ["even","staggered"]
    #chart.set_legend(category)
    ids = ids[::-1]

    chart.set_axis_labels(Axis.LEFT, ids)
    chart.set_axis_labels(Axis.BOTTOM,
                          [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100])
    #chart.set_axis_labels(Axis.LEFT, ["0)
    index = chart.set_axis_labels(Axis.BOTTOM, ['Abundance (%)'])
    chart.set_axis_style(index, '202020', font_size=10, alignment=0)
    chart.set_axis_positions(index, [50])

    index = chart.set_axis_labels(Axis.LEFT, ['Phylum'])
    chart.set_axis_style(index, '202020', font_size=10, alignment=0)
    chart.set_axis_positions(index, [50])

    try:
        chart.download(html_prefix + 'bar-phylum.png')
    except:
        print "Warning: could not download bar-phylum.png"

    dt = datetime.now()
    ds = dt.strftime("%d %b %Y,<br/>%l:%M%p")
    title = "metAMOS report"
    # header is blank for now
    header = []

    # write the javascript we need on the page
    script = []
    script.append("<script type=\"text/javascript\">")
    script.append("var steps = ['%s'];" % ("','".join(steps)))
    script.append("function load(step) {")
    for step in steps:
        if step_status[step] != "OK":
            script.append(
                "   if (step.toLowerCase() == \"%s\".toLowerCase()) {" %
                (step))
            script.append("      return;")
            script.append("   }")
    script.append("   for (var i = 0; i < steps.length; i++) {")
    script.append("      var current = steps[i].toLowerCase();")
    script.append("      if (current == step) {")
    script.append(
        "         document.getElementById(step + 'Button').className = 'menuItemSelected';"
    )
    script.append(
        "         document.getElementById(step).style.display = 'block';")
    script.append(
        "         document.getElementById(step + 'Marker').className = 'markerSelected';"
    )
    script.append("      } else {")
    script.append(
        "         document.getElementById(current + 'Button').className = 'menuItemUnselected';"
    )
    script.append(
        "         document.getElementById(current).style.display = 'none';")
    script.append(
        "         document.getElementById(current + 'Marker').className = 'markerUnselected';"
    )
    script.append("      }")
    script.append("   }")
    script.append("}")
    script.append("")
    script.append("</script>")

    #<link rel="shortcut icon" href="../assets/ico/favicon.ico">
    #<link rel="apple-touch-icon-precomposed" sizes="144x144" href="../assets/ico/apple-touch-icon-144-precomposed.png">
    #<link rel="apple-touch-icon-precomposed" sizes="114x114" href="../assets/ico/apple-touch-icon-114-precomposed.png">
    #<link rel="apple-touch-icon-precomposed" sizes="72x72" href="../assets/ico/apple-touch-icon-72-precomposed.png">
    #<link rel="apple-touch-icon-precomposed" href="../assets/ico/apple-touch-icon-57-precomposed.png">

    # generate the dictionary of javascript pages we need
    scripts = {}
    #    scripts["file://%s/javascript/jquery-latest.js"%(utils)] = "javascript"
    #    scripts["http://code.jquery.com/jquery-latest.js"] = "javascript"
    # now a javascript for each page
    for step in steps:
        scripts["%s.js" % (step.lower())] = "javascript"

    # attributes for the body tax
    body = {}
    body["onload"] = "load('%s')" % (initialStep.lower())

    # the footer for the page

    footer = ""  #"Generated %s"%(ds)
    #styles = ( 'style2.css')#'./html/bootstrap.css', './html/boostrap-responsive.css')#'style2.css')#'layout.css', 'alt.css', 'images.css' )
    #styles = ( 'layout.css', 'alt.css', 'images.css' )
    #meta = ('viewport':"width=device-width, initial-scale=1.0",'description':'','author':'')

    # create HTML page
    page = markup.page()
    # add the javascript free form
    page.add("\n".join(script))
    # initialize the rest of the body/html headers
    page.init( title=title,   \
               css='style.css', \
               script=scripts,\
               header='\n'.join(header), \
               bodyattrs=body, \
               footer=footer )

    #    page.br()
    #page.div( class_ = 'navbar navbar-fixed-top')
    #page.div( class_ = 'navbar-inner')

    #page.div( class_ = 'container', style_='width:100%;height=100%')

    #page.div.close()
    #page.div.close()
    #page.div.close()
    #page.div( id_='page' )

    # header

    #    page.add('<table style="width:100%;"><tr><td><img src="blocks_small.jpg"/></td><td><a target="_blank" href="https://github.com/treangen/metAMOS/wiki"><div><img src="name.jpg"/><br/>Under peer review</a></div></td><td class="title" style="width:100%"></td></tr></table>')
    '''
    page.div( id_='header', style="background-color:#B8B8B8;clear:both;text-align:center;width:100%;height:7%;border:1px solid black") 
    page.h1("<u>MetAMOS <font color=\"blue\">v1.0</font> metagenomic assembly & analysis report</u>" , style_="text-align:center;vertical-align:top")
    page.h1.close()
    #page.div( id_='title')# style="vertical-align:bottom;")
    #page.font( size=14)
    #page.br( )
    page.div.close()
    '''

    #<frameset rows="40%,60%"cols="80%,20%">
    #<frame src="report.krona.html">
    #<frameset rows="20%,20%">
    #<frame src="report.krona.html">
    #<frame src="report.krona.html">
    #</frameset>
    #<frameset rows="60%" cols="40%,40%">
    #<frame src="report.krona.html">
    #<frame src="report.krona2.html">
    #</frameset>f
    #<frameset rows="20%,20%,20%" cols="20%">
    #<frame src="report.krona.html">
    #<frame src="report.krona.html">
    #<frame src="report.krona.html">
    #</frameset>
    #</frameset>
    #</html>
    #font, estimate
    #page.div.close()
    #page.frameset( rows_="40%,60%", cols_ = "80%,20%")
    #page.div()

    page.table(style_="width:100%;height:100%;")
    page.tr()
    page.td(id_="menu", style_="padding:0px;")
    page.div(style_="height:100%;")

    #    page.table(style_="height:100%")
    #    page.tr()
    #    page.td()#style_="border-right:1px solid black")
    #    page.div(style_="box-shadow:inset -1px -1px 5px #555555;")
    page.add(
        "<a target=\"_blank\" href=\"https://github.com/treangen/metAMOS/wiki\"><img style=\"padding-top:5px;\" src=\"name.png\"/>"
    )
    page.add("<img src=\"blocks_dark_tiny.png\"/></a>")
    #    page.add("<img src=\"blocks_tiny2.jpg\"/>")
    page.add(
        "<div style=\"padding:2px;font-size:12px;\"><a target=\"_blank\" href=\"http://genomebiology.com/2013/14/1/R2\">Treangen TJ, Koren S, et. al.  Genome Biol. 2013 Jan 15;14(1):R2. PMID: 23320958.</a></div>"
    )
    page.add("<br/>")
    #    page.div.close()
    #    page.td.close()
    #    page.tr.close()

    #items = ["<a href=\"http://cbcb.umd.edu/software/metamos\">metAMOS website</a>", ]
    #page.ul()
    #    page.tr()
    #    page.td(style_="padding:0px;")
    page.table(id_="links", class_="menu")
    for step in steps:
        page.tr()
        status = "NA"
        try:
            if step_status[step] == "OK":
                status = "OK"
            elif step_status[step] == "FAIL":
                status = "FAIL"
            elif step_status[step] == "SKIP":
                status = "SKIPPED"
        except KeyError:
            continue

        tableHTML = []
        tableHTML.append(
            "<td class=\"menuItemTd\"><a class=\"menuLink\" href=\"javascript:void(0)\"><div class=\"menuItem %s\"><div id=\"%sButton\" class=\"menuItemUnselected\" onclick=\"load('%s');\">"
            % (status.lower(), step.lower(), step.lower()))
        tableHTML.append(
            "<table style='width:100%%;'><tr><td style='width:100%%;'><span class='step %sText'>%s</span>"
            % (status.lower(), step))
        tableHTML.append("<br>")
        tableHTML.append(
            "<span class='status %sText'>%s</span></td></tr></table>" %
            (status.lower(), status))
        tableHTML.append(
            "</div></div></a></td><td><div id='%sMarker' class='markerUnselected'>&#x25CF;</div></td>"
            % (step.lower()))
        page.add("\n".join(tableHTML))
        page.tr.close()

    page.table.close()
    #    page.td.close()
    #    page.tr.close()
    #page.ul.close()

    #    page.tr()
    #    page.td(style_="height:100%;")#border-right:1px solid black")
    page.div(class_="notes")
    page.add(
        "<div style=\"font-size:14px;\"><br/><a target=\"_blank\" href=\"pipeline.summary\">Pipeline summary</a><br/>"
    )
    page.add(
        "<a target=\"_blank\" href=\"pipeline.commands\">Run commands</a><br/><br/></div>"
    )
    tableHTML = []
    tableHTML.append("<table style=\"font-size:12px\"><tr>")
    tableHTML.append("<tr><td>Version:</td><td>%s</td></tr>" % (version))
    tableHTML.append("<tr><td>Created:<br/>&nbsp;</td><td>%s</td></tr>" % (ds))
    tableHTML.append("</table>")
    page.add("\n".join(tableHTML))
    page.div.close()
    #    page.td.close()
    #    page.tr.close()
    #    page.table.close()

    page.div.close()
    page.td.close()

    page.td(id_="krona", style_="width:100%;height:100%padding:0px;")
    page.table(class_="charts", style_="width:100%;height:100%")
    page.tr()
    page.td(class_="main", style_="height:100%", colspan_="4")
    page.div(class_="shadow")
    page.table(style_="width:100%;height:100%")
    page.tr()
    page.td(class_="corner")
    page.td.close()
    page.td()
    page.td.close()
    page.td(class_="corner")
    page.td.close()
    page.tr.close()
    page.tr()
    page.td()
    page.td.close()
    page.td(class_="inset")
    for step in steps:
        if step == "Browse Results":
            page.iframe(id_=step.lower(), src_="../.", style_="display:none;")
        else:
            page.iframe(id_=step.lower(),
                        src_="%s.html" % (step),
                        style_="display:none;")
        page.iframe.close()
    page.td.close()
    page.td()
    page.td.close()
    page.tr.close()
    page.tr()
    page.td(class_="corner")
    page.td.close()
    page.td()
    page.td.close()
    page.td(class_="corner")
    page.td.close()
    page.tr.close()
    page.table.close()
    page.div.close()
    page.td.close()
    page.tr.close()
    #page.tr()
    #page.div(id_="sideplots")#, style_="background-color:#FFFFFF;width:20.5%%;height:88%%;float:right;border:1px")
    #page.div(id_="sideplot1", style_="background-color:#FFFFFF;width:20.5%;height:22%;float:right")
    #page.td(style_="width:25%")
    #page.img(class_="chart", src_="ContigSizes.png")
    #page.td.close()
    #page.td(style_="width:25%")
    #page.div.close()
    #page.div(id_="sideplot2", style_="background-color:#FFFFFF;width:20.5%;height:22%;float:right")
    #page.img(class_="chart", src_="hist_contigs.png")
    #page.td.close()
    #page.td(style_="width:25%")
    #page.div.close()
    #page.div(id_="sideplot3", style_="background-color:#FFFFFF;width:20.5%;height:22%;float:right")
    #page.img(class_="chart", src_="ScaffoldSizes.png")
    #page.td.close()
    #page.td(style_="width:25%")
    #page.div.close()
    #page.div(id_="sideplot4", style_="background-color:#FFFFFF;width:20.5%;height:22%;float:right")
    #page.img(class_="chart", src_="hist_scaffold.png")
    #page.td.close()
    #page.div.close()
    #page.div.close()
    #page.td.close()
    #page.tr.close()
    page.table.close()
    #page.iframe(src_="bar-phylum.png",style_="width:100%;height:100%;hspace=10")
    #page.frameset(rows_="100%" ,cols_="100%")
    page.td.close()

    #page.li("<a target=\"_blank\" href=\"http://cbcb.umd.edu/software/metamos\">metAMOS website</a>")
    #page.li("<a href=\"http://cbcb.umd.edu/~mpop/Software.shtml\">Related software</a>")
    #page.li("<a href=\"http://cbcb.umd.edu\">CBCB</a>")

    #    page.li( items[1] )
    #page.ul.close( )
    #page.div.close()

    page.div(id_="content")

    #page.div( id_='wrapper')
    #page.div( id_="content")

    #page.a( "Reference assembly:", class_='internal', href='%s'%(ref_asm) )

    #paragraphs = ( ddf )
    cnt = 0
    #table_html = ""
    if 0:
        page.table(border="1", style_="width=80%")
        for contig in covdata:
            if cnt == 0:
                #table_html += "<table border=\"1\">\n"
                page.tr()
                page.td("High Coverage Contig ID")
                page.td("Coverage")
                page.tr.close()
                #table_html += "<tr><td> High Coverage Contig ID </td> <td> Coverage </td></tr>\n"
            page.tr()
            page.td(contig.split("\t")[0])
            page.td(contig.split(" ")[-1])

            cnt += 1
    '''
    #page.table.close()        
    #page.p( paragraphs )
    #page.p(style_="font-size:6px")
    page.table(border="0")
    #page.tr()
    #page.(
    if 1:
        #table_html = ""
        #table_html += "<table border=\"1\">\n"
        for contig in rdata:
            page.tr()
            #table_html += "<tr>\n"
            index = 0
            for item in contig.split("\t"):
                index +=1
                if index == 8 or index == 7:
                    continue
                elif index == 1 and "File" not in item:
                    page.td("<a target=\"_blank\" href=\""+ref_asm+"\">%s</a>"%(ref_asm.split("/")[-1]))
                    continue

                page.td("<p style=\"font-size:15px\">"+item+"</p>")
                #table_html += "<td> %s </td> \n"%(item)
            page.tr.close()
            #table_html += "</tr>\n"
        page.table.close()
        #table_html += "</table>\n"
        #page.p( table_html )    
    #page.p.close()
    page.div.close()
    '''
    page.td(id_="quick")
    page.div(style_="height:100%")
    #items = ["<a href=\"http://cbcb.umd.edu/software/metamos\">metAMOS website</a>", ]
    #page.ul()
    page.br()
    page.div(class_="stats")
    page.table(class_="stats")
    page.add("<tr><td class=\"number\">%s</td><td>Reads</td></tr>" %
             intOrZero(readcount))
    page.add("<tr><td class=\"number\">%s</td><td>Contigs</td></tr>" %
             intOrZero(contigcount))
    page.add("<tr><td class=\"number\">%s</td><td>Scaffolds</td></tr>" %
             intOrZero(scaffoldcount))
    page.add("<tr><td class=\"number\">%s</td><td>ORFs</td></tr>" %
             intOrZero(orfcount))
    page.add("<tr><td class=\"number\">%s</td><td>Motifs</td></tr>" %
             intOrZero(motifcount))
    page.table.close()
    page.div.close()

    page.div.close()
    page.td.close()
    page.tr.close()
    page.table.close()

    #page.div( id_="metaphyler", style="float:left;width:28%;height:70%")
    #page.img(  hspace=10, alt='Abundance', src='bar-phylum.png' )
    #page.div.close()

    #page.img( hspace=10, width=600, height=500, alt='Abundance', src='bar-phylum.png' )

    #page.div.close()

    fout = open(html_prefix + "summary.html", 'w')
    fout.write(page.__str__())
    fout.close()
コード例 #19
0
#!/usr/bin/env python2
#!-*- encoding: cp949 -*-

from pygooglechart import PieChart3D

chart = PieChart3D(250, 100)
chart.add_data([20, 10])
chart.set_pie_labels([u'¾È³ç'.encode('utf-8'), u'¼¼»ó'.encode('utf-8')])
print chart.get_url()
chart.download('pie_ko.png')
コード例 #20
0
def hello_world():
    chart = PieChart3D(settings.width, settings.height)
    chart.add_data([ord(a) for a in 'hW'])
    chart.set_pie_labels(['Hello', 'World'])
    chart.download('pie-hello-world.png')
コード例 #21
0
contracts = scraperwiki.sqlite.select('''
contract_info.event_class, SUM(volume)
FROM contract_info INNER JOIN contract_volume 
ON contract_info.id = contract_volume.id
WHERE contract_volume.date = ?
GROUP BY event_class
''', latest_date)

volumes = dict([(d['event_class'], d['SUM(volume)']) for d in contracts])
print '<h2>Contract Volume by Category</h2>'
print '<table>'
for k,v in sorted(volumes.items(), key=lambda v:v[1], reverse=True):
    print '<tr><td>{}</td><td>{:,}</td></tr>'.format(k,v)
print '</table>'

chart = PieChart3D(300,300)
chart.add_data(volumes.values())
chart.set_pie_labels(volumes.keys())
chart_url = chart.get_url()

print '<img src = "{}">'.format(chart_url)
import scraperwiki
from pygooglechart import PieChart3D

sourcescraper = 'intrade_total_trading_volume'


scraperwiki.sqlite.attach(sourcescraper, 't')

volume = scraperwiki.sqlite.select('* FROM contract_volume')
latest_date = max([v['date'] for v in volume])
コード例 #22
0
ファイル: create_report.py プロジェクト: omsai/metAMOS
        if ">phylum" in line:
            phylum = True
        if len(line) < 3:
            continue
        data = line.split("\t")
        if len(data) < 2:
            continue
        if not phylum:
            continue
        ids.append(data[0])
        #cov.append(int(float(data[2])))
        abund.append(100 * float(data[1]))

    # Create a chart object of 200x100 pixels
#    chart2 = StackedVerticalBarChart(600, 300)
    chart2 = PieChart3D(550, 300)

    chart2.set_colours(["0A8C8A", "EBB671", "DE091A"])
    # Add some data
    chart2.add_data(abund)
    #    chart2.add_data(abund2)

    # Assign the labels to the pie data
    chart2.set_pie_labels(ids)
    #    chart2.set_axis_labels(Axis.BOTTOM, ids)

    # Download the chart
    try:
        chart2.download(prefix + 'abund.png')
    except:
        print "Warning: could not download abund.png"