我在想我该如何定义一个后骨模型中的实例变量。这是我目前这样做的方式:
class GeneSet extends Backbone.Model
initialize: (parsedGenes)->
@set parsedGenes: parsedGenes
@set geneNames: (gene.gene_name for gene in @get("parsedGenes"))
@set geneIds: ("gene_#{id}" for id in [1..@get("parsedGenes").length])
@set columnNames: @getColumnNames()
@set columnGroups: @getColumnGroups()
@set geneExpressions: @getGeneExpressions()
@set groupedGeneExpressions: @getGroupedGeneExpressions()
@set extent: @getExtent()
clusterColor: ->
d3.scale.category20()()
getGeneNameById: (geneId)->
@get("geneNames")[@get("geneIds").indexOf(geneId)]
getColumnGroups: ->
_.uniq((@get("columnNames")).map((columnName)->
columnName.split("_")[0]
))
getExtent: ->
expressions = _.flatten(@get("geneExpressions").map (geneExpression)->
geneExpression.map (item)->
item.y
)
d3.extent(expressions)
getColumnNames: ->
Object.keys(@get("parsedGenes")[0]).filter (columnName) ->
!columnName.match(/cluster/) && isNumber(parsedGenes[1][columnName])
getGeneExpressions: ->
@get("parsedGenes").map (gene) =>
@get("columnNames").map (columnName) ->
x: columnName
y: +gene[columnName] # make numeric
这似乎有点多余, 需要做
class GeneSet extends Backbone.Model
initialize: (parsedGenes)->
@parsedGenes = parsedGenes
@geneNames = (gene.gene_name for gene in @parsedGenes)
@geneIds = ("gene_#{id}" for id in [[email protected]])
@clusters = (gene.cluster for gene in @parsedGenes)
@descriptions = (gene.description for gene in @parsedGenes)
@columnNames = @getColumnNames()
@columnGroups = @getColumnGroups()
@geneExpressions = @getGeneExpressions()
@groupedGeneExpressions = @getGroupedGeneExpressions()
@extent = @getExtent()
然后,从视觉上看, 只是在做