Пример #1
0
        /// <summary>
        ///   Reads a FASTQ entry
        ///   Note that this assumes the ILMN format (4 lines per read). FASTQ files with multiline 
        ///     sequences will likely cause issues
        /// </summary>
        /// <returns>Returns false if no more entries are available.</returns>
        public bool GetNextFastqEntry(ref BoltRead read)
        {
            // grab the next entry
            bool foundProblem = false; string header;
            if ((header = reader.ReadLine()) == null) return false;
            if ((read.Bases = reader.ReadLine()) == null) foundProblem = true;
            if ((reader.ReadLine()) == null) foundProblem = true;
            if ((read.Qualities = reader.ReadLine()) == null) foundProblem = true;

            if (foundProblem)
            {
                throw new ApplicationException(
                    string.Format("ERROR: Unable to read the entire FASTQ entry in {0}. Is the file truncated?",
                                  FileName));
            }

            read.Header = header;
            if (! SkipAllReadNameParsing)
            {
                // parse the secondary information
                Match headerMatch = headerRegex.Match(header);
                if (! headerMatch.Success)
                {
                    throw new ApplicationException(string.Format("Unexpected FastQ header {0}", header));
                }

                read.UnparsedName = headerMatch.Groups[1].Value;

                if (headerMatch.Groups.Count > 2)
                {
                    read.ReadNum = int.Parse(headerMatch.Groups[2].Value);
                    read.IsFiltered = (headerMatch.Groups[3].Value[0] == 'Y');
                    read.Index = headerMatch.Groups[4].Value;
                }
                
                // parse the read name
                if (! SkipReadNameParsing)
                {   
                    if (headerMatch.Groups.Count != 5 || !read.ParseReadName())
                    {
                        throw new ApplicationException(string.Format("Invalid field count in FastQ header {0}", header));
                    }
                }

            }


            return true;
        }
Пример #2
0
 /// <summary>
 ///     Writes the FASTQ entry
 /// </summary>
 public void WriteFastqEntry(BoltRead read)
 {
     // sanity check
     if (!IsOpen)
     {
         throw new ApplicationException("ERROR: An attempt was made to write a FASTQ entry to an unopened file.");
     }
     if (read.Header != null)
     {
         _writer.WriteLine(read.Header);
     }
     else if (read.UMI != null)
     {
         _writer.WriteLine(string.Format("@{0}:{1}:{2}:{3}:{4}:{5}:{6}:{7} {8}:{9}:0:{10}",
                                        read.InstrumentName,
                                        read.RunID,
                                        read.FlowcellID,
                                        read.Lane,
                                        read.Tile,
                                        read.X,
                                        read.Y,
                                        read.UMI, 
                                        read.ReadNum,
                                        (read.IsFiltered ? 'Y' : 'N'),
                                        read.Index));
     }
     else
     {
         _writer.WriteLine(string.Format("@{0}:{1}:{2}:{3}:{4}:{5}:{6} {7}:{8}:0:{9}",
                                        read.InstrumentName,
                                        read.RunID,
                                        read.FlowcellID,
                                        read.Lane,
                                        read.Tile,
                                        read.X,
                                        read.Y,
                                        read.ReadNum,
                                        (read.IsFiltered ? 'Y' : 'N'),
                                        read.Index));
     }
     _writer.WriteLine(read.Bases);
     _writer.WriteLine("+");
     _writer.WriteLine(read.Qualities);
 }