Posts

Showing posts from July, 2016

perl2python: Reading files

Table of Contents File Read files HERE documents File Read files •               perl #!/usr/bin/perl -w use   strict ; open  FILE,  " data/test.fa "   or   die   " $! " ; while ( my   $line  =  <FILE>  ){      print   " $line " ; } ## >gene1 ## ATGGCTAGCATCGTACGTCG ## >gene2 ## ATGGCTAGCTACGTACGTAG •               python infile  =   open ( "data/test.fa" ,  'r' ) for  line  in  infile.readlines():   line  =  line.rstrip( ' \n ' )    print  line ## >gene1 ## ATGGCTAGCATCGTACGTCG ## >gene2 ## ATGGCTAGCTACGTACGTAG Here  readline()  reads one line character at a time,  readlines()  reads in the whole file at once and splits it by line. The xreadlines() function should be used for big files: infile  =   open ( "data/test.fa" ,  'r' ) for  line  in  infile.xreadlines():   line  =  line.rstrip( ' \n ' )    print  line ## >gene1 ## ATGGCTAGC

R tips: two methods for the "q" problem

1)  postscript(file="plot.eps") plot(object) dev.off() 2)  dat <- sample(1:1000,100) pdf("plot.pdf",useDingbats=F) plot(dat) dev.off() References: http://boopsboops.blogspot.com/2011/07/importing-pdf-r-plots-into-inkscape-q.html http://stackoverflow.com/questions/23524262/why-doesnt-inkscape-correctly-read-pdf-files-generated-by-r

R tips: R + Inkscape

    In my work, I use R a lot to generate figures. I generate most of my figures using R. One problem is sometime I need to add or edit the content of the figures.       The way I do this is to use powerful INKSCAPE . Inkscape is an Open Source alternative (read that as free) to edit the figures.        You can save the figures as PDF or EPS files. Then import the figures into Inkscape. In Inkscape, you can just click, drag, rotate the vectors in the pdf as you want.

Installing and Using the Vim Text Editor on a Cloud Server

On DigitalOcean, default vi doesn't have color scheme. You can use vim to enable the color scheme. References https://www.digitalocean.com/community/tutorials/installing-and-using-the-vim-text-editor-on-a-cloud-server

Not written by me: Hidden Markov Models for Dummies

This article is a great collection of the best resources available on the web which explain   Hidden Markov Models   and their applications. I think there is never a "best place" to learn  all  the points of a new concept/idea. But, you need to go through a lot of sources (books, webpages, jounals, etc) to understand something. If you are done with learning what HMMs can do, you can checkout this  post which discusses about selecting optimal parameters for training of a HMM classifier. Here is a  really good explanation  of what  HMMs  are all about. You need some  background  (Bayesian Networks) with Probability though. The above website  Autonlab  (from  Carnegie Mellon University ) has really good explanation/slides for Data Mining, Machine Learning, Pattern Recognition which is helpful to Math, Statistics, Computer Science researchers. Here is another  link  (from  University of Otago , they make really good tutorials which start from basics) that explains  HMMs

Not written by me: Hidden Markov Models for Dummies

This article is a great collection of the best resources available on the web which explain   Hidden Markov Models   and their applications. I think there is never a "best place" to learn  all  the points of a new concept/idea. But, you need to go through a lot of sources (books, webpages, jounals, etc) to understand something. If you are done with learning what HMMs can do, you can checkout this  post which discusses about selecting optimal parameters for training of a HMM classifier. Here is a  really good explanation  of what  HMMs  are all about. You need some  background  (Bayesian Networks) with Probability though. The above website  Autonlab  (from  Carnegie Mellon University ) has really good explanation/slides for Data Mining, Machine Learning, Pattern Recognition which is helpful to Math, Statistics, Computer Science researchers. Here is another  link  (from  University of Otago , they make really good tutorials which start from basics) that explains  HMMs

Perl2Python: Get the current working path

Perl Cwd can be used to get pathname of current working directory. use Cwd; my $dir = getcwd; Python To get the current working directory use os.getcwd() The question asked for the directory of a given file, so the proper answer is: import os os.path.dirname(os.path.realpath(__file__))

Perl2Python: Get the current working path

Perl Cwd can be used to get pathname of current working directory. use Cwd; my $dir = getcwd; Python To get the current working directory use os.getcwd() The question asked for the directory of a given file, so the proper answer is: import os os.path.dirname(os.path.realpath(__file__))