Archive

gnu/linux

I had a file containing ~1M SNPs in their rsid (and their position). I needed to complete the information with their chromosome.

Since the list is really large I use scan combined with a bash command (to know the length of the file).

I found this solution:

library("SNPlocs.Hsapiens.dbSNP.20120608")

## Create connection to big file
inputName <- "input_file.gen"
outputName <- "output_file.gen"
inputCon <- file(description = inputName, open = "r")
outputCon <- file(description = outputName, open = "w")

## We need to know the number of lines of the big file
## This will work for GNU/Linux environments
command <- paste("wc -l ", inputName, " | awk '{ print $1 }'", sep="")
nLines <- as.numeric(system(command = command, intern = TRUE))
rm(command)

## Loop over the file connection until end of lines
pb <- txtProgressBar(min = 0, max = nLines, style = 3)
for(ii in 1:nLines) {
  readLine <- scan(file = inputCon, nlines = 1, what = "list", quiet = TRUE)

  ## Get the chr from the SNP
  x <- tryCatch({
    x <- rsidsToGRanges(readLine[[2]])
    as.character(x@seqnames[1])
  }, error = function(e) {
    "---"
  })

  ## Update on list and save on output
  readLine[[1]] <- x
  writeLines(paste(readLine, collapse = " "), outputCon)

  setTxtProgressBar(pb, ii)
}

close(inputCon)
close(outputCon)

This solution is really slow but it gets the SNP’s chromosome and fills it as "---" when the SNP is not found in dbSNP.

WARNING: The SNP’s rsid must be located into the second column of the file. Take a look at readLine[[2]] in the for.


I am open to know different ways of doing this.

Using bash and ImageMagick we can crop all the pictures in a folder in a single shoot:

fix='crop'
it=1
for file in $2/*; 
do
    if [[ -f $file ]]; 
    then
        output=$2/${fix}${it}.png
        echo "$file --> $output"
        convert -crop $1 "$file" "$output"
        it=$((it+1))
    fi
done

The script, called crop.sh is run as:

./crop.sh 525x240+675+150 ~/Pictures/

The first argument is the argument for the ImageMagick’s crop tool and the second argumen is the folder where the pictures to be cropped are.

For this examples the user is called darth_vader and the remote host death_star.gov.

Single File

From host to server

In this section the user wants to upload the file called rebel_ids.tsv from his localhost to remotehost.

$ scp rebel_ids.tsv darth_vader@death_star.gov:/home/darth_vader/targets 

From server to host

The user wants to download fr the remotehost the file called flight_path.gpx.

$ scp darth_vader@death_star.gov:/shared/patrols/darth_vader/flight_path.gpx /home/darth_vader/autopilot/ 

Multiple Files

From host to server

Now, the user wants to upload two files, alderaan.gpx and despayre.gpx, to his home into remotehost:

$ scp alderaan.gpx despayre.gpx darth_vader@death_star.gov

From server to host

The user wants to download two files, personal_solo.pdf and personal_chubaca.pdf from remotehost

$ scp darth_vader@death_star.gov:/shared/intelligence/targets/{personal_solo.pdf,personal_chubaca.pdf} .

Direcotry

From host to server

$ scp -r foo darth_vader@death_star.gov:/home/darth_vader/personal/remote/directory/bar 

From server to host

$ scp -r darth_vader@death_star.gov:/home/darth_vader/jedi_doc .

Today I was installing openbox to my Linux Mint. I wanted to add a slot into obmenu called Exit to turn off the computer but asking me how:

Exit Message

The picture above is the result. The way I created is us trough gxmessage, an alternative to xmessage. This tool allows us to create little question boxes using gtk.

So I created abash script with (~/scripts/openbox_logour.sh) having the following content:

#!/bin/bash

gmessage "The system will be shut down. Are your sure?" -center -title "System Shutdown" -default "Cancel" -buttons "_Shut down":1,"_Reboot":2,"_Log out":3,"_Cancel":4 > /dev/null 

case $? in
    1)
        sudo shutdown -h now;;
    2)
        sudo shutdown -r now;;
    3)
        killall openbox;;
    4)
        echo "Exit";;
esac

So we can see out audio settings by using the alsa command:

[carleshf@earth ~]$ amixer -D pulse
Simple mixer control 'Master',0
  Capabilities: pvolume pswitch pswitch-joined
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 65536
  Mono:
  Front Left: Playback 32360 [49%] [on]
  Front Right: Playback 32360 [49%] [on]
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch cswitch-joined
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 65536
  Front Left: Capture 16462 [25%] [on]
  Front Right: Capture 16462 [25%] [on]

So we can see that the volume range goes from 0 to 65536. In this range a 5% takes the value 3276.8, so by running …

amixer -D pulse set Master 3276+ unmute

… we are increasing a 5% the actual volume, and by running …

amixer -D pulse set Master 3276- unmute

… we are decreasing it. Moreover we can use …

amixer -D pulse set Master toggle

… to toggle between mute and unmute.

DISCLAIMER: I’m running a linux mint system with openbox.