Showing posts with label tips. Show all posts
Showing posts with label tips. Show all posts

Wednesday, December 26, 2018

foreach run on R needs large RAM

turn off Dropbox, OneDrive, and GoogleDrive can clear off some large chunks of RAM.

Sunday, January 21, 2018

Tuesday, June 20, 2017

current date in R markdown



date: "May 4 2017 - `r format(Sys.time(), '%d %B, %Y')`"

See
https://stackoverflow.com/questions/23449319/yaml-current-date-in-rmarkdown

Friday, July 8, 2016

OR statement in R


x = 1; y = -2
if( x > 0 | y > 0) {
  print ( "TRUE :: x > 0 | y > 0")
} else {
  print ( "FALSE :: x > 0 | y >0")
}
## [1] "TRUE :: x > 0 | y > 0"

x = -1; y = -2
if( x > 0 | y > 0) {
  print ( "TRUE :: x > 0 | y > 0")
} else {
  print ( "FALSE :: x > 0 | y >0")
}

## [1] "FALSE :: x > 0 | y >0"

Wednesday, December 30, 2015

git retrieve a single file


http://stackoverflow.com/questions/610208/how-to-retrieve-a-single-file-from-specific-revision-in-git

git checkout 08618129e66127921fbfcbc205a06153c92622fe -- [full/path]
To clarify with an example:
git checkout mybranchname ~/src/myapp/myfile.txt

In my case, I need to roll back netwk_aging_sim.v0.1.R.

$ git checkout 4bb272d6a304168fc6711479a8b0b34c55e47182 netwk_aging_sim.v0.1.R
It worked.

The longnumber (branchname?) was found here:




Wednesday, October 7, 2015

Monday, July 20, 2015

R reshape data.frame

df <- read.csv('data.txt', sep=' ')
l <- reshape(df, idvar="ID", varying = list(c("comp1","comp2","comp3"),c("
Num1","
Num2","Num3")), v.names = c("comp", "Num"), direction="long")


l <- reshape(df, direction="long", idvar=1,
             varying=c(c(2,4,6), c(3,5,7)), sep="")

Wednesday, June 24, 2015

command line argument in R

http://stackoverflow.com/questions/2151212/how-can-i-read-command-line-parameters-from-an-r-script

Byte-2:R-args hqin$ 
Byte-2:R-args hqin$ cat R-args.R 
options(echo=TRUE) # if you want see commands in output file
args <- commandArgs(trailingOnly = TRUE)
print(args)
# trailingOnly=TRUE means that only your arguments are returned, check:
# print(commandsArgs(trailingOnly=FALSE))

i = as.integer(args[1])
j = as.integer(args[2])
x = seq(i, j)
print(x)



Byte-2:R-args hqin$ R -f R-args.R --args 2 5

R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin10.8.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> options(echo=TRUE) # if you want see commands in output file
> args <- commandArgs(trailingOnly = TRUE)
> print(args)
[1] "2" "5"
> # trailingOnly=TRUE means that only your arguments are returned, check:
> # print(commandsArgs(trailingOnly=FALSE))
> i = as.integer(args[1])
> j = as.integer(args[2])
> x = seq(i, j)
> print(x)

[1] 2 3 4 5

Wednesday, February 4, 2015

R plot of population heterozygoy



https://github.com/cooplab/popgen-notes/blob/master/Rcode/Loss_of_heterozyg_varying_pop.R

Thursday, January 15, 2015

Socrative, report student results

It seems Socrative can only require student names in the pre-defined quizzes.

I solve this problem by writing a generic quiz on Socrative. I then started Socrative in teacher mode on Mac-tower, and tried student login in two other computers. I loginto Socrative through gmail directly.  After finish the quiz, I save the quiz results to my GoogleDrive directly in a ZIP file that contains the students names and their answers in a Excel file.

Apparently, Socrative does not students to change their answers after their initial submission.

Wednesday, January 14, 2015

Sunday, January 4, 2015

writing in academy,

http://www.theguardian.com/higher-education-network/blog/2013/sep/06/academic-journal-writing-top-tips

1) Have a strategy, make a plan
2) Analyse writing in journals in your field
3) Do an outline and just write
4) Get feedback from start to finish
5) Set specific writing goals and sub-goals
6) Write with others
7) Do a warm up before you write
8) Analyse reviewers' feedback on your submission
9) Be persistent, thick-skinned and resilient
10) Take care of yourself       


http://serialmentor.com/blog/2014/11/16/how-to-prepare-an-article-for-resubmission
 

Monday, December 22, 2014

Useful Unix / Linux shell commands


 cat tmp.txt | sed s/CREATE/DROP/


 who | cut -c1-8 | sort | uniq | nl
 cat /usr/local/apache2/logs/access_log | grep 128\.135 | cut -c1-16 | uniq     
 ps -ef | grep nohup | cut -c53-57 | sort | uniq | nl 

 /sbin/shutdown -r now ?
 lsof

 /etc/rc.local  # system startup configuration

 grep CREATE ensembl_mart_16_1.sql | sed s/CREATE/DROP/ | sed s/\(/\;/ > $HOME/trim_mart.sql

ls enc.* | sed "s/^/\"/" | sed "s/$/\"\,/"

Monday, September 29, 2014

reverse complementary sequences in R seqinr

##
## Show that comp() does *not* return the reverve complementary strand:
##
c2s(comp(s2c("aaaattttggggcccc")))
##
## Show how to get the reverse complementary strand:
##
c2s(rev(comp(s2c("aaaattttggggcccc"))))
##
## Show what happens with non allowed values:
##
c2s(rev(comp(s2c("aaaaXttttYggggZcccc"))))
##
## Show what happens with ambiguous bases:
##
allbases <- s2c("abcdghkmstvwn")
comp(allbases) # NA are produced

comp(allbases, ambiguous = TRUE) # No more NA


my code: _get_double_strand.R

setwd("~/github/ctls/sequences")
install.packages("seqinr")
library(seqinr);
list.files()

seqs = read.fasta("panda16srDNA.fasta")
str(seqs);

seqs[[1]]
length(seqs[[1]])
c2s( rev( comp(seqs[[1]]) ) )

c2s(seqs[[1]][1:120])
c2s(comp(seqs[[1]][1:120]))




Sunday, July 13, 2014

Link files names to numbers, R, example

mixed_names = c(
  "BY4742_MATalpha_temp30_media_YPD  10 ngmL cycloheximide_n80.csv",  10,
  "BY4742_MATalpha_temp30_media_YPD + 10ngml cycloheximide_n120.csv", 10,
  "BY4742_MATalpha_temp30_media_YPD  10ngml cycloheximide_n120.csv",  10,
  "BY4742_MATalpha_temp30_media_YPD + 25 ngmL cycloheximide_n160.csv", 25,
  "BY4742_MATalpha_temp30_media_YPD  25 ngmL cycloheximide_n160.csv", 25,
  "BY4742_MATalpha_temp30_media_YPD  30ngml cycloheximide_n40.csv",   30,
  "BY4742_MATalpha_temp30_media_YPD  35ngml cycloheximide_n40.csv",   35,
  "BY4742_MATalpha_temp30_media_YPD  40ngml cycloheximide_n40.csv",   40,
  "BY4742_MATalpha_temp30_media_YPD  45ngml cycloheximide_n40.csv",   45,
  "BY4742_MATalpha_temp30_media_YPD  50 ngmL cycloheximide_n37.csv",  50,
  "BY4742_MATalpha_temp30_media_YPD  50ngml cycloheximide_n140.csv",  50,
  "BY4742_MATalpha_temp30_media_YPD + 30ngml cycloheximide_n40.csv",  30,
  "BY4742_MATalpha_temp30_media_YPD + 35ngml cycloheximide_n40.csv",  35,
  "BY4742_MATalpha_temp30_media_YPD + 40ngml cycloheximide_n40.csv",  40,
  "BY4742_MATalpha_temp30_media_YPD + 45ngml cycloheximide_n40.csv",  45,
  "BY4742_MATalpha_temp30_media_YPD + 50ngml cycloheximide_n140.csv", 50,
  "BY4742_MATalpha_temp30_media_YPD + 100ngml cycloheximide_n139.csv",100,
  "BY4742_MATalpha_temp30_media_YPD  100ngml cycloheximide_n139.csv",100
);
files = mixed_names[seq(1,(length(mixed_names)-1), 2)]
cycloheximide = as.numeric( mixed_names[seq(2,(length(mixed_names)), 2)] )

Wednesday, July 9, 2014

remove backslash from string in R using stringr


    require(stringr)
    conditions$media[r] = str_replace( conditions$media[r], "\\/", "")

R excel

require(xlsx)

kino = read.xlsx("data/kinetochore_list.xls", 1)
names(kino)= c("id", "ORF", "name", "desc", "alias", "genelen")


Monday, April 14, 2014

Yeast media


http://www.sunrisescience.com/pages/ystmedia_faq_home.html