private void WriteOutputs(string fastaPath, string outputPath) { int chromosomeIndex = -1; using (FastaReader reader = new FastaReader(fastaPath)) using (FastaWriter writer = new FastaWriter(outputPath)) { GenericRead fastaEntry = new GenericRead(); while (reader.GetNextEntry(ref fastaEntry)) { chromosomeIndex++; StringBuilder baseBuilder = new StringBuilder(); BitArray nonUniqueFlags = ChromosomeNonUniqueFlags[chromosomeIndex]; for (int chromPos = 0; chromPos < fastaEntry.Bases.Length; chromPos++) { if (nonUniqueFlags[chromPos]) { baseBuilder.Append(char.ToLowerInvariant(fastaEntry.Bases[chromPos])); } else { baseBuilder.Append(char.ToUpperInvariant(fastaEntry.Bases[chromPos])); } } writer.WriteEntry(fastaEntry.Name, baseBuilder.ToString()); } } }
public void WriteFasta(string fasta_file, FastaWriter Writer) { bool MakeDecoy = false; if (Options.OutputType == DatabaseType.Target || Options.OutputType == DatabaseType.Concatenated) { MakeDecoy = false; } else if (Options.OutputType == DatabaseType.Decoy || Options.OutputType == DatabaseType.Concatenated) { MakeDecoy = true; } using (FastaReader reader = new FastaReader(fasta_file)) { foreach (Fasta fasta in reader.ReadNextFasta()) { Regex uniprotRegex = new Regex(@"(.+)\|(.+)\|(.+?)\s(.+?)\sOS=(.+?)(?:\sGN=(.+?))?(?:$|PE=(\d+)\sSV=(\d+))", RegexOptions.ExplicitCapture); Match UniprotMatch = uniprotRegex.Match(fasta.Description); string HeaderFile = "InvalidUniprotheaders.txt"; string headerFolder = Path.GetDirectoryName(Options.InputFiles[0]); if (Options.EnforceUniprot && !UniprotMatch.Success) { using (StreamWriter log = new StreamWriter(Path.Combine(headerFolder, HeaderFile), true)) { log.WriteLine("Invalid Header:"); log.WriteLine(); log.WriteLine(fasta.Description); log.WriteLine(); InvalidHeader(fasta); } } if (UniprotMatch.Success) { bool excludeMethionine = false; if (Options.ExcludeNTerminalMethionine && !Options.ExcludeNTerminalResidue) { excludeMethionine = true; } if (MakeDecoy) { Writer.Write(fasta.ToDecoy(Options.DecoyPrefix, Options.DecoyType, (excludeMethionine || Options.ExcludeNTerminalResidue), Options.ExcludeNTerminalMethionine)); } else { Writer.Write(fasta); } } } } }
public void CreateDatabase() { try { // Validate Options are kosher if (Options.InputFiles == null || Options.InputFiles.Count == 0) { throw new ArgumentNullException("Input Files"); } string ext = Path.GetExtension(Options.OutputFastaFile); if (string.IsNullOrEmpty(ext)) { ext = ".fasta"; } string output_filename = Path.GetFullPath(Options.OutputFastaFile); if (Options.DoNotAppendDatabaseType) { output_filename = output_filename + ext; if (Options.InputFiles.Contains(output_filename)) { throw new ArgumentException("Output file path cannot be the same as an input file."); } } else { switch (Options.OutputType) { case DatabaseType.Target: output_filename += "_TARGET" + ext; break; case DatabaseType.Decoy: output_filename += "_DECOY" + ext; break; case DatabaseType.Concatenated: default: output_filename += "_CONCAT" + ext; break; } } string logFilename = Path.GetFileNameWithoutExtension(Options.OutputFastaFile); string outputFolder = Path.GetDirectoryName(Options.OutputFastaFile); if (!Directory.Exists(outputFolder)) { outputFolder = Directory.GetCurrentDirectory(); } if (Options.GenerateLogFile) { switch (Options.OutputType) { case DatabaseType.Target: logFilename += "_TARGET.log"; break; case DatabaseType.Decoy: logFilename += "_DECOY.log"; break; case DatabaseType.Concatenated: default: logFilename += "_CONCAT.log"; break; } GenerateLog(outputFolder, logFilename); } string outputPath = Path.Combine(outputFolder, output_filename); if (Options.DoNotMergeFiles) { foreach (string fastaFile in Options.InputFiles) { using (FastaWriter writer = new FastaWriter(outputPath)) { WriteFasta(fastaFile, writer); } } } else { using (FastaWriter writer = new FastaWriter(outputPath)) { foreach (string fastaFile in Options.InputFiles) { WriteFasta(fastaFile, writer); } } } if (Options.BlastDatabase) { MakeBlastDatabase(outputFolder, output_filename, Path.GetFileNameWithoutExtension(output_filename)); } } catch (DirectoryNotFoundException) { } }