Thursday, July 31, 2014

How to change decimal numbers to integers in a column of a file in Unix

If you have file with 5 columns and want to change last 5th column from decimal to integer use awk:

awk '{print $1,$2,$3,$4,int($5)}' file.txt > file_integer.txt

Tuesday, July 22, 2014

Abline doesn't work in R

It may happen that you are plotting a linear regression line with abline command in R and that it didn't appear on the graph.
Most probable explanation (as it was for me) is that you have to inverse x and y in abline.

> plot(merge, col="blue", cex=1.5, xlab="X axis title", ylab="Y axis title", main="Main title of the graph")

> abline(lm(merge[,1]~merge[,2]), col=14, lwd=2)

Didn't work but this worked:

> plot(merge, col="blue", cex=1.5, xlab="X axis title", ylab="Y axis title", main="Main title of the graph")

> abline(lm(merge[,2]~merge[,1]), col=14, lwd=2)




Increasing dot size in R

With cex=1:

plot(merge, col="blue", cex=1, xlab="X axis title", ylab="Y axis title", main="Main title of the graph")





With cex=1.5:

plot(merge, col="blue", cex=1.5, xlab="X axis title", ylab="Y axis title", main="Main title of the graph")





How to remove specific lines from file in Unix

To remove line 126 from file use sed command:

sed -i.bak -e '126d' file.txt

Original file.txt will be saved in a bak copy.

To remove line 126 and lines 136-140:

sed -i.bak -e '126d; 136,140d' file.txt

Monday, July 21, 2014

How to obtain regions within bed files that do not overlap

If you have two bed files and want to obtain regions that do not overlap use bedtools intersect with -v option:

bedtools intersect -a file1.bed -b file2.bed -v > output.bed

Friday, July 18, 2014

How to intersect bed file with multiple other bed files simultaneously

Use bed files that end with bb.bed.cut_tabseparated and intersect them with L2_TCCTGAGC_L002_peaks:

for f in $(find . -name \*bb.bed.cut_tabseparated\*)
do
bedtools intersect -a L2_TCCTGAGC_L002_peaks.bed -b "$f" -wa > "$f"_intersect;
done

Thursday, July 17, 2014

How to run a command on a subgroup of files within the folder

To access files that end with bb.bed.cut that are located in the same folder (and not to use other files in that folder) and to run a command on them e.g. print their names with _tabsep extension, run this code:

for f in $(find . -name \*bb.bed.cut\*)
do
echo "$f"_tabsep;
done

How to change spaces to tabs in multiple files simultaneously

If you have created bed files by cutting it from a file using awk as in this post
http://milospjanic.blogspot.com/2014/07/how-to-select-two-or-more-columns-from.html
it may be that columns are separated by spaces, which will cause bedtools unable to read files.

If you want to convert spaces to tabs you can copy those files that have been cut from the original bed files to a new folder and run a code:

for filename in *; do awk -v OFS="\t" '$1=$1' ${filename} > ${filename}_tabseparated; done

Alternatively, to do this with in the original folder, i.e. to select *bb.bed.cut files within the original folder and to perform the change with the awk command run the following code:

for f in $(find . -name \*bb.bed.cut\*)
do
awk -v OFS="\t" '$1=$1' "$f"> "$f"_tabseparated;
done

How to select two or more columns from a file / multiple files in Unix

If you want to e.g. select first 3 columns from a file use awk command:

awk '{print $1,$2,$3}' test.txt > output.txt

To repeat this for all files in a folder:

for filename in *; do awk '{print $1,$2,$3}' ${filename} > ${filename}.cut; done

Tuesday, July 15, 2014

How to notify yourself via email when your process is done

Lets say that you are running a script and you don't want to check all the time whether it is finished.
You can notify yourself via email, just add this line at the end of your script:

echo my job is completed | sendmail <your email address>

You will receive an email with the text: my job is completed

How to see number of lines of files with names containing one but not other pattern

If you want to see number of lines for each of the files in your folder that contain one pattern in their names but not the other one use wc and pipe it with grep.

For example to see count of lines for files that end with .bed and do nt contain 'peaks in their names use:

wc -l *.bed | grep -v "peaks"

If you want to see the same but for the files that do contain 'peaks' use:

wc -l *.bed | grep "peaks"

If you want to see the same but for files that end with '.bed', and contain both 'peaks' and 'normalized' use:

wc -l *.bed | grep "peaks" | grep "normalized"

etc.

How to list files that match one but not other pattern

If you want to list files that match one pattern but not other pipe grep command twice.
For example to list files that are .bed files but that do not contain phrase 'peaks' in them use:

ls | grep ".bed" | grep -v "peaks"

Or to list files that are .bed files that do contain this phrase in the name of the file:

ls | grep ".bed" | grep "peaks"

Friday, July 11, 2014

How to manipulate with multiple files in Unix

If you want to apply certain Unix command on each file present in your folder,
type:

for filename in *; do <command> ${filename}; done

e.g.
for filename in *; do echo ${filename}; done

This example will print the names of the files in terminal.

How to convert multiple bigBed files to bed

If you want to convert bigBed to bed download bigBedToBed from
http://hgdownload.cse.ucsc.edu/admin/exe/linux.x86_64.v287/
(for linux 64 bit binary)
Then to convert multiple bigBed from your folder type:

for filename in *; do ./bigBedToBed ${filename} ${filename}.bed; done

How to batch download files from ENCODE or any other ftp server

If you need to batch download files from server, lets say you want to download DNase Seq files from ENCODE consortium you can do this using rsync
Type in terminal:
rsync -a -rsync://ftp.ebi.ac.uk/pub/databases/ensembl/encode/integration_data_jan2011/byDataType/openchrom/jan2011/fdrPeaks/ ./

This will download all the files from the ftp server:

http://ftp.ebi.ac.uk/pub/databases/ensembl/encode/integration_data_jan2011/byDataType/openchrom/jan2011/fdrPeaks/

to the current folder you are in.

Logitech K400r keyboard not pairing - solution

So you bought your Logitech K400r keyboard and it works fine, but when you tried to access settings in Setpoint there is no tab for keyboard. So there is no way you can modify speed of the touch-pad (which is very important) or other settings. You are stuck with the default settings.

You've tried everything and you are at the edge of your nerves.

Go to the Setpoint. Click on Unifying (3 button from the left).
Open Unifying Software.
Advanced
Click on Keyboard K400
Un-pair
Pair a new device
Off-On on keyboard.
Wait for the device to be paired.

After this you will have My Keyboard and My Mouse tabs in Setpoint.

Thursday, July 10, 2014

How to make multiple symbolic links simultaneously

If you have multiple files e.g. file1.txt, file2.txt, file3.txt you want to link to, you can do this in a single command.
Go to the folder where you want links to be.
ln -s <folderpath>/file* -t .

Monday, July 7, 2014

How to copy paste in Putty

If you need to copy and paste in Putty doing ctrl-C and ctrl-V will not work. Ctrl-C may even terminate the process you are running.
Instead select with mouse the part you want to copy. It is immediately copied to the clipboard.
Then to paste, right click with the mouse or press shift-insert.