{"id":1891,"date":"2023-07-16T07:57:45","date_gmt":"2023-07-16T14:57:45","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=1891"},"modified":"2023-07-16T07:59:48","modified_gmt":"2023-07-16T14:59:48","slug":"362-create-n-strings-of-length-k-using-symbols-from-the-given-alphabet-using-python","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2023\/07\/362-create-n-strings-of-length-k-using-symbols-from-the-given-alphabet-using-python\/","title":{"rendered":"#362 Create n strings of length k using symbols from the given alphabet using python."},"content":{"rendered":"<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport random\r\ndef random_char(y):\r\n    alphabet = &#x5B;'A', 'T', 'C', 'G']\r\n    return ''.join(random.choice(alphabet) for x in range(y))\r\n\r\nn=20\r\nk=10\r\nfor i in range(0,n):\r\n    print(random_char(k))\r\n<\/pre>\n<p>Output:<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nTCTGTTCCAG\r\nGACTAATACA\r\nAGAACTAAGT\r\nCCTCACCATG\r\nGACTTCCAGG\r\nCTGAGGCTTG\r\nTGAGACAGAG\r\nGATCTACCGA\r\nTCAAACTAAT\r\nATCCGATCTT\r\nGAGGCACTCC\r\nAACCGAATGT\r\nCTCACTGTTC\r\nGTCCCTGGGA\r\nCGTGGTCCAA\r\nAGCCCGATGA\r\nCCTTCTCTCA\r\nGGCCGCTCGT\r\nCACCGGAGTG\r\nGAAGTGACGA\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import random def random_char(y): alphabet = &#x5B;&#8217;A&#8217;, &#8216;T&#8217;, &#8216;C&#8217;, &#8216;G&#8217;] return &#8221;.join(random.choice(alphabet) for x in range(y)) n=20 k=10 for i in range(0,n): print(random_char(k)) Output: TCTGTTCCAG GACTAATACA AGAACTAAGT CCTCACCATG GACTTCCAGG CTGAGGCTTG TGAGACAGAG GATCTACCGA TCAAACTAAT ATCCGATCTT GAGGCACTCC AACCGAATGT CTCACTGTTC GTCCCTGGGA CGTGGTCCAA AGCCCGATGA CCTTCTCTCA GGCCGCTCGT CACCGGAGTG GAAGTGACGA<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[30,2],"tags":[],"class_list":["post-1891","post","type-post","status-publish","format-standard","hentry","category-bioinformatics","category-python"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-uv","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1746,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/01\/204-mandelbrot-fractal-using-python-2-2-2-2-2-2-2-2-2-2\/","url_meta":{"origin":1891,"position":0},"title":"#331 Interpolation with Newton&#8217;s polynomial using python","author":"gantovnik","date":"2023-01-04","format":false,"excerpt":"interpolation.py [code language=\"python\"] def interpolation(c,x,x0): # Evaluate Newton's polynomial at x0. # Degree of polynomial n = len(x) - 1 y0 = c[n] for k in range(1,n+1): y0 = c[n-k] + (x0 - x[n-k]) * y0 return y0 def coef(x,y): # Computes the coefficients of Newton's polynomial. # Number of\u2026","rel":"","context":"In &quot;interpolation&quot;","block_context":{"text":"interpolation","link":"https:\/\/gantovnik.com\/bio-tips\/category\/interpolation\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/01\/ex331.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":894,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/02\/160-max-and-min-using-argmax-and-argmax-in-python\/","url_meta":{"origin":1891,"position":1},"title":"#160 Max and min using argmax and argmax in python","author":"gantovnik","date":"2021-02-14","format":false,"excerpt":"#160 Max and min using argmax and argmax in python [code language=\"python\"] import numpy as np import matplotlib.pyplot as plt import os os.chdir(r'D:\\projects\\wordpress\\ex160') os.getcwd() def main(): N = 100 L = 1 def f(i, n): x = i * L \/ N lam = 2 * L \/ (n+1) return\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/02\/example160.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/02\/example160.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/02\/example160.png?resize=525%2C300 1.5x"},"classes":[]},{"id":1109,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/193-animation-using-python\/","url_meta":{"origin":1891,"position":2},"title":"#193 Animation using python","author":"gantovnik","date":"2021-11-19","format":false,"excerpt":"[code language=\"python\"] # create an animation import numpy as np import matplotlib.pyplot as plt import matplotlib. Animation as manimation n = 1000 x = np.linspace(0, 6*np.pi, n) y = np.sin(x) # Define the meta data for the movie FFMpegWriter = manimation.writers[\"ffmpeg\"] metadata = dict(title=\"Movie Test\", artist=\"Matplotlib\", comment=\"a red circle following\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex193.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex193.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex193.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex193.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1793,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/02\/341-ridgeline-plot-using-plotly\/","url_meta":{"origin":1891,"position":3},"title":"#341 Solving ODE using python","author":"gantovnik","date":"2023-02-16","format":false,"excerpt":"[code language=\"python\"] import os import matplotlib.pyplot as plt import numpy as np import scipy.integrate as si os.chdir(r'D:\\projects\\wordpress\\ex341') os.getcwd() def model1(y,t): k = 0.1 dydt = -k*y return dydt def model2(y,t): k = 0.5 dydt = -k*y return dydt inits = [5] ts = np.linspace (0, 20) ys1 = si.odeint(model1 ,\u2026","rel":"","context":"In &quot;numerical&quot;","block_context":{"text":"numerical","link":"https:\/\/gantovnik.com\/bio-tips\/category\/numerical\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/02\/ex341.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/02\/ex341.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2023\/02\/ex341.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":2219,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/06\/431-hypermesh-python-script-to-create-nodes-using-coordinates-from-csv-file\/","url_meta":{"origin":1891,"position":4},"title":"#431 HyperMesh python script to create nodes using coordinates from csv file","author":"gantovnik","date":"2024-06-24","format":false,"excerpt":"Finally, I read how to write a script for HyperMesh in python. In this example, the script reads the coordinates of points from a cvs file. [code language=\"python\"] import os import hm import hm.entities as e from hwx import gui import csv model=hm.Model() os.chdir(r\"D:\\projects\\wordpress\\ex431\") with open('ex431_coordinates.csv', mode ='r') as file:\u2026","rel":"","context":"In &quot;HyperMesh&quot;","block_context":{"text":"HyperMesh","link":"https:\/\/gantovnik.com\/bio-tips\/category\/hypermesh\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/06\/ex431.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":897,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/02\/161-euler-spiral-using-python\/","url_meta":{"origin":1891,"position":5},"title":"#161 Euler spiral using python","author":"gantovnik","date":"2021-02-14","format":false,"excerpt":"#161 Euler spiral using python The curve described by the parametric equations (x, y) = (S (t),C(t)) is called a clothoid (or Euler spiral) and has the property that its curvature is proportional to the distance along the path of the curve. [code language=\"python\"] import numpy as np import matplotlib.pyplot\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/02\/example161.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/02\/example161.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/02\/example161.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1891","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=1891"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/1891\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=1891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=1891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=1891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}