Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

2012-12-04

Recover deleted file under linux

Here is a nice summary, but the bottom line is that the Ubuntu/Debian package testdisk has a nice utility called photorec that can be used to search for deleted files and recover. This is not a GUI program, though!

2011-04-01

Redish color of screen for evening or night work

While reading local computer magazine (Monitor) I find out about f.lux, which is program that changes the color of screen to more redish for evening or night work. They claim that this protects our eyes and sleep pattern. I like the idea. Linux support has some problems, but their is alternative that works with Linux - redshift (see here and here for installation).

2010-12-18

ASReml-R: Storing A inverse as a sparse matrix

I was testing ASReml-R program (an R package that links propriety ASReml binaries that can be used only with valid licence) this week and had to do some manipulations with the numerator relationship matrix (A). ASReml-R provides a function (asreml.Ainverse) that can create inverse of A directly from the pedigree as this inverse is needed in pedigree based mixed model. Bulding inverse of A directly from a pedigree is a well known result dating back to Henderson in 1970s or so. The funny thing is that it is cheaper to setup inverse of A directly than to setup up first A and then to invert it. In addition, inverse of A is very spare so it is easy/cheap to store it. Documentation for asreml.Ainverse has a tiny example of usage. Since the result of this function is a list with several elements (data.frame with "triplets" for non-zero elements of inverse of A, inbreeding coefficients, ...) example also shows how to create a matrix object in R as shown bellow:
library(package="asreml")
## Create test pedigree
ped <- data.frame( me=c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
dad=c(0, 0, 0, 1, 1, 2, 4, 5, 7, 9),
mum=c(0, 0, 0, 1, 1, 2, 6, 6, 8, 9))
## Create inverse of A in triplet form
tmp <- asreml.Ainverse(pedigree=ped)$ginv
## Create a "proper" matrix
AInv <- asreml.sparse2mat(x=tmp)
## Print AInv
AInv
So the inverse of A would be:
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]      [,9]     [,10]
[1,] 5 0 0 -2 -2 0 0.0 0.0 0.000000 0.000000
[2,] 0 3 0 0 0 -2 0.0 0.0 0.000000 0.000000
[3,] 0 0 1 0 0 0 0.0 0.0 0.000000 0.000000
[4,] -2 0 0 3 0 1 -2.0 0.0 0.000000 0.000000
[5,] -2 0 0 0 3 1 0.0 -2.0 0.000000 0.000000
[6,] 0 -2 0 1 1 4 -2.0 -2.0 0.000000 0.000000
[7,] 0 0 0 -2 0 -2 4.5 0.5 -1.000000 0.000000
[8,] 0 0 0 0 -2 -2 0.5 4.5 -1.000000 0.000000
[9,] 0 0 0 0 0 0 -1.0 -1.0 4.909091 -2.909091
[10,] 0 0 0 0 0 0 0.0 0.0 -2.909091 2.909091
However, this is problematic as it creates a dense matrix - zero values are also stored (you can see them). If we would have 1,000 individuals, such a matrix would consume 7.6 Mb of RAM (= (((1000 * (1000 + 1)) / 2) * 16) / 2^20). This is not a lot, but with 10,000 individuals we would already need 763 Mb of RAM, which can create some bottlenecks. A solution is to create a sparse matrix using the Matrix R package. Luckily we have all the ingredients prepared by asreml.Ainverse function - the triplets. However, the essential R code is a bit daunting and I had to test several options before I figured it out - code from my previous post helped;)
## Load package
library(package="Matrix")
## Number of pedigree members
nI <- nrow(ped)
## Store inverse of A in sparse form
AInv2 <- as(new("dsTMatrix",
Dim=c(nI, nI),
uplo="L",
i=(as.integer(tmp$Row) - 1L),
j=(as.integer(tmp$Column) - 1L),
x=tmp$Ainverse),
"dsCMatrix")
## Add row and column names - optional
dimnames(AInv2) <- list(attr(x=tmp, which="rowNames"),
attr(x=tmp, which="rowNames"))
## Print AInv
AInv2
And the inverse of A is now:
10 x 10 sparse Matrix of class "dsCMatrix"
[[ suppressing 10 column names ‘1’, ‘2’, ‘3’ ... ]]

1 5 . . -2 -2 . . . . .
2 . 3 . . . -2 . . . .
3 . . 1 . . . . . . .
4 -2 . . 3 . 1 -2.0 . . .
5 -2 . . . 3 1 . -2.0 . .
6 . -2 . 1 1 4 -2.0 -2.0 . .
7 . . . -2 . -2 4.5 0.5 -1.000000 .
8 . . . . -2 -2 0.5 4.5 -1.000000 .
9 . . . . . . -1.0 -1.0 4.909091 -2.909091
10 . . . . . . . . -2.909091 2.909091
you can clearly see the structure and it soon becomes obvious why such a storage is more efficient.

If we want to go back from matrix to triplet form (this might be useful if we want to create a matrix for programs as ASReml) we can use the following code:
## Convert back to triplet form - first the matrix
tmp2 <- as(AInv2, "dsTMatrix")
## ... - now to data.frame
tmp3 <- data.frame(Row=tmp2@i + 1, Column=tmp2@j + 1, Ainverse=tmp2@x)
## Sort
tmp3 <- tmp3[order(tmp3$Row, tmp3$Column), ]
## Test that we get the same stuff
any((tmp[, 3] - tmp3[, 3]) > 0)
## ASReml-R specificities
attr(x=tmp3, which="rowNames") <- rownames(tmp)
attr(x=tmp3, which="geneticGroups") <- c(0, 0)

2009-11-12

Sweave-Lyx from terminal on Mac

Mark Heckmann writes:
In your paper "Using Sweave with Lyx" (great work bty) you pointed out that one can see the sweave error code when processing when starting lyx from the terminal. I just changed from Windows to Mac so that's new for me. Could you send me a few lines how to do that, that is how to operate lyx from terminal and sweave the content from the terminal.
I am not familiar with Mac, though would be happy to own one;) Since Mac OS is build on top of some linux/unix like system you need to start the terminal (console) with shell and find the lyx binary. Perhaps something like this on my linux box (text following $ are shell commands)

# Find the lyx binary
$ which lyx
/usr/bin/lyx

# Start lyx from console
$ lyx&

2008-11-02

Nemške ambasade gredo na Linux

Na Slo-Tech-u so objavili novico "Nemške ambasade gredo na Linux". Zanimiva novica. Menim tudi, da so nekateri komentarji zelo relevantni.

2007-08-08

Tora

Installed TOra on my Ubuntu GNU/Linux (check this howto as well as mine howto for details on Oracle instantclient) and Windows XP box.

2007-07-09

Pedigree viewer on GNU/Linux

Hi, it's time to share some good news with others. I have managed to install, run, and use Pedigree Viewer (a program that draws and manipulates pedigree diagrams, written by Brian and Sandy Kinghorn) under my laptop running GNU/Linux. Since this is a MS Windows application, wine emulator is being used of course. Bellow is a set of terminal commands one needs to issue to get the whole thing working.


# Create temporary folder
mkdir pedigreeViewer
cd pedigreeViewer

# Get the program and unzip it
wget http://www-personal.une.edu.au/%7Ebkinghor/pedigree.zip
unzip pedigree.zip

# Install the program
wine setup.exe

# Run it
wine /path/to/your/wine/drive_c/Program\ Files/Pedigree\ Viewer/Pedigree.exe &

# /path/to/your/wine depends on your configuration of wine
# usually it is ~/.wine/dosdevices/c:

# Optionally create alias for future use and put it into file like
# ~/.bashrc
alias PedigreeViewer='wine /path/to/your/wine/drive_c/Program\ Files/Pedigree\ Viewer/Pedigree.exe'


I have the following software:
Ubuntu GNU/Linux version 7.04 (Feisty Fawn)
wine version 0.9.33

2007-05-18

Move to *ubuntu

I had to install GNU/Linux on my box at work and have looked yesterday at Ubuntu (uses Debian as a source of packages) and its derivatives (Kubuntu an Xubuntu). I decided to take Xubuntu, because I will use this machine for a bit more involved computing and I do not want to spend to much resources on eye-candy stuff. Additionally, Xubuntu should be the right choice for my poor laptop.

It turned out that this was very good choice. I had running linux in say 20 min. It is very nicely packed and organized. Up to now I have used RedHat and Debian and this is the best of all! Not to mention the quality of help - really clean, straight, nicely written. Impressive! Debian has great package management, but Ubuntu has pushed this even further. Very slick. I think I will install it also on my laptop over the weekend. I hope wireless will work OK.

I am installing now VirtualBox. Virtualization seems to be very easy these days. Looks like I will be able to abandon dual booting. Oh, at last.

2007-04-13

Installing PyPedal under Debian

Here is my initial attempt about installing PyPedal on my Debian box. ## mark my comments and the rest are shell commands:


## Switch to root user
su -

## First install non-python stuff in Debian
##
## Software Debian package
## Graphviz graphviz
## SQLite sqlite3
##
## Note that there are sqlite and sqlite3 in Debian and
## I took the new one

aptitude install graphviz sqlite3

## Now we get to python modules that are
## already packaged in Debian
## Module Debian package
## elementtree python-elementtree
## matplotlib python-matplotlib
## NetworkX python-networkx
## NumPy python-numpy
## PIL python-imaging
## pydot python-pydot
## PyGraphviz python-pygraphviz
## pyparsing python-pyparsing
## pysqlite python-pysqlite2
## ReportLab python-reportlab
## setuptools python-setuptools

## Again, there are python-sqlite (for SQLite 2),
## python-pysqlite1.1 and python-pysqlite2
## (both for SQLite 3)

aptitude install python-elementtree\
python-matplotlib \
python-networkx \
python-numpy \
python-imaging \
python-pydot \
python-pygraphviz \
python-pyparsing \
python-pysqlite2 \
python-reportlab \
python-setuptools

## Other Python modules not in Debian

## According to Python inst. doc especially this section
## we should use the following way to install
## non-debianized modules
##
## python setup.py install --prefix=/usr/local

## PythonDoc
## Site: http://effbot.org/zone/pythondoc.htm
## At the time of writting I issued the following

wget http://effbot.org/downloads/pythondoc-2.1b6-20060406.tar.gz

tar -xzvvf pythondoc-*
cd pythondoc-*
python setup.py install --prefix=/usr/local
cd ..
rm -R -f pythondoc-*

## testoob
## Site: http://testoob.sourceforge.net/
## At the time of writting I issued the following

wget http://kent.dl.sourceforge.net/sourceforge/testoob/testoob-1.13.tar.gz

tar -xzvvf testoob-*
cd testoob-*
python setup.py install --prefix=/usr/local
cd ..
rm -R -f testoob-*

## PyPedal
## Site: http://pypedal.sourceforge.net/
## At the time of writting I issued the following

wget http://puzzle.dl.sourceforge.net/sourceforge/pypedal/PyPedal-2.0.0b21.tar.gz

tar -xzvvf PyPedal-*
cd PyPedal-*
python setup.py install --prefix=/usr/local

## Upps! The last one does not install cleanly as
## reported on SF mailist list for PyPedal.

2007-04-01

Oracle instantclient + ODBC on Debian GNU/Linux

I have finally managed to properly install Oracle's instantclient and ODBC drivers on my Debian GNU/Linux box. Here is my mini HOWTO. Lines that start with # are comments.

# Change to root (as usual)

su -

# Go to link bellow and register

http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/linuxsoft.html

# Download

Instant Client Package - Basic: All files required to run OCI, OCCI, and
JDBC-OCI applications

oracle-instantclient-basic-10.2.0.3-1.i386.rpm

Instant Client Package - SDK: Additional header files and an example makefile for developing Oracle applications with Instant Client

oracle-instantclient-devel-10.2.0.3-1.i386.rpm

Instant Client Package - JDBC Supplement: Additional support for XA,
Internationalization, and RowSet operations under JDBC

oracle-instantclient-jdbc-10.2.0.3-1.i386.rpm

Instant Client Package - SQL*Plus: Additional libraries and executable for
running SQL*Plus with Instant Client

oracle-instantclient-sqlplus-10.2.0.3-1.i386.rpm

Instant Client Package - ODBC: Additional libraries for enabling ODBC applications

instantclient-odbc-linux32-10.2.0.3-20061115.zip

# Convert rpm to deb

alien oracle-instantclient-*

# Install

dpkg -i oracle-instantclient-*deb

# Remove deb and rpm files

rm -f oracle-instantclient-*rpm oracle-instantclient-*deb

# Installed files are

dpkg -L oracle-instantclient-basic
/usr
/usr/share
/usr/share/doc
/usr/share/doc/oracle-instantclient-basic
/usr/share/doc/oracle-instantclient-basic/copyright
/usr/share/doc/oracle-instantclient-basic/changelog.Debian.gz
/usr/lib
/usr/lib/oracle
/usr/lib/oracle/10.2.0.3
/usr/lib/oracle/10.2.0.3/client
/usr/lib/oracle/10.2.0.3/client/bin
/usr/lib/oracle/10.2.0.3/client/bin/genezi
/usr/lib/oracle/10.2.0.3/client/lib
/usr/lib/oracle/10.2.0.3/client/lib/libclntsh.so.10.1
/usr/lib/oracle/10.2.0.3/client/lib/libnnz10.so
/usr/lib/oracle/10.2.0.3/client/lib/libocci.so.10.1
/usr/lib/oracle/10.2.0.3/client/lib/libociei.so
/usr/lib/oracle/10.2.0.3/client/lib/libocijdbc10.so
/usr/lib/oracle/10.2.0.3/client/lib/ojdbc14.jar

dpkg -L oracle-instantclient-devel
/usr
/usr/share
/usr/share/doc
/usr/share/doc/oracle-instantclient-devel
/usr/share/doc/oracle-instantclient-devel/copyright
/usr/share/doc/oracle-instantclient-devel/changelog.Debian.gz
/usr/share/oracle
/usr/share/oracle/10.2.0.3
/usr/share/oracle/10.2.0.3/client
/usr/share/oracle/10.2.0.3/client/cdemo81.c
/usr/share/oracle/10.2.0.3/client/demo.mk
/usr/share/oracle/10.2.0.3/client/occidemo.sql
/usr/share/oracle/10.2.0.3/client/occidemod.sql
/usr/share/oracle/10.2.0.3/client/occidml.cpp
/usr/include
/usr/include/oracle
/usr/include/oracle/10.2.0.3
/usr/include/oracle/10.2.0.3/client
/usr/include/oracle/10.2.0.3/client/nzerror.h
/usr/include/oracle/10.2.0.3/client/nzt.h
/usr/include/oracle/10.2.0.3/client/occi.h
/usr/include/oracle/10.2.0.3/client/occiAQ.h
/usr/include/oracle/10.2.0.3/client/occiCommon.h
/usr/include/oracle/10.2.0.3/client/occiControl.h
/usr/include/oracle/10.2.0.3/client/occiData.h
/usr/include/oracle/10.2.0.3/client/occiObjects.h
/usr/include/oracle/10.2.0.3/client/oci.h
/usr/include/oracle/10.2.0.3/client/oci1.h
/usr/include/oracle/10.2.0.3/client/oci8dp.h
/usr/include/oracle/10.2.0.3/client/ociap.h
/usr/include/oracle/10.2.0.3/client/ociapr.h
/usr/include/oracle/10.2.0.3/client/ocidef.h
/usr/include/oracle/10.2.0.3/client/ocidem.h
/usr/include/oracle/10.2.0.3/client/ocidfn.h
/usr/include/oracle/10.2.0.3/client/ociextp.h
/usr/include/oracle/10.2.0.3/client/ocikpr.h
/usr/include/oracle/10.2.0.3/client/ocixmldb.h
/usr/include/oracle/10.2.0.3/client/odci.h
/usr/include/oracle/10.2.0.3/client/oratypes.h
/usr/include/oracle/10.2.0.3/client/ori.h
/usr/include/oracle/10.2.0.3/client/orid.h
/usr/include/oracle/10.2.0.3/client/orl.h
/usr/include/oracle/10.2.0.3/client/oro.h
/usr/include/oracle/10.2.0.3/client/ort.h
/usr/include/oracle/10.2.0.3/client/xa.h
/usr/lib
/usr/lib/oracle
/usr/lib/oracle/10.2.0.3
/usr/lib/oracle/10.2.0.3/client
/usr/lib/oracle/10.2.0.3/client/lib
/usr/lib/oracle/10.2.0.3/client/lib/libclntsh.so
/usr/lib/oracle/10.2.0.3/client/lib/libocci.so

dpkg -L oracle-instantclient-jdbc
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/oracle-instantclient-jdbc
/usr/share/doc/oracle-instantclient-jdbc/copyright
/usr/share/doc/oracle-instantclient-jdbc/changelog.Debian.gz
/usr/lib
/usr/lib/oracle
/usr/lib/oracle/10.2.0.3
/usr/lib/oracle/10.2.0.3/client
/usr/lib/oracle/10.2.0.3/client/lib
/usr/lib/oracle/10.2.0.3/client/lib/libheteroxa10.so
/usr/lib/oracle/10.2.0.3/client/lib/orai18n.jar

dpkg -L oracle-instantclient-sqlplus
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/oracle-instantclient-sqlplus
/usr/share/doc/oracle-instantclient-sqlplus/copyright
/usr/share/doc/oracle-instantclient-sqlplus/changelog.Debian.gz
/usr/bin
/usr/lib
/usr/lib/oracle
/usr/lib/oracle/10.2.0.3
/usr/lib/oracle/10.2.0.3/client
/usr/lib/oracle/10.2.0.3/client/bin
/usr/lib/oracle/10.2.0.3/client/bin/sqlplus
/usr/lib/oracle/10.2.0.3/client/lib
/usr/lib/oracle/10.2.0.3/client/lib/glogin.sql
/usr/lib/oracle/10.2.0.3/client/lib/libsqlplus.so
/usr/lib/oracle/10.2.0.3/client/lib/libsqlplusic.so
/usr/bin/sqlplus

# Configuration

# Create a general link so that env. variables bellow can be more general
# between different versions

cd /usr/lib/oracle/
ln -s 10.2.0.3/ default

# Add the following lines in '/etc/profile' so that all users will benefit

echo 'export SQLPATH=/usr/lib/oracle/default/client/lib' >> /etc/profile
echo 'export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SQLPATH"' >> /etc/profile

# LD_LIBRARY_PATH can be clobbered by unknown system to me and it is
# probably nicer to add library location via the following way, which will
# work out of the box for all users.

echo '/usr/lib/oracle/default/client/lib' >> /etc/ld.so.conf
ldconfig

# Set TNS_ADMIN, which should point to map with 'TNSNAMES.ORA' file. Hmm,
# where do you get that file? You should ask database administrator. I got
# it from him and put it via commands bellow. Additionally, I also needed
# file 'SQLNET.ORA' in same place!

cd /usr/lib/oracle/
mkdir -p network/admin
mv TNSNAMES.ORA SQLNET.ORA /usr/lib/oracle/network/admin/.
## keep in uppercase !!!!
echo 'export TNS_ADMIN=/usr/lib/oracle/network/admin' >> /etc/profile

# Login to database with

sqlplus username/password@//machineName:port/databaseName

# Additionally, ODBC drivers where not available as RPM package so I need
# to do installation by hand.

# Unpack
unzip instantclient-odbc-linux32-10.2.0.3-20061115.zip
Archive: instantclient-odbc-linux32-10.2.0.3-20061115.zip
inflating: instantclient_10_2/ODBCRelnotesJA.htm
inflating: instantclient_10_2/ODBCRelnotesUS.htm
inflating: instantclient_10_2/ODBC_IC_Readme_Linux.html
inflating: instantclient_10_2/libsqora.so.10.1
inflating: instantclient_10_2/odbc_update_ini.sh

# Move files to proper place
mv instantclient_10_2/* /usr/lib/oracle/default/client/lib/.
cd /usr/lib/oracle/default/client/lib/.

# Create link - just to be sure
ln -s libsqora.so.10.1 libsqora.so

# We need system ODBC stuff
aptitude install odbcinst1

# Issue ODBC configuration via available shell script. I had a problem to
# understandwhat and where is driver manager directory. Looking in install
# script revealed that this is a root directory, since I should pass
# something like $DM_HOME/etc/odbc.ini. Since 'odbc.ini' is in '/etc',
# driver manager home is just '/'.
chmod a+x odbc_update_ini.sh
./odbc_update_ini.sh /

# Now let's take a look
cat /etc/odbcinst.ini

[Oracle 10g ODBC driver]
Description = Oracle ODBC driver for Oracle 10g
Driver = /usr/lib/oracle/10.2.0.3/client/lib/libsqora.so.10.1
Setup =
FileUsage =
CPTimeout =
CPReuse =

cat $HOME/.odbc.ini

[_yourDSN_]
Application Attributes = T
Attributes = W
BatchAutocommitMode = IfAllSuccessful
BindAsFLOAT = F
CloseCursor = F
DisableDPM = F
DisableMTS = T
Driver = Oracle 10g ODBC driver
DSN = OracleODBC-10g
EXECSchemaOpt =
EXECSyntax = T
Failover = T
FailoverDelay = 10
FailoverRetryCount = 10
FetchBufferSize = 64000
ForceWCHAR = F
Lobs = T
Longs = T
MetadataIdDefault = F
QueryTimeout = T
ResultSets = T
ServerName = _yourServerName_
SQLGetData extensions = F
Translation DLL =
Translation Option = 0
DisableRULEHint = T
UserID = _yourUserID_

# Exit root account
exit

# Copy roots' '.odbc.ini' to users home and modify it that it matches to your
# database.
cat /root/.odbc.ini >> .odbc.ini

# You can play with graphical tools

DataManager &
DataManagerII &
OBCDConfig & # I got crash here when I wanted to connect to database

# Or with command line

isql -v _yourDSN_ _yourUserName_ _yourPassword_

# Now slick stuff with RODBC

su - # again as root
aptitude install r-cran-rodbc
exit

# Start R

library(RODBC)

channel <- odbcConnect(dsn=_yourDSN_, uid=_yourUserID_, pwd=_yourPassword_,
case="oracle", believeNRows=FALSE)
odbcGetInfo(channel)

# Simple query
query <- "query1;"
zival <- sqlQuery(channel, query)

# Or a set of queries, where sprintf can be nicely used

query <- c(
"query1;",
sprintf("CREATE TABLE tmp AS
SELECT bla1,
bla2,
FROM tableX
WHERE bla3 = '%s';", x),
"query3;")

sapply(query, sqlQuery, channel=channel)

2007-03-03

NTFS with Linux

As a Linux user I always had problems with NTFS drivers for Windows disk/partition. I used drivers that come with a kernel, but only read was supported. Now, we can have also write support with NTFS-3G. Debian users can simply type

aptitude install ntfs-3g

NTFS-3G site shows how to use this "driver". Now I have the following in my /etc/auto.mnt

flash -fstype=ntfs-3g,gid=usb,umask=002,sync :/dev/sda1
slimwin -fstype=ntfs-3g,gid=usb,umask=002,sync :/dev/sda1


This also means that I can safely reformat my USB stick from VFAT to NTFS and no more "problems" with long filenames. I was unable to format USB to NTFS. I followed this note.

Finally, this is one barrier less for use of Linux. Great!