"+r+"
"+f(a,o,l);n.set("content.text",u)}}})})}function h(t,e){var n=t.count||0;"frequency"in t||(t.frequency=n/e);var i=(100*t.frequency).toFixed(1)+"%";return _.template("{{percent}} ({{count}} of {{total}} sequenced samples)")({percent:i,count:n,total:e})}function f(t,e,n){return""+C+": "+h(t,n)+"
Other "+Y+" mutations: "+h(e,n)+"
"}function g(t){return z.filter(function(e){return e.cancer_study===t})}a=a||{},a=a.sparkline?_.extend({margin:{top:-12,right:0,bottom:0,left:0},width:30,height:12,this_cancer_study:void 0},a):_.extend({margin:{top:6,right:10,bottom:20,left:40},width:600,height:300,this_cancer_study:void 0},a);var v=r(n),b=_.keys(v),y=o(t),T=o(e),C=y[0].hugo+" "+y[0].protein_pos_start;y=d(y).map(function(t){return t.keyword=C,t}),T=d(T);var P={bykeyword:r(y),bygene:r(T)},S=_.intersection(_.keys(P.bykeyword),_.keys(P.bygene));if(y=[],T=[],_.each(S,function(t){y.push(P.bykeyword[t]),T.push(P.bygene[t])}),T.length!==y.length)throw new Error("must be same length");if(T.length!==b.length)throw new Error("there must be a datum for every cancer study and visa versa");T.forEach(function(t){var e=P.bykeyword[t.cancer_study],n=t.count-e.count;if(0>n)throw new Error("more mutations for a particular keyword than for all keywords of a particular gene");t.count=n});var w=_.reduce(T,function(t,e){return t+e.count},0),D=_.reduce(y,function(t,e){return t+e.count},0),x=_.reduce(v,function(t,e){return t+e.num_sequenced_samples},0);_.mixin({unzip:function(t){return _.zip.apply(_,t)}});var M=y.concat(T);try{M=_.chain(M).map(l).groupBy(function(t){return t.cancer_study}).map(_.identity).sortBy(s).unzip().value()}catch(A){throw new Error(A)}var I=a.width-a.margin.left-a.margin.left,F=a.height-a.margin.top-a.margin.bottom,L=d3.select(i).append("svg").attr("width",a.width).attr("height",a.height).append("g").attr("transform","translate("+a.margin.left+","+a.margin.top+")"),k=d3.layout.stack().x(function(t){return t.cancer_study}).y(function(t){return t.frequency}),E=k(M),V=d3.scale.ordinal().domain(M[0].map(function(t){return t.cancer_study})).rangeBands([0,I],.1),B=.2,O=a.sparkline?B:d3.max(E,function(t){return d3.max(t,function(t){return t.y0+t.y})}),N=d3.scale.linear().domain([0,O]).range([F,0]).clamp(!0),R="LimeGreen",q="Green",U=L.selectAll(".layer").data(E).enter().append("g").attr("class","layer").style("fill",function(t,e){return[q,R][e]}),z=U.selectAll("rect").data(function(t){return t}).enter().append("rect").attr("x",function(t){return V(t.cancer_study)}).attr("y",function(t){return N(t.y0+t.y)}).attr("width",function(t){return V.rangeBand()}).attr("height",function(t){return N(t.y0)-N(t.y0+t.y)});if(a.sparkline)return{el:i,qtip:function(){throw new Error("don't qtip a sparkline")}};var H=d3.format(O>.1?".0%":".1%"),G=d3.svg.axis().scale(N).tickFormat(H).orient("left");G.tickSize(G.tickSize(),0,0);var j=function(){function t(t){return{cancer_type:t.cancer_type,start:t.cancer_study,end:t.cancer_study,color:v[t.cancer_study].color}}var e=M[0][0];return _.chain(M[0]).reduce(function(e,n){var i=_.last(e);return i.cancer_type!==n.cancer_type?e.concat(t(n)):i.cancer_type===n.cancer_type?(i.end=n.cancer_study,e):void 0},[t(e)]).value()}();L.selectAll("line").data(j).enter().append("line").attr("x1",function(t){return V(t.start)}).attr("x2",function(t){return V(t.end)+V.rangeBand()}).attr("y1",F+a.margin.bottom/3).attr("y2",F+a.margin.bottom/3).style("stroke-width",5).style("stroke",function(t){return t.color});var Y=(L.append("g").call(G).attr("stroke","#000").attr("shape-rendering","crispEdges"),_.find(E[0],function(t){return void 0!==t.hugo}).hugo),C=_.find(E[0],function(t){return void 0!==t.keyword}).keyword;return _.isUndefined(a.this_cancer_study)||p(),{el:i,qtip:m,overallCountText:function(){return f({count:D},{count:w},x)}}}function MainMutationController(t,e){function n(){e.dispatcher.on(MutationDetailsEvents.ALL_LOLLIPOPS_DESELECTED,o),e.dispatcher.on(MutationDetailsEvents.LOLLIPOP_DESELECTED,r),e.dispatcher.on(MutationDetailsEvents.LOLLIPOP_SELECTED,l),e.dispatcher.on(MutationDetailsEvents.DIAGRAM_PLOT_UPDATED,a),t.addResetCallback(i)}function i(n){e.resetPlot(),t.hideFilterInfo()}function a(){e.isFiltered()?t.showFilterInfo():t.hideFilterInfo()}function o(){e.isFiltered()||t.hideFilterInfo()}function r(t,n){0==e.getSelectedElements().length&&o()}function l(e,n){t.showFilterInfo()}n()}function Mutation3dController(t,e,n,i,a,o,r,l,u,s){function c(){l.dispatcher.on(MutationDetailsEvents.ALL_LOLLIPOPS_DESELECTED,D),l.dispatcher.on(MutationDetailsEvents.LOLLIPOP_DESELECTED,x),l.dispatcher.on(MutationDetailsEvents.LOLLIPOP_SELECTED,M),l.dispatcher.on(MutationDetailsEvents.LOLLIPOP_MOUSEOVER,A),l.dispatcher.on(MutationDetailsEvents.LOLLIPOP_MOUSEOUT,I),l.dispatcher.on(MutationDetailsEvents.DIAGRAM_PLOT_UPDATED,w),l.dispatcher.on(MutationDetailsEvents.DIAGRAM_PLOT_RESET,S),u.dispatcher.on(MutationDetailsEvents.PDB_LINK_CLICKED,L),u.dispatcher.on(MutationDetailsEvents.PROTEIN_CHANGE_LINK_CLICKED,F),i.addInitCallback(m),n.dispatcher.on(MutationDetailsEvents.VIEW_3D_PANEL_CLOSED,p),n.dispatcher.on(MutationDetailsEvents.VIEW_3D_STRUCTURE_RELOADED,v),t.dispatcher.on(MutationDetailsEvents.GENE_TAB_SELECTED,d)}function d(t){n&&(n.resetPanelPosition(),n.hideView())}function p(){N&&N.hideView()}function m(t){B(),null!=n&&(n.resetPanelPosition(),n.maximizeView())}function h(t,e,n){t>n&&N.toggleScrollBar(n)}function f(t,e,n){n>=t&&N.toggleScrollBar(-1),e!=t&&N.scrollToSelected()}function g(t){q&&N.scrollToSelected();var e=t.datum();null!=n&&(n.maximizeView(),n.updateView(s,e.pdbId,e.chain)),q||null==R||(R.resetFilters(),R.selectChain(e.pdbId,e.chain.chainId),R.scrollToSelected()),q=!1}function v(){i.isVisible()&&l.isHighlighted()&&V()}function b(t,e){t&&e&&(N.selectChain(t,e),q=!0)}function y(){N.pdbPanel.minimizeToHighlighted()}function T(t,e){t&&e&&N.pdbPanel.minimizeToChain(N.pdbPanel.getChainGroup(t,e))}function C(t){null==R&&null!=N&&t.length>0&&(R=N.initPdbTableView(t,function(t,e){e.dispatcher.on(MutationDetailsEvents.PDB_TABLE_READY,P),R=t}),R.pdbTable.dispatcher.on(MutationDetailsEvents.TABLE_CHAIN_SELECTED,b),R.pdbTable.dispatcher.on(MutationDetailsEvents.TABLE_CHAIN_MOUSEOUT,y),R.pdbTable.dispatcher.on(MutationDetailsEvents.TABLE_CHAIN_MOUSEOVER,T)),null!=N&&null!=R&&(N.toggleTableControls(),R.toggleView())}function P(){if(null!=N){var t=N.getSelectedChain();if(null!=t){var e=t.datum();R.selectChain(e.pdbId,e.chain.chainId),R.scrollToSelected()}}}function S(){n&&n.isVisible()&&n.refreshView()}function w(){n&&n.isVisible()&&n.refreshView()}function D(){n&&n.isVisible()&&(n.resetHighlight(),n.hideResidueWarning())}function x(t,e){l.isHighlighted()?M():D()}function M(t,e){n&&n.isVisible()&&V()}function A(t,e){if(n&&n.isVisible()){var i=E();i.push(t),$(i,!0)}}function I(t,e){x(t,e)}function F(t){var e=k(t);e&&n&&n.isVisible()&&V()}function L(t){var e=k(t);e&&B(e.pdbMatch.pdbId,e.pdbMatch.chainId)}function k(t){var e=r.getMutationIdMap(),n=e[t];return n&&(l.clearHighlights(),l.highlightMutation(n.mutationSid)),n}function E(){var t=[];return _.each(l.getSelectedElements(),function(e,n){t=t.concat(e.datum())}),t}function V(){var t=E();$(t)}function $(t,e){var i=n.highlightView(t,!0),a=t.length-i;e||(a>0?n.showResidueWarning(a,t.length):n.hideResidueWarning())}function B(t,a){var r=i.model.uniprotId,l=function(i){null==N&&(N=e.initPdbPanelView(i),N.pdbPanel.dispatcher.on(MutationDetailsEvents.PANEL_CHAIN_SELECTED,g),N.pdbPanel.dispatcher.on(MutationDetailsEvents.PDB_PANEL_RESIZE_STARTED,h),N.pdbPanel.dispatcher.on(MutationDetailsEvents.PDB_PANEL_RESIZE_ENDED,f),N.addInitCallback(function(t){C(i)})),null!=n&&null!=N&&i.length>0&&(O(),N.showView(),t&&a?N.selectChain(t,a):N.selectDefaultChain(),N.autoCollapse())};o.getPdbData(r,l)}function O(){var t=function(t,e,n){return l.mutationColorMap[t]};a.updateOptions({mutationColorMapper:t})}var N=null,R=null,q=!1;c()}function MutationDetailsController(t,e,n,i,a,o){function r(){t.dispatcher.on(MutationDetailsEvents.GENE_TAB_SELECTED,l),t.dispatcher.on(MutationDetailsEvents.GENE_TABS_CREATED,u)}function l(t){null==h[t]&&s(t,n,i,a)}function u(){var e=t.$el.find(".mutation-3d-container");if(o){var r=new Mutation3dVisView({el:e,mut3dVis:o,pdbProxy:m,mutationProxy:d});r.render(),f=r}else $(e).hide();var l=d.getGeneList();s(l[0],n,i,a)}function s(n,i,a,r){var l=function(l,u,s){u=c(u,d.getMutationUtil(),s);var p=d.getMutationUtil(),g={geneSymbol:n,mutationData:u,dataProxies:e,sequence:l,sampleArray:i,diagramOpts:a,tableOpts:r},v=new MainMutationView({el:"#mutation_details_"+cbio.util.safeProperty(n),model:g});v.render(),h[n].mainMutationView=v;var b=v.initComponents(f);(null==u||0==u.length)&&(v.showNoDataInfo(),b.tableView.hideView()),new MainMutationController(v,b.diagram),new MutationDetailsTableController(b.tableView,b.diagram,t),o&&f&&new Mutation3dController(t,v,f,b.view3d,o,m,p,b.diagram,b.tableView.tableUtil,n),new MutationDiagramController(b.diagram,b.tableView.tableUtil,p)};d.getMutationData(n,function(t){h[n]={},null==t&&(t=[]);var e=d.getMutationUtil().dataFieldCount(n,"uniprotAcc",["NA"]),i=null,a={geneSymbol:n};e.length>0&&(i=e[0].uniprotAcc),i&&(a.uniprotAcc=i),p.getPfamData(a,function(e){if(null==e)return void console.log("[warning] no pfam data found: %o",a);var n=e[0];if(m){var i=n.metadata.identifier;m.getPdbRowData(i,function(e){l(n,t,e)})}else l(n,t)})})}function c(t,e,n){if(!n)return t;var i=e.getMutationIdMap();return _.each(t,function(t,e){if(null==t)return void console.log("warning [processMutationData]: mutation (at index %d) is null.",e);var a=i[t.mutationId],o=PdbDataUtil.mutationToPdb(a,n);t.pdbMatch=o,a.pdbMatch=o}),t}var d=e.mutationProxy,p=e.pfamProxy,m=e.pdbProxy,h={},f=null;r()}function MutationDetailsTableController(t,e,n){function i(){e.dispatcher.on(MutationDetailsEvents.ALL_LOLLIPOPS_DESELECTED,o),e.dispatcher.on(MutationDetailsEvents.LOLLIPOP_DESELECTED,r),e.dispatcher.on(MutationDetailsEvents.LOLLIPOP_SELECTED,l),e.dispatcher.on(MutationDetailsEvents.LOLLIPOP_MOUSEOVER,u),e.dispatcher.on(MutationDetailsEvents.LOLLIPOP_MOUSEOUT,s),e.dispatcher.on(MutationDetailsEvents.DIAGRAM_PLOT_RESET,a),n.dispatcher.on(MutationDetailsEvents.GENE_TAB_SELECTED,c)}function a(){t&&t.resetFilters()}function o(){t&&(t.clearHighlights(),t.rollBack())}function r(n,i){if(t){t.clearHighlights();var a=[];_.each(e.getSelectedElements(),function(t,e){a=a.concat(t.datum().mutations)}),a.length>0?t.filter(a):t.rollBack()}}function l(n,i){if(t){t.clearHighlights();var a=[];_.each(e.getSelectedElements(),function(t,e){a=a.concat(t.datum().mutations)}),t.filter(a)}}function u(e,n){t&&t.highlight(e.mutations)}function s(e,n){t&&t.clearHighlights()}function c(e){if(t){var n=t.tableUtil.getDataTable();n.is(":visible")&&n.fnAdjustColumnSizing()}}i()}function MutationDiagramController(t,e,n){function i(){e.dispatcher.on(MutationDetailsEvents.MUTATION_TABLE_FILTERED,a)}function a(e){var n=[],i=[];try{i=$(e).DataTable().rows({filter:"applied"}).data()}catch(a){i=$(e).dataTable()._("tr",{filter:"applied"})}if(_.each(i,function(t,e){var i=t[0].mutation;i&&n.push(i)}),null!==t){var o=new MutationCollection(n);t.updatePlot(PileupUtil.convertToPileups(o))}}i()}function MutationMapper(t){function e(t){a.proxy.mutationProxy.options.geneList=a.data.geneList.join(" ");var e=DataProxyUtil.initDataProxies(a.proxy,t),i={mutationProxy:e.mutationProxy,sampleArray:a.data.sampleList,tableOpts:a.view.mutationTable,diagramOpts:a.view.mutationDiagram},o={el:a.el,model:i,mut3dVis:t},r=new MutationDetailsView(o);n=r;new MutationDetailsController(r,e,i.sampleArray,i.diagramOpts,i.tableOpts,t);r.render()}var n=null,i={el:"#mutation_details",data:{geneList:[],sampleList:[]},view:{mutationDiagram:{},mutationTable:{},pdbPanel:{},pdbTable:{},vis3d:{}},proxy:{pfamProxy:{instance:null,instanceClass:PfamDataProxy,options:{data:{}}},mutationProxy:{instance:null,instanceClass:MutationDataProxy,options:{data:{},params:{},geneList:""}},pdbProxy:{instance:null,instanceClass:PdbDataProxy,options:{data:{pdbData:{},infoData:{},summaryData:{},positionData:{}},mutationUtil:{}}},pancanProxy:{instance:null,instanceClass:PancanMutationDataProxy,options:{data:{byKeyword:{},byProteinChange:{},byProteinPosition:{},byGeneSymbol:{}}}},mutationAlignerProxy:{instance:null,instanceClass:MutationAlignerDataProxy,options:{data:{}}},portalProxy:{instance:null,instanceClass:PortalDataProxy,options:{data:{}}}}},a=jQuery.extend(!0,{},i,t);this.init=e,this.getView=function(){return n}}var DataTableUtil=function(){function t(t){var e={};return _.each(t,function(t,n){null==e[t]&&(e[t]=n)}),e}function e(t){var e={};return _.each(_.pairs(t),function(t,n){var i=t[0],a=t[1];null!=a.sTitle&&a.sTitle.length>0&&(e[a.sTitle]=i)}),e}function n(t,e){var n={};return _.each(t,function(t,i){null==n[t]&&(_.isFunction(e)?n[t]=e(t):n[t]="hidden")}),n}function i(t,e){var n={};return _.each(t,function(t,i){null==n[t]&&(n[t]=_.isFunction(e)&&e(t))}),n}function a(t,e,n){var i=[];return _.each(t,function(t,a){"visible"!=n[t]&&i.push(e[t])}),i}function o(t,e,n){var i=[];return _.each(t,function(t,a){"excluded"==n[t]&&i.push(e[t])}),i}function r(t,e,n){var i=[];return _.each(t,function(t,a){n[t]===!1&&i.push(e[t])}),i}function l(t,e){var n=[];return _.each(_.pairs(t),function(t){var i=t[0],a=t[1],o=e[i];if(null!=o){var r={fnRender:function(t){var n=t.aData[e.datum];return a(t,n)},aTargets:[o]};n.push(r)}}),n}function u(t,e,n,i,a){var o={};return _.each(_.pairs(e),function(e){var a=e[0],r=e[1],l=n[a],u=i[a],s=t[a],c=function(t){return null!=l?l(t):r(t)};if(null!=s){var d={mData:function(e,n,i){var a=e[t.datum];return"set"===n?null:"display"===n?r(a):"sort"===n?c(a):"filter"===n?null!=u?u(a):c(a):e[s]},aTargets:[s]};o[a]=d}}),_.each(_.pairs(a),function(e){var n=e[0],i=e[1],a=t[n],r={mData:function(e,n,a){return i(e,n,a,t)},aTargets:[a]};o[n]=r}),_.values(o)}function s(t,e){var n=[];return _.each(_.pairs(t),function(t){var i=t[0],a=t[1],o=e[i];o>0&&(n[o]=a)}),n}function c(t){var e=$(t).attr("alt"),n=parseFloat(e);return isNaN(n)&&(n=""),n}function d(t){return-1!=t.indexOf("label")?$(t).find("label").text().trim()||$(t).text().trim():-1}function p(t){return-1!=t.indexOf("label")?parseInt($(t).text()):-1}function m(t){return-1!=t.indexOf("label")?parseFloat($(t).text()):-1}function h(t,e,n,i){return n>=0?i>=0?n==i?0:i>n?-1:1:-1:i>=0?1:t==e?0:e>t?1:-1}function f(t,e,n,i){return n>=0?i>=0?n==i?0:i>n?1:-1:-1:i>=0?1:t==e?0:e>t?-1:1}return{buildColumnIndexMap:t,buildColumnNameMap:e,buildColumnVisMap:n,buildColumnSearchMap:i,getHiddenColumns:a,getExcludedColumns:o,getNonSearchableColumns:r,getColumnOptions:s,getColumnRenderers:l,getColumnData:u,compareSortAsc:h,compareSortDesc:f,getAltTextValue:c,getLabelTextValue:d,getLabelTextIntValue:p,getLabelTextFloatValue:m}}(),MutationViewsUtil=function(){function t(t,e,n,i,a){var o=new MutationMapper(e),r=!1;return $(t).is(":visible")&&(o.init(a),r=!0),$(n).bind("tabsactivate",function(t,e){e.newTab.text().trim().toLowerCase()==i.toLowerCase()&&(r?o.getView().refreshGenesTab():(o.init(a),r=!0))}),o}function e(){return{mutationType:i,validationStatus:a,mutationStatus:o,omaScore:r,cna:l}}function n(){return{content:{attr:"alt"},show:{event:"mouseover"},hide:{fixed:!0,delay:100,event:"mouseout"},style:{classes:"mutation-details-tooltip qtip-shadow qtip-light qtip-rounded"},position:{my:"top left",at:"bottom right",viewport:$(window)}}}var i={missense_mutation:{label:"Missense",style:"missense_mutation"},nonsense_mutation:{label:"Nonsense",style:"trunc_mutation"},nonstop_mutation:{label:"Nonstop",style:"trunc_mutation"},frame_shift_del:{label:"FS del",style:"trunc_mutation"},frame_shift_ins:{label:"FS ins",style:"trunc_mutation"},in_frame_ins:{label:"IF ins",style:"inframe_mutation"},in_frame_del:{label:"IF del",style:"inframe_mutation"},splice_site:{label:"Splice",style:"trunc_mutation"},other:{style:"other_mutation"}},a={valid:{label:"V",style:"valid",tooltip:"Valid"},validated:{label:"V",style:"valid",tooltip:"Valid"},wildtype:{label:"W",style:"wildtype",tooltip:"Wildtype"},unknown:{label:"U",style:"unknown",tooltip:"Unknown"},not_tested:{label:"U",style:"unknown",tooltip:"Unknown"},none:{label:"U",style:"unknown",tooltip:"Unknown"},na:{label:"U",style:"unknown",tooltip:"Unknown"}},o={somatic:{label:"S",style:"somatic",tooltip:"Somatic"},germline:{label:"G",style:"germline",tooltip:"Germline"},unknown:{label:"U",style:"unknown",tooltip:"Unknown"},none:{label:"U",style:"unknown",tooltip:"Unknown"},na:{label:"U",style:"unknown",tooltip:"Unknown"}},r={h:{label:"High",style:"oma_high",tooltip:"High"},m:{label:"Medium",style:"oma_medium",tooltip:"Medium"},l:{label:"Low",style:"oma_low",tooltip:"Low"},n:{label:"Neutral",style:"oma_neutral",tooltip:"Neutral"}},l={"-2":{label:"DeepDel",style:"cna-homdel",tooltip:"Deep deletion"},"-1":{label:"ShallowDel",style:"cna-hetloss",tooltip:"Shallow deletion"},0:{label:"Diploid",style:"cna-diploid",tooltip:"Diploid / normal"},1:{label:"Gain",style:"cna-gain",tooltip:"Low-level gain"},2:{label:"AMP",style:"cna-amp",tooltip:"High-level amplification"},unknown:{label:"NA",style:"cna-unknown",tooltip:"CNA data is not available for this gene"}};return{initMutationMapper:t,defaultTableTooltipOpts:n,getVisualStyleMaps:e}}(),MutationDetailsTableFormatter=function(){function t(t){return e(F,t)}function e(t,e){var n,i,a;return null!=t[e]?(n=t[e].style,i=t[e].label,a=t[e].tooltip):(n=t.unknown.style,i=t.unknown.label,a=t.unknown.tooltip),{style:n,tip:a,text:i}}function n(t){var e=16,n=t,i="",a=t;return t.length>e+2&&(n=t.substring(0,e)+"...",i="simple-tip"),{style:i,tip:a,text:n}}function i(t){return a(x,t)}function a(t,e){var n,i;return e=e.toLowerCase(),null!=t[e]?(n=t[e].style,i=t[e].label):(n=t.other.style,i=e),{style:n,text:i}}function o(t){return r(A,t)}function r(t,e){var n="simple-tip",i=e,a="";return e=e.toLowerCase(),null!=t[e]&&(n=t[e].style,i=t[e].label,a=t[e].tooltip),{style:n,tip:a,text:i}}function l(t){return u(M,t)}function u(t,e){var n,i,a;return e=e.toLowerCase(),null!=t[e]?(n=t[e].style,i=t[e].label,a=t[e].tooltip):(n=t.unknown.style,i=t.unknown.label,a=t.unknown.tooltip),{style:n,tip:a,text:i}}function s(t,e){return c(I,t,e)}function c(t,e,n){var i="",a="",o="",r="";return e=e.toLowerCase(),null!=t[e]&&(r=t[e].tooltip,null!=n&&(r=n.toFixed(2)),i=t[e].label,a=t[e].style,o="oma_link"),{fisClass:a,omaClass:o,value:r,text:i}}function d(t,e,n,i){var a="NA",o=e+n,r="",l="";return t&&(r="mutation_table_allele_freq",a=t.toFixed(2),l=i),{text:a,total:o,style:r,tipClass:l}}function p(t){return h(t.pdbMatch)}function m(t){return h(t.igvLink)}function h(t){return t?"#":""}function f(t){var e="mutation-table-protein-change",n="click to highlight the position on the diagram",i="";return null!=t.aminoAcidChange&&t.aminoAcidChange.length>0&&"NA"!=t.aminoAcidChange&&-1!=t.cancerStudyShort.toLowerCase().indexOf("msk-impact")&&g(t.proteinChange,t.aminoAcidChange)&&(i="The original annotation file indicates a different value: "+v(t.aminoAcidChange)+""),{text:v(t.proteinChange),style:e,tip:n,additionalTip:i}}function g(t,e){var n=!1;if(t=v(t),e=v(e),e!==t){var i=t.match(/[A-Z]/g),a=e.match(/[A-Z]/g),o=t.match(/[0-9]+/),r=e.match(/[0-9]+/),l=t.match(/([a-z]+)/),u=e.match(/([a-z]+)/);o&&r&&o.length>0&&r.length>0&&o[0]!=r[0]?n=!0:i&&a&&i.length>0&&a.length>0&&"X"!==i[0]&&"X"!==a[0]&&i[0]!==a[0]?n=!0:i&&a&&i.length>1&&a.length>1&&i[1]!==a[1]?n=!0:l&&u&&l.length>0&&u.length>0&&l[0]!==u[0]&&(n=!0)}return n}function v(t){var e="p.";return-1!=t.indexOf(e)&&(t=t.substr(t.indexOf(e)+e.length)),t}function b(t){var e="tumor_type",n="";return{text:t.tumorType,style:e,tip:n}}function y(t){var e="",n="";return t>0&&(e="mutation_table_cosmic",n=t),{style:e,count:n}}function _(t){var e="",n="";return t>0&&(e="mutation_table_cbio_portal",n=t),{style:e,frequency:n}}function T(t){var e=t,n="mutation_table_int_value";return null==t&&(e="NA",n=""),{text:e,style:n}}function C(t){var e=t,n="mutation_table_allele_count";return null==t&&(e="NA",n=""),{text:e,style:n}}function P(t,e){var n;return t=t.toLowerCase(),n="low"==t||"l"==t?2:"medium"==t||"m"==t?3:"high"==t||"h"==t?4:"neutral"==t||"n"==t?1:-1,n>0&&!isNaN(e)&&(n+=e/1e3),n}function S(t){var e=parseInt(t);return isNaN(e)&&(e=-(1/0)),e}function w(t){var e=parseFloat(t);return isNaN(e)&&(e=-(1/0)),e}var D=MutationViewsUtil.getVisualStyleMaps(),x=D.mutationType,M=D.validationStatus,A=D.mutationStatus,I=D.omaScore,F=D.cna;return{getCaseId:n,getProteinChange:f,getPdbMatchLink:p,getIgvLink:m,getAlleleCount:C,getAlleleFreq:d,getCNA:t,getMutationType:i,getMutationStatus:o,getValidationStatus:l,getFis:s,getTumorType:b,getCosmic:y,getCbioPortal:_,getIntValue:T,assignValueToPredictedImpact:P,assignIntValue:S,assignFloatValue:w}}(),PileupUtil=function(){function t(t){for(var e=t.mutations,n={},i=0;i"+r+"
"+f(a,o,l);n.set("content.text",s)}}})})}function h(t,e){var n=t.count||0;"frequency"in t||(t.frequency=n/e);var i=(100*t.frequency).toFixed(1)+"%";return _.template("{{percent}} ({{count}} of {{total}} sequenced samples)")({percent:i,count:n,total:e})}function f(t,e,n){return""+C+": "+h(t,n)+"
Other "+Y+" mutations: "+h(e,n)+"
"}function g(t){return z.filter(function(e){return e.cancer_study===t})}a=a||{},a=a.sparkline?_.extend({margin:{top:-12,right:0,bottom:0,left:0},width:30,height:12,this_cancer_study:void 0},a):_.extend({margin:{top:6,right:10,bottom:20,left:40},width:600,height:300,this_cancer_study:void 0},a);var v=r(n),y=_.keys(v),b=o(t),T=o(e),C=b[0].hugo+" "+b[0].protein_pos_start;b=d(b).map(function(t){return t.keyword=C,t}),T=d(T);var P={bykeyword:r(b),bygene:r(T)},D=_.intersection(_.keys(P.bykeyword),_.keys(P.bygene));if(b=[],T=[],_.each(D,function(t){b.push(P.bykeyword[t]),T.push(P.bygene[t])}),T.length!==b.length)throw new Error("must be same length");if(T.length!==y.length)throw new Error("there must be a datum for every cancer study and visa versa");T.forEach(function(t){var e=P.bykeyword[t.cancer_study],n=t.count-e.count;if(0>n)throw new Error("more mutations for a particular keyword than for all keywords of a particular gene");t.count=n});var w=_.reduce(T,function(t,e){return t+e.count},0),S=_.reduce(b,function(t,e){return t+e.count},0),M=_.reduce(v,function(t,e){return t+e.num_sequenced_samples},0);_.mixin({unzip:function(t){return _.zip.apply(_,t)}});var x=b.concat(T);try{x=_.chain(x).map(l).groupBy(function(t){return t.cancer_study}).map(_.identity).sortBy(u).unzip().value()}catch(A){throw new Error(A)}var I=a.width-a.margin.left-a.margin.left,E=a.height-a.margin.top-a.margin.bottom,L=d3.select(i).append("svg").attr("width",a.width).attr("height",a.height).append("g").attr("transform","translate("+a.margin.left+","+a.margin.top+")"),F=d3.layout.stack().x(function(t){return t.cancer_study}).y(function(t){return t.frequency}),k=F(x),V=d3.scale.ordinal().domain(x[0].map(function(t){return t.cancer_study})).rangeBands([0,I],.1),N=.2,B=a.sparkline?N:d3.max(k,function(t){return d3.max(t,function(t){return t.y0+t.y})}),O=d3.scale.linear().domain([0,B]).range([E,0]).clamp(!0),R="LimeGreen",U="Green",q=L.selectAll(".layer").data(k).enter().append("g").attr("class","layer").style("fill",function(t,e){return[U,R][e]}),z=q.selectAll("rect").data(function(t){return t}).enter().append("rect").attr("x",function(t){return V(t.cancer_study)}).attr("y",function(t){return O(t.y0+t.y)}).attr("width",function(t){return V.rangeBand()}).attr("height",function(t){return O(t.y0)-O(t.y0+t.y)});if(a.sparkline)return{el:i,qtip:function(){throw new Error("don't qtip a sparkline")}};var H=d3.format(B>.1?".0%":".1%"),j=d3.svg.axis().scale(O).tickFormat(H).orient("left");j.tickSize(j.tickSize(),0,0);var G=function(){function t(t){return{cancer_type:t.cancer_type,start:t.cancer_study,end:t.cancer_study,color:v[t.cancer_study].color}}var e=x[0][0];return _.chain(x[0]).reduce(function(e,n){var i=_.last(e);return i.cancer_type!==n.cancer_type?e.concat(t(n)):i.cancer_type===n.cancer_type?(i.end=n.cancer_study,e):void 0},[t(e)]).value()}();L.selectAll("line").data(G).enter().append("line").attr("x1",function(t){return V(t.start)}).attr("x2",function(t){return V(t.end)+V.rangeBand()}).attr("y1",E+a.margin.bottom/3).attr("y2",E+a.margin.bottom/3).style("stroke-width",5).style("stroke",function(t){return t.color});var Y=(L.append("g").call(j).attr("stroke","#000").attr("shape-rendering","crispEdges"),_.find(k[0],function(t){return void 0!==t.hugo}).hugo),C=_.find(k[0],function(t){return void 0!==t.keyword}).keyword;return _.isUndefined(a.this_cancer_study)||p(),{el:i,qtip:m,overallCountText:function(){return f({count:S},{count:w},M)}}}function MainMutationController(t){function e(){t.diagramView?n(t.diagramView.mutationDiagram):t.dispatcher.on(MutationDetailsEvents.DIAGRAM_INIT,n),t.addResetCallback(i)}function n(t){s=t,t.dispatcher.on(MutationDetailsEvents.ALL_LOLLIPOPS_DESELECTED,o),t.dispatcher.on(MutationDetailsEvents.LOLLIPOP_DESELECTED,r),t.dispatcher.on(MutationDetailsEvents.LOLLIPOP_SELECTED,l),t.dispatcher.on(MutationDetailsEvents.DIAGRAM_PLOT_UPDATED,a)}function i(e){s&&s.resetPlot(),t.hideFilterInfo()}function a(){s&&s.isFiltered()?t.showFilterInfo():t.hideFilterInfo()}function o(){s&&!s.isFiltered()&&t.hideFilterInfo()}function r(t,e){s&&0==s.getSelectedElements().length&&o()}function l(e,n){t.showFilterInfo()}var s=null;e()}function Mutation3dController(t,e,n,i,a,o,r){function l(){e.diagramView?s(e.diagramView.mutationDiagram):e.dispatcher.on(MutationDetailsEvents.DIAGRAM_INIT,s),e.tableView&&e.tableView.mutationTable&&(e.tableView.mutationTable.dispatcher.on(MutationDetailsEvents.PDB_LINK_CLICKED,L),e.tableView.mutationTable.dispatcher.on(MutationDetailsEvents.PROTEIN_CHANGE_LINK_CLICKED,E)),i.addInitCallback(p),t.dispatcher.on(MutationDetailsEvents.GENE_TAB_SELECTED,c),n?u(n):t.dispatcher.on(MutationDetailsEvents.VIS_3D_PANEL_CREATED,u)}function s(t){z=t,t.dispatcher.on(MutationDetailsEvents.ALL_LOLLIPOPS_DESELECTED,S),t.dispatcher.on(MutationDetailsEvents.LOLLIPOP_DESELECTED,M),t.dispatcher.on(MutationDetailsEvents.LOLLIPOP_SELECTED,x),t.dispatcher.on(MutationDetailsEvents.LOLLIPOP_MOUSEOVER,A),t.dispatcher.on(MutationDetailsEvents.LOLLIPOP_MOUSEOUT,I),t.dispatcher.on(MutationDetailsEvents.DIAGRAM_PLOT_UPDATED,w),t.dispatcher.on(MutationDetailsEvents.DIAGRAM_PLOT_RESET,D)}function u(t){t&&(U=t,q=t.options.mut3dVis,U.dispatcher.on(MutationDetailsEvents.VIEW_3D_PANEL_CLOSED,d),U.dispatcher.on(MutationDetailsEvents.VIEW_3D_STRUCTURE_RELOADED,g))}function c(t){U&&(U.resetPanelPosition(),U.hideView())}function d(){$&&$.hideView()}function p(t){B(),null!=U&&(U.resetPanelPosition(),U.maximizeView())}function m(t,e,n){t>n&&$.toggleScrollBar(n)}function h(t,e,n){n>=t&&$.toggleScrollBar(-1),e!=t&&$.scrollToSelected()}function f(t){H&&$.scrollToSelected();var e=t.datum();null!=U&&(U.maximizeView(),U.updateView(r,e.pdbId,e.chain)),H||null==R||(R.resetFilters(),R.selectChain(e.pdbId,e.chain.chainId),R.scrollToSelected()),H=!1}function g(){i.isVisible()&&z&&z.isHighlighted()&&V()}function v(t,e){t&&e&&($.selectChain(t,e),H=!0)}function y(){$.pdbPanel.minimizeToHighlighted()}function b(t,e){t&&e&&$.pdbPanel.minimizeToChain($.pdbPanel.getChainGroup(t,e))}function T(t){null==$&&($=e.initPdbPanelView(t),$.pdbPanel&&($.pdbPanel.dispatcher.on(MutationDetailsEvents.PANEL_CHAIN_SELECTED,f),$.pdbPanel.dispatcher.on(MutationDetailsEvents.PDB_PANEL_RESIZE_STARTED,m),$.pdbPanel.dispatcher.on(MutationDetailsEvents.PDB_PANEL_RESIZE_ENDED,h)),$.addInitCallback(function(e){C(t)}))}function C(t){null==R&&null!=$&&t.length>0&&(R=$.initPdbTableView(t,function(t,e){e.dispatcher.on(MutationDetailsEvents.PDB_TABLE_READY,P),R=t}),R.pdbTable.dispatcher.on(MutationDetailsEvents.TABLE_CHAIN_SELECTED,v),R.pdbTable.dispatcher.on(MutationDetailsEvents.TABLE_CHAIN_MOUSEOUT,y),R.pdbTable.dispatcher.on(MutationDetailsEvents.TABLE_CHAIN_MOUSEOVER,b)),null!=$&&null!=R&&($.toggleTableControls(),R.toggleView())}function P(){if(null!=$){var t=$.getSelectedChain();if(null!=t){var e=t.datum();R.selectChain(e.pdbId,e.chain.chainId),R.scrollToSelected()}}}function D(){U&&U.isVisible()&&U.refreshView()}function w(){U&&U.isVisible()&&U.refreshView()}function S(){U&&U.isVisible()&&(U.resetHighlight(),U.hideResidueWarning())}function M(t,e){z&&z.isHighlighted()?x():S()}function x(t,e){U&&U.isVisible()&&V()}function A(t,e){if(U&&U.isVisible()){var n=k();n.push(t),N(n,!0)}}function I(t,e){M(t,e)}function E(t){var e=F(t);e&&U&&U.isVisible()&&V()}function L(t){var e=F(t);e&&B(e.get("pdbMatch").pdbId,e.get("pdbMatch").chainId)}function F(t){var e=o.getMutationIdMap(),n=e[t];return n&&z&&(z.clearHighlights(),z.highlightMutation(n.get("mutationSid"))),n}function k(){var t=[];return z&&_.each(z.getSelectedElements(),function(e,n){t=t.concat(e.datum())}),t}function V(){var t=k();N(t)}function N(t,e){var n=U.highlightView(t,!0),i=t.length-n;e||(i>0?U.showResidueWarning(i,t.length):U.hideResidueWarning())}function B(e,n){var o=i.model.uniprotId;t.is3dPanelInitialized()||t.init3dPanel();var r=function(t){null==$&&T(t),null!=U&&null!=$&&t.length>0&&(O(),$.showView(),e&&n?$.selectChain(e,n):$.selectDefaultChain(),$.autoCollapse())};a.getPdbData(o,r)}function O(){if(z){var t=function(t,e,n){return z.mutationColorMap[t]};q.updateOptions({mutationColorMapper:t})}}var $=null,R=null,U=null,q=null,z=null,H=!1;l()}function MutationDetailsController(t,e,n,i){function a(){t.dispatcher.on(MutationDetailsEvents.GENE_TAB_SELECTED,r),t.dispatcher.on(MutationDetailsEvents.GENE_TABS_CREATED,l),t.dispatcher.on(MutationDetailsEvents.VIS_3D_PANEL_INIT,o)}function o(t){var e=p.vis3d;if(e){var n={appOptions:{el:t||"#mutation_details"}},i=jQuery.extend(!0,{},n,e),a=new Mutation3dVis("default3dView",i);a.init(),s(a)}}function r(t){null==v[t]&&u(t,d,p)}function l(){t.$el.find(".mutation-3d-container").hide();var e=h.getGeneList();u(e[0],d,p)}function s(e){var n=t.$el.find(".mutation-3d-container");if(e){var i=new Mutation3dVisView({el:n,config:m.mutation3dVis,mut3dVis:e,pdbProxy:g,mutationProxy:h});i.render(),_=i,t.dispatcher.trigger(MutationDetailsEvents.VIS_3D_PANEL_CREATED,i)}else $(n).hide()}function u(i,a,o){var r=function(r,l){var s=h.getMutationUtil(),u={geneSymbol:i,mutationData:l,dataProxies:n,dataManager:e,uniprotId:r.metadata.identifier,sampleArray:a},d=new MainMutationView({el:"#mutation_details_"+cbio.util.safeProperty(i),config:m.mainMutation,model:u});t.dispatcher.trigger(MutationDetailsEvents.MAIN_VIEW_INIT,d),d.render(),v[i].mainMutationView=d,e.addView(i,d),null==l||0==l.length?d.showNoDataInfo():c(d,i,s,r,o)};h.getMutationData(i,function(t){v[i]={},null==t&&(t=[]);var n=h.getMutationUtil().dataFieldCount(i,"uniprotAcc",["NA"]),a=null,o={geneSymbol:i};n.length>0&&(a=n[0].uniprotAcc),a&&(o.uniprotAcc=a),f.getPfamData(o,function(n){if(null==n)return void console.log("[warning] no pfam data found: %o",o);var i=n[0];e.getData("variantAnnotation",{mutations:t},function(t,e){r(i,t.mutations)})})})}function c(n,i,a,o,r){function l(){if(s){f=n.initMutationDiagramView(s,o);var t=null;m&&(t=m.mutationTable);var e=null;d&&(e=n.initMutationInfoView(d),new MutationInfoController(n)),new MutationDiagramController(f.mutationDiagram,t,e,a)}}var s=r.mutationDiagram,u=r.mutationTable,c=r.vis3d,d=r.infoPanel,p=r.mutationSummary,m=null;u&&(m=n.initMutationTableView(u),new MutationDetailsTableController(n,t));var h=null;p&&(h=n.initSummaryView(u));var f=null;if(a.containsProteinChange(i)?l():e.getData("variantAnnotation",{mutations:n.model.mutationData},function(t,e){l()}),new MainMutationController(n),c){var v=n.init3dView(null);new Mutation3dController(t,n,_,v,g,a,i)}}var d=i.data.sampleList,p=i.view,m=i.render,h=n.mutationProxy,f=n.pfamProxy,g=n.pdbProxy,v={},_=null;a(),this.getMainView=function(t){return v[t]},this.get3dVisView=function(){return _},this.getMainViews=function(){return v},this.getDataManager=function(){return e},this.getDataProxies=function(){return n}}function MutationDetailsTableController(t,e){function n(){t.diagramView?i(t.diagramView.mutationDiagram):t.dispatcher.on(MutationDetailsEvents.DIAGRAM_INIT,i),t.infoView?a(t.infoView):t.dispatcher.on(MutationDetailsEvents.INFO_PANEL_INIT,a),e.dispatcher.on(MutationDetailsEvents.GENE_TAB_SELECTED,p)}function i(t){m=t,t.dispatcher.on(MutationDetailsEvents.ALL_LOLLIPOPS_DESELECTED,r),t.dispatcher.on(MutationDetailsEvents.LOLLIPOP_DESELECTED,l),t.dispatcher.on(MutationDetailsEvents.LOLLIPOP_SELECTED,s),t.dispatcher.on(MutationDetailsEvents.LOLLIPOP_MOUSEOVER,c),t.dispatcher.on(MutationDetailsEvents.LOLLIPOP_MOUSEOUT,d),t.dispatcher.on(MutationDetailsEvents.DIAGRAM_PLOT_RESET,o)}function a(t){t&&t.dispatcher.on(MutationDetailsEvents.INFO_PANEL_MUTATION_TYPE_SELECTED,u)}function o(){t.tableView&&t.tableView.resetFilters()}function r(){t.tableView&&(t.tableView.clearHighlights(),t.tableView.filter(PileupUtil.getPileupMutations(m.pileups)))}function l(e,n){if(t.tableView){t.tableView.clearHighlights();var i=[];m&&_.each(m.getSelectedElements(),function(t,e){i=i.concat(t.datum().mutations)}),i.length>0?t.tableView.filter(i):t.tableView.filter(PileupUtil.getPileupMutations(m.pileups))}}function s(e,n){if(t.tableView){t.tableView.clearHighlights();var i=[];m&&_.each(m.getSelectedElements(),function(t,e){i=i.concat(t.datum().mutations)}),t.tableView.filter(i)}}function u(e){if(null!==t.tableView){var n=t.infoView.currentMapByType[e];_.size(n)>0?t.tableView.filter(n):(n=t.infoView.initialMapByType[e],t.tableView.filter(n),t.tableView.clearSearchBox())}}function c(e,n){t.tableView&&t.tableView.highlight(e.mutations)}function d(e,n){t.tableView&&t.tableView.clearHighlights()}function p(e){if(t.tableView){var n=t.tableView.mutationTable.getDataTable();n.is(":visible")&&n.fnAdjustColumnSizing()}}var m=null;n()}function MutationDiagramController(t,e,n,i){function a(){e&&e.dispatcher.on(MutationDetailsEvents.MUTATION_TABLE_FILTERED,o),n&&n.dispatcher.on(MutationDetailsEvents.INFO_PANEL_MUTATION_TYPE_SELECTED,r)}function o(e){var n=[],i=[];try{i=$(e).DataTable().rows({filter:"applied"}).data()}catch(a){i=$(e).dataTable()._("tr",{filter:"applied"})}if(_.each(i,function(t,e){var i=t[0].mutation;i&&n.push(i)}),null!==t){var o=new MutationCollection(n);t.updatePlot(PileupUtil.convertToPileups(o))}}function r(e){if(null!==t){var i=n.currentMapByType[e];_.size(i)>0?t.updatePlot(PileupUtil.convertToPileups(new MutationCollection(i))):(i=n.initialMapByType[e],t.updatePlot(PileupUtil.convertToPileups(new MutationCollection(i))))}}a()}function MutationInfoController(t){function e(){t.diagramView?n(t.diagramView.mutationDiagram):t.dispatcher.on(MutationDetailsEvents.DIAGRAM_INIT,n)}function n(t){s=t,t.dispatcher.on(MutationDetailsEvents.DIAGRAM_PLOT_RESET,r),t.dispatcher.on(MutationDetailsEvents.DIAGRAM_PLOT_UPDATED,l),t.dispatcher.on(MutationDetailsEvents.LOLLIPOP_SELECTED,o),t.dispatcher.on(MutationDetailsEvents.LOLLIPOP_DESELECTED,a),t.dispatcher.on(MutationDetailsEvents.ALL_LOLLIPOPS_DESELECTED,i)}function i(){l()}function a(e,n){if(t.infoView){var i=[];s&&_.each(s.getSelectedElements(),function(t,e){i=i.concat(t.datum())}),i.length>0?t.infoView.updateView(PileupUtil.getPileupMutations(i)):l()}}function o(t,e){a(t,e)}function r(){l()}function l(){t.infoView&&t.infoView.updateView(PileupUtil.getPileupMutations(s.pileups))}var s=null;e()}function MutationMapper(t){function e(){o.proxy.mutationProxy.options.geneList=o.data.geneList.join(" ");var t=DataProxyUtil.initDataProxies(o.proxy);o.dataManager=jQuery.extend(!0,{},o.dataManager,{dataProxies:t});var e=new MutationDataManager(o.dataManager),a={mutationProxy:t.mutationProxy},r={el:o.el,config:o.render.mutationDetails,model:a},l=new MutationDetailsView(r);n=l;var s=new MutationDetailsController(l,e,t,o);i=s,l.render()}var n=null,i=null,a={el:"#mutation_details",data:{geneList:[],sampleList:[]},view:{mutationDiagram:{},mutationTable:{},mutationSummary:{},pdbPanel:{},pdbTable:{},infoPanel:{},vis3d:{}},render:{mutationDetails:{init:null,format:null},mainMutation:{},mutation3dVis:{}},proxy:{pfamProxy:{instance:null,instanceClass:PfamDataProxy,options:{data:{}}},variantAnnotationProxy:{instance:null,instanceClass:VariantAnnotationDataProxy,options:{data:{}}},mutationProxy:{instance:null,instanceClass:MutationDataProxy,options:{data:{},params:{},geneList:""}},clinicalProxy:{instance:null,instanceClass:ClinicalDataProxy,options:{data:{}}},pdbProxy:{instance:null,instanceClass:PdbDataProxy,options:{data:{pdbData:{},infoData:{},summaryData:{},positionData:{}},mutationUtil:{}}},pancanProxy:{instance:null,instanceClass:PancanMutationDataProxy,options:{data:{byKeyword:{},byProteinChange:{},byProteinPosition:{},byGeneSymbol:{}}}},mutationAlignerProxy:{instance:null,instanceClass:MutationAlignerDataProxy,options:{data:{}}},portalProxy:{instance:null,instanceClass:PortalDataProxy,options:{data:{}}}},dataManager:{dataFn:{},dataProxies:{}}},o=jQuery.extend(!0,{},a,t);this.init=e,this.getView=function(){return n},this.getController=function(){return i}}var DataTableUtil=function(){function t(t){var e={};return _.each(t,function(t,n){null==e[t]&&(e[t]=n)}),e}function e(t){var e={};return _.each(_.pairs(t),function(t,n){var i=t[0],a=t[1];null!=a.sTitle&&a.sTitle.length>0&&(e[a.sTitle]=i)}),e}function n(t,e){var n={};return _.each(t,function(t,i){null==n[t]&&(_.isFunction(e)?n[t]=e(t):n[t]="hidden")}),n}function i(t,e){var n={};return _.each(t,function(t,i){null==n[t]&&(n[t]=_.isFunction(e)&&e(t))}),n}function a(t,e,n){var i=[];return _.each(t,function(t,a){"visible"!=n[t]&&i.push(e[t])}),i}function o(t,e,n){var i=[];return _.each(t,function(t,a){"excluded"==n[t]&&i.push(e[t])}),i}function r(t,e,n){var i=[];return _.each(t,function(t,a){n[t]===!1&&i.push(e[t])}),i}function l(t,e){var n=[];return _.each(_.pairs(t),function(t){var i=t[0],a=t[1],o=e[i];if(null!=o){var r={fnRender:function(t){var n=t.aData[e.datum];return a(t,n)},aTargets:[o]};n.push(r)}}),n}function s(t,e,n,i,a){var o={};return _.each(_.pairs(e),function(e){var a=e[0],r=e[1],l=n[a],s=i[a],u=t[a],c=function(t){return null!=l?l(t):r(t)};if(null!=u){var d={mData:function(e,n,i){var a=e[t.datum];return"set"===n?null:"display"===n?r(a):"sort"===n?c(a):"filter"===n?null!=s?s(a):c(a):e[u]},aTargets:[u]};o[a]=d}}),_.each(_.pairs(a),function(e){var n=e[0],i=e[1],a=t[n],r={mData:function(e,n,a){return i(e,n,a,t)},aTargets:[a]};o[n]=r}),_.values(o)}function u(t,e){var n=[];return _.each(_.pairs(t),function(t){var i=t[0],a=t[1],o=e[i];o>0&&(n[o]=a)}),n}function c(t){var e=$(t).attr("alt"),n=parseFloat(e);return isNaN(n)&&(n=""),n}function d(t){return-1!=t.indexOf("label")?$(t).find("label").text().trim()||$(t).text().trim():-1}function p(t){return-1!=t.indexOf("label")?parseInt($(t).text()):-1}function m(t){return-1!=t.indexOf("label")?parseFloat($(t).text()):-1}function h(t,e,n,i){return n>=0?i>=0?n==i?0:i>n?-1:1:-1:i>=0?1:t==e?0:e>t?1:-1}function f(t,e,n,i){return n>=0?i>=0?n==i?0:i>n?1:-1:-1:i>=0?1:t==e?0:e>t?-1:1}return{buildColumnIndexMap:t,buildColumnNameMap:e,buildColumnVisMap:n,buildColumnSearchMap:i,getHiddenColumns:a,getExcludedColumns:o,getNonSearchableColumns:r,getColumnOptions:u,getColumnRenderers:l,getColumnData:s,compareSortAsc:h,compareSortDesc:f,getAltTextValue:c,getLabelTextValue:d,getLabelTextIntValue:p,getLabelTextFloatValue:m}}(),MutationViewsUtil=function(){function t(t,e,n,i){var a=new MutationMapper(e),o=!1;return $(t).is(":visible")&&(a.init(),o=!0),$(n).bind("tabsactivate",function(t,e){e.newTab.text().trim().toLowerCase()==i.toLowerCase()&&(o?a.getView().refreshGenesTab():(a.init(),o=!0))}),a}function e(){return{mutationType:r,validationStatus:l,mutationStatus:s,omaScore:u,cna:c}}function n(){return{content:{attr:"alt"},show:{event:"mouseover"},hide:{fixed:!0,delay:100,event:"mouseout"},style:{classes:"mutation-details-tooltip qtip-shadow qtip-light qtip-rounded"},position:{my:"top left",at:"bottom right",viewport:$(window)}}}function i(t){t=t||"images/ajax-loader.gif";var e={loaderImage:t,width:15,height:15},n=BackboneTemplateCache.getTemplateFn("mutation_table_placeholder_template");return n(e)}function a(t,e,n){var i=t.fnGetData();_.each(i,function(i,a){t.fnUpdate(null,a,e[n],!1,!1)}),i.length>0&&t.fnUpdate(null,0,e[n])}var o={missense:{label:"Missense",longName:"Missense",style:"missense_mutation",mainType:"missense",priority:1},inframe:{label:"IF",longName:"In-frame",style:"inframe_mutation",mainType:"inframe",priority:2},truncating:{label:"Truncating",longName:"Truncating",style:"trunc_mutation",mainType:"truncating",priority:4},nonsense:{label:"Nonsense",longName:"Nonsense",style:"trunc_mutation",mainType:"truncating",priority:6},nonstop:{label:"Nonstop",longName:"Nonstop",style:"trunc_mutation",mainType:"truncating",priority:7},nonstart:{label:"Nonstart",longName:"Nonstart",style:"trunc_mutation",mainType:"truncating",priority:8},frameshift:{label:"FS",longName:"Frame Shift",style:"trunc_mutation",mainType:"truncating",priority:4},frame_shift_del:{label:"FS del",longName:"Frame Shift Deletion",style:"trunc_mutation",mainType:"truncating",priority:4},frame_shift_ins:{label:"FS ins",longName:"Frame Shift Insertion",style:"trunc_mutation",mainType:"truncating",priority:5},in_frame_ins:{label:"IF ins",longName:"In-frame Insertion",style:"inframe_mutation",mainType:"inframe",priority:3},in_frame_del:{label:"IF del",longName:"In-frame Deletion",style:"inframe_mutation",mainType:"inframe",priority:2},splice_site:{label:"Splice",longName:"Splice site",style:"trunc_mutation",mainType:"truncating",priority:9},fusion:{label:"Fusion",longName:"Fusion",style:"fusion",mainType:"other",priority:10},other:{style:"other_mutation",mainType:"other",priority:11}},r={missense_mutation:o.missense,missense:o.missense,missense_variant:o.missense,frame_shift_ins:o.frame_shift_ins,frame_shift_del:o.frame_shift_del,frameshift:o.frameshift,frameshift_deletion:o.frame_shift_del,frameshift_insertion:o.frame_shift_ins,de_novo_start_outofframe:o.frameshift,frameshift_variant:o.frameshift,nonsense_mutation:o.nonsense,nonsense:o.nonsense,stopgain_snv:o.nonsense,splice_site:o.splice_site,splice:o.splice_site,"splice site":o.splice_site,splicing:o.splice_site,splice_site_snp:o.splice_site,splice_site_del:o.splice_site,splice_site_indel:o.splice_site,translation_start_site:o.nonstart,start_codon_snp:o.nonstart,start_codon_del:o.nonstart,nonstop_mutation:o.nonstop,in_frame_del:o.in_frame_del,in_frame_ins:o.in_frame_ins,indel:o.in_frame_del,nonframeshift_deletion:o.inframe,nonframeshift:o.inframe,"nonframeshift insertion":o.inframe,nonframeshift_insertion:o.inframe,targeted_region:o.inframe,inframe:o.inframe,truncating:o.truncating,fusion:o.fusion,other:o.other},l={valid:{label:"V",style:"valid",tooltip:"Valid"},validated:{label:"V",style:"valid",tooltip:"Valid"},wildtype:{label:"W",style:"wildtype",tooltip:"Wildtype"},unknown:{label:"U",style:"unknown",tooltip:"Unknown"},not_tested:{label:"U",style:"unknown",tooltip:"Unknown"},none:{label:"U",style:"unknown",tooltip:"Unknown"},na:{label:"U",style:"unknown",tooltip:"Unknown"}},s={somatic:{label:"S",style:"somatic",tooltip:"Somatic"},germline:{label:"G",style:"germline",tooltip:"Germline"},unknown:{label:"U",style:"unknown",tooltip:"Unknown"},none:{label:"U",style:"unknown",tooltip:"Unknown"},na:{label:"U",style:"unknown",tooltip:"Unknown"}},u={h:{label:"High",style:"oma_high",tooltip:"High"},m:{label:"Medium",style:"oma_medium",tooltip:"Medium"},l:{label:"Low",style:"oma_low",tooltip:"Low"},n:{label:"Neutral",style:"oma_neutral",tooltip:"Neutral"}},c={"-2":{label:"DeepDel",style:"cna-homdel",tooltip:"Deep deletion"},"-1":{label:"ShallowDel",style:"cna-hetloss",tooltip:"Shallow deletion"},0:{label:"Diploid",style:"cna-diploid",tooltip:"Diploid / normal"},1:{label:"Gain",style:"cna-gain",tooltip:"Low-level gain"},2:{label:"AMP",style:"cna-amp",tooltip:"High-level amplification"},unknown:{label:"NA",style:"cna-unknown",tooltip:"CNA data is not available for this gene"}};return{initMutationMapper:t,renderTablePlaceHolder:i,refreshTableColumn:a,defaultTableTooltipOpts:n,getVisualStyleMaps:e}}(),MutationDetailsTableFormatter=function(){function t(t){return e(E,t)}function e(t,e){var n,i,a;return null!=t[e]?(n=t[e].style, +i=t[e].label,a=t[e].tooltip):(n=t.unknown.style,i=t.unknown.label,a=t.unknown.tooltip),{style:n,tip:a,text:i}}function n(t){var e=16,n=t,i="",a=t;return null!=t&&t.length>e+2&&(n=t.substring(0,e)+"...",i="simple-tip"),{style:i,tip:a,text:n}}function i(t){return a(M,t)}function a(t,e){var n,i;return null!=e&&(e=e.toLowerCase()),null!=t[e]?(n=t[e].style,i=t[e].label):(n=t.other.style,i=e),{style:n,text:i}}function o(t){return r(A,t)}function r(t,e){var n="simple-tip",i=e,a="";return null!=e&&(e=e.toLowerCase()),null!=t[e]&&(n=t[e].style,i=t[e].label,a=t[e].tooltip),{style:n,tip:a,text:i}}function l(t){return s(x,t)}function s(t,e){var n,i,a;return null!=e&&(e=e.toLowerCase()),null!=t[e]?(n=t[e].style,i=t[e].label,a=t[e].tooltip):(n=t.unknown.style,i=t.unknown.label,a=t.unknown.tooltip),{style:n,tip:a,text:i}}function u(t,e){return c(I,t,e)}function c(t,e,n){var i="",a="",o="",r="";return null!=e&&(e=e.toLowerCase()),null!=t[e]&&(r=t[e].tooltip,null!=n&&(r=n.toFixed(2)),i=t[e].label,a=t[e].style,o="oma_link"),{fisClass:a,omaClass:o,value:r,text:i}}function d(t,e,n,i){var a="NA",o=e+n,r="",l="";return t&&(r="mutation_table_allele_freq",a=t.toFixed(2),l=i),{text:a,total:o,style:r,tipClass:l}}function p(t){return h(t.get("pdbMatch"))}function m(t){return h(t.get("igvLink"))}function h(t){return t?"#":""}function f(t){var e="mutation-table-protein-change",n="click to highlight the position on the diagram",i="";return null!=t.get("aminoAcidChange")&&t.get("aminoAcidChange").length>0&&"NA"!==t.get("aminoAcidChange")&&null!=t.get("cancerStudyShort")&&-1!=t.get("cancerStudyShort").toLowerCase().indexOf("msk-impact")&&g(t.get("proteinChange"),t.get("aminoAcidChange"))&&(i="The original annotation file indicates a different value: "+v(t.get("aminoAcidChange"))+""),{text:v(t.get("proteinChange")),style:e,tip:n,additionalTip:i}}function g(t,e){var n=!1;if(t=v(t),e=v(e),e!==t){var i=t.match(/[A-Z]/g),a=e.match(/[A-Z]/g),o=t.match(/[0-9]+/),r=e.match(/[0-9]+/),l=t.match(/([a-z]+)/),s=e.match(/([a-z]+)/);o&&r&&o.length>0&&r.length>0&&o[0]!=r[0]?n=!0:i&&a&&i.length>0&&a.length>0&&"X"!==i[0]&&"X"!==a[0]&&i[0]!==a[0]?n=!0:i&&a&&i.length>1&&a.length>1&&i[1]!==a[1]?n=!0:l&&s&&l.length>0&&s.length>0&&l[0]!==s[0]&&(n=!0)}return n}function v(t){var e="p.";return-1!=t.indexOf(e)&&(t=t.substr(t.indexOf(e)+e.length)),t}function _(t){var e="tumor_type",n="";return{text:t.get("tumorType"),style:e,tip:n}}function y(t){var e="",n="";return t>0&&(e="mutation_table_cosmic",n=t),{style:e,count:n}}function b(t){var e="",n="";return t>0&&(e="mutation_table_cbio_portal",n=t),{style:e,frequency:n}}function T(t){var e=t,n="mutation_table_int_value";return null==t&&(e="NA",n=""),{text:e,style:n}}function C(t){var e=t,n="mutation_table_allele_count";return null==t&&(e="NA",n=""),{text:e,style:n}}function P(t,e){var n;return null!=t&&(t=t.toLowerCase()),n="low"==t||"l"==t?2:"medium"==t||"m"==t?3:"high"==t||"h"==t?4:"neutral"==t||"n"==t?1:-1,n>0&&!isNaN(e)&&(n+=e/1e3),n}function D(t){var e=parseInt(t);return isNaN(e)&&(e=-(1/0)),e}function w(t){var e=parseFloat(t);return isNaN(e)&&(e=-(1/0)),e}var S=MutationViewsUtil.getVisualStyleMaps(),M=S.mutationType,x=S.validationStatus,A=S.mutationStatus,I=S.omaScore,E=S.cna;return{getCaseId:n,getProteinChange:f,getPdbMatchLink:p,getIgvLink:m,getAlleleCount:C,getAlleleFreq:d,getCNA:t,getMutationType:i,getMutationStatus:o,getValidationStatus:l,getFis:u,getTumorType:_,getCosmic:y,getCbioPortal:b,getIntValue:T,assignValueToPredictedImpact:P,assignIntValue:D,assignFloatValue:w}}(),PileupUtil=function(){function t(t){var e=t.mutations,n={};return _.each(e,function(t){var e=t.get("mutationType")||"";e=e.trim().toLowerCase(),void 0==n[e]&&(n[e]=[]),n[e].push(t)}),n}function e(e){var n=t(e),i=[];return _.each(_.keys(n),function(t){i.push({type:t,count:n[t].length})}),i.sort(function(t,e){return e.count-t.count}),i}function n(e){var n=MutationViewsUtil.getVisualStyleMaps().mutationType,i=t(e),a=[],o={};return _.each(_.keys(i),function(t){var e=void 0;null!=n[t]&&(e=n[t].mainType),void 0==e&&(e=n.other.mainType),void 0==o[e]&&(o[e]=0),o[e]+=i[t].length}),_.each(_.keys(o),function(t){a.push({type:t,count:o[t],priority:n[t].priority})}),a.sort(function(t,e){return e.count===t.count?e.priority-t.priority:e.count-t.count}),a}function i(){return c++,"pileup_"+c}function a(t){var e={};return _.each(t,function(t){_.each(t.mutations,function(n){e[n.get("mutationSid")]=t.pileupId})}),e}function o(t){t=r(t);for(var e={},n=0;n