public static string[,] MotifSpreadsheet(List <MotifHitSpreadsheetRecord> motifHitSpreadsheetRecordList) { if (motifHitSpreadsheetRecordList == null) { throw new ArgumentNullException(nameof(motifHitSpreadsheetRecordList)); } var result = new List <string[]> { Header().ToStrings() }; foreach (var record in motifHitSpreadsheetRecordList .OrderByDescending(a => ProteinDataBankFileOperations.NullableTryParseInt32(string.IsNullOrWhiteSpace(a.TotalDatabaseHitsPdb) ? "0" : a.TotalDatabaseHitsPdb) + ProteinDataBankFileOperations.NullableTryParseInt32(string.IsNullOrWhiteSpace(a.TotalDatabaseHitsUniProtKbSwissProt) ? "0" : a.TotalDatabaseHitsUniProtKbSwissProt) + ProteinDataBankFileOperations.NullableTryParseInt32(string.IsNullOrWhiteSpace(a.TotalDatabaseHitsUniProtKbTrEmbl) ? "0" : a.TotalDatabaseHitsUniProtKbTrEmbl)) .ThenByDescending(a => ProteinDataBankFileOperations.NullableTryParseInt32(string.IsNullOrWhiteSpace(a.TotalDatabaseSequencesPdb) ? "0" : a.TotalDatabaseSequencesPdb) + ProteinDataBankFileOperations.NullableTryParseInt32(string.IsNullOrWhiteSpace(a.TotalDatabaseSequencesUniProtKbSwissProt) ? "0" : a.TotalDatabaseSequencesUniProtKbSwissProt) + ProteinDataBankFileOperations.NullableTryParseInt32(string.IsNullOrWhiteSpace(a.TotalDatabaseSequencesUniProtKbTrEmbl) ? "0" : a.TotalDatabaseSequencesUniProtKbTrEmbl)) .ThenByDescending(a => ProteinDataBankFileOperations.NullableTryParseInt32(string.IsNullOrWhiteSpace(a.TotalTimesSuggestedFwd) ? "0" : a.TotalTimesSuggestedFwd) + ProteinDataBankFileOperations.NullableTryParseInt32(string.IsNullOrWhiteSpace(a.TotalTimesSuggestedRev) ? "0" : a.TotalTimesSuggestedRev) + ProteinDataBankFileOperations.NullableTryParseInt32(string.IsNullOrWhiteSpace(a.TotalTimesSuggestedMix) ? "0" : a.TotalTimesSuggestedMix))) { result.Add(record.ToStrings()); } return(ConvertTypes.StringJagged2DArrayTo2DArray(result.ToArray())); }
/// <summary> /// Texture の export index を得る /// </summary> /// <param name="src"></param> /// <param name="textureType"></param> /// <returns></returns> public int GetTextureIndex(Texture src, ConvertTypes textureType) { if (src == null) { return(-1); } return(m_exportMap[new ExportKey(src, textureType)]); }
public ExportKey(Texture src, ConvertTypes type) { if (src == null) { throw new ArgumentNullException(); } Src = src; TextureType = type; }
static void EnumConversion() { ConvertTypes lab2 = new ConvertTypes(); lab2.ConversionFeet(4.5, ConvertTypes.FeetConvert.Centimeters); lab2.ConversionFeet(15.3, ConvertTypes.FeetConvert.Inches); lab2.ConversionFeet(8.33, ConvertTypes.FeetConvert.Yards); lab2.ConversionFeet(2.21, ConvertTypes.FeetConvert.Meters); lab2.ConversionFeet(11.1, ConvertTypes.FeetConvert.Millimeters); }
/*public static void OutputUpgmaLog(string outputFilename, List<UpgmaNode> nodeList, List<decimal[,]> distanceMatrixCache, List<List<List<int>>> distanceMatrixMapCache) * { * var sb = new StringBuilder(); * * for (int index = 0; index < nodeList.Count; index++) * { * var node = nodeList[index]; * * var nodeId = string.Join("_", node.VectorIndexes); * var childNodeId = node.ChildNode != null ? string.Join("_", node.ChildNode.VectorIndexes) : "null"; * var parentNodeIdA = node.ParentNodeA != null ? string.Join("_", node.ParentNodeA.VectorIndexes) : "null"; * var parentNodeIdB = node.ParentNodeB != null ? string.Join("_", node.ParentNodeB.VectorIndexes) : "null"; * * sb.AppendLine("Node #" + index + ": " + nodeId); * sb.AppendLine("Is leaf node: " + node.IsLeafNode()); * sb.AppendLine("Is root node: " + node.IsRootNode()); * sb.AppendLine("Is branch node: " + node.IsBranchNode()); * sb.AppendLine("Is unclustered node: " + node.IsNodeUnclustered()); * sb.AppendLine("Loop iteration: " + node.DistanceMatrixIterationNumber); * sb.AppendLine("Child node: " + childNodeId + ". Distance: " + node.DistanceChildNode); * sb.AppendLine("Parent node 1: " + parentNodeIdA + ". Distance: " + node.DistanceParentNodeA); * sb.AppendLine("Parent node 2: " + parentNodeIdB + ". Distance: " + node.DistanceParentNodeB); * sb.AppendLine(); * } * * for (int index = 0; index < distanceMatrixCache.Count; index++) * { * var distanceMatrix = distanceMatrixCache[index]; * * var distanceMatrixMap = distanceMatrixMapCache[index]; * * sb.AppendLine("Distance Matrix Iteration #" + index + ". " + distanceMatrix.GetLength(0) + " x " + distanceMatrix.GetLength(1) + " matrix:"); * * * sb.AppendLine(); * * for (var matrixIndex = 0; matrixIndex < distanceMatrixMap.Count; matrixIndex++) * { * var matrixIndexIdList = distanceMatrixMap[matrixIndex]; * * sb.AppendLine("Matrix index #" + matrixIndex + ": " + string.Join(", ", matrixIndexIdList)); * } * * sb.AppendLine(); * * var width = distanceMatrix.Cast<decimal>().Select(a => a.ToString().Length).Max() + 1; * * if (distanceMatrix.GetLength(0).ToString().Length + 1 > width) width = distanceMatrix.GetLength(0).ToString().Length + 1; * if (distanceMatrix.GetLength(1).ToString().Length + 1 > width) width = distanceMatrix.GetLength(1).ToString().Length + 1; * * sb.Append("".PadLeft(width)); * for (var x = 0; x < distanceMatrix.GetLength(0); x++) * { * sb.Append(x.ToString().PadLeft(width)); * } * * sb.AppendLine(); * * for (var y = 0; y < distanceMatrix.GetLength(1); y++) * { * sb.Append(y.ToString().PadLeft(width)); * * for (var x = 0; x < distanceMatrix.GetLength(0); x++) * { * string s = distanceMatrix[x, y].ToString().PadLeft(width); * sb.Append(s); * } * * sb.AppendLine(); * } * * sb.AppendLine(); * } * * File.WriteAllText(outputFilename, sb.ToString()); * }*/ /*public static void CacheUpgmaMatrixes(decimal[,] distanceMatrix, List<decimal[,]> distanceMatrixCache, List<List<int>> distanceMatrixMap, List<List<List<int>>> distanceMatrixMapCache) * { * // Copy distance matrix * var distanceMatrixCacheCopy = new decimal[distanceMatrix.GetLength(0), distanceMatrix.GetLength(1)]; * Array.Copy(distanceMatrix, distanceMatrixCacheCopy, distanceMatrix.Length); * * // Cache distance matrix * distanceMatrixCache.Add(distanceMatrixCacheCopy); * * * // Copy matrix map * var distanceMatrixMapCacheCopy = new List<List<int>>(); * for (var i = 0; i < distanceMatrixMap.Count; i++) * { * distanceMatrixMapCacheCopy.Add(new List<int>()); * distanceMatrixMapCacheCopy[i].AddRange(distanceMatrixMap[i].Select(a => a).ToList()); * } * * // Cache matrix map * distanceMatrixMapCache.Add(distanceMatrixMapCacheCopy); * }*/ public static void Upgma(decimal[,] distanceMatrix, List <string> vectorNames, int minimumOutputTreeLeafs, out List <List <UpgmaNode> > nodeListList, out List <List <string> > treeListList, out List <string> finalTreeLeafOrderList, bool newickTreeEveryIteration = false, ProgressActionSet progressActionSet = null) { if (distanceMatrix == null || distanceMatrix.GetLength(0) == 0 || distanceMatrix.GetLength(1) == 0) { throw new ArgumentOutOfRangeException(nameof(distanceMatrix), "distance matrix is null or empty"); } Upgma(ConvertTypes.Decimal2DArrayToDecimalListList(distanceMatrix), vectorNames, minimumOutputTreeLeafs, out nodeListList, out treeListList, out finalTreeLeafOrderList, newickTreeEveryIteration, progressActionSet); }
static void Main(string[] args) { // Execute all the classes containing type exploration code Strings.Execute(); DateTimes.Execute(); ParseFormat.Execute(); ConvertTypes.Execute(); Numbers.Execute(); Enums.Execute(); Unicode.Execute(); OS.Execute(); }
public static string[] SaveSpreadsheet(string saveFilename, string[] sheetNames, List <SpreadsheetCell[, ]> spreadsheet, ProgressActionSet progressActionSet = null, bool tsvFormat = false, bool xlsxFormat = true, FileExistsHandler.FileExistsOptions fileExistsOptions = FileExistsHandler.FileExistsOptions.AppendNumberToFilename) { var convertedSpreadsheet = new List <List <SpreadsheetCell[]> >(); foreach (var sheet in spreadsheet) { var convertedSheet = ConvertTypes.SpreadsheetCell2DArrayToJaggedArray(sheet).ToList(); convertedSpreadsheet.Add(convertedSheet); } return(SaveSpreadsheet(saveFilename, sheetNames, convertedSpreadsheet, progressActionSet, tsvFormat, xlsxFormat, fileExistsOptions)); }
public static string[,] MotifSpreadsheet(List <ProproteinInterfaceSpreadsheetRecord> proproteinInterfaceSpreadsheetRecordList) { if (proproteinInterfaceSpreadsheetRecordList == null) { throw new ArgumentNullException(nameof(proproteinInterfaceSpreadsheetRecordList)); } var result = new List <string[]>(); result.Add(Header().ToStrings()); result.AddRange(proproteinInterfaceSpreadsheetRecordList.OrderByDescending(a => ProteinDataBankFileOperations.NullableTryParseInt32(a.TotalFound)).Select(record => record.ToStrings())); return(ConvertTypes.StringJagged2DArrayTo2DArray(result.ToArray())); }
public static string[,] CountPatternsSpreadsheet(string patternName, string[,] treeDataSheet, int columnIndex) { if (patternName == null) { throw new ArgumentNullException(nameof(patternName)); } if (treeDataSheet == null) { throw new ArgumentNullException(nameof(treeDataSheet)); } var countedPatterns = CountPatterns(treeDataSheet, columnIndex); var spreadsheet = SpreadsheetStrings(countedPatterns, patternName); return(ConvertTypes.StringJagged2DArrayTo2DArray(spreadsheet)); }
public static string[,] Spreadsheet(List <AminoAcidDistributionSpreadsheetRecord> aminoAcidDistributionSpreadsheetRecordList) { if (aminoAcidDistributionSpreadsheetRecordList == null) { throw new ArgumentNullException(nameof(aminoAcidDistributionSpreadsheetRecordList)); } // for each short/long vector pattern, show the sd aa for all proteinInterfaces in the pattern, all proteins in the pattern // also show for entire set // // Num. samples A B C D E F ... Total AAs // Uniprot - whole database // All - whole protein // All - whole proteinInterface // All - proteinInterface interactions // pattern 1010101 - whole protein // pattern 1010101 - whole proteinInterfaces // pattern 1010101 - proteinInterface interactions // // // % property for each protein, chain, proteinInterface // // // var header = Header(); //var totalRows = aminoAcidDistributionSpreadsheetRecordList.Count + 1; //var totalColumns = header.Length; var result = new List <string[]>(); result.Add(header); result.Add(UniProtKb().ToStrings()); //var overallDistribution = OverallDistributionRecords(); //var patternDistribution = PatternDistributionSpreadsheetRecords(); // distribution formatting String.Format("{0:0.00}", dist) result.AddRange(aminoAcidDistributionSpreadsheetRecordList.Select(record => record.ToStrings())); return(ConvertTypes.StringJagged2DArrayTo2DArray(result.ToArray())); }
public void TestUpgmaLowestDistanceIndexes() { decimal[,] distanceMatrix1 = { { 0, 1, 2, 3, 4 }, { 0, 1, 2, 3, 4 }, { 0, 1, 2, 3, 4 }, { 0, 1, 2, 3, 4 }, { 0, 1, 2, 3, 4 }, }; decimal[,] distanceMatrix2 = { { 10, 1, 2, 3, 4 }, { 10, 1, 2, 3, 4 }, { 10, 1, 2, 0, 4 }, { 10, 1, 2, 3, 4 }, { 10, 1, 2, 3, 4 }, }; decimal[,] distanceMatrix3 = { { 10, 1, 2, 3, 4 }, { 10, 1, 2, 3, 4 }, { 10, 1, 2, 3, 4 }, { 10, 1, 2, 3, 0 }, { 10, 1, 2, 0, 0 }, }; var result1 = UpgmaClustering.UpgmaLowestDistanceIndexes(ConvertTypes.Decimal2DArrayToDecimalListList(distanceMatrix1)); var result2 = UpgmaClustering.UpgmaLowestDistanceIndexes(ConvertTypes.Decimal2DArrayToDecimalListList(distanceMatrix2)); var result3 = UpgmaClustering.UpgmaLowestDistanceIndexes(ConvertTypes.Decimal2DArrayToDecimalListList(distanceMatrix3)); Assert.IsTrue(result1.X == 0 && result1.Y == 1); Assert.IsTrue(result2.X == 2 && result2.Y == 3); Assert.IsTrue(result3.X == 3 && result3.Y == 4); }
/// <summary> /// 半角全角変換 /// </summary> /// <param name="convertString">対象文字列</param> /// <param name="convertTypes">変換対象</param> /// <returns>変換後文字列</returns> public static string ToFull(this string convertString, ConvertTypes convertTypes) { if (convertTypes == ConvertTypes.All || convertTypes == ConvertTypes.Numeric) { for (int i = 0; i < HalfWidthNumeric.Length; i++) { convertString = convertString.Replace(HalfWidthNumeric[i], FullWidthNumeric[i]); } } if (convertTypes == ConvertTypes.All || convertTypes == ConvertTypes.Symbol) { for (int i = 0; i < HalfWidthSymbol.Length; i++) { convertString = convertString.Replace(HalfWidthSymbol[i], FullWidthSymbol[i]); } } if (convertTypes == ConvertTypes.All || convertTypes == ConvertTypes.Alphabet) { for (int i = 0; i < HalfWidthAlphabet.Length; i++) { convertString = convertString.Replace(HalfWidthAlphabet[i], FullWidthAlphabet[i]); } } if (convertTypes == ConvertTypes.All || convertTypes == ConvertTypes.Katakana) { for (int i = (HalfWidthKatakana.Length - 1); i >= 0; i--) { convertString = convertString.Replace(HalfWidthKatakana[i], FullWidthKatakana[i]); } } return(convertString); }
public static void PrintMatrix(List <List <decimal> > matrix) { PrintMatrix(ConvertTypes.ListDecimalListToDecimal2DArray(matrix)); }
public ConvertJob(ConvertTypes ct, string[] file, bool mergeScenarios) { ConvertType = ct; Files = Array.ConvertAll(file, path => new RfLogFile(path)); MergeScenarios = mergeScenarios; }
public void BeginProcessFiles(string[] files, bool mergeScenarios, ConvertTypes convertType) { Task.Factory.StartNew(() => _loadQueue.Add(new ConvertJob(convertType, files, mergeScenarios))); }
public static Table CreateSchema(CodeTypeDeclaration ctd, CodeCompileUnit cu, List <CodeMemberField> lFieldMembers) { Table t = new Table(); t.Name = Format.CamelCaseId(ctd.Name); t.Namespace = cu.Namespaces[0].Name; List <CodeMemberField> publicFields = lFieldMembers.Where(fm => fm.Attributes == MemberAttributes.Public).ToList(); foreach (CodeMemberField cmf in publicFields) { string fName = ConvertTypes.GetNameFromCodeMemberField(cmf); Components.Field f = new Components.Field(); //if (fName == "Metadata" && t.Name == "TGlobalElementWithMetadata") //{ } if (fName == "Id") { fName = t.Name + "Id"; f.Name = fName; f.IsPrimary = true; f.IsClustered = true; f.IdentitySpecification = new IdentitySpecification(); f.AllowNull = false; } else if (fName.ToUpper() == "ID") { if (t.Fields.Count(fi => fi.IsPrimary == true) == 0) { f.IsPrimary = true; f.IsClustered = true; f.IdentitySpecification = new IdentitySpecification(); f.AllowNull = false; } fName = Format.CamelCaseId(fName); } else if (fName.Length > 1 && fName.Substring(fName.Length - 2, 2).ToUpper() == "ID") { if (t.Fields.Count(fi => fi.IsPrimary == true) == 0) { f.IsPrimary = true; f.IsClustered = true; f.IdentitySpecification = new IdentitySpecification(); f.AllowNull = false; } fName = Format.CamelCaseId(fName); } else { f.Name = fName; } Table tTemp = ConvertTypes.SQLToBase(t, f, cmf.Type, cmf, ctd); if (tTemp != null) { t = tTemp; //Catch un-named fields, code error only. Not possible to complie XSD with empty field names if (t.Fields.Count(ft => ft.Name == null) > 0) { } } } return(t); }
public static string[,] Spreadsheet(List <MotifProfileSpreadsheetRecord> motifProfileSpreadsheetRecordList) { if (motifProfileSpreadsheetRecordList == null) { throw new ArgumentNullException(nameof(motifProfileSpreadsheetRecordList)); } var result = new List <string[]>(); var totalAminoAcids = AminoAcidTotals.TotalAminoAcids(); var sheetHeader = new List <string>() { "Motif Name", "Motif Source", "Direction", "Total Found", //"Total Found In Heterodimers", //"Total Found In Homodimers", "Profile Position", }; sheetHeader.AddRange(AminoAcidConversions.AminoAcidCodeArray1L()); result.Add(sheetHeader.ToArray()); foreach (var record in motifProfileSpreadsheetRecordList.OrderByDescending(a => ProteinDataBankFileOperations.NullableTryParseInt32(a.TotalFound))) { result.Add(new string[] { }); var recordHeader = new List <string>() { record.MotifName, record.MotifSource, record.Direction, record.TotalFound, //record.TotalFoundInHeterodimers, //record.TotalFoundInHomodimers, "", }; recordHeader.AddRange(AminoAcidConversions.AminoAcidCodeArray1L()); result.Add(recordHeader.ToArray()); for (var positionIndex = 0; positionIndex < record.AminoAcidProfile.Length; positionIndex++) { var row = new string[sheetHeader.Count]; row[sheetHeader.IndexOf("Profile Position")] = "" + (positionIndex + 1); for (var aaIndex = 0; aaIndex < record.AminoAcidProfile[positionIndex].Length; aaIndex++) { row[aaIndex + sheetHeader.IndexOf("Profile Position") + 1] = $"{record.AminoAcidProfile[positionIndex][aaIndex]:0.00}"; } result.Add(row); } var rowAverage = new string[sheetHeader.Count]; rowAverage[sheetHeader.IndexOf("Profile Position")] = "Average"; for (var aaIndex = 0; aaIndex < record.AverageProfile.Length; aaIndex++) { rowAverage[aaIndex + sheetHeader.IndexOf("Profile Position") + 1] = $"{record.AverageProfile[aaIndex]:0.00}"; } result.Add(rowAverage); } return(ConvertTypes.StringJagged2DArrayTo2DArray(result.ToArray())); }
public static string[] SaveSpreadsheet(string saveFilename, string[] sheetNames, SpreadsheetCell[,] spreadsheet, ProgressActionSet progressActionSet = null, bool tsvFormat = false, bool xlsxFormat = true, FileExistsHandler.FileExistsOptions fileExistsOptions = FileExistsHandler.FileExistsOptions.AppendNumberToFilename) { var convertedSpreadsheet = ConvertTypes.SpreadsheetCell2DArrayToJaggedArray(spreadsheet); return(SaveSpreadsheet(saveFilename, sheetNames, convertedSpreadsheet.ToList(), progressActionSet, tsvFormat, xlsxFormat, fileExistsOptions)); }