tag:blogger.com,1999:blog-42453727428731633572024-02-08T09:51:52.637-08:00Coding MonkeyAschenbachhttp://www.blogger.com/profile/16446220655420341803noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-4245372742873163357.post-29081058666669591262011-07-19T06:46:00.000-07:002011-07-19T06:48:28.193-07:00BioPythonAside from OS threading and OO programming, I came across something of interests to me. While parsing through fasta and genbank files from the Biopython tutorial site, a few of their examples were not able to run in a python script. After looking into the error messages. i've noticed the function SeqIO.parse() takes a file object instead of the filename.<br />
<br />
i am currently utilizing python 2.6.5 and BioPython 1.53. The Codes below work well for me. <br />
<br />
#!/usr/bin/env python<br />
<br />
from Bio import SeqIO<br />
<br />
file = open("./ls_orchid.fasta")<br />
<br />
for sequ in SeqIO.parse(file, "fasta"):<br />
print sequ.id<br />
print repr(sequ.seq)<br />
print len(sequ)<br />
<br />
file.close()Aschenbachhttp://www.blogger.com/profile/16446220655420341803noreply@blogger.com0tag:blogger.com,1999:blog-4245372742873163357.post-55820194090646398722010-10-15T08:45:00.000-07:002011-07-24T15:53:28.610-07:00Pythonic ConcurrencyI have been fascinated by multi-threaded programs for a few years, and have never quite grasped the power of concurrency during the day of my studies at various schools. My understading of how concurrency function is by no means affluent, but my knowledge will grow in the coming weeks. In my endaevour to construct a simple application with concurrency in mind was my focus in today's topic.<br />
<br />
With my fascination with this subject matter, i shall continue with some concurrency code. <br />
<br />
I want to pose two important questions, which i have yet to understand:<br />
1) How does one explain a process is running multiple threads in a program ?<br />
2) How does one explain multiple processes are running in a program with one thread per process ?<br />
<br />
How does a process definied itself ? A process is defined as a program being run in memory which generates a process ID, this main process will fork other processes accordingly. In accordance with a typical Linux OS, by running this command: python genLottoNum.py, the main process will ultimately be python itself residing in memory. The sub-process which it depends upon will be the file that is running in memory. One can see a process running "ps auxf". A thead is more like a sub-process where even when running the command above would not allow a user to see a running thread.<br />
<br />
Those were the core questions i woud like to pose, which i have yet to figure out in code. My sample program will answer either Q1 or Q2. <br />
<br />
In my sample code, i have two threads randomly generating values, which is done via a pseudo-random number generator to produce numbers in the form of a lottory ticket. <br />
<br />
import threading<br />
import random<br />
import time<br />
import math<br />
<br />
def genLotto():<br />
a=0 <br />
list=[]<br />
random.seed(time.time()*random.gauss(random.random()*math.sqrt(math.pi),time.time()*math.pi))<br />
while a < 6:<br />
list.append(int(random.random()*60))<br />
a=a+1<br />
<br />
return list<br />
<br />
def prtLottoNum():<br />
num = genLotto()<br />
print num <br />
<br />
def main():<br />
# handling Threading processes<br />
t1 = threading.Thread(name="m5", target=genLotto)<br />
t1 = threading.Thread(name="m5", target=prtLottoNum)<br />
t2 = threading.Thread(name="m6", target=genLotto)<br />
t2 = threading.Thread(name="m6", target=prtLottoNum)<br />
<br />
# starting the threading processes<br />
t1.start()<br />
# this code will allow to work in windows and better in *nix<br />
time.sleep(1)<br />
t2.start()<br />
<br />
main()Aschenbachhttp://www.blogger.com/profile/16446220655420341803noreply@blogger.com0tag:blogger.com,1999:blog-4245372742873163357.post-27450220798661597652010-10-06T11:01:00.000-07:002011-07-15T12:16:21.996-07:00Skype linki received a random skype post about my system being infected while leaving skype idle. <br />
<br />
Do not click on www.updatemk.com/<br />
It is a virus or trojan.<br />
<br />
if you run: "jwhois updatemk.com" on a linux box, you can learn about the location of the culprit. Aschenbachhttp://www.blogger.com/profile/16446220655420341803noreply@blogger.com0tag:blogger.com,1999:blog-4245372742873163357.post-71812916217527918942010-10-01T07:48:00.000-07:002010-10-01T07:48:04.075-07:00change coindef changeCoin():<br />
mess = raw_input("Enter in the amount to change coin? ")<br />
amt = float(mess)<br />
q = int(amt / .25)<br />
rmd = amt - (q * .25)<br />
d = int(rmd / .10)<br />
rmd = amt - ((d*.1)+(q*.25))<br />
n = int(rmd / .05)<br />
rmd = amt - ((n*.05) + (d*.1) + (q*.25))<br />
p = int(rmd / .01)<br />
print q, d, n, pAschenbachhttp://www.blogger.com/profile/16446220655420341803noreply@blogger.com0tag:blogger.com,1999:blog-4245372742873163357.post-89555592139231112712010-09-28T11:08:00.001-07:002010-09-28T11:12:11.120-07:00ignoring linespace and count linedef countLine():<br />
fileName='file'<br />
f=open(fileName)<br />
count = 0<br />
for i in f:<br />
if i.strip() != "":<br />
count = count + 1<br />
<br />
f.close()<br />
return countAschenbachhttp://www.blogger.com/profile/16446220655420341803noreply@blogger.com0tag:blogger.com,1999:blog-4245372742873163357.post-37148797898231251212010-09-27T17:51:00.001-07:002010-09-28T11:13:35.795-07:00count line including linespacedef checkFile():<br />
f=open("./file")<br />
a=0<br />
for line in f:<br />
a = a + 1<br />
f.close()<br />
return aAschenbachhttp://www.blogger.com/profile/16446220655420341803noreply@blogger.com0tag:blogger.com,1999:blog-4245372742873163357.post-72491258416980280742010-09-26T14:53:00.000-07:002010-09-28T11:13:07.908-07:00count line without linespacedef countLineInFile():<br />
f=open('./filename.txt')<br />
line = f.readline()<br />
lineNumber = 0<br />
while line != "":<br />
line = f.readline()<br />
lineNumber = lineNumber + 1<br />
<br />
f.close()<br />
<br />
return lineNumberAschenbachhttp://www.blogger.com/profile/16446220655420341803noreply@blogger.com0