Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Thursday, September 13, 2012

Plotting them means

Plotting means in R by normal distributions with alpha levels and barplots and styles (here)

Package for plotting means + SD + SEM on Matlab (NotBoxPlots)

Thursday, June 28, 2012

All Machine Learning Methods Explained

I found a good tutorial/wiki course about machine learning methods and some code on how to implement them here

Thursday, April 5, 2012

SQLite, Python+SQLite + CSV files


some Python+SQLite examples here and here

Examples of playing with the CSV module from Python here

Information of When/Where to use SQLite

Monday, April 2, 2012

R syntax in Textmate


Instruction on how to install the R Bundle for Textmate here

Thursday, March 15, 2012

Python, Numpy, Scipy, Matplotlib and many others in one package


Instead of jousting with macports, fink or downloading all packages separately, the best way to get them all together working is Enthought

Download the packages for windows, mac or linux here

Monday, March 5, 2012

Inset to create a plot inside a plot in matlab


figure(1)
clf;

x=[0:0.1:20]
y=sin(x)

subplot(1,1,1) ; % main plot

plot(x,y,'b')
xlabel('x','fontsize',18)
ylabel('sin(x)','fontsize',18)

axes('position',[0.5 0.6 0.3 0.2]) ; % inset

plot(x,abs(y),'r')
xlabel('x','fontsize',15)
ylabel('abs(sin(x))','fontsize',15)

from this matlab intro.

Monday, February 13, 2012

Thursday, January 5, 2012

Matlab Teaching Codes

Matlab code for Linear Algebra methods here

Saturday, September 17, 2011

Perl one liner to rename files


Where aaa is the pattern we want to replace with bbb

ls | perl -ne 'chomp; next unless -e; $o = $_; s/aaa/bbb/; next if -e; rename $o, $_';

at the /g to search all the string (replace more than once)

ls | perl -ne 'chomp; next unless -e; $o = $_; s/aaa/bbb/g; next if -e; rename $o, $_';

originally posted with a list of other perl one liners.

Thursday, March 18, 2010

Vectorization in Matlab

This i found in the net, (not my material), however i think is actually good to have this at hand.

Faster calculations in Matlab Manual

Saturday, March 6, 2010

File Preprocessing with awk and Perl

In the last week i have been written bash, perl, python, sed, awk scripts, i have been writting even scripts to write my scripts, this are the tricks i want to save for later...

- how to get rid of the blank lines of a file
awk '$1 !~ /(^$)/' someFile > someNewFile

this will do the same

cat somefile | grep -v '^$' >> someNewFile

Other problem i have run into, has been the problems with carriage return in unix and other systems, in some systems is "\r" in unix is "\n", the worst part happens when you want to read a file in bash and nothing happens and then you check by using

od -c

and realize that all the newlines are "\r". I found that the best way to solve this is to use a simple Perl one liner:

perl -pe 's/\r\n|\n|\r/\n/g'

which i found in the newline wiki page

Monday, February 8, 2010

Reading files into a dictionary in python

This one i use all the time to read massive datasets, it is equivalent to what you can do in perl with the @

import os,sys
import linecache
import string

if __name__ == "__main__":

#print len(sys.argv)
if (len(sys.argv) == 2): #arg 0 = name, arg 1 = argument
file=sys.argv[1] #get the pointer to file

rfp = open('results.txt',"w") #open a file to print results

arr = linecache.getlines(file) #get the file into the dictionary called arr
lines = len(arr)

for i in xrange(lines):
arr[i]= arr[i].strip().split() #by default split by \t, but can be changed to whatever symbol

for i in xrange(lines): #remember the line number will be the key to access the list of fields (columns if spreedsheet)
print arr[i]
print arr[i][0], arr[i][n]

Pick up lines with Perl

There are people who are good at saying or creating pick up lines and use them at bars, pubs and clubs.

Here a Perl 'one-liner' that will help process that 500mb text file (if you are doing bioinformatics, you might know what i am talking about)

If the file has columns separated by space, and you want to get the scores over a certain threshold and print that line to a file (also can be used $. to get the line number)

perl -ane 'if ($F[column_number] > score) {print $_}' filename.txt

if separated by something else

perl -F'symbol' -ane 'if ($F[column_number] > score) {print $_}' filename.txt

some more info

http://www.cbs.dtu.dk/courses/27619/lesson13.html