Wednesday, July 20, 2011

sed linux/mac

windows下,每一行的结尾是\n\r,而在linux下文件的结尾是\n,那么你在windows下编辑过的文件在linux下打开看的时候每一行的结尾就会多出来一个字符\r, 用cat -A urfile时你可以看到这个\r字符被显示为^M,这时候只需要删除这个字符就可以了。可以使用命令

Linux

sed -i 's/\r$//' urfile

Mac:

sed 's/\r$//' urfile > newfile
or
sed -i '' 's/\r$//' urfile


Removing one (or several) line (s) of a file


Syntax:


sed '{[/]<n>|<string>|<regex>[/]}d' <fileName>
sed '{[/]<adr1>[,<adr2>][/]d' <fileName>
  • /.../=delimiters
  • n = line number
  • string = string found in in line
  • regex = regular expression corresponding to the searched pattern
  • addr = address of a line (number or pattern )
  • d = delete


Examples

Remove the 3rd line:

sed '3d' fileName.txt


Removal of the line containing the string "awk":

sed '/awk/d' filename.txt


Remove the last line:

sed '$d' filename.txt



Remove all empty lines:

sed '/^$/d' filename.txt
sed '/./!d' filename.txt


Remove line "matched" by a regular expression (by eliminating one containing digital characters (at least 1 digit) located at the end of the line).

sed '/[0-9/][0-9]*$/d' filename.txt


Removing the interval between lines 7 and 9.

sed '7,9d' filename.txt 


Same operation but replacing the address by "parameters".

sed '/-Start/,/-End/d' filename.txt



The above examples are only change at the display of the file (stdout1= screen).

For permanent changes to the old versions (<4) use a temporary file for GNU sed use the "-i[suffix]":

sed -i".bak" '3d' filename.txt

source: http://en.kioskea.net/faq/1451-sed-delete-one-or-more-lines-from-a-file

Monday, July 18, 2011

R Plot

1. X/Y 坐标值
x <- seq(-4, 4, len = 101)
y <- cbind(sin(x), cos(x))
matplot(x, y, type = "l", xaxt = "n", yaxt="n")
### xaxt = "n", yaxt="n" => x, y 不画x, y坐标
axis(1, at = c(-pi, -pi/2, 0, pi/2, pi), labels = expression(-pi, -pi/2, 0, pi/2, pi))
###x轴 画坐标,在指定的位置画指定的坐标 
axis(2, at = c(-0.8, -0.5, 0, 03, 0.7), labels = expression(-pi, -pi/2, 0, pi/2, pi))
###y轴 画坐标,在指定的位置画指定的坐标
2. Lengend
legend(1, 0.4, c("Case", "Control", "HapMap"), col = c("red", "blue", "green"), lty = c(1, 1, 1), pch = c(1, 1, 1), merge = TRUE, bg = 'gray90')

第一项:x坐标;第二项:y坐标;第三项:text;第四项:颜色;第五项:线型;第六项:点型

Monday, July 11, 2011

Acer aspire one d255 system restore

Before you go rushing into anything.there is a general confusion when people talk about restore.

Do you mean to restore back a few days or perhaps a week for some reason, or restore/recover the system back to factory conditions ie as you bought it. two totally different operations.

If it is the first one then go to START, ALL PROGRAMS, select ACCESSORIES, Then select SYSTEM TOOLS, Then SYSTEM RESTORE. Click restore. You can then select a highlighted restore point This should be much the same for win 7.

If you mean recover back to factory settings, which will destroy all your data you have added if you do not back it up. Then at start up and during the Acer logo display press and hold down the ALT key and repeatedly press the F10 key.

source:http://answers.yahoo.com/question/index?qid=20110109143354AAgJ559

linux move directory

<Creating directories >
Creating a new, empty directory is very easy. You use the mkdir command:

$ mkdir dir1

That's it. It's really that easy!

< Removing directories >

There are two commands you can use for removing directories.

If the directory is empty, you can use rmdir:

$ rmdir dir1

You can use rmdir only if the directory is empty. If you want to remove a directory with all its contents, you can use rm with the -r option. The -r option tells rm to remove a directory recursively:

$ rm -r dir1

It goes without saying that you can cause a lot of trouble with rm -r if you're not careful! In some cases it might be a good thing to use the -i option when deleting a directory with its contents so that you'd be prompted before each file in the directory gets deleted:

$ rm -ir dir1

< Copying and moving directories >

For copying and moving directories you can use the cp and mv commands just like you use them with files.

Yeah, I know. If you've already tried to copy a directory with cp, you've probably noticed that cp just complains at you. Probably it says something like cp: omitting directory yadda yadda. You see, the cp command wants you to use the -r option if you want to copy a directory with its contents. The -r means "copy recursively":

$ cp -r dir1 dir2

The above creates a directory named dir2 whose contents will be identical to dir1. However, if dir2 already exists, nothing will be overwritten: the directory dir1 will be copied into the dir2 directory under the name dir2/dir1.

When renaming directories, you use the mv command exactly the same way as with files:

$ mv dir1 dir2

When dealing with directories, mv works a bit like cp does. If dir2 doesn't exist, the above will rename dir1 to dir2, but if dir2 exists, the directory dir1 will be moved into the dir2 directory under the name dir2/dir1.


source: http://www.tuxfiles.org/linuxhelp/dirman.html

Friday, July 8, 2011

Installing BioPerl on Mac OS 10.6 Snow Leopard in 6 Easy Steps

source: http://www.sysarchitects.com/bioperl
The strategy I used to install BioPerl was as follows:
1. Use MacPorts to install Perl.
2. Use CPAN to install BioPerl.
Here are the nitty gritty details. You need a live internet connection, as both MacPorts and CPAN expect to be able to download packages.

Step One: XCode Tools

Before MacPorts can be installed, XCode Tools needs to be installed. This is free from Apple and can be installed from the original OS X 10.6 DVD or downloaded from Apple's developer site.
You can tell that XCode Tools is installed by looking for a Developer directory at the root of your hard drive.

Step Two: MacPorts

I simply downloaded the MacPorts Package Installer from the MacPorts site.

Step Three: Install Perl

sudo port install perl5.12

Step Four: Install GraphViz

This is a prerequisite of BioPerl and the BioPerl build will fail if it is not installed. It will download a ton of prequisites first. After typing the following, get a coffee and a sandwich.
sudo port install graphviz

Step Five: Configure CPAN

CPAN likes to have YAML installed. So:
sudo cpan YAML
At this point cpan will realize it's being run for the first time and ask you some questions like
Would you like me to configure as much as possible automatically? [yes]
Selecting the defaults worked fine.
It's nice to have LWP too.
To install LWP, first get to the cpan command prompt:
sudo cpan
Then install it:
install Bundle::LWP

Step Six: Build BioPerl

To install BioPerl, first get to the cpan command prompt:
sudo cpan
At the command prompt, tell CPAN that you want it to automatically get and install any prerequisites it comes across (this saves you hours of choosing "Yes"):
cpan[1]> o conf prerequisites_policy follow
And now, at the cpan prompt, install BioPerl:
install C/CJ/CJFIELDS/BioPerl-1.6.1.tar.gz
[force install C/CJ/CJFIELDS/BioPerl-1.6.1.tar.gz]
It will stop several times along the way. Except for the following question where my selection was to install all optional external modules, the defaults were fine.
Install [a]ll optional external modules, [n]one, or choose [i]nteractively? [n] a
During the tests that BioPerl runs, I saw the following:
Replacement list is longer than search list at Bio/Range.pm line 251.
According to this post, The above are warnings from perl 5.12 that can be ignored (they have been fixed in bioperl-live on github).
For a quick test of BioPerl, put the following into a file named test.pl:

use Bio::Perl;
# this script will only work if you have an internet connection on the
# computer you're using, the databases you can get sequences from
# are 'swiss', 'genbank', 'genpept', 'embl', and 'refseq'
$seq_object = get_sequence('embl',"AI129902");
write_sequence(">roa1.fasta",'fasta',$seq_object);

Then run it:
perl test.pl
and sure enough, a file named roa1.fasta gets written. Yay!
If you are installing BioPerl on a Mac that has multiple user accounts, you'll need to make sure that the following exists in each user's .profile file (at /Users/john/.profile, for example):

# MacPorts Installer addition on 2010-10-04_at_15:32:08: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.

This makes it so that when you type perl the Mac will find and use the Perl from MacPorts instead of the system Perl. Also, be aware of scripts that say #!/usr/bin/perl at the top.

Friday, July 1, 2011

R max-vsize and Haploview memory

Use command line options to control the memory available for R.

R --min-vsize=vl --max-vsize=vu --min-nsize=nl --max-nsize=nu --max-ppsize=N

vl, vu, vsizeHeap memory in bytes.
nl, nu, nsizeNumber of cons cells.
NNumber of nested PROTECT calls.

Both options must be integers or integers followed by G, M, K, or k meaning Giga (2^{30} = 1073741824) Mega (2^{20} = 1048576), (computer) Kilo (2^{10} = 1024), or regular kilo (1000).

R --max-vsize=3G   ### 3G, R max

java -jar Haploview.jar -memory 4000 ### 4G memory