Booom...........

LabNotes and Random Thoughts...............
Showing posts with label R. Show all posts
Showing posts with label R. Show all posts

Thursday, October 8, 2015

Rant

Rants .....

Ugly indeed

d = """@christophergandrud, C. Jason Liang, Clay Ford, @cornelius1729, @cplouffe, Craig Citro, @crossfitAL, @crowding, @crtahlin, Crt Ahlin, @cscheid, @csgillespie, @cusanovich, @cwarden, @cwickham, Daniel Lee, @darrkj, @Dasonk, David Hajage, David LeBauer, @dchudz, dennis feehan, @dfeehan, Dirk Eddelbuettel, @dkahle, @dlebauer, @dlschweizer, @dmontaner, @dougmitarotonda, @dpatschke, @duncandonutz, @EdFineOKL, @EDiLD, @eipi10, @elegrand, @EmilRehnberg, Eric C. Anderson, @etb, @fabian-s, Facundo Muñoz, @flammy0530"""


print( unlist(strsplit(d,", "))[ grep( "^@",unlist(strsplit(d,", ") )) ] )

or

d2 = unlist(strsplit(d,", ")
print( d2[ grep( "^@",d2 )) ] )

 [1] "@christophergandrud" "@cornelius1729"      "@cplouffe"          
 [4] "@crossfitAL"         "@crowding"           "@crtahlin"          
 [7] "@cscheid"            "@csgillespie"        "@cusanovich"        
[10] "@cwarden"            "@cwickham"           "@darrkj"            
[13] "@Dasonk"             "@dchudz"             "@dfeehan"           
[16] "@dkahle"             "@dlebauer"           "@dlschweizer"       
[19] "@dmontaner"          "@dougmitarotonda"    "@dpatschke"         
[22] "@duncandonutz"       "@EdFineOKL"          "@EDiLD"             
[25] "@eipi10"             "@elegrand"           "@EmilRehnberg"      
[28] "@etb"                "@fabian-s"           "@flammy0530"        

Pythonish....

print([ i for i in d.split(", ") if i.startswith("@") ])

['@christophergandrud', '@cornelius1729', '@cplouffe', '@crossfitAL', '@crowding', '@crtahlin', '@cscheid', '@csgillespie', '@cusanovich', '@cwarden', '@cwickham', '@darrkj', '@Dasonk', '@dchudz', '@dfeehan', '@dkahle', '@dlebauer', '@dlschweizer', '@dmontaner', '@dougmitarotonda', '@dpatschke', '@duncandonutz', '@EdFineOKL', '@EDiLD', '@eipi10', '@elegrand', '@EmilRehnberg', '@etb', '@fabian-s', '@flammy0530']


Wednesday, August 12, 2015

Plotting the read length frequency

The source of fasta file is after merging R1s and R2s suing pandaseq

This one liner gives the length distribution and which can be plotted using gnuplot

infoseq -only -length -auto -heading N testV.fasta | sort | uniq -c | sort -k2nr| awk 'BEGIN{print"len\tfreq"}{printf("%s\t%s\n",$2,$1)}' >ldist

so I try doing it on R , even though the initial steps are comparatively slow  compared to the Biopython 

Total number of reads : 1160974 here is the code in R and the Plot.
Untitled

Ploting the length distribution of merged fasta files from pandaseq output

In [1]:
# source("http://bioconductor.org/biocLite.R")
# biocLite(Biostrings)

suppressMessages(library(Biostrings))
filename = 'testV.fasta'
sr = readDNAStringSet(filename, format="fasta")
freq=table(width(sr))
len=as.numeric(names(freq))
In [2]:
plot(range(width(sr)), range(as.numeric( freq )), type='n',
     xlab=" read length", 
     ylab="freq",
     main="Distribution of length of fasta")
lines(len, freq, type='b', lwd=.3, col='black', pch=18)