#get-mean-log2.py #This program takes 4 command line options: #A file of log2 value, chromosome name, and coordinate begin and end #it prints out the number of probes in the #indicated interval and their average and mean log2 values import sys import math #return mean value of entries in a list def calcMean(values): n=0 sum=0 for i in values: sum+=i n+=1 return float(sum)/float(n) #return standard deviation of entries in a list def calcStdDev(values): mean=calcMean(values) sumMeanDiffSqrd=0 for i in values: sumMeanDiffSqrd+=(i-mean)**2 stdDev=math.sqrt(sumMeanDiffSqrd/len(values)) return stdDev #read command line options fileName=sys.argv[1] chrName=sys.argv[2] chrStart=int(sys.argv[3]) chrEnd=int(sys.argv[4]) myFile=open(fileName,'r') values=[] n=0 for line in myFile: line.rstrip() (chr,probePos,log2)=line.split() probePos=int(probePos) log2=float(log2) #only consider probes on the right chromosome #and within the indicated interval if chr == chrName and probePos >= chrStart and probePos <= chrEnd : values.append(log2) n+=1 myFile.close numProbes=len(values) mean=calcMean(values) stdDev=calcStdDev(values) print numProbes,'probes in interval' print 'mean: ',mean print 'standard deviation',stdDev