@@ -17,7 +17,7 @@ isore.combineTranscriptCandidates <- function(readClassList,
1717 combinedSplicedTranscripts <-
1818 combineSplicedTranscriptModels(readClassList , bpParameters ,
1919 min.readCount , min.readFractionByGene ,
20- min.txScore.multiExon , min.txScore.singleExon , verbose ) % > % data.table()
20+ min.txScore.multiExon , min.txScore.singleExon , verbose )
2121 combinedSplicedTranscripts [,confidenceType : = " highConfidenceJunctionReads" ]
2222 combinedUnsplicedTranscripts <-
2323 combineUnsplicedTranscriptModels(readClassList , bpParameters ,
@@ -88,40 +88,34 @@ sequentialCombineFeatureTibble <- function(readClassList,
8888
8989# ' @noRd
9090updateStartEndReadCount <- function (combinedFeatureTibble ){
91- combinedFeatureTibble <- combinedFeatureTibble %> %
92- mutate(rowID = row_number())
93-
94- startEndCountTibble <- combinedFeatureTibble %> %
95- select(rowID , starts_with(" start" ),starts_with(" end" ),
96- starts_with(" readCount" )) %> %
97- tidyr :: pivot_longer(c(starts_with(" start" ),starts_with(" end" ),
98- starts_with(" readCount" )), names_to = c(" .value" ," set" ),
99- names_pattern = " (.*)\\ .(.)" ) %> %
100- group_by(rowID ) %> %
101- mutate(sumReadCount = sum(readCount ,na.rm = TRUE ))
91+ setDT(combinedFeatureTibble )
92+ combinedFeatureTibble [, rowID : = .I ]
10293
103- startTibble <- select(startEndCountTibble , rowID , start , readCount ,
104- sumReadCount ) %> %
105- arrange(start ) %> %
106- filter(cumsum(readCount )/ sumReadCount > = 0.5 ) %> %
107- filter(row_number()== 1 )
108- endTibble <- select(startEndCountTibble , rowID , end , readCount ,
109- sumReadCount ) %> %
110- arrange(end ) %> %
111- filter(cumsum(readCount )/ sumReadCount > = 0.5 ) %> %
112- filter(row_number()== 1 )
94+ colNames <- colnames(combinedFeatureTibble )
95+ readCountCols <- sort(colNames [grep(" ^readCount" , colNames )]) # to make sure it's ordered by sample name
96+ startCols <- sort(colNames [grep(" ^start" , colNames )])
97+ endCols <- sort(colNames [grep(" ^end" , colNames )])
11398
114- combinedFeatureTibble <- combinedFeatureTibble %> %
115- dplyr :: select(intronStarts , intronEnds , chr , strand , maxTxScore ,
116- maxTxScore.noFit , NSampleReadCount , NSampleReadProp ,
117- NSampleTxScore , rowID ) %> %
118- full_join(select(startTibble , rowID , start ), by = " rowID" ) %> %
119- full_join(select(endTibble , rowID , end , readCount = sumReadCount ),
120- by = " rowID" ) %> %
121- select(- rowID )
99+ startEndDt <- combinedFeatureTibble [,
100+ .(start = readCountWeightedMedian(.SD ,x ,y ),
101+ end = readCountWeightedMedian(.SD ,z ,y ),
102+ readCount = sum(.SD [,y ], na.rm = TRUE )),
103+ by = rowID , env = I(list (x = startCols , y = readCountCols ,z = endCols ))]
104+
105+ combinedFeatureTibble <- startEndDt [combinedFeatureTibble [,.(intronStarts , intronEnds , chr , strand , maxTxScore ,
106+ maxTxScore.noFit , NSampleReadCount , NSampleReadProp ,
107+ NSampleTxScore , rowID )], on = " rowID" ]
108+ combinedFeatureTibble [, rowID : = NULL ]
122109 return (combinedFeatureTibble )
123110}
124111
112+ # ' Function to get median value without interpolation using certain column names
113+ # ' @noRd
114+ readCountWeightedMedian <- function (dt , valuevar , timesvar ){
115+ sortVector <- rep(na.omit(unlist(dt [,..valuevar ])),
116+ times = as.integer(na.omit(unlist(dt [,..timesvar ]))))
117+ return (min(sortVector [sortVector > = quantile(sortVector , probs = 0.5 )]))
118+ }
125119
126120
127121# ' Function to combine featureTibble and create the NSample variables
0 commit comments