Beispiel #1
0
        //search level 4 code
        static public void SearchLevel_4(string fileName, string parameter1, string parameter2, string resultFile)
        {
            List <string> indexList       = Function.CreateListFromFile(parameter1); // List whith the sequeces plus offset
            List <string> queryList       = Function.CreateListFromFile(parameter2); // List with the sequeces to be searched
            List <string> sequenceFound   = new List <string>();
            List <int>    sequenceOffSet  = new List <int>();                        // Hold the list of offset to be used in the direct access
            List <int>    sequenceSize    = new List <int>();                        // Hold the sequence size to be used in the direct access
            List <string> sequenceDnaList = new List <string>();                     // Hold the sequence found to be used in writed file and erro alerts

            // Split the data from the file index and put in lists
            for (int q = 0; q < queryList.Count; q++)
            {
                for (int i = 0; i < indexList.Count; i++)
                {
                    string[] sequenceId = indexList[i].Split(' ');
                    if (queryList[q] == sequenceId[0])
                    {
                        int offSet = Int32.Parse(sequenceId[1]);
                        int size   = Int32.Parse(sequenceId[2]);
                        sequenceFound.Add(sequenceId[0]);
                        sequenceOffSet.Add(offSet);
                        sequenceSize.Add(size);
                    }
                }
            }
            // Search the file using direct access
            using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            {
                for (int i = 0; i < sequenceFound.Count; i++)
                {
                    byte[] bytes = new byte[sequenceSize[i] - 1];
                    fs.Seek(sequenceOffSet[i], SeekOrigin.Begin);
                    fs.Read(bytes, 0, sequenceSize[i] - 1);         // Get data from the file
                    string sequenceDna = Encoding.Default.GetString(bytes);
                    if (!sequenceDnaList.Contains(sequenceDna))     // Avoid duplicate data in the file
                    {
                        sequenceDnaList.Add(sequenceDna);
                    }
                }
            }
            // Write sequences found in a file
            try
            {
                Function.WriteToFile(resultFile, sequenceDnaList.ToArray());
                // Send alerts to the user informing the sequeces not found
                for (int i = 0; i < queryList.Count; i++)
                {
                    if (!sequenceFound.Contains(queryList[i]))
                    {
                        Alerts.Alert_9(queryList[i]);
                    }
                }
            }
            catch  // If 'resulFile' name is invalid
            {
                Alerts.Alert_8(resultFile);
            }
        }
Beispiel #2
0
 // Write to file sequences found and print message for sequences not found (Search level 3)
 static public void ValidationOutput(string searchParameter2, List <string> query, int[] queryFound, string[] sequencesFound)
 {
     try
     {
         Function.WriteToFile(searchParameter2, sequencesFound);
         for (int i = 0; i < queryFound.Length; i++)
         {
             if (queryFound[i] == 0)
             {
                 Alerts.Alert_9(query[i]);
             }
         }
     }
     catch
     {
         Alerts.Alert_8(searchParameter2);
     }
 }