Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scVizIt
Manage
Activity
Members
Labels
Plan
Issues
8
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
CRI
scVizIt
Commits
24cb6e2f
There was an error fetching the commit references. Please try again later.
Commit
24cb6e2f
authored
1 year ago
by
Zhiyu Zhao
Browse files
Options
Downloads
Patches
Plain Diff
05162024: SeuratObjectFunctions.R changed.
parent
bcd4b134
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
vizapp/shinyapp/functions/SeuratObjectFunctions.R
+16
-13
16 additions, 13 deletions
vizapp/shinyapp/functions/SeuratObjectFunctions.R
with
16 additions
and
13 deletions
vizapp/shinyapp/functions/SeuratObjectFunctions.R
+
16
−
13
View file @
24cb6e2f
...
@@ -213,18 +213,22 @@ getAvgExp=function(seuratObject,cells,colID,geneDescriptions,features) {
...
@@ -213,18 +213,22 @@ getAvgExp=function(seuratObject,cells,colID,geneDescriptions,features) {
colID
=
'Altogether'
colID
=
'Altogether'
cells
$
Altogether
=
'all'
cells
$
Altogether
=
'all'
}
}
Idents
(
seuratObject
)
=
cells
[,
colID
]
features
=
unique
(
features
)
features
=
unique
(
features
)
expressions
=
AverageExpression
(
seuratObject
,
assays
=
'RNA'
,
features
=
features
)
#By default this uses non-scaled values.
if
(
length
(
features
)
==
1
)
rownames
(
expressions
[[
'RNA'
]])
=
features
expressions
[[
'RNA'
]]
=
expressions
[[
'RNA'
]][,
mixedsort
(
colnames
(
expressions
[[
'RNA'
]])),
drop
=
F
]
stats
=
cells
%>%
count
(
!!
as.name
(
colID
))
stats
=
cells
%>%
count
(
!!
as.name
(
colID
))
rownames
(
stats
)
=
stats
[,
1
]
rownames
(
stats
)
=
stats
[,
1
]
stats
=
stats
[
colnames
(
expressions
[[
'RNA'
]]),]
ids
=
1
:
(
dim
(
stats
)[
1
])
colnames
(
expressions
[[
'RNA'
]])
=
paste0
(
colnames
(
expressions
[[
'RNA'
]]),
'(n='
,
stats
$
n
,
')'
)
names
(
ids
)
=
rownames
(
stats
)
if
(
colID
==
'Altogether'
)
Idents
(
seuratObject
)
=
'all'
else
Idents
(
seuratObject
)
=
paste0
(
'ID'
,
ids
[
cells
[,
colID
]],
'@'
,
cells
[,
colID
])
expressions
=
AverageExpression
(
seuratObject
,
assays
=
'RNA'
,
features
=
features
)
#By default this uses non-scaled values. #This function doesn't preserve column names of expressions. a 'g' can be added as prefix.
if
(
length
(
features
)
==
1
)
rownames
(
expressions
[[
'RNA'
]])
=
features
expressions
[[
'RNA'
]]
=
data.frame
(
expressions
[[
'RNA'
]][,
mixedsort
(
colnames
(
expressions
[[
'RNA'
]])),
drop
=
F
],
check.names
=
F
)
colnames
(
expressions
[[
'RNA'
]])
=
paste0
(
rownames
(
stats
),
'(n='
,
stats
$
n
,
')'
)
if
(
!
is.null
(
geneDescriptions
))
if
(
!
is.null
(
geneDescriptions
))
expressions
[[
'RNA'
]]
=
cbind
(
name
=
paste0
(
'"'
,
left_join
(
data.frame
(
gene
=
rownames
(
expressions
[[
'RNA'
]])),
geneDescriptions
,
by
=
c
(
'gene'
=
'SYMBOL'
))
$
name
,
'"'
),
expressions
[[
'RNA'
]])
expressions
[[
'RNA'
]]
=
cbind
2
(
name
=
paste0
(
'"'
,
left_join
(
data.frame
(
gene
=
rownames
(
expressions
[[
'RNA'
]])),
geneDescriptions
,
by
=
c
(
'gene'
=
'SYMBOL'
))
$
name
,
'"'
),
expressions
[[
'RNA'
]])
return
(
expressions
)
return
(
expressions
)
}
}
...
@@ -238,11 +242,10 @@ getPercentExp=function(seuratObject,cells,colID,geneDescriptions,features) {
...
@@ -238,11 +242,10 @@ getPercentExp=function(seuratObject,cells,colID,geneDescriptions,features) {
else
else
data
=
t
(
GetAssayData
(
seuratObject
,
assay
=
'RNA'
)[
features
,,
drop
=
F
]
>
0
)
data
=
t
(
GetAssayData
(
seuratObject
,
assay
=
'RNA'
)[
features
,,
drop
=
F
]
>
0
)
percent
=
aggregate.Matrix
(
data
,
cells
[,
colID
])
percent
=
aggregate.Matrix
(
data
,
cells
[,
colID
])
tempNames
=
rownames
(
percent
)
stats
=
cells
%>%
count
(
!!
as.name
(
colID
))
stats
=
cells
%>%
count
(
!!
as.name
(
colID
))
percent
=
data.frame
(
t
(
percent
*
100
/
stats
$
n
))
rownames
(
stats
)
=
stats
[,
1
]
coln
ame
s
(
percent
)
=
paste0
(
tempNames
,
'(n='
,
stats
$
n
,
')'
)
percent
=
data.fr
ame
(
t
(
percent
[
rownames
(
stats
),,
drop
=
F
]
*
100
/
stats
$
n
),
check.names
=
F
)
percent
=
p
ercent
[,
mixedsort
(
colnames
(
percent
)),
drop
=
F
]
colnames
(
percent
)
=
p
aste0
(
rownames
(
stats
),
'(n='
,
stats
$
n
,
')'
)
if
(
!
is.null
(
geneDescriptions
))
if
(
!
is.null
(
geneDescriptions
))
percent
=
cbind
(
name
=
paste0
(
'"'
,
left_join
(
data.frame
(
gene
=
rownames
(
percent
)),
geneDescriptions
,
by
=
c
(
'gene'
=
'SYMBOL'
))
$
name
,
'"'
),
percent
)
percent
=
cbind
(
name
=
paste0
(
'"'
,
left_join
(
data.frame
(
gene
=
rownames
(
percent
)),
geneDescriptions
,
by
=
c
(
'gene'
=
'SYMBOL'
))
$
name
,
'"'
),
percent
)
return
(
percent
)
return
(
percent
)
...
@@ -442,7 +445,7 @@ saveDimPlots=function(seuratObject,fileName,format='png',split.by=NULL,shape.by=
...
@@ -442,7 +445,7 @@ saveDimPlots=function(seuratObject,fileName,format='png',split.by=NULL,shape.by=
if
(
is.null
(
split.by
))
if
(
is.null
(
split.by
))
ggsave
(
paste0
(
fileName
,
'.'
,
i
),
plot
=
p
,
height
=
20
,
width
=
20
)
ggsave
(
paste0
(
fileName
,
'.'
,
i
),
plot
=
p
,
height
=
20
,
width
=
20
)
else
else
ggsave
(
paste0
(
fileName
,
'.'
,
i
),
plot
=
p
,
height
=
10
,
width
=
30
)
#
ggsave(paste0(fileName,'.',i),plot=p,height=10,width=30)
ggsave
(
paste0
(
fileName
,
'.'
,
i
),
plot
=
p
,
height
=
min
(
48
,
max
(
4
,
ceiling
(
infoList
$
nClusters
/
12
)
*
4
)),
width
=
min
(
48
,
max
(
4
,
infoList
$
nClusters
*
4
)))
ggsave
(
paste0
(
fileName
,
'.'
,
i
),
plot
=
p
,
height
=
min
(
48
,
max
(
4
,
ceiling
(
infoList
$
nClusters
/
12
)
*
4
)),
width
=
min
(
48
,
max
(
4
,
infoList
$
nClusters
*
4
)))
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment