Tuesday, August 24, 2010

vim magic

So I have a bunch of sequences in fasta format - and I need to rearrange the mo'fos.

To start with the entries look like this:
>F13C5.1        CE19383 WBGene00017422  status:Partially_confirmed      UniProt:O76564  protein_id:AAC64611.1


Run this vim command:
:%s:>\(\S\{4,}\)\t.*UniProt\:\(\S\{6,}\).*$:>\1_CAEEL__\2:g


And now they look like this:
>geneName_OrgID__UniProtAccNo

Thursday, August 5, 2010

LaCie Network Space

So.. you've hacked your network space and got root. But your lazy and you can't find up to date instructions on installing ipkg?

wget http://ipkg.nslu2-linux.org/feeds/optware/mssii/cross/stable/mssii-bootstrap_1.2-7_arm.xsh

and then sh mssii-bootstrap_1.2-7_arm.xsh

Now you have ipkg goodness.

Friday, July 30, 2010

Quick and Dirty histogram in awk

awk '{histogram[int(($2*100)/100)]++;}END{for (i in histogram) { print i, histogram[i] }}' somerandomfilewithatagandcountdataincol2 | sort -n -k 1 > hist

Print every other line of a file

cat blah | awk 'BEGIN{n=0}{if(n%2==0) print $0;n++;}'

Wednesday, July 28, 2010

Getting started with Cython on Centos 5.4 64Bit

Centos is a nightmare. OK so first up I wanted to do with with Python 2.6 for which there is no official Centos package. So get the geekymedia repos which has a version of Python 2.6 which will install along side the existing 2.4 (and can be access as python26) here: here.

Then download the Cython tarball. Before you build Cython make sure you setup compile flags for 32bitness and make sure python 2.6 gets used i.e.

export CFLAGS="-m32 -march=i386"
export PYTHON="python26"

then run python26 setup.py install in the Cython directory. I had to do some other hacking of -m32 and -march=i386 on to things, but I think doing it this way should work. That should build and install Cython.

Put the following example in a file called demo.pyx:

cdef extern from "math.h":
double sin(double)

cdef double f(double x):
return sin(x)

print f(2.0)



Then make the following Makefile. Make sure you have tabs!


demo: demo.pyx
cython demo.pyx --embed
gcc -g -pthread -m32 -march=i386 demo.c -L/usr/lib -lm -lpython2.6 -o ./demo -I/usr/include/python2.6




Then just type make and it should build a binary called demo.

Monday, June 14, 2010

Digital Archaeology Tags

It's fairly clear that in the future archaeology will move in to the digital domain with researchers digging through hard discs, USB keys, floppy discs, tapes, EEPROMs etc. I've often though it would be nice to drop them a message every so often, or just leave a note apologizing for my appalling spelling and grammar. So I suggest the following tags, to be encoded in 8bit ASCII when possible:

DIGIARCHNOTESTART

DIGIARCHNOTEEND

Dear future archaeologists, I shall use this in my documents from now on when I want to give you some background, point you in the direction of more information, or just say Hi, so grep away!

Wednesday, June 2, 2010

Grab all hrefs from a html page which have text containing View associated with them

Quick and dirty perl program to grab all links from a webpage which have have anchors with the text "View" in them:

#!/usr/bin/perl

use constant false => 0;
use constant true => 1;

use HTML::TreeBuilder;
use HTML::FormatText;

$html = HTML::TreeBuilder->new();
$html->parse_file($ARGV[0]);

my @stuff = $html->look_down( '_tag' , 'a' );

my $seqtag = "";
my $use_next = false;

for my $i (@stuff) {
my @thing = $i->content();
my $target = $i->attr('href');
my $str = $thing[0][0];

# string contains View
if($str =~ m/View/) {
print $target . "\n";
}
}