Exemplo n.º 1
0
        public void FastqTrimNullTest()
        {
            ISequence seqObj = new QualitativeSequence(Alphabets.DNA, FastQFormatType.Sanger,
                                                       "GGCGCACTTACACCCTACATCCATTG", "IIIIG1?II;IIIII1IIII1%.I7I");
            double       trimLength    = seqObj.Count + 1;
            bool         trimFromStart = false;
            TrimByLength target        = new TrimByLength(new FastQParser(), new FastQFormatter(), null, trimLength, trimFromStart);
            ISequence    actual;

            actual = target.Trim(seqObj);
            Assert.IsNull(actual);
        }
Exemplo n.º 2
0
        public void FastqTrimFromLeftTest2()
        {
            ISequence seqObj = new QualitativeSequence(Alphabets.DNA, FastQFormatType.Sanger,
                                                       "GGCGCACTTACACCCTACATCCATTG", "IIIIG1?II;IIIII1IIII1%.I7I");
            ISequence expected = new QualitativeSequence(Alphabets.DNA, FastQFormatType.Sanger,
                                                         "G", "I");
            double       trimLength    = 1;
            bool         trimFromStart = true;
            TrimByLength target        = new TrimByLength(new FastQParser(), new FastQFormatter(), null, trimLength, trimFromStart);
            ISequence    actual;

            actual = target.Trim(seqObj);
            Assert.AreEqual(BioHelper.GetStringSequence(expected), BioHelper.GetStringSequence(actual));
            Assert.AreEqual((expected as QualitativeSequence).QualityScores.ToString(), (actual as QualitativeSequence).QualityScores.ToString());
        }
Exemplo n.º 3
0
 /// <summary>
 /// Constructor for holding Trim by length event arguments
 /// </summary>
 /// <param name="trimFromStart"></param>
 /// <param name="input"></param>
 /// <param name="filtered"></param>
 /// <param name="discarded"></param>
 public TrimByLengthArgs(double newLength, bool trimFromStart, InputSubmission input, ISequenceFormatter filtered, ISequenceFormatter discarded, string outFile)
     : base(input, outFile)
 {
     trimmer = new TrimByLength(input.Parser, filtered, discarded, newLength, trimFromStart);
 }
Exemplo n.º 4
0
        /// <summary>
        /// usage: SeqcosTrimmerUtil.exe [options] <input> <output>
        /// </summary>
        /// <param name="args">Command line arguments</param>
        static void Main(string[] args)
        {
            Console.Error.WriteLine(SplashString());

            CommandLineOptions myArgs = ProcessCommandLine(args);

            #region Trimming
            // Determine parser
            InputSubmission input = new InputSubmission(myArgs.InputFile);
            input.DetermineParserUtil();

            // Create a sequence filteredFormatter object
            ISequenceFormatter filteredFormatter;
            ISequenceFormatter discardedFormatter = null;

            // If the format is FASTA, then output will be FASTA.
            // Everything else (assuming quality scores are available)
            // will be outputted to FASTQ.
            if (input.Parser is FastAParser)
            {
                if (myArgs.TrimByQuality > 0)
                {
                    Console.Error.WriteLine("Cannot trim by quality using a FASTA file.");
                    Environment.Exit(-1);
                }

                if (myArgs.DiscardedFile != null)
                {
                    discardedFormatter = new FastAFormatter(myArgs.DiscardedFile);
                }

                filteredFormatter = new FastAFormatter(myArgs.OutputFile);
            }
            else
            {
                if (myArgs.DiscardedFile != null)
                {
                    discardedFormatter = new FastQFormatter(myArgs.DiscardedFile);
                }

                filteredFormatter = new FastQFormatter(myArgs.OutputFile);
            }

            // Initialize a Trimmer object
            Trimmer myTrimmer = null;

            // By now, we should have sanity checked the command line arguments. So we should be able to
            // figure out what mode is being used simply by checking the properties.
            if (myArgs.TrimByLength > 0)
            {
                Console.Error.WriteLine("Trimming reads to length {0}", myArgs.TrimByLength);
                myTrimmer = new TrimByLength(input.Parser, filteredFormatter, discardedFormatter, myArgs.TrimByLength, myArgs.Left);
            }

            else if (myArgs.TrimByQuality > 0)
            {
                if (!(input.Parser is FastQParser))
                {
                    throw new ArgumentException("Input file must be in FASTQ format.");
                }

                Console.Error.WriteLine("Trimming reads based on quality score {0}", myArgs.TrimByQuality);
                myTrimmer = new TrimByQuality(input.Parser, filteredFormatter, discardedFormatter, (byte)myArgs.TrimByQuality, myArgs.Left, (int)Math.Round(myArgs.TrimByLength));
            }

            else if (myArgs.TrimByRegex != null)
            {
                Console.Error.WriteLine("Trimming reads based on the regular expression pattern {0}", myArgs.TrimByRegex);
                myTrimmer = new TrimByRegex(input.Parser, filteredFormatter, discardedFormatter, myArgs.TrimByRegex);
            }

            else
            {
                // Should never reach this line.
                Console.Error.WriteLine("Invalid trim mode. Use '-l' or '-q'.");
                Environment.Exit(-1);
            }


            myTrimmer.TrimAll();


            #endregion

            if (myArgs.Verbose)
            {
                Console.Error.WriteLine("Trimmed {0}/{1} sequences.", myTrimmer.TrimCount, myTrimmer.Counted);
                Console.Error.WriteLine("Discarded {0}/{1} sequences.", myTrimmer.DiscardCount, myTrimmer.Counted);
                Console.Error.WriteLine("Output saved in {0}.", Path.GetFullPath(myArgs.OutputFile));
                Console.Error.WriteLine("Warning: Output may not be in the same order as the original input.");
            }

            input.Parser.Close();
            filteredFormatter.Close();
            if (discardedFormatter != null)
            {
                discardedFormatter.Close();
            }
        }