Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Linq;
  4.  
  5. namespace BioHelper
  6. {
  7.     class Program
  8.     {
  9.         static List<(string, string)> ReadFasta(string fileName)
  10.         {
  11.             var fileLines = File.ReadAllLines(fileName);
  12.             var output = new List<(string, string)>();
  13.             string curContent = "";
  14.             string curName = "";
  15.             foreach (var line in fileLines)
  16.             {
  17.                 if (line.Contains(">"))
  18.                 {
  19.                     if (curContent != "")
  20.                     {
  21.                         output.Add((curName, curContent));
  22.                     }
  23.                     curName = line;
  24.                     curContent = "";
  25.                 }
  26.                 else
  27.                 {
  28.                     curContent += line;
  29.                 }
  30.             }
  31.             return output;
  32.         }
  33.  
  34.         static void Main(string[] args)
  35.         {
  36.             var proteins = ReadFasta("augustus.whole_downloaded.aa");
  37.             var queries = ReadFasta("dna_associated_proteins.fasta");
  38.             List<string> result = new List<string>();
  39.             foreach(var protein in proteins)
  40.             {
  41.                 if (queries.Any(x => protein.Item2.Contains(x.Item2)))
  42.                 {
  43.                     result.Add(protein.Item2);
  44.                 }
  45.             }
  46.             File.WriteAllLines("result.txt", result);
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement