Entering edit mode
9.7 years ago
Aishwarya.Kulkarni
▴
30
Hi,
I am trying to output a result of matchPWM
and I get the following error when I try to output it using write
command:
write(as.data.frame(data), "chr9_RBPJ_R.txt", sep="\n")
cannot coerce class 'structure("IRanges", package = "IRanges")' into a data.frame
where data is
data<-list(hits = as(hits, "IRanges"), scores = scores)
hits
=results of matchPWM
and scores
are the scores for each hit.
here is the sessioninfo
> sessionInfo()
R version 2.15.3 (2013-03-01)
Platform: x86_64-unknown-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] BSgenome.Hsapiens.UCSC.hg19_1.3.19 BSgenome_1.26.1
[3] GenomicRanges_1.10.7 Biostrings_2.26.3
[5] IRanges_1.16.6 BiocGenerics_0.4.0
loaded via a namespace (and not attached):
[1] parallel_2.15.3 stats4_2.15.3 tools_2.15.3
Thanks in advance
Why would you expect there to be a coercion method for a custom structure?
ok, if that's the case then how do I output the structure into a file?
help(save)
I did try saving it with save , however it gives me a gibberish output in the file.
The results from save() aren't meant to be human readable. If you want this written to a text file then you'll need to either write a method to convert it to a type that can be directly written as text or write your own method to write it in some convenient text format.
cat(data, file="Report.out")
save()
is meant for saving your current workspace which can be read back from the file at a later date by using the functionload
. It is not for printing the output to a filesave()
can save individual objects, not just the workspace.Ya individual objects can be saved, but it can be retrieved to the workspace by
load()
method. But here she wants to print the data to a file, not for loading the data to the workspace.Thanks a lot!
when I give the command, it gives me an error
Are you trying to write the pair wise alignments to a file? Can you give some code to show your data & what functions you used? Some reproducible example?
Hi I am using matchPWM a function to scan a position weight matrix on and sequence to get the hits, and I am trying to output these hits into a file.
You can use sink
It can output any variable into a file including XStringViews
Ok it is still difficult to debug your problem without a reproducible example but anyway, does your "data" object look like this:
And do you want to write this entire set to a file or just the matched sequences given within the square brackets?
Yes exactly!
then you can sink
subject(hits)
to a fileI didn't quiet understand, do you mean
cat(hits, file="ABC.txt")
?Use it to save the hits
Give some code to show your data, or you can try use sink