public static void SeparateForwardAndReverse(string fastaFile) { try { FileStream fs; try { fs = new FileStream(fastaFile, FileMode.Open, FileAccess.Read, FileShare.Read); } catch (System.Exception) { fs = new FileStream(fastaFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); } vsCSVWriter wrForward = new vsCSVWriter(vsCSV.GetFolder(fastaFile) + vsCSV.GetFileName_NoExtension(fastaFile) + "_ForwardOnly.fasta"); vsCSVWriter wrReverse = new vsCSVWriter(vsCSV.GetFolder(fastaFile) + vsCSV.GetFileName_NoExtension(fastaFile) + "_ReverseOnly.fasta"); using (StreamReader sr = new StreamReader(fs)) { ProteinIdType idType = ProteinIdType.Unknown; string line; while ((line = sr.ReadLine()) != null) { if (line.StartsWith(">")) { if (line.StartsWith(">REVERSE_")) { idType = ProteinIdType.Reverse; } else { idType = ProteinIdType.Forward; } } switch (idType) { case ProteinIdType.Forward: wrForward.AddLine(line); break; case ProteinIdType.Reverse: wrReverse.AddLine(line); break; case ProteinIdType.Unknown: break; } } } fs.Close(); wrForward.WriteToFile(); wrReverse.WriteToFile(); } catch (System.Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } }
public static void ShuffleSequences(string fastaFile) { try { FileStream fs; try { fs = new FileStream(fastaFile, FileMode.Open, FileAccess.Read, FileShare.Read); } catch (System.Exception) { fs = new FileStream(fastaFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); } vsCSVWriter wrShuffled = new vsCSVWriter(vsCSV.GetFolder(fastaFile) + vsCSV.GetFileName_NoExtension(fastaFile) + "_Shuffled.fasta"); using (StreamReader sr = new StreamReader(fs)) { ProteinIdType idType = ProteinIdType.Unknown; string line; string aaSeq = ""; while ((line = sr.ReadLine()) != null) { if (line.StartsWith(">")) { if (!string.IsNullOrEmpty(aaSeq)) { wrShuffled.AddLine(Proteomics.Utilities.Tools.AminoAcidTools.Shuffle(aaSeq)); } wrShuffled.AddLine(line); aaSeq = ""; } else { aaSeq += line; } } if (!string.IsNullOrEmpty(aaSeq)) { wrShuffled.AddLine(Proteomics.Utilities.Tools.AminoAcidTools.Shuffle(aaSeq)); } } fs.Close(); wrShuffled.WriteToFile(); } catch (System.Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } }
public static void MergeSequences(string fastaFolder) { try { FileStream fsOut = new FileStream(fastaFolder + "merge3.fasta", FileMode.CreateNew); using (StreamWriter sw = new StreamWriter(fsOut)) { foreach (string fastaFile in Directory.EnumerateFiles(fastaFolder, "whole_genome.fasta")) { FileStream fs; try { fs = new FileStream(fastaFile, FileMode.Open, FileAccess.Read, FileShare.Read); } catch (System.Exception) { fs = new FileStream(fastaFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); } using (StreamReader sr = new StreamReader(fs)) { ProteinIdType idType = ProteinIdType.Unknown; string line; while ((line = sr.ReadLine()) != null) { if (!string.IsNullOrEmpty(line)) { sw.WriteLine(line); } } } fs.Close(); } } fsOut.Close(); } catch (System.Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } }