Wednesday, May 30, 2007

Ruby: Separete OA and Control data

Separete OA and Control date from txt files.


#!/usr/bin/env ruby
#divOAvsControl.rb
sfh = File.new('~/myruby/lud/pairs.txt','r')
nameA=Array.new
sfh.each_line {|line| nameA.push line.chomp; }
sfh.close

dataF= Hash.new

fbase='Sta_fs'
fbase=ARGV[0] if ARGV.length>0


File.new(fbase+'.txt','r').each_line {|l|
fname=l.split[0]
dataF[fname.chomp]= l.chomp;
}

dataOA=Array.new
dataC=Array.new

nameA.each {|l|
control=l.split[0]
oa=l.split[1];
oa.gsub!(/\.tiff/,'')
control.gsub!(/\.tiff/,'')
oaData=dataF[oa.chomp]
oaC=dataF[control.chomp]
if oaData!=nil
dataOA.push oaData
else
puts oa.chomp
end
if oaC!=nil
dataC.push oaC
end
}

puts dataOA.length, dataC.length

open(fbase+'_OA.txt', 'w') do |f|
dataOA.each { |i| f << i <<"\n" }
end


open(fbase+'_Control.txt', 'w') do |f|
dataC.each { |i| f << i << "\n" }
end

Example usage:
divOAvsControl.rb Sta_fs.txt
divOAvsControl.rb Str_fs.txt
divOAvsControl.rb Std_fs.txt

Source in: ~/myruby/lud/.

Tuesday, May 29, 2007

rar: compress and divide large file to bunch of small ones

rar a -s -v30000 -m5 test.rar test/*where 30000 means 30MB.
Uncompress:rar x dvd1.part001.rar

Thursday, May 17, 2007

VirtualBox, Intel Mac X, Ubuntu (Ubuntu Server Edition)

Having Mac X at work is really nice thing. However sometimes one would like to use something else like Linux or Windows or whatever. I'm one of those guys that needs usually more than one operating systems, just to test something, or just because there is some feature that is present in e.g. Linux which is not available in Mac X. I decided to try VirtualBox beta for Intel Mac X, and to install Ubuntu. My choice of Ubuntu was driven only because where I work, Ubuntu is Ubuntu available at local ftp i.e. do not need to download it form the Internet.

Even thought VirtualBox for Intel Mac X is in beta stage, the installation was smooth, installation of Ubuntu also. Ubuntu on VirtualBox had out-of-the box internet and network working. In other words, there was no problems in installing, running, and using virtual Ubuntu.

The only problem there was/is with shearing folders. This is not VitualBox fold (I thinks so), but Ubuntu's mounting schema. What I mean is, that after mounting share folder, only root can write to it. Unfortunately it is not possible to set up umask=000 (everyone can read/write).

Below some screens of Mac and Ubuntu.


Share folders:mount -t vboxsf [-o OPTIONS] sharename mountpoint

As a matter of fact, I would prefer to have Windows XP on Virtual Box, but to install it, first I have to talk with our IT manager, because he has Windows installation cd-rom.

What about Ubuntu Server Edition? I wander if it was possible to install Ubuntu Server Edition on VirtualBox on Mac X, and use it just like server i.e. to set up an internet website on a virtual server. To check it, and to check Ubuntu Server Edition I decided to install this os on VirtualBox and try to set up a working, virtual LAMP server.
Unfortunately the answer to the above question is: Installation of Ubuntu Server Edition failed. In fact installation went fine, but first booting just after the installation resulted in:


I decided to check something else also. I was wandering if I can copy virtual Ubuntu created in Mac X to Windows XP and run in successfully there.

Wednesday, May 16, 2007

Mac X: Project-R

The problem with Intel Mac is that there are no software for it. Since maybe two months there is Matlab, thanks God, but I still miss SPSS, or any other statistical software different than Excel!. I have just receive an email about something called project R. I was interested by the mail; hence, I found out that it is a statistical program. I hope that it is what I was looking for, or at least will be easy to learn, on the condition that it will be nice. At the moment I'm waiting, because installation through DarwinPorts takes ages, thus I have time to write something (in fact, I have not time, but checking this new soft is just excuse from work). As soon as the installation succeed I will check it, whether it was worth installing or not.

Installation has just succeeded, although it was very, very long. Just to check it, I used an example (creation of box plots) available in a official manual:
A <- scan()
79.98 80.04 80.02 80.04 80.03 80.03 80.04 79.97
80.05 80.03 80.02 80.00 80.02

B <- scan()
80.02 79.94 79.98 79.97 79.97 80.03 79.95 79.97

boxplot(A, B)




One can see that it was very easy, and this fast test is quite encouraging to spend some more time with this R.

95% confidence interval in R:
>X1 <- scan()
1: 205 179 185 210 128 145 177 117 221 159
2: 205 128 165 180 198 158 132 283 269 204
> a <- mean(X1)
> s <- sd(X1)
> n <- length(X1)
> errZ <- qnorm(0.975)*s/sqrt(n)
> errT <- qt(0.975,df=n-1)*s/sqrt(n)
>left <- a-errT
>right <- a+errT

Saturday, May 12, 2007

Latex: font sizes

\tiny
\scriptsize
\footnotesize
\small
\normalsize
\large
\Large
\LARGE
\huge
\Huge

or to change font in larger text part:\begin{small}
something something ...
\end{small}

Double spacing\usepackage{setspace}
\doublespacing
or arbitrary spacing e.g.:\setstretch{2.5}
Two column article:\documentclass[twocolumn,11pt]{article}
In a text, to switch from one to two column use \onecolumn and \twocolumn.
in two-column documents, \begin{figure*} \end{figure*} provides a floating page-wide figure (and \begin{table*} \end{table*} a page-wide table). The "*"ed float environments can only appear at the top of a page, or on a whole page - h or b float placement directives are simply ignored.

Monday, May 07, 2007

Latex: too many unprocessed floats

If you have it, it means that you have put to many figures or tables one next to each other, and Latex cannot locate them all. The quick solution to this is to add:\clearpage or \cleardoublepage command between your float objects. I does not give blank page in our documents, it just give one more page for latex to put your objects on it.

Sunday, May 06, 2007

100% CPU usage by spoolsv.exe in Win XP

Spoolsv.exe is a windows server application to manage printing queue. My friend had problem in his laptop becuase this application was using 100 % CPU; hence, computer was very slow. If you kill it, it will start again in a few minutes.
The problem was caused by the fact, that there were few files in a queue to print, but no printer. Hence, he went to C:\windows\system32\spool\PRINTER and deleted everything what was there. Sometimes you must first kill spoolsv.exe in task manager prior to removing files. This helped.

Sunday, April 29, 2007

Coefficient of variation

The coefficient of variation is a dimensionless number that allows comparison of the variation of populations that have significantly different mean values. It is defined as:cv=std(X)/mean(X);
For example if:
X= [1.7 1.6 2.8 5.6 1.3 2.2 1.3 1.1 3.2 1.5 5.2 4.6 5.8 3.0];
then cv=0.5846.

P-value and t-critical values in Matlab and Octave

If one use to calculate t-critical and P-values using t statistis, those functins in Matlab/Octave do it:
t_critical= tinv(1-alpha/2,n-2);

where alpha is confidence level (e.g. alpha=0.05 for 95% confidence level);
Pval=2*(1-tcdf(abs(t),n-2))

where t is our calculated value of t statistics.

With regard to Octave, it depends which version you use. You may find that instead of tint and tcdf there are t_int and t_cdf functions.

Friday, April 27, 2007

Latex: Miktex (Windows) and TexShop (Mac X) and tetex (Linux)

Latex is great tool for writing scientific texts. You just write and do not worry about sorting references, formatting them, changing numeration when you add or remove figures, create subfigures, subtables, etc. It is just nice and I am big fun of it, even thought creating tables is not so convenient. Nevertheless, I have had lately one big problem with Latex, or rather I should say problems between Windows’ and Mac X’s Latex software.

At work I use Mac X 10.4 and I have TexShop to write in Latex. On Windows there is Miktex. Separately both tools are just fine. However, when I tried to edit tex file in Miktex file which initially was written in TexShop I found big problems. First of all, basic Miktex installation do not include subfig package. Which is very, very bed due to the fact that my PC box do not have internet connection. But after connecting to the internet and installing subfig and many other missing packages it did not help much. I still have huge problems with compiling tex files that were written in TexShop.

I know that Latex should be multiplatform but in my case it is not. As far as I can say TexShop in Mac X and MikTex in Windows are totally different, and one cannot use both. Maybe if I spend more time, I could solve all the problems and run my file on Windows, but in fact I do not have time and energy to do it. Even though I’m computer geek, believe me or not I have more important thing to do than to investigate what is happening with MikTex. I need to write, and not to waste time make MikTex working with my files from Mac XĂ…DMaybe if I install full MikTex, rather than basic, but this is not possible because full MikTex is just too big to download from the internet. One other fast possible solution is maybe to use Cygwin and to use some linux based latex software to write latex. This I can check quite quickly, but first I need to install Cygwin.

As a result I am considering working with OpenOffice or even Microsoft office, because they just work. Not perfectly but at least I can write. To be honest I’m I would prefer to work in Latex, and maybe I will do all the writing on Mac X, because Latex is much better for me than MS Office or OpenOffice.

By the way, I think that TexShop for Mac X is much better and easier to use than MikText. I wander how it looks like in Linux. I have Ubuntu on my other PC box, and maybe I will install some Latex environment there just to see if I experience the same problems or everything will work.

I also wander if only I have such problems between latex in Mac X and Windows XP, or it is rather common?

UPDATE
I have just tested latex on Ubuntu with tetex and auctex. Anfortunately the same proplems as before. I can not compile Latex files for Mac X - too many errors.

CONCLUSION
Latex is totally incompatible between different operating systems if one tries to write a little more complicated (subtables, subfigures, two column) article !!!