last day (14 days later) » 

2:52 PM
0
Q: Resampling overlap between two lists

user964689I have two .txt files. Both files are lists of strings with one string per row eg. GRIM1 PHOXA2 SLITRK4 Both text files are ~ 20,000 rows long. I want to randomly sample 500 strings from file 1 and 700 strings from file 2. Then I want to count the number of strings that overlap both these sub...

 
DMT
check the class of listA and listB. the first argument for sample needs to be a vector or integer, and is most likely a data frame here. The error is saying the number of items in x is less than the number of samples you want to take, which is not allowed when replace=FALSE
 
the class is a character.
And yes length of lists is 1. That must be it. So I should convert them to vectors? If I convert them to integers how will I check for overlap, won't the integers represent their line number rather than the strings themselves?
 
DMT
@user964689 can you run dput(listA) and dput(listB) after the as.character calls and post those results in your question?
 
Yes added to question as requested
 
DMT
@user964689 how about this, can you make two new txt files, say with only 20 rows each, and then post the entire dput for both lists? I'm just looking for something I can reproduce. On another note, looks like you're getting a bunch of numbers where you expected strings!
@user964689 edited my above comment
first thing you may want to do is set stringsAsFactors=FALSE in the read.csv calls so you don't have to call as.character
 
2:54 PM
hey new to this chat, do you see this?
 
DMT
yep, Stack Overflow has this thing where they don't like a lot of comments
so we go to chat
 
great thanks
 
DMT
anyway, I just want to have exactly the data you're working with one way or another, so pairing down the text files to a small number of rows then posting the dput would be nice
 
here is output for list one with only 20 rows:
"c(16, 1, 20, 10, 2, 13, 14, 18, 4, 5, 15, 9, 8, 3, 7, 6, 11, 19, 12, 17)"
 
DMT
yeah so you expect those to be strings right?
 
2:56 PM
the original input file was TPPP
ARIH1
ZBTB49
ME3
CHMP6
SNRNP70
SYT10
UNC45A
CRLS1
EML6
TAB2
LOC684709
INS1
CLEC4A3
FOXK2
EPX
NR4A2
VOM2R16
SEC23B
TRAFD1
yes exactly
 
DMT
so set stringsAsFactors = FALSE in the read.csv file and try again, the strings are being converted to factors
which are represented as numerics
 
ok one sec
"c(\"RNLS\", \"MAP2K3\", \"TMEM11\", \"USP22\", \"TNFRSF13B\", \"MPRIP\", \"Flcn\", \"COPS3\", \"NT5M\", \"RASD1\", \"PEMT\", \"RAI1\", \"SREBF1\", \"TOM1L2\", \"LRRC48\", \"ATPAF2\", \"GID4\", \"DRG2\", \"MYO15A\", \"ALKBH5\")"
looks better
 
DMT
good, so if you shouldn't have to do the as.character call now
and if you run through the code that does sampling, do you still get the same error?
 
or dput right
 
DMT
yes, dput is just for testing
remember to change the number of samples you want to do down to reflect the smaller list size
 
2:59 PM
i still get the same error tho ( i did change the number of samples down to 5)
 
DMT
"c(\"RNLS\", \"MAP2K3\", \"TMEM11\", \"USP22\", \"TNFRSF13B\", \"MPRIP\", \"Flcn\", \"COPS3\", \"NT5M\", \"RASD1\", \"PEMT\", \"RAI1\", \"SREBF1\", \"TOM1L2\", \"LRRC48\", \"ATPAF2\", \"GID4\", \"DRG2\", \"MYO15A\", \"ALKBH5\")"
that is what's returned by dput?
 
yes
 
DMT
ok one sec
let me try it out
 
thanks so much
 
DMT
so I did this

test<-c("RNLS", "MAP2K3", "TMEM11", "USP22", "TNFRSF13B", "MPRIP", "Flcn", "COPS3", "NT5M", "RASD1", "PEMT", "RAI1", "SREBF1", "TOM1L2", "LRRC48", "ATPAF2", "GID4", "DRG2", "MYO15A", "ALKBH5")

sample(test, size=5, replace=FALSE)
and I had no problems
 
3:04 PM
ok let me double check
 
DMT
I think your trouble is that read.csv is not returning what you expect.
 
yes
is there a read.txt ? maybe i should be using that!
it still says my length of listA is 1, when it has 20 rows
my input : listA <- read.csv(file="/mnt/genotyping/Alex/wholegenome/sandbox/Dog_rat_mink_overlap/SNP‌​overlap_comparison/VEPoutput/Resampling/Rat_SNP_genes_test.txt", header=F, stringsAsFactors = FALSE)
 
DMT
just testing out read.csv
right now one sec
ok so I copied this into notepad
TPPP
ARIH1
ZBTB49
ME3
CHMP6
SNRNP70
SYT10
UNC45A
CRLS1
EML6
TAB2
LOC684709
INS1
CLEC4A3
FOXK2
EPX
NR4A2
VOM2R16
SEC23B
TRAFD1
and saved it, then read it in with read.csv, header=f, stringsAsFactors=FALS
E
 
DMT
it turned out to what I initially thought, a dataframe
so read.csv read it in as a dataframe
then setting listA<-listA[,1]
 
3:10 PM
ok have to go for two mins then back and will test
 
DMT
sample worked just fune
**fine
 
so what should the code look like to read it in as a datafram?
ah ok
i just add
listA<-listA[,1]
in the line after reading it in?
seems to work
will test with full data
 
DMT
so you should do the read.csv as we described above, then instead of as.character set listA<-listA[,1] and listB<-listB[,1], which converts them to vectors
the code after that should run fine
 
perfect thank you
it does
 
DMT
woot
 
3:18 PM
how do i give you credit in main question?
 
DMT
I'll post what we went over as an answer
 
great thanks
and ill tick your answer
thanks again , so great!
 

last day (14 days later) »