protected bool Equals(Metabolite obj) { if (obj.HMDB != null && this.HMDB != null) { return(this.HMDB.Equals(obj.HMDB)); } return(false); }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Invalid number of arguments."); Console.ReadLine(); } else { List <Metabolite> metabolites = new List <Metabolite>(); string path = Environment.CurrentDirectory; //Read in metabolite database to match against using (StreamReader reader = new StreamReader(@"MetaboliteOntology.txt")) { var map = ColumnMap(reader.ReadLine()); string line; while ((line = reader.ReadLine()) != null) { var m = new Metabolite(); var split = line.Split('\t', '\n'); if (map.ContainsKey(HMDB)) { m.HMDB = split[map[HMDB]]; } if (map.ContainsKey(Pubchem)) { m.Pubchem = split[map[Pubchem]]; } if (map.ContainsKey(CAS)) { m.CAS = split[map[CAS]]; } if (map.ContainsKey(KEGG)) { m.KEGG = split[map[KEGG]]; } if (map.ContainsKey(ChEBI)) { m.ChEBI = split[map[ChEBI]]; } if (map.ContainsKey(InChI)) { m.InChI = split[map[InChI]]; } if (map.ContainsKey(InChIKey)) { m.InChIKey = split[map[InChIKey]]; } if (map.ContainsKey(CommonName)) { m.CommonName = split[map[CommonName]]; } if (map.ContainsKey(SYNONYMS)) { m.Synonyms = split[map[SYNONYMS]]; } if (map.ContainsKey(SuperClass)) { m.SuperClass = split[map[SuperClass]]; } if (map.ContainsKey(Class)) { m.Class = split[map[Class]]; } if (map.ContainsKey(DirectParent)) { m.DirectParent = split[map[DirectParent]]; } if (map.ContainsKey(Pathways)) { m.Pathways = split[map[Pathways]]; } metabolites.Add(m); } reader.Close(); } //Read metabolite names to search for string queryPath = args[0]; using (StreamReader reader = new StreamReader(queryPath)) { StreamWriter writer = new StreamWriter(Path.GetFullPath(queryPath).Replace(".txt", "_MetFound.txt")); writer.WriteLine("Query\tHMDB\tPubChem CID\tCAS\tKEGG\tChEBI\tInChI\tInChIKey\tCommon Name\tSynonyms\tSuper Class\tClass\tDirect Parent\tPathways"); string line; while ((line = reader.ReadLine()) != null) { var m = line.Split('\t', '\n')[0]; /* * var matches = new List<Metabolite>(); * foreach (var metabolite in metabolites) * { * foreach (var syn in metabolite.Synonyms) * { * if (syn.ToUpper().Contains(m.ToUpper())) * { * matches.Add(metabolite); * } * } * }*/ //var matches = (from metabolite in metabolites from syn in metabolite.Synonyms where syn.ToUpper().Contains(m.ToUpper()) select metabolite).ToList(); string mstring = m.ToUpper().Replace(" ", ""); var matches = (from metabolite in metabolites from syn in metabolite.AllNames where syn.ToUpper().Replace(" ", "").Equals(m.ToUpper().Replace(" ", "")) select metabolite).Distinct().ToList(); if (matches.Any()) { foreach (var match in matches) { string synString = match.Synonyms.Aggregate("", (current, syn) => current + (syn + ", ")); writer.WriteLine( String.Format( "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}\t{12}\t{13}", m, match.HMDB, match.Pubchem, match.CAS, match.KEGG, match.ChEBI, match.InChI, match.InChIKey, match.CommonName, match.Synonyms, match.SuperClass, match.Class, match.DirectParent, match.Pathways)); } } else { writer.WriteLine(String.Format("{0}\t{1}\t{1}\t{1}\t{1}\t{1}\t{1}\t{1}\t{1}\t{1}\t{1}\t{1}\t{1}\t{1}", m, "NA")); } } reader.Close(); writer.Close(); } } }