Tuesday, July 19, 2011


Aside 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.

i am currently utilizing python 2.6.5 and BioPython 1.53.  The Codes below work well for me.

#!/usr/bin/env python

from Bio import SeqIO

file = open("./ls_orchid.fasta")

for sequ in SeqIO.parse(file, "fasta"):
    print sequ.id
    print repr(sequ.seq)
    print len(sequ)


Friday, October 15, 2010

Pythonic Concurrency

I 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.

With my fascination with this subject matter, i shall continue with some concurrency code.

I want to pose two important questions, which i have yet to understand:
1) How does one explain a process is running multiple threads in a program ?
2) How does one explain multiple processes are running in a program with one thread per process ?

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.

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.

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.

import threading
import random
import time
import math

def genLotto():
    while a < 6:

    return list

def prtLottoNum():
    num = genLotto()
    print num

def main():
    # handling Threading processes
    t1 = threading.Thread(name="m5", target=genLotto)
    t1 = threading.Thread(name="m5", target=prtLottoNum)
    t2 = threading.Thread(name="m6", target=genLotto)
    t2 = threading.Thread(name="m6", target=prtLottoNum)

    # starting the threading processes
    # this code will allow to work in windows and better in *nix


Wednesday, October 6, 2010

Skype link

i received a random skype post about my system being infected while leaving skype idle.

Do not click on www.updatemk.com/
It is a virus or trojan.

if you run:  "jwhois  updatemk.com" on a linux box, you can learn about the location of the culprit. 

Friday, October 1, 2010

change coin

def changeCoin():
    mess = raw_input("Enter in the amount to change coin? ")
    amt = float(mess)
    q = int(amt / .25)
    rmd = amt - (q * .25)
    d = int(rmd / .10)
    rmd = amt - ((d*.1)+(q*.25))
    n = int(rmd / .05)
    rmd = amt - ((n*.05) + (d*.1) + (q*.25))
    p = int(rmd / .01)
    print q, d, n, p

Tuesday, September 28, 2010

ignoring linespace and count line

def countLine():
        count = 0
        for i in f:
                if i.strip() != "":
                        count = count + 1

        return count

Monday, September 27, 2010

count line including linespace

def checkFile():
    for line in f:
            a = a + 1
    return a

Sunday, September 26, 2010

count line without linespace

def countLineInFile():
    line = f.readline()
    lineNumber = 0
   while line != "":
        line = f.readline()
        lineNumber = lineNumber + 1


    return lineNumber