//CYTOSCAPE SCRIPT private static string get_script(int feature_count, IGoAnalysis quantitative, string node_position, string edges_path, string nodes_path, string styles_path, string style_name) { double sleep_factor = feature_count / 1000; string node_column_types = quantitative != null ? "s,s,d,s,i,d,d,boolean,s" : "s,s,d,s,i"; //Cytoscape bug: "b" doesn't work in 3.4.0, only "boolean" does string edge_column_types = "s,s,s,s,s"; return(string.Join(Environment.NewLine, new string[] { //Load Tables "network import file file=\"" + edges_path + "\" firstRowAsColumnNames=true delimiters=\"\\t\" indexColumnSourceInteraction=\"1\" indexColumnTargetInteraction=\"3\" startLoadRow=\"0\" dataTypeList=\"" + edge_column_types + "\"", "command sleep duration=" + (0.8 + Math.Round((1.0 * sleep_factor), 2)).ToString(), "table import file file=\"" + nodes_path + "\" startLoadRow=\"0\" keyColumnIndex=\"1\" DataTypeTargetForNetworkCollection=\"Node Table Columns\" dataTypeList=\"" + node_column_types + "\"", "command sleep duration=" + (0.5 + Math.Round((0.5 * sleep_factor), 2)).ToString(), //Load Settings "vizmap load file file=\"" + styles_path + "\"", "command sleep duration=" + (1.0 + Math.Round((1.0 * sleep_factor), 2)).ToString(), Lollipop.node_positioning.ToList().IndexOf(node_position) == 0 ? "layout degree-circle" : "layout attribute-circle NodeAttribute=" + layout_header, "command sleep duration=" + (0.5 + Math.Round((0.5 * sleep_factor), 2)).ToString(), "view fit content", //Mash applying the style because it flakes out "command sleep duration=1", "vizmap apply styles=\"" + style_name + "\"", "command sleep duration=1", "vizmap apply styles=\"" + style_name + "\"", "command sleep duration=1", "vizmap apply styles=\"" + style_name + "\"", })); }
public DisplayQuantitativeValues(QuantitativeProteoformValues q, IGoAnalysis analysis) : base(q) { proteoform = q.proteoform; qval = q; this.analysis = analysis; }
public override void reestablishSignficance(IGoAnalysis analysis) { if (!Sweet.lollipop.useLocalFdrCutoff) { relativeDifferenceFDR = computeRelativeDifferenceFDR(avgSortedPermutationRelativeDifferences, sortedProteoformRelativeDifferences, Sweet.lollipop.satisfactoryProteoforms, flattenedPermutedRelativeDifferences, Sweet.lollipop.offsetTestStatistics); } else { Parallel.ForEach(Sweet.lollipop.satisfactoryProteoforms, eP => { eP.quant.TusherValues2.significant = eP.quant.TusherValues2.roughSignificanceFDR <= Sweet.lollipop.localFdrCutoff; }); } inducedOrRepressedProteins = Sweet.lollipop.getInducedOrRepressedProteins(Sweet.lollipop.satisfactoryProteoforms.Where(pf => pf.quant.TusherValues2.significant), GoAnalysis); }
public static string write_cytoscape_script(List <ProteoformFamily> families, List <ProteoformFamily> all_families, string folder_path, string file_prefix, string time_stamp, IGoAnalysis quantitative, bool quantitative_redBorder, bool quantitative_boldFace, string color_scheme, string edge_label, string node_label, string node_label_position, string node_position, int double_rounding, bool gene_centric_families, string prefered_gene_label) { return(write_script(families, all_families, folder_path, file_prefix, time_stamp, quantitative, quantitative_redBorder, quantitative_boldFace, color_scheme, edge_label, node_label, node_label_position, node_position, double_rounding, gene_centric_families, prefered_gene_label, false)); }
private static string write_script(List <ProteoformFamily> families, List <ProteoformFamily> all_families, string folder_path, string file_prefix, string time_stamp, IGoAnalysis quantitative, bool quantitative_redBorder, bool quantitative_boldFace, string color_scheme, string edge_label, string node_label, string node_label_position, string node_position, int double_rounding, bool gene_centric_families, string preferred_gene_label, bool scale_node_size) { //Check if valid folder if (folder_path == "" || !Directory.Exists(folder_path)) { return("Please choose a folder in which the families will be built, so you can load them into Cytoscape."); } if (families.Any(f => f.experimental_proteoforms.Count == 0)) { return("Error: there is a family with zero experimental proteoforms."); } string nodes_path = Path.Combine(folder_path, file_prefix + node_file_prefix + time_stamp + node_file_extension); string edges_path = Path.Combine(folder_path, file_prefix + edge_file_prefix + time_stamp + edge_file_extension); string styles_path = Path.Combine(folder_path, file_prefix + style_file_prefix + time_stamp + style_file_extension); string script_path = Path.Combine(folder_path, file_prefix + script_file_prefix + time_stamp + script_file_extension); string style_name = "ProteoformFamilies" + time_stamp; IEnumerable <TheoreticalProteoform> theoreticals = families.SelectMany(f => f.theoretical_proteoforms); //Dictionary<string, GeneName> gene_dict = new Dictionary<string, GeneName>(); //if (gene_centric_families) // foreach (TheoreticalProteoform t in theoreticals) // { // string preferred = t.gene_name.get_prefered_name(prefered_gene_label); // if (gene_dict.ContainsKey(preferred)) gene_dict[preferred].merge(t.gene_name); // else gene_dict.Add(preferred, t.gene_name); // } string script = get_script(families.Sum(f => f.proteoforms.Count() + f.relations.Count), quantitative, node_position, edges_path, nodes_path, styles_path, style_name); string node_table = get_cytoscape_nodes_tsv(families, quantitative, color_scheme, node_label, node_label_position, node_position, double_rounding, theoreticals, gene_centric_families, preferred_gene_label); string edge_table = get_cytoscape_edges_tsv(families, edge_label, node_label, double_rounding, theoreticals, gene_centric_families, preferred_gene_label); File.WriteAllText(edges_path, edge_table); File.WriteAllText(nodes_path, node_table); File.WriteAllText(script_path, script); write_styles(scale_node_size ? families : all_families, styles_path, style_name, time_stamp, edge_label, node_label, node_label_position, color_scheme, quantitative, quantitative_redBorder, quantitative_boldFace); string selected_family_string = "Finished building selected famil"; selected_family_string += families.Count == 1 ? "y :" : "ies :#"; selected_family_string += (families.Count <= 3) ? string.Join(", #", families.Select(f => f.family_id)) : string.Join(", #", families.Select(f => f.family_id).ToList().Take(3)) + ", etc."; return(selected_family_string + ".\n\nPlease load them into Cytoscape 3.0 or later using \"Tools\" -> \"Execute Command File\" and choosing the script_[TIMESTAMP].txt file in your specified directory."); }
public static string write_cytoscape_script(object[] stuff, List <ProteoformFamily> all_families, string folder_path, string file_prefix, string time_stamp, IGoAnalysis quantitative, bool quantitative_redBorder, bool quantitative_boldFace, string color_scheme, string edge_label, string node_label, string node_label_position, string node_position, int double_rounding, bool gene_centric_families, string prefered_gene_label, bool scale_node_size) { List <ProteoformFamily> families = stuff.OfType <ProteoformFamily>().ToList(); if (stuff.Length <= 0) { return("No objects were selected"); } if (families.Count <= 0 && typeof(TheoreticalProteoform).IsAssignableFrom(stuff[0].GetType())) { families = get_families(stuff.OfType <TheoreticalProteoform>(), all_families).Distinct().ToList(); } if (families.Count <= 0 && typeof(GoTerm) == stuff[0].GetType()) { families = get_families(stuff.OfType <GoTerm>(), all_families).Distinct().ToList(); } if (families.Count <= 0 && typeof(GoTermNumber) == stuff[0].GetType()) { families = get_families(stuff.OfType <GoTermNumber>(), all_families).Distinct().ToList(); } if (families.Count <= 0 && typeof(QuantitativeProteoformValues).IsAssignableFrom(stuff[0].GetType())) { families = get_families(stuff.OfType <QuantitativeProteoformValues>(), all_families).Distinct().ToList(); } if (families.Count <= 0) { return("Selected objects were not recognized."); } return(write_script(families, all_families, folder_path, file_prefix, time_stamp, quantitative, quantitative_redBorder, quantitative_boldFace, color_scheme, edge_label, node_label, node_label_position, node_position, double_rounding, gene_centric_families, prefered_gene_label, scale_node_size)); }
public static void write_styles(List <ProteoformFamily> all_families, string styles_path, string style_name, string time_stamp, string edge_label, string node_label, string node_label_position, string color_scheme, IGoAnalysis quantitative, bool quantitative_redBorder, bool quantitative_boldFace) { XmlWriterSettings xmlWriterSettings = new XmlWriterSettings() { Indent = true, IndentChars = " " }; using (XmlWriter writer = XmlWriter.Create(styles_path, xmlWriterSettings)) { writer.WriteStartDocument(); writer.WriteStartElement("vizmap"); writer.WriteAttributeString("documentVersion", "3.0"); writer.WriteAttributeString("id", time_stamp); writer.WriteStartElement("visualStyle"); writer.WriteAttributeString("name", style_name); //NETWORK PROPERTIES writer.WriteStartElement("network"); IEnumerable <KeyValuePair <string, string> > default_network_styles = default_styles.Where(n => n.Key.StartsWith("NETWORK")); foreach (KeyValuePair <string, string> style in default_network_styles) { writer.WriteStartElement("visualProperty"); writer.WriteAttributeString("name", style.Key); writer.WriteAttributeString("default", style.Value); writer.WriteEndElement(); } writer.WriteEndElement(); //NODE PROPERTIES double max_total_intensity = all_families.SelectMany(f => f.experimental_proteoforms.Where(e => !e.topdown_id)).Count() > 0 ? quantitative != null ? (double)all_families.SelectMany(f => f.experimental_proteoforms).Max(p => p.quant.intensitySum) : all_families.SelectMany(f => f.experimental_proteoforms).Max(p => p.agg_intensity) : 1e6; writer.WriteStartElement("node"); writer.WriteStartElement("dependency"); writer.WriteAttributeString("name", "nodeCustomGraphicsSizeSync"); writer.WriteAttributeString("value", "true"); writer.WriteEndElement(); writer.WriteStartElement("dependency"); writer.WriteAttributeString("name", "nodeSizeLocked"); writer.WriteAttributeString("value", "true"); writer.WriteEndElement(); IEnumerable <KeyValuePair <string, string> > default_node_styles = default_styles.Where(n => n.Key.StartsWith("NODE") || n.Key.StartsWith("COMPOUND_NODE")); foreach (KeyValuePair <string, string> style in default_node_styles) { writer.WriteStartElement("visualProperty"); writer.WriteAttributeString("name", style.Key); //Defaults if (style.Key == "NODE_LABEL_POSITION") { if (node_label_position == node_label_positions[1]) { writer.WriteAttributeString("default", "N,S,c,0.00,0.00"); } else if (node_label_position == node_label_positions[2]) { writer.WriteAttributeString("default", "S,N,c,0.00,0.00"); } writer.WriteEndElement(); continue; } else { writer.WriteAttributeString("default", style.Value); } //Discrete and continuous mapping if (style.Key == "NODE_FILL_COLOR") { write_discreteMapping(writer, "string", proteoform_type_header, new List <Tuple <string, string> >() { new Tuple <string, string>(quantitative != null ? "#FFFFFF" : color_schemes[color_scheme][0], experimental_label), new Tuple <string, string>(not_quantified, experimental_notQuantified_label), new Tuple <string, string>(color_schemes[color_scheme][1], modified_theoretical_label), new Tuple <string, string>(color_schemes[color_scheme][2], unmodified_theoretical_label), new Tuple <string, string>(color_schemes[color_scheme][6], td_label), new Tuple <string, string>(color_schemes[color_scheme][4], gene_name_label) //new Tuple<string, string>(color_schemes[color_scheme][4], transcript_name_label) }); } if (style.Key == "NODE_SHAPE") { write_discreteMapping(writer, "string", proteoform_type_header, new List <Tuple <string, string> >() { new Tuple <string, string>("ELLIPSE", experimental_label), new Tuple <string, string>("ELLIPSE", experimental_notQuantified_label), new Tuple <string, string>("ELLIPSE", modified_theoretical_label), new Tuple <string, string>("ELLIPSE", unmodified_theoretical_label), new Tuple <string, string>("RECTANGLE", gene_name_label) //new Tuple<string, string>("DIAMOND", transcript_name_label) }); } if (style.Key == "NODE_LABEL_FONT_FACE") { write_discreteMapping(writer, "string", proteoform_type_header, new List <Tuple <string, string> >() { new Tuple <string, string>("Arial Italic,plain,14", gene_name_label), new Tuple <string, string>("Arial,plain,14", modified_theoretical_label), new Tuple <string, string>("Arial,plain,14", unmodified_theoretical_label), new Tuple <string, string>("Arial,plain,14", experimental_label), new Tuple <string, string>("Arial,plain,14", experimental_notQuantified_label) }); } if (style.Key == "NODE_LABEL_COLOR") { write_passthrough(writer, "string", "shared name"); } if (style.Key == "NODE_LABEL") { write_passthrough(writer, "string", "name"); } if (style.Key == "NODE_SIZE") { write_continuousMapping(writer, "float", size_header, new List <Tuple <string, string, string, string> >() { new Tuple <string, string, string, string>("1.0", "20.0", "20.0", "1.0"), new Tuple <string, string, string, string>("300.0", "1.0", "300.0", max_total_intensity.ToString()) //max node size should be set to the total intensity of the proteoform }); } if (style.Key == "NODE_CUSTOMGRAPHICS_1" && quantitative != null) { write_passthrough(writer, "string", piechart_header); } if (style.Key == "NODE_BORDER_WIDTH" && quantitative != null && quantitative_redBorder) { write_discreteMapping(writer, "boolean", significant_header, new List <Tuple <string, string> >() { new Tuple <string, string>("7.0", "True") }); } if (style.Key == "NODE_BORDER_PAINT" && quantitative != null && quantitative_redBorder) { write_discreteMapping(writer, "boolean", significant_header, new List <Tuple <string, string> >() { new Tuple <string, string>("#FFFFFF", "False"), new Tuple <string, string>(color_schemes[color_scheme][5], "True") }); } if (style.Key == "NODE_BORDER_TRANSPARENCY" && quantitative != null && quantitative_redBorder) { write_discreteMapping(writer, "boolean", significant_header, new List <Tuple <string, string> >() { new Tuple <string, string>("255", "True"), }); } if (style.Key == "NODE_LABEL_FONT_FACE" && quantitative != null && quantitative_boldFace) { write_discreteMapping(writer, "boolean", significant_header, new List <Tuple <string, string> >() { new Tuple <string, string>("Dialog.bold,plain,14", "True"), }); } if (style.Key == "NODE_TOOLTIP") { write_passthrough(writer, "string", tooltip_header); } writer.WriteEndElement(); } writer.WriteEndElement(); //EDGE PROPERTIES writer.WriteStartElement("edge"); writer.WriteStartElement("dependency"); writer.WriteAttributeString("name", "arrowColorMatchesEdge"); writer.WriteAttributeString("value", "false"); writer.WriteEndElement(); IEnumerable <KeyValuePair <string, string> > default_edge_styles = default_styles.Where(n => n.Key.StartsWith("EDGE")); foreach (KeyValuePair <string, string> style in default_edge_styles) { writer.WriteStartElement("visualProperty"); writer.WriteAttributeString("name", style.Key); writer.WriteAttributeString("default", style.Value); if (style.Key == "EDGE_LABEL" && edge_label == Lollipop.edge_labels[0]) { write_passthrough(writer, "string", delta_mass_header); } if (style.Key == "EDGE_LABEL" && edge_label == Lollipop.edge_labels[1]) { write_passthrough(writer, "string", edge_ptm_header); } writer.WriteEndElement(); } writer.WriteEndElement(); //OTHER PROPERTIES // none, currently writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); } }
public static string get_cytoscape_nodes_tsv(List <ProteoformFamily> families, IGoAnalysis quantitative, string color_scheme, string node_label, string node_label_position, string node_position, int double_rounding, IEnumerable <TheoreticalProteoform> theoreticals, bool gene_centric_families, string preferred_gene_label) { DataTable node_table = new DataTable(); node_table.Columns.Add("accession", typeof(string)); node_table.Columns.Add(proteoform_type_header, typeof(string)); node_table.Columns.Add(size_header, typeof(double)); node_table.Columns.Add(tooltip_header, typeof(string)); node_table.Columns.Add(layout_header, typeof(int)); if (quantitative != null) { node_table.Columns.Add(Sweet.lollipop.numerator_condition, typeof(string)); node_table.Columns.Add(Sweet.lollipop.denominator_condition, typeof(string)); node_table.Columns.Add(significant_header, typeof(string)); node_table.Columns.Add(piechart_header, typeof(string)); } //Choose the layout order IEnumerable <Proteoform> layout_order; switch (Lollipop.node_positioning.ToList().IndexOf(node_position)) { case 0: //arbitrary circle case 2: //mass circle default: layout_order = families.SelectMany(f => f.experimental_proteoforms).OfType <Proteoform>().Concat(theoreticals).OrderBy(p => p.modified_mass); break; case 1: //mass-based spiral layout_order = theoreticals.OrderByDescending(p => p.modified_mass).OfType <Proteoform>().Concat(families.SelectMany(f => f.experimental_proteoforms).OfType <Proteoform>().OrderBy(p => p.modified_mass)); break; } int layout_rank = 1; string node_rows = ""; foreach (Proteoform p in layout_order.ToList()) { if (p as TheoreticalProteoform != null) { string node_type = String.Equals(p.ptm_set.ptm_description, "unmodified", StringComparison.CurrentCultureIgnoreCase) ? unmodified_theoretical_label : modified_theoretical_label; node_table.Rows.Add(get_proteoform_shared_name(p, node_label, double_rounding), node_type, mock_intensity, "", layout_rank); } if (p as ExperimentalProteoform != null) { ExperimentalProteoform ep = p as ExperimentalProteoform; string node_type = quantitative != null && ep.quant.intensitySum == 0 ? experimental_notQuantified_label : quantitative == null && ep.topdown_id ? td_label : experimental_label; string total_intensity = quantitative != null ? ep.quant.intensitySum == 0 ? mock_intensity : ((double)ep.quant.intensitySum).ToString() : ep.agg_intensity == 0 ? mock_intensity : ep.agg_intensity.ToString(); //Names and size node_rows += string.Join("\t", new List <string> { get_proteoform_shared_name(p, node_label, double_rounding), node_type, total_intensity }); //Set tooltip information string tooltip = string.Join("; ", new string[] { "Accession = " + p.accession.ToString(), "Aggregated Mass = " + ep.agg_mass.ToString(), "Aggregated Retention Time = " + ep.agg_rt.ToString(), "Total Intensity = " + total_intensity.ToString(), "Aggregated Component Count = " + (ep.topdown_id ? (ep as TopDownProteoform).topdown_hits.Count.ToString() : ep.aggregated.Count.ToString()), Sweet.lollipop.neucode_labeled ? "; Lysine Count = " + p.lysine_count : "", "Abundant Component for Manual Validation of Identification: " + ep.manual_validation_id, "Abundant Component for Manual Validation of Identification Validation: " + ep.manual_validation_verification }); if (quantitative != null && ep.quant.intensitySum > 0) { tooltip += "\\n\\nQuantitation Results:" + string.Join("; ", new string[] { "Q-Value = " + (quantitative as TusherAnalysis1 != null ? ep.quant.TusherValues1.roughSignificanceFDR.ToString() : quantitative as TusherAnalysis2 != null ? ep.quant.TusherValues2.roughSignificanceFDR.ToString() : ""), "Log2FC = " + (quantitative as Log2FoldChangeAnalysis != null ? ep.quant.Log2FoldChangeValues.logfold2change.ToString() : ep.quant.tusherlogFoldChange.ToString()), "Significant = " + (quantitative as TusherAnalysis1 != null ? ep.quant.TusherValues1.significant.ToString() : quantitative as TusherAnalysis2 != null ? ep.quant.TusherValues2.significant.ToString() : quantitative as Log2FoldChangeAnalysis != null ? ep.quant.Log2FoldChangeValues.significant.ToString() : ""), Sweet.lollipop.numerator_condition + " Quantitative Component Count = " + ep.lt_quant_components.Count.ToString(), Sweet.lollipop.denominator_condition + " Quantitative Component Count = " + ep.hv_quant_components.Count.ToString(), "Abundant Component for Manual Validation of Quantification: " + ep.manual_validation_quant }); } if (quantitative as TusherAnalysis1 != null && ep.quant.intensitySum != 0) { node_table.Rows.Add(get_proteoform_shared_name(p, node_label, double_rounding), node_type, total_intensity, tooltip, layout_rank, ((double)ep.quant.TusherValues1.numeratorIntensitySum).ToString(), ((double)ep.quant.TusherValues1.denominatorIntensitySum).ToString(), ep.quant.TusherValues1.significant.ToString(), get_piechart_string(color_scheme)); } else if (quantitative as TusherAnalysis2 != null && ep.quant.intensitySum != 0) { node_table.Rows.Add(get_proteoform_shared_name(p, node_label, double_rounding), node_type, total_intensity, tooltip, layout_rank, ((double)ep.quant.TusherValues2.numeratorIntensitySum).ToString(), ((double)ep.quant.TusherValues2.denominatorIntensitySum).ToString(), ep.quant.TusherValues2.significant.ToString(), get_piechart_string(color_scheme)); } else if (quantitative as Log2FoldChangeAnalysis != null && ep.quant.intensitySum != 0) { node_table.Rows.Add(get_proteoform_shared_name(p, node_label, double_rounding), node_type, total_intensity, tooltip, layout_rank, ep.quant.Log2FoldChangeValues.allIntensities.Where(kv => kv.Value.condition == Sweet.lollipop.induced_condition).Sum(kv => kv.Value.intensity_sum).ToString(), ep.quant.Log2FoldChangeValues.allIntensities.Where(kv => kv.Value.condition != Sweet.lollipop.induced_condition).Sum(kv => kv.Value.intensity_sum).ToString(), ep.quant.Log2FoldChangeValues.significant.ToString(), get_piechart_string(color_scheme)); } else if (quantitative != null) { node_table.Rows.Add(get_proteoform_shared_name(p, node_label, double_rounding), node_type, total_intensity, tooltip, layout_rank, "", "", "", ""); } else { node_table.Rows.Add(get_proteoform_shared_name(p, node_label, double_rounding), node_type, total_intensity, tooltip, layout_rank); } } layout_rank++; } if (gene_centric_families) { foreach (string gene_name in theoreticals.Select(t => t.gene_name.get_prefered_name(preferred_gene_label)).ToList(). Concat(families.SelectMany(f => f.experimental_proteoforms.Where(pf => pf.topdown_id)). Select(t => t.gene_name.get_prefered_name(preferred_gene_label))).Distinct()) { if (gene_name != null && quantitative != null) { node_table.Rows.Add(gene_name, gene_name_label, mock_intensity, "Other Gene Names: ", 0, "", "", "", ""); } else if (gene_name != null) { node_table.Rows.Add(gene_name, gene_name_label, mock_intensity, "Other Gene Names: ", 0); } } } return(get_table_string(node_table)); }
public abstract void reestablishSignficance(IGoAnalysis analysis);