On Mon, Feb 27, 2012 at 1:57 AM, Jesper Gådin <jesper.gadin@gmail.com>wrote:

> Thanks for your fast reply. I have updated to R 2.15 dev and also using
> the dev version of GenomicRanges. This map method seems to be exactly what
> I was looking for! I am now wondering if it is possible to pass on all
> information that was stored in the GRanges object "reads" like
> elementMetadata to the output? I've seen that it is a slot for
> elementMetadata from the example you gave me, but unfortunately it is
> empty. I do also wonder just by curiosity, if I could get a deeper
> explanation of what is meant by "transformed ranges", and in which
> situation to use it?
>
>
Hi Jesper,

Maybe you can help me better understand what you need as your result. The
transformed ranges are the "mapped" ranges, i.e., the from_gr has been
translated into the coordinate space of each read. Looking at your output
though I kind of think there is a bug somewhere, because the same hit
between your from_gr range and read #44 is repeated many times.

Michael

My output looks like this:
> > from_gr <- GRanges("chr12", IRanges(57537220, 57537220))
> > test3 <- map(from_gr, reads)
> > test3
> An object of class "RangesMapping"
> Slot "matching":
> An object of class "Hits"
> Slot "queryHits":
>  [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
> 1 1 1
> [39] 1 1 1 1 1 1 1 1 1 1 1 1
>
> Slot "subjectHits":
>  [1] 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44
> 44 44
> [26] 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44 44
> 44 44
>
> Slot "queryLength":
> [1] 1
>
> Slot "subjectLength":
> [1] 73
>
> Slot "elementMetadata":
> NULL
>
> Slot "metadata":
> list()
>
>
> Slot "space":
> 'factor' Rle of length 50 with 1 run
>   Lengths:    50
>   Values : chr12
> Levels(1): chr12
>
> Slot "ranges":
> IRanges of length 50
>      start  end width
> [1]   1562 1562     1
> [2]   1600 1600     1
> [3]   1638 1638     1
> [4]   1676 1676     1
> [5]   1714 1714     1
> [6]   1752 1752     1
> [7]   1790 1790     1
> [8]   1828 1828     1
> [9]   1866 1866     1
> ...    ...  ...   ...
> [42]  3101 3101     1
> [43]  3137 3137     1
> [44]  3173 3173     1
> [45]  3209 3209     1
> [46]  3245 3245     1
> [47]  3281 3281     1
> [48]  3317 3317     1
> [49]  3353 3353     1
> [50]  3389 3389     1
>
> Sincerely,
> Jesper
>
> P.S Also thanks for the proposol of the use of vector arithmetic, which
> will speed up this code additionaly.
>
> On Wed, Feb 22, 2012 at 2:06 PM, Michael Lawrence <
> lawrence.michael@gene.com> wrote:
>
>> Hi Jesper,
>>
>> If you are able to update to R 2.15 (devel) and use the devel version of
>> GenomicRanges, there is a "map" method that takes a GRanges of "genomic"
>> positions and a GappedAlignments object of your reads. It then returns a
>> RangesMapping object with the matchings between genomic ranges and reads,
>> and the transformed ranges, i.e., the matching genomic ranges relative to
>> the read.
>>
>> So you would have something like:
>>
>> from_gr <- GRanges(chr, IRanges(someposition, someposition))
>> mapping <- map(from_gr, reads)
>>
>> You can coerce that mapping object to a GRanges of the transformed
>> ranges, plus "query" and "subject" value columns indicating the matchings,
>> as indices into "from_gr" and "reads".
>>
>> as(mapping, "GenomicRanges")
>>
>> Sorry I have not had a change to document these facilities yet.
>>
>> Michael
>>
>> On Wed, Feb 22, 2012 at 4:15 AM, Jesper Gådin <jesper.gadin@gmail.com>wrote:
>>
>>> Hi everyone!
>>> I want to find all reads that map to a specific position in a GRanges
>>> object.
>>> In my case this object is named "reads" and I have tried using the
>>> function
>>> below.
>>>
>>>
>>> #From a given position and chromosome, find the reads where this position
>>> map
>>> fun_find_reads_from_pos <- function(reads,chr,someposition,
>>> verbose=TRUE) {
>>>
>>>    #get length over the sample list
>>>    nr_samples <-length(reads)
>>>
>>>    for (j in (1:nr_samples)) {
>>>        onePerson <- reads[[j]]
>>>        chr_onePerson <- onePerson[seqnames(onePerson)==chr]
>>>        pre_seq<-
>>> chr_onePerson[(ranges(chr_onePerson))%in%(IRanges(start=someposition,
>>> width=1)),6]
>>>
>>>        if(!length(pre_seq)==0) {
>>>            for (k in (1:length(pre_seq))) {
>>>                position <- (someposition-start(pre_seq[k])) +1
>>> #57537220
>>>                print("found the given someposition on this position
>>> within
>>> the read")
>>>                print(position)
>>>            }
>>>        }
>>>    }
>>>
>>> } #End of function
>>>
>>>
>>> To use the function try:
>>> fun_find_reads_from_pos(reads,"chr12",57537220)
>>>
>>> Now that should work.
>>> And everything would be fine if it wasnt for the time issue.
>>> The time-thief I guess is that I have to loop over every read
>>> in every sample to get to the information I want. Is it
>>> possible to use the data structure in another better way to
>>> avoid unnecessary looping. Anyone have an idea?
>>>
>>> This function would be the core function of my future package.
>>> So its important that it is effective.
>>>
>>> Sincerely,
>>> Jesper
>>>
>>> Link to the reads object needed to run the function:
>>> http://uppsalanf.se/sites/default/files/reads_object.RData
>>> And the function itself (same as above):
>>> http://uppsalanf.se/sites/default/files/example-bioc-dev.R
>>>
>>>
>>> > sessionInfo()
>>> R version 2.13.2 (2011-09-30)
>>> Platform: x86_64-pc-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=C              LC_MESSAGES=en_US.UTF-8
>>>  [7] LC_PAPER=en_US.UTF-8       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] Biostrings_2.20.4   GenomicRanges_1.4.8 IRanges_1.10.6
>>> > ?GRanges
>>> > sessionInfo()
>>> R version 2.13.2 (2011-09-30)
>>> Platform: x86_64-pc-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=C              LC_MESSAGES=en_US.UTF-8
>>>  [7] LC_PAPER=en_US.UTF-8       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] Biostrings_2.20.4   GenomicRanges_1.4.8 IRanges_1.10.6
>>>
>>> loaded via a namespace (and not attached):
>>> [1] tools_2.13.2
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> Bioc-devel@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/bioc-devel
>>>
>>
>>
>

	[[alternative HTML version deleted]]

