Wednesday, March 21, 2007

Counting the number of instances of a letter in a file

To explain why this might be necessary:

First I have an xml file with some sequences in it. I grep the xml file finding the instances I am interested in and save these to a file, stripping out the xml using vim.

grep -A 5 \<type\>Dis filename.xml | grep \<sequence\> > file_raw_seq.txt
Alternatively I could use the fasta file and strip the headers using grep -v \>.

I am now left with the raw text of the sequences from the xml file that I am interested in.

I can now run the following command to check out the number of times say M appears in the file;

tr -dc M < input.fa | wc -c


Easy. The alternative was to write a C++ program to do all this - which would have taken considerably longer. Especially given that some people haven't committed working versions of their code. I'm looking at you Mr. TreeCreate and Mr IntVector.

Thursday, March 1, 2007

Sticky

Further to the back up stuff I been documenting recently, I was told of this useful (?) little titbit. I have a spare disk called /dataStore that is mounted locally on my workstation. Other people log in to my computer to compile stuff, maybe run some stuff etc. So I am letting them back their stuff up locally on my computer. In order to give them the appropriate permissions on the data disk I have made a directory in this disk called imaginatively enough backup.

I have made this directory group writable so that everyone can use this disk. However, in order to ensure that no one fucks up anyone else's data I have made the directory a sticky. To do this type:

chmod +t dir

This is as close to an explanation as I could find:
http://www.uwsg.iu.edu/UAU/files/sticky.html

Wednesday, February 28, 2007

Monday, February 19, 2007

Crontab

This is a useful program for scheduling routine tasks initiated by scripts. Developing on the search installation from last week, we will write a crontab entry to update the namazu index daily.

First of all check which jobs are currently scheduled:

user@compy:~> crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.XXXX8NR6OC installed on Mon Feb 5 17:51:55 2007)
# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
0 5 * * * /home/user/.backup.sh


This is the rsync job from the other week. So, next we need to create a script to run the namazu index. This is a simple shell script with the following command in it:
#!/bin/bash
mknmz -O ~/.namazu/index/ ~/work/articles/

Save this file somewhere like in ~/.namazu/.index.sh. Append this to the crontab in the same way as the rsync script was added - i.e. type crontab -e and add the following line:
0 5 * * * /home/user/.namazu/.index.sh

Then, type crontab -l to check that it has been added. You should now have a namazu index that updates everyday at 5AM.

Wednesday, February 7, 2007

Namazu Config

Namazu is a search engine. Whilst its no replacement for find and grep in most cases, it is useful for searching a directory of pdf files, and this can be made available through a web interface - which is quite useful if you have a lot of pdfs.

Download and install the program - its available for most distributions. You will need to edit the config file namazurc and the index config file mknmzrc. I needed to change the max file size variable to accommodate my pdfs.

In the mknmzrc file I changed the following lines:
# The max file size for indexing. Files larger than this
# will be ignored.
# NOTE: This value is usually larger than TEXT_SIZE_MAX because
# binary-formated files such as PDF, Word are larger.
#
$FILE_SIZE_MAX = 10000000;

#
# The max text size for indexing. Files larger than this
# will be ignored.
#
$TEXT_SIZE_MAX = 6000000;



I then created an index directory in my home directory. If you are setting this up for a web server you may wish to keep the index files elsewhere. So then I ran the mknmz program:

mknmz -O ~/.namazu/index/ ~/work/articles/


This creates the index of the articles directory and stores it in the .namazu/index directory. From the command line you can now enter:
namazu "epitope not cell"


Not that that search makes any sense but you get the idea.

Friday, February 2, 2007

ssh bash completion in Ubuntu

SSH bash completion doesn't currently work in 6.10. This is because hostnames are now stored as hashes in ~/.ssh/known_hosts. To disable storing hostnames as hashes and allow ssh hostname completion to work correctly you need to edit: /etc/ssh/ssh_config and change HashKnownHosts to No.

Thanks to Ubuntu forums for the answer.

Thursday, February 1, 2007

Set up subversion

If you are comfortable with CVS - changing over to svn shouldn't be too hard. First make sure you download the latest version of svn from your package manager.

Then to create the new svn repository type:
svnadmin create /foo/bar/repo


Then to check it out, you need to create a working directory and know the url of the svnserve. In my case this is a local server running on just my machine so the following will work:
mkdir svndir

svn checkout file:///foo/bar/repo svndir


You can now move into the svndir and start working.

Its probably well worth reading up on the differences between cvs projects and svn directories. Its probably easiest to think of creating a new svn repository for what would have been a cvs project. Also its worth bearing in mind that changes in a svn repository tag the whole project rather than a single file.