~ubuntu-branches/ubuntu/utopic/r-bioc-cummerbund/utopic

« back to all changes in this revision

Viewing changes to R/methods-CuffGene.R

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2013-12-28 17:17:25 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20131228171725-polmzo8go4m371c6
Tags: 2.4.1-1
* New upstream version
* debian/rules: Remove useless creation of ${R-Depends}
* debian/control: Versioned Build-Depends: r-base-dev (>= 3.0)
* debian/README.test: add hint how to test the package

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#################
17
17
#Validate               #
18
18
#################
19
 
 
 
19
#TODO: Add validity constraints
 
20
setValidity("CuffGene",function(object){
 
21
                        objLen = length(object)
 
22
                        if(objLen==0){
 
23
                                write("No gene set returned (Gene might not be in database?)",stderr())
 
24
                                return(FALSE)
 
25
                        }
 
26
                        if(objLen>1){
 
27
                                write("Warning: Possibly more than one gene returned",stderr())
 
28
                                return(TRUE)
 
29
                        }
 
30
                }
 
31
)               
20
32
 
21
33
#################
22
34
#Class Methods  #
23
35
#################
24
36
setMethod("show","CuffGene",function(object){
25
37
                cat(class(object),"instance for gene",object@id,"\nShort name:\t",unique(object@annotation$gene_short_name),
26
 
                                                "\nSlots:\n\t annotation\n\t fpkm\n\t diff\n\t",
 
38
                                                "\nSlots:\n\t annotation\n\t features\n\t fpkm\n\t repFpkm\n\t diff\n\t count\n\t",
27
39
                                                "isoforms\t",class(object@isoforms),"instance of size",length(object@isoforms),"\n\t",
28
40
                                                "TSS\t\t",class(object@TSS),"instance of size",length(object@TSS),"\n\t",
29
41
                                                "CDS\t\t",class(object@CDS),"instance of size",length(object@CDS),"\n"
31
43
                }
32
44
)
33
45
 
 
46
setMethod("length","CuffGene",
 
47
                function(x){
 
48
                        dim(x@annotation)[1]
 
49
                }
 
50
)
 
51
 
34
52
#################
35
53
#Subsetting             #
36
54
#################
65
83
                        return(object@relCDS)
66
84
                })
67
85
 
 
86
#features
 
87
setMethod("features","CuffGene",function(object){
 
88
                        return(object@features)
 
89
                })
 
90
 
68
91
#################
69
92
#Plotting               #
70
93
#################
71
 
 
72
 
 
73
 
#################
74
 
#Misc                   #
75
 
#################
 
 
b'\\ No newline at end of file'
 
94
.makeGeneRegionTrack<-function(object){
 
95
        featCols<-c('seqnames','start','end','source','gene_id','exon_number','isoform_id','isoform_id','exon_number','strand')
 
96
        feats<-features(object)[,featCols]
 
97
        newColnames<-c('seqnames','start','end','feature','gene','exon','transcript','symbol','rank','strand')
 
98
        mychr<-unique(feats$seqnames)
 
99
        colnames(feats)<-newColnames
 
100
        feats<-feats[,-1]
 
101
        #print(feats)
 
102
        feats$symbol[is.na(feats$symbol)]<-"NA"
 
103
        #THIS NEEDS TO BE MADE GENERIC
 
104
        genetrack<-GeneRegionTrack(feats,genome=object@genome,chromosome=mychr,name='CuffDiff',showId=T,stacking="pack")
 
105
        genetrack
 
106
}
 
107
 
 
108
setMethod("makeGeneRegionTrack",signature(object="CuffGene"),.makeGeneRegionTrack)
 
109
 
 
110
.plot<-function(object){
 
111
        trackList<-list()
 
112
        myStart<-min(object@features$start)
 
113
        myEnd<-max(object@features$end)
 
114
        #Make the following conditional on network connectivity
 
115
        ideoTrack <- IdeogramTrack(genome = object@genome, chromosome = unique(object@features$seqnames))
 
116
        trackList<-c(trackList,ideoTrack)
 
117
        
 
118
        axtrack<-GenomeAxisTrack()
 
119
        trackList<-c(trackList,axtrack)
 
120
        
 
121
        genetrack<-.makeGeneRegionTrack(object)
 
122
        
 
123
        trackList<-c(trackList,genetrack)
 
124
        
 
125
        biomTrack<-BiomartGeneRegionTrack(genome=object@genome,chromosome=as.character(unique(object@features$seqnames)),start=myStart,end=myEnd,name="ENSEMBL",showId=T)
 
126
        trackList<-c(trackList,biomTrack)
 
127
        
 
128
        
 
129
        plotTracks(trackList,from=myStart-2000,to=myEnd+2000)
 
130
}
 
131
 
 
132
setMethod("genePlot",signature(object="CuffGene"),.plot)
 
133
 
 
134
#################
 
135
#Coersion methods
 
136
#################
 
137
#As GRanges
 
138
.asGRanges<-function(object){
 
139
        #featCols<-c('seqnames','start','end','source','gene_id','exon_number','isoform_id','isoform_id','exon_number','strand')
 
140
        feats<-object@features
 
141
        #newColnames<-c('seqnames','start','end','feature','gene','exon','transcript','symbol','rank','strand')
 
142
        colnames(feats)[colnames(feats)=='isoform_id']<-'transcript'
 
143
        colnames(feats)[colnames(feats)=='gene_id']<-'gene'
 
144
        colnames(feats)[colnames(feats)=='exon_number']<-'exon'
 
145
        colnames(feats)[colnames(feats)=='source']<-'feature'
 
146
        feats$symbol<-feats$transcript
 
147
        corCols<-c('seqnames','start','end','strand')
 
148
        myGR<-GRanges(Rle(feats$seqnames),ranges=IRanges(feats$start,end=feats$end),strand=Rle(feats$strand),elementMetadata=feats[,!colnames(feats) %in% corCols])
 
149
        myGR
 
150
}
 
151
 
 
152
#As GRangesList
 
 
b'\\ No newline at end of file'