How to use monkey1 method in localstack

Best Python code snippet using localstack_python

PlotPedigreeKinshipVsGeneticIBD.py

Source:PlotPedigreeKinshipVsGeneticIBD.py Github

copy

Full Screen

1#!/usr/bin/env python2"""3Examples:4 %s 5 6 # 2012.8.217 %s -i ~/NetworkData/vervet/Kinx2Apr2012.txt -l LDPrunedMerged.genome -O Kinx2Apr2012VsIBDPI -u yh8 -D IBDCheckPIHat -x 2xKinship9 10Description:11 2012.8.2112 Program that plots kinship vs. PI_hat from plinkIBD result.13 inputFname is the kinship file from Sue.14 Besides the png scatterplot (_scatter.png), a tsv file (_table.tsv) will be created to hold pedigree kinship vs. IBD PI_HAT. 15"""16import sys, os, math17__doc__ = __doc__%(sys.argv[0], sys.argv[0])18#bit_number = math.log(sys.maxint)/math.log(2)19#if bit_number>40: #64bit20# sys.path.insert(0, os.path.expanduser('~/lib64/python'))21# sys.path.insert(0, os.path.join(os.path.expanduser('~/script64')))22#else: #32bit23sys.path.insert(0, os.path.expanduser('~/lib/python'))24sys.path.insert(0, os.path.join(os.path.expanduser('~/script')))25import matplotlib; matplotlib.use("Agg") #to disable pop-up requirement26import csv27from pymodule import ProcessOptions, getListOutOfStr, PassingData, getColName2IndexFromHeader, figureOutDelimiter28from pymodule.utils import getColName2IndexFromHeader, getListOutOfStr, figureOutDelimiter29from pymodule import yh_matplotlib, GenomeDB30from pymodule import MatrixFile31from pymodule import SNP32import numpy, random, pylab33import numpy as np34from pymodule.plot.AbstractPlot import AbstractPlot35from vervet.src import VervetDB36class PlotPedigreeKinshipVsGeneticIBD(AbstractPlot):37 __doc__ = __doc__38# 39 option_default_dict = AbstractPlot.option_default_dict.copy()40 option_default_dict.pop(('xColumnHeader', 1, ))41 #option_default_dict.pop(('xColumnPlotLabel', 0, ))42 option_default_dict.update({43 ('plinkIBDCheckOutputFname', 1, ): ["", 'l', 1, 'file that contains IBD check result'], \44 ('drivername', 1,):['postgresql', '', 1, 'which type of database? mysql or postgresql', ],\45 ('hostname', 1, ): ['localhost', 'z', 1, 'hostname of the db server', ],\46 ('dbname', 1, ): ['vervetdb', 'd', 1, 'database name', ],\47 ('schema', 0, ): ['public', 'k', 1, 'database schema name', ],\48 ('db_user', 1, ): [None, 'u', 1, 'database username', ],\49 ('db_passwd', 1, ): [None, 'q', 1, 'database password', ],\50 ('port', 0, ):[None, '', 1, 'database port number'],\51 ('doPairwiseLabelCheck', 0, int):[0, '', 0, 'toggle to output two more tsv files: \52 _SumAbsDelta.tsv, _pairwiseCorOfKinshipIBDDelta.tsv'],\53 })54 55 def __init__(self, inputFnameLs=None, **keywords):56 """57 """58 AbstractPlot.__init__(self, inputFnameLs=inputFnameLs, **keywords)59 if self.outputFname and not self.outputFnamePrefix:60 self.outputFnamePrefix = os.path.splitext(self.outputFname)[0]61 62 63 def getMonkeyKinshipData(self, inputFname=None):64 """65 2012.8.2266 use SNP.readAdjacencyListDataIntoMatrix(), and defaultValue=067 2012.2.1068 """69 70 sys.stderr.write("Reading kinship from %s ... "%(inputFname))71 kinshipData = SNP.readAdjacencyListDataIntoMatrix(inputFname=inputFname, rowIDHeader=None, colIDHeader=None, rowIDIndex=0, colIDIndex=1, \72 dataHeader=None, dataIndex=2, hasHeader=False, defaultValue=0)73 #set kinshipData diagonal to 174 for i in xrange(len(kinshipData.row_id_ls)):75 kinshipData.data_matrix[i][i] = 176 return kinshipData77 """78 header = reader.next()79 col_name2index = getColName2IndexFromHeader(header, skipEmptyColumn=True)80 monkey1_id_index = col_name2index.get("monkeyId1")81 monkey2_id_index = col_name2index.get("monkeyId2")82 kinship_index = col_name2index.get("kinship")83 """84 """85 #reader = csv.reader(open(inputFname), delimiter=figureOutDelimiter(inputFname))86 monkey1_id_index = 087 monkey2_id_index = 188 kinship_index = 289 monkey_id_pair2kinship = {}90 for row in reader:91 monkey1_id = row[monkey1_id_index]92 monkey2_id = row[monkey2_id_index]93 kinship = float(row[kinship_index])94 pair_in_ls = [monkey1_id, monkey2_id]95 pair_in_ls.sort()96 monkey_id_pair2kinship[tuple(pair_in_ls)] = kinship97 del reader98 sys.stderr.write("%s pairs of monkeys.\n"%(len(monkey_id_pair2kinship)))99 return monkey_id_pair2kinship100 """101 102 def getMonkeyIDPair2Correlation(self, smartpcaCorrelationFname=None):103 """104 2012.3.1105 smartpcaCorrelationFname is output from PCAOnVCFWorkflow.py (with modified smartpca). tab-delimited.106 553_2_VRC_ref_GA_vs_524 555_15_1987079_GA_vs_524 Case Case 0.025107 553_2_VRC_ref_GA_vs_524 556_16_1985088_GA_vs_524 Case Case -0.020108 553_2_VRC_ref_GA_vs_524 557_17_1986014_GA_vs_524 Case Case -0.106109 553_2_VRC_ref_GA_vs_524 558_18_1988009_GA_vs_524 Case Case -0.059110 111 """112 sys.stderr.write("Reading correlation from %s ... "%(smartpcaCorrelationFname))113 monkey_id_pair2genotype_correlation = {}114 import csv115 reader = csv.reader(open(smartpcaCorrelationFname), delimiter=figureOutDelimiter(smartpcaCorrelationFname))116 monkey_id_extract = lambda x: x.split('_')[2]117 for row in reader:118 monkey1 = row[0]119 monkey2 = row[1]120 cor = float(row[4])121 pair_in_ls = [monkey_id_extract(monkey1), monkey_id_extract(monkey2)]122 pair_in_ls.sort()123 pair_key = tuple(pair_in_ls)124 monkey_id_pair2genotype_correlation[pair_key] = cor125 sys.stderr.write("%s pairs .\n"%(len(monkey_id_pair2genotype_correlation)))126 return monkey_id_pair2genotype_correlation127 128 129 def getMonkeyIBDCheckData(self, inputFname=None):130 """131 2012.8.21132 inputFname is output of plink ibd check.133 FID1 IID1 FID2 IID2 RT EZ Z0 Z1 Z2 PI_HAT PHE DST PPC RATIO134 1 1996093 1 1995025 OT 0 1.0000 0.0000 0.0000 0.0000 -1 0.654218 0.3630 1.9764135 1 1996093 1 2001039 OT 0 0.9832 0.0000 0.0168 0.0168 -1 0.653608 0.0318 1.8792136 1 1996093 1 1984011 OT 0 1.0000 0.0000 0.0000 0.0000 -1 0.645011 0.0168 1.8624137 1 1996093 1 1987004 OT 0 0.9260 0.0628 0.0113 0.0427 -1 0.660490 0.9999 2.2805138 139 """140 sys.stderr.write("Reading PI_hat from %s ... "%(inputFname))141 ibdData = SNP.readAdjacencyListDataIntoMatrix(inputFname=inputFname, rowIDHeader="IID1", colIDHeader="IID2", rowIDIndex=None, colIDIndex=None, \142 dataHeader="PI_HAT", dataIndex=None, hasHeader=True)143 return ibdData144 """145 monkey_id_pair2genotype_correlation = {}146 147 reader = MatrixFile(inputFname=inputFname)148 header = reader.next()149 col_name2index = getColName2IndexFromHeader(header)150 monkey1Index = col_name2index.get('IID1')151 monkey2Index = col_name2index.get('IID2')152 PI_HATIndex = col_name2index.get("PI_HAT")153 154 for row in reader:155 monkey1 = row[monkey1Index]156 monkey2 = row[monkey2Index]157 PI_HAT = float(row[PI_HATIndex])158 pair_in_ls = [monkey1, monkey2]159 pair_in_ls.sort()160 pair_key = tuple(pair_in_ls)161 monkey_id_pair2genotype_correlation[pair_key] = PI_HAT162 sys.stderr.write("%s pairs .\n"%(len(monkey_id_pair2genotype_correlation)))163 return monkey_id_pair2genotype_correlation164 """165 166 def getMonkeyDBEntry(self, db_vervet=None, ucla_id=None):167 """168 2012.8.21169 """170 return db_vervet.getIndividualDBEntry(ucla_id=ucla_id)171 172 173 def plotPairwiseKinshipFromPedigreeVsGenotype(self, db_vervet=None, kinshipFname=None, plinkIBDCheckOutputFname=None, \174 outputFnamePrefix=None, doPairwiseLabelCheck=False):175 """176 2012.8.17177 do full join, output pairs with data in only one source178 2012.3.1179 smartpcaCorrelationFname is output from PCAOnVCFWorkflow.py (with modified smartpca). tab-delimited.180 kinshipFname is from Sue (estimated by SOLAR based on pedigree)181 182 """183 ibdData = self.getMonkeyIBDCheckData(plinkIBDCheckOutputFname)184 kinshipData = self.getMonkeyKinshipData(kinshipFname)185 186 tableOutputWriter = csv.writer(open("%s_table.tsv"%(outputFnamePrefix), 'w'), delimiter='\t')187 header = ['monkey_pair', 'pedigree_kinship', 'IBD_PI_HAT', 'kinshipIBDDelta','age_difference']188 tableOutputWriter.writerow(header)189 190 monkey_id_pair_ls = []191 x_ls = []192 y_ls = []193 194 monkey_id2index = {} #2012.8.21195 monkey_id_pair2kinship_ibd_delta = {}196 shared_monkey_id_set = set(ibdData.row_id_ls)&set(kinshipData.row_id_ls)197 shared_monkey_id_ls = list(shared_monkey_id_set)198 no_of_monkeys = len(shared_monkey_id_ls)199 for i in xrange(no_of_monkeys):200 monkey1_id = shared_monkey_id_ls[i]201 202 for j in xrange(i+1, no_of_monkeys):203 monkey2_id = shared_monkey_id_ls[j]204 205 ibd = ibdData.getCellDataGivenRowColID(monkey1_id, monkey2_id)206 kinship = kinshipData.getCellDataGivenRowColID(monkey1_id, monkey2_id)207 if (not hasattr(ibd, 'mask')) and not numpy.isnan(ibd) and (not hasattr(kinship, 'mask'))\208 and (not numpy.isnan(kinship)):209 x_ls.append(kinship)210 y_ls.append(ibd)211 monkey_id_pair = [monkey1_id, monkey2_id]212 monkey_id_pair.sort()213 monkey_id_pair = tuple(monkey_id_pair)214 monkey1 = self.getMonkeyDBEntry(db_vervet=db_vervet, ucla_id=monkey1_id)215 if monkey1_id not in monkey_id2index:216 monkey_id2index[monkey1_id] = len(monkey_id2index)217 monkey2 = self.getMonkeyDBEntry(db_vervet=db_vervet, ucla_id=monkey2_id)218 if monkey2_id not in monkey_id2index:219 monkey_id2index[monkey2_id] = len(monkey_id2index)220 221 if monkey1 and monkey2 and monkey1.getCurrentAge() and monkey2.getCurrentAge():222 ageDelta = abs(monkey1.getCurrentAge() - monkey2.getCurrentAge())223 else:224 ageDelta = ''225 data_row = ['_'.join(monkey_id_pair), kinship, ibd, kinship-ibd, ageDelta]226 227 tableOutputWriter.writerow(data_row)228 monkey_id_pair2kinship_ibd_delta[monkey_id_pair] = kinship-ibd229 del tableOutputWriter230 231 sys.stderr.write("%s pairs overlap between pedigree kinship and genotype correlation, among %s monkeys.\n"%\232 (len(x_ls), len(monkey_id2index)))233 from pymodule import yh_matplotlib234 fig_fname = '%s_scatter.png'%(outputFnamePrefix)235 yh_matplotlib.drawScatter(x_ls, y_ls, fig_fname=fig_fname, title=None, xlabel=self.xColumnPlotLabel, \236 ylabel=self.whichColumnPlotLabel, dpi=self.figureDPI)237 238 if doPairwiseLabelCheck:239 sys.stderr.write("Pairwise calculation using kinship-ibdcheck ...")240 no_of_monkeys = len(monkey_id2index)241 kinship_ibd_deltaMatrix = numpy.zeros([no_of_monkeys, no_of_monkeys], dtype=numpy.float32)242 kinship_ibd_deltaMatrix[:] = numpy.nan243 for monkey_id_pair, kinship_ibd_delta in monkey_id_pair2kinship_ibd_delta.iteritems():244 monkey1_id = monkey_id_pair[0]245 monkey2_id = monkey_id_pair[1]246 monkey1_index = monkey_id2index.get(monkey1_id)247 monkey2_index = monkey_id2index.get(monkey2_id)248 kinship_ibd_deltaMatrix[monkey1_index][monkey2_index] = kinship_ibd_delta249 kinship_ibd_deltaMatrix[monkey2_index][monkey1_index] = kinship_ibd_delta250 251 maskedMatrix = np.ma.array(kinship_ibd_deltaMatrix, mask=np.isnan(kinship_ibd_deltaMatrix))252 outputFname = '%s_SumAbsDelta.tsv'%(outputFnamePrefix)253 writer = csv.writer(open(outputFname, 'w'), delimiter='\t')254 header = ['monkey_pair', 'index', 'sumAbsDelta', 'noOfNonMissing', 'avgAbsDelta', 'medianAbsDelta']255 writer.writerow(header)256 monkey_id2medianAbsDelta = {}257 for monkey_id , index in monkey_id2index.iteritems():258 259 sumAbsDelta = numpy.ma.sum(numpy.ma.abs(maskedMatrix[index,:]))260 noOfNonMissing = len(maskedMatrix[index,:]) - numpy.ma.sum(maskedMatrix[index,:].mask)261 medianAbsDelta = numpy.ma.median(numpy.ma.abs(maskedMatrix[index,:]))262 data_row = [monkey_id, index, sumAbsDelta, noOfNonMissing, sumAbsDelta/float(noOfNonMissing), medianAbsDelta]263 monkey_id2medianAbsDelta[monkey_id] = medianAbsDelta264 writer.writerow(data_row)265 del writer266 267 outputFname = '%s_pairwiseCorOfKinshipIBDDelta.tsv'%(outputFnamePrefix)268 writer = csv.writer(open(outputFname, 'w'), delimiter='\t')269 header = ['monkey_pair', 'noOfValidPairs', 'corr', 'monkey1_medianAbsDelta', 'monkey2_medianAbsDelta']270 writer.writerow(header)271 monkey_id_ls = monkey_id2index.keys()272 monkey_id_ls.sort()273 no_of_monkeys = len(monkey_id_ls)274 for i in xrange(no_of_monkeys):275 monkey1_id = monkey_id_ls[i]276 monkey1_index = monkey_id2index.get(monkey1_id)277 for j in xrange(i+1, no_of_monkeys):278 monkey2_id = monkey_id_ls[j]279 monkey2_index = monkey_id2index.get(monkey2_id)280 monkey1_vector = maskedMatrix[monkey1_index,:]281 monkey2_vector = maskedMatrix[monkey2_index,:]282 orMask = numpy.ma.mask_or(monkey1_vector.mask, monkey2_vector.mask)283 noOfValidPairs = len(monkey1_vector) - numpy.sum(orMask)284 corr = numpy.ma.corrcoef(monkey1_vector, monkey2_vector, \285 rowvar=True)[0,1]286 if not hasattr(corr, 'mask'): #valid float correlation, not a masked array cell (which means not enough valid data) 287 # if (abs(corr)>0.2):288 #output the plot289 data_row = ['%s_%s'%(monkey1_id, monkey2_id), noOfValidPairs, corr, monkey_id2medianAbsDelta.get(monkey1_id),\290 monkey_id2medianAbsDelta.get(monkey2_id)]291 writer.writerow(data_row)292 del writer293 sys.stderr.write(".\n")294 295 """296 #2012.3.1297 kinshipFname = "/Network/Data/vervet/Kinx2Jan2012.txt"298 smartpcaCorrelationFname= "/Network/Data/vervet/vervetPipeline/PCAOnVCFWorkflow_VRC105_Top1000Contigs.2012.3.1T1505/pca/smartpca.cor"299 outputFnamePrefix = os.path.expanduser("~/script/vervet//data/VRC105_Top1000Contigs_pedigree_kinship_vs_genotype_correlation")300 DBVervet.plotPairwiseKinshipFromPedigreeVsGenotype(db_vervet, kinshipFname=kinshipFname, \301 smartpcaCorrelationFname=smartpcaCorrelationFname,\302 outputFnamePrefix=outputFnamePrefix)303 sys.exit(3)304 305 """306 307 def run(self):308 """309 """310 311 if self.debug:312 import pdb313 pdb.set_trace()314 315 db_vervet = VervetDB.VervetDB(drivername=self.drivername, db_user=self.db_user, db_passwd=self.db_passwd, \316 hostname=self.hostname, dbname=self.dbname, schema=self.schema, port=self.port)317 db_vervet.setup(create_tables=False)318 self.db_vervet = db_vervet319 320 self.plotPairwiseKinshipFromPedigreeVsGenotype(db_vervet=db_vervet, kinshipFname=self.inputFname, \321 plinkIBDCheckOutputFname=self.plinkIBDCheckOutputFname, \322 outputFnamePrefix=self.outputFnamePrefix,\323 doPairwiseLabelCheck=self.doPairwiseLabelCheck)324 325if __name__ == '__main__':326 main_class = PlotPedigreeKinshipVsGeneticIBD327 po = ProcessOptions(sys.argv, main_class.option_default_dict, error_doc=main_class.__doc__)328 instance = main_class(po.arguments, **po.long_option2value)...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

1from ctypes import util2from email import utils3import string4from tkinter import Canvas, Tk5import helpers6import utilities7import helpers8import time9import random10import math11gui = Tk()12gui.title('My Terrarium')13# initialize canvas:14window_width = gui.winfo_screenwidth()15window_height = gui.winfo_screenheight()16canvas = Canvas(gui, width=window_width,17 height=window_height, background='white')18canvas.pack()19########################## YOUR CODE BELOW THIS LINE ##############################20# initialize oscillations21# oscillations = range22def make_world(canvas, morning_color='#4beff2', night_color='#3b46c4', tag='sky', duration=5):23 '''Makes everything'''24 # start timer25 start = time.time()26 27 # make morning sky28 setting = 'morning'29 utilities.make_rectangle(canvas, (0, 0), 2000, 2000, morning_color, tag=tag)30 helpers.make_cloud(canvas, (200, 300), size=30, tag='cloud1')31 helpers.make_cloud(canvas, (600, 400), size=100, tag='cloud2')32 helpers.make_cloud(canvas, (200, 100), size=60, tag='cloud3')33 helpers.make_cloud(canvas, (600, 250), size=130, tag='cloud4')34 # make background35 helpers.make_sun(canvas, (1250, 200))36 utilities.make_rectangle(canvas, (0, 750), 2000, 300, '#573a0f')37 helpers.make_landscape_object(canvas, (100,600))38 helpers.make_landscape_object(canvas, (540,600))39 helpers.make_landscape_object(canvas, (700,600), 110)40 helpers.make_landscape_object(canvas, (900,600), 90)41 helpers.make_landscape_object(canvas, (1130,600), 125)42 helpers.make_landscape_object(canvas, (300,600), 130)43 helpers.make_landscape_object(canvas, (1320,600), 50)44 # make monkeys45 helpers.make_creature(canvas, (200, 600), 15, 'monkey1')46 monkey1_direction = 'down'47 helpers.make_creature(canvas, (500, 600), 50, 'monkey2')48 monkey2_x_direction = 'right'49 helpers.make_creature(canvas, (800, 650), 25, 'monkey3')50 monkey3_direction = 'up'51 helpers.make_creature(canvas, (1300, 600), 70, 'monkey4')52 monkey4_x_direction = 'left'53 # animation loop54 while True:55 time_elapsed = round(time.time() - start)56 # cloud logic57 cloud1_left_coord = utilities.get_left(canvas, 'cloud1')58 if cloud1_left_coord >= window_width:59 utilities.update_position_by_tag(canvas, 'cloud1', window_width*-1, 0)60 cloud2_left_coord = utilities.get_left(canvas, 'cloud2')61 if cloud2_left_coord >= window_width:62 utilities.update_position_by_tag(canvas, 'cloud2', window_width*-1, 0)63 cloud3_right_coord = utilities.get_right(canvas, 'cloud3')64 if cloud3_right_coord <= 0:65 utilities.update_position_by_tag(canvas, 'cloud3', window_width, 0)66 cloud4_right_coord = utilities.get_right(canvas, 'cloud4')67 if cloud4_right_coord <= 0:68 utilities.update_position_by_tag(canvas, 'cloud4', window_width, 0)69 # animate clouds70 utilities.update_position_by_tag(canvas, 'cloud1', x=3, y=0)71 utilities.update_position_by_tag(canvas, 'cloud2', x=3, y=0)72 utilities.update_position_by_tag(canvas, 'cloud3', x=-3, y=0)73 utilities.update_position_by_tag(canvas, 'cloud4', x=-3, y=0)74 # monkey1 logic75 monkey1_y_position = utilities.get_bottom(canvas, 'monkey1')76 if monkey1_direction == 'down':77 utilities.update_position_by_tag(canvas, 'monkey1', x=0, y=4)78 if monkey1_y_position > 750:79 monkey1_direction = 'up'80 if monkey1_direction == 'up':81 utilities.update_position_by_tag(canvas, 'monkey1', x=0, y=-4)82 if monkey1_y_position < 700:83 monkey1_direction = 'down'84 # monkey2 logic85 monkey2_x_position = utilities.get_center(canvas, 'monkey2')86 if monkey2_x_direction == 'right':87 utilities.update_position_by_tag(canvas, 'monkey2', x=1, y=0)88 if monkey2_x_position > 550:89 monkey2_x_direction = 'left'90 if monkey2_x_direction == 'left':91 utilities.update_position_by_tag(canvas, 'monkey2', x=-1, y=0)92 if monkey2_x_position < 450:93 monkey2_x_direction = 'right'94 # monkey3 logic95 monkey3_y_position = utilities.get_bottom(canvas, 'monkey3')96 if monkey3_direction == 'down':97 utilities.update_position_by_tag(canvas, 'monkey3', x=0, y=1)98 if monkey3_y_position > 750:99 monkey3_direction = 'up'100 if monkey3_direction == 'up':101 utilities.update_position_by_tag(canvas, 'monkey3', x=0, y=-1)102 if monkey3_y_position < 700:103 monkey3_direction = 'down'104 # monkey4 logic105 monkey4_x_position = utilities.get_center(canvas, 'monkey4')106 if monkey4_x_direction == 'right':107 utilities.update_position_by_tag(canvas, 'monkey4', x=3, y=0)108 if monkey4_x_position > 1350:109 monkey4_x_direction = 'left'110 if monkey4_x_direction == 'left':111 utilities.update_position_by_tag(canvas, 'monkey4', x=-3, y=0)112 if monkey4_x_position < 1100:113 monkey4_x_direction = 'right'114 gui.update()115 # morning to night116 if setting == 'morning' and time_elapsed == duration:117 # reset conditionals118 start = time.time()119 setting = 'night'120 # change cloud colors121 utilities.update_fill_by_tag(canvas, 'cloud1', color='#5c5c5c')122 utilities.update_fill_by_tag(canvas, 'cloud2', color='#5c5c5c')123 utilities.update_fill_by_tag(canvas, 'cloud3', color='#5c5c5c')124 utilities.update_fill_by_tag(canvas, 'cloud4', color='#5c5c5c')125 # change sky126 utilities.delete_by_tag(canvas, 'sun')127 helpers.make_moon(canvas, (100, 100))128 # update gui129 utilities.update_fill_by_tag(canvas, tag, night_color)130 gui.update()131 continue132 # night to morning133 elif setting == 'night' and time_elapsed == duration:134 # reset conditionals135 start = time.time()136 setting = 'morning'137 # change cloud colors138 utilities.update_fill_by_tag(canvas, 'cloud1', color='#ffffff')139 utilities.update_fill_by_tag(canvas, 'cloud2', color='#ffffff')140 utilities.update_fill_by_tag(canvas, 'cloud3', color='#ffffff')141 utilities.update_fill_by_tag(canvas, 'cloud4', color='#ffffff')142 # change sky143 utilities.delete_by_tag(canvas, 'moon')144 helpers.make_sun(canvas, (1250, 200))145 # update gui146 utilities.update_fill_by_tag(canvas, tag, morning_color)147 gui.update()148 continue149 # make floor150 utilities.make_rectangle(canvas, (0, 1000), 2000, 50, 'brown')151# main152make_world(canvas)153# canvas.bind('<b-Button-1>', click_handle) # this doesnt work154# while True:155########################## YOUR CODE ABOVE THIS LINE ##############################156# makes sure the canvas keeps running:...

Full Screen

Full Screen

Monke.py

Source:Monke.py Github

copy

Full Screen

1#mothers day gift2import turtle3screen = turtle.Screen()4screen.bgcolor("white")5# base color6monkey1 = turtle.Turtle()7monkey1.shape("arrow")8monkey1.color("#654321")9monkey1.width(30)10monkey1.speed(1000)11# secondary color12monkey2 = turtle.Turtle()13monkey2.shape("arrow")14monkey2.color("#D2B48C")15monkey2.width(15)16monkey2.speed(1000)17# detail18monkey3 = turtle.Turtle()19monkey3.shape("arrow")20monkey3.color("#000000")21monkey3.width(20)22monkey3.speed(100)23def monke():24 print("Reject humanity..")25 print("Return to Monke")26 monkey1.pendown()27 monkey1.begin_fill()28 amt = 6029 while amt > 0:30 monkey1.right(6)31 monkey1.forward(10)32 amt = amt - 133 monkey1.end_fill()34 monkey1.penup()35 samt = 6036#monkey arms + body37 while samt > 0:38 monkey1.right(6)39 monkey1.forward(10)40 samt = samt - 641 monkey1.pendown()42 amt2 = 6043 while amt2 > 0:44 monkey1.left(5)45 monkey1.forward(8)46 amt2 = amt2 - 347 monkey1.penup()48 monkey1.home()49 monkey1.left(180)50 monkey1.pendown()51 samt2 = 6052 while samt2 > 0:53 monkey1.left(6)54 monkey1.forward(10)55 samt2 = samt2 - 656 amt3 = 6057 while amt3 > 0:58 monkey1.right(5)59 monkey1.forward(8)60 amt3 = amt3 - 361 monkey1.penup()62 monkey1.home()63 monkey1.forward(30)64 monkey1.left(90)65 monkey1.forward(70)66 monkey1.pendown()67 monkey1.forward(15)68 monkey1.begin_fill()69 amt4 = 2070 while amt4 > 0:71 monkey1.left(9)72 monkey1.forward(5)73 amt4 = amt4 - 174 monkey1.forward(15)75 monkey1.left(90)76 monkey1.forward(60)77 monkey1.end_fill()78 monkey1.penup()79 monkey1.right(90)80 monkey1.forward(250)81 monkey1.left(45)82 monkey1.pendown()83 amt5 = 1084 while amt5 > 0:85 monkey1.right(5)86 monkey1.forward(15)87 amt5 = amt5 - 188 monkey1.penup()89 monkey1.left(180)90 amt6 = 1091 while amt6 > 0:92 monkey1.forward(15)93 monkey1.left(5)94 amt6 = amt6 - 195 monkey1.left(60)96 monkey1.forward(60)97 monkey1.pendown()98 monkey1.forward(10)99 monkey1.left(30)100 amt7 = 10101#head102 while amt7 > 0:103 monkey1.left(5)104 monkey1.forward(15)105 amt7 = amt7 - 1106 monkey1.penup()107 monkey2.penup()108 monkey2.left(90)109 monkey2.forward(5)110 monkey2.right(90)111 monkey2.pendown()112 monkey2.begin_fill()113 monkey2.forward(40)114 amt8 = 30115 while amt8 > 0:116 monkey2.left(6)117 monkey2.forward(2)118 amt8 = amt8 - 1119 monkey2.forward(80)120 amt9 = 30121 while amt9 > 0:122 monkey2.left(6)123 monkey2.forward(2)124 amt9 = amt9 - 1125 monkey2.forward(60)126 monkey2.end_fill()127 monkey2.penup()128 monkey2.back(20)129 monkey2.right(90)130 monkey2.forward(20)131 monkey2.left(90)132 monkey2.begin_fill()133 monkey2.pendown()134 amt10 = 60135 while amt10 > 0:136 monkey2.right(6)137 monkey2.forward(8)138 amt10 = amt10 - 1139 monkey2.end_fill()140 monkey2.penup()141 monkey2.forward(1000)142 monkey3.penup()143 monkey3.forward(30)144 monkey3.left(90)145 monkey3.forward(20)146 monkey3.pendown()147 monkey3.forward(1)148 monkey3.penup()149 monkey3.left(90)150 monkey3.forward(60)151 monkey3.left(90)152 monkey3.pendown()153 monkey3.forward(1)154 monkey3.penup()155 monkey3.right(180)156 monkey3.forward(70)157 monkey3.right(90)158 monkey3.forward(5)159 monkey3.right(90)160 monkey3.pendown()161 monkey3.forward(3)162 monkey3.penup()163 monkey3.left(90)164 monkey3.forward(40)165 monkey3.left(90)166 monkey3.pendown()167 monkey3.forward(3)168 monkey3.penup()169 monkey3.forward(1000)170 171 172 ...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful