Exemplo n.º 1
0
        /// <summary>
        /// Gets the paired reads type.
        /// </summary>
        /// <param name="pairedRead">Paired read.</param>
        /// <param name="libraryInfo">Library information.</param>
        /// <param name="useInsertLengthOfReads">
        /// If this flag is set to true then insert length will be calculated from read1 and read2,
        /// else InsertLength in spcified paired read will be used.
        /// </param>
        public static PairedReadType GetPairedReadType(PairedRead pairedRead, CloneLibraryInformation libraryInfo, bool useInsertLengthOfReads)
        {
            if (pairedRead == null)
            {
                throw new ArgumentNullException("pairedRead");
            }

            if (libraryInfo == null)
            {
                throw new ArgumentNullException("libraryInfo");
            }

            return(GetPairedReadType(pairedRead, libraryInfo.MeanLengthOfInsert, libraryInfo.StandardDeviationOfInsert, useInsertLengthOfReads));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the paired reads type.
        /// </summary>
        /// <param name="pairedRead">Paired read.</param>
        /// <param name="libraryName">library name.</param>
        /// <param name="useInsertLengthOfReads">
        /// If this flag is set to true then insert length will be calculated from read1 and read2,
        /// else InsertLength in spcified paired read will be used.
        /// </param>
        public static PairedReadType GetPairedReadType(PairedRead pairedRead, string libraryName, bool useInsertLengthOfReads)
        {
            if (pairedRead == null)
            {
                throw new ArgumentNullException("pairedRead");
            }

            if (string.IsNullOrEmpty(libraryName))
            {
                throw new ArgumentNullException("libraryName");
            }

            CloneLibraryInformation libraryInfo = CloneLibrary.Instance.GetLibraryInformation(libraryName);

            if (libraryInfo == null)
            {
                throw new ArgumentOutOfRangeException("libraryName");
            }

            return(GetPairedReadType(pairedRead, libraryInfo, useInsertLengthOfReads));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the paired reads type.
        /// </summary>
        /// <param name="pairedRead">Paired read.</param>
        /// <param name="meanLengthOfInsert">Mean of the insertion length.</param>
        /// <param name="standardDeviationOfInsert">Standard deviation of insertion length.</param>
        /// <param name="useInsertLengthOfReads">
        /// If this flag is set to true then insert length will be calculated from read1 and read2,
        /// else InsertLength in spcified paired read will be used.
        /// By default this will be set to false.
        /// </param>
        public static PairedReadType GetPairedReadType(PairedRead pairedRead, float meanLengthOfInsert, float standardDeviationOfInsert, bool useInsertLengthOfReads)
        {
            if (pairedRead == null)
            {
                throw new ArgumentNullException("pairedRead");
            }

            if (pairedRead._alignedSequences.Count > 2)
            {
                return(PairedReadType.MultipleHits);
            }

            if (useInsertLengthOfReads)
            {
                return(GetPairedReadType(pairedRead.Read1, pairedRead.Read2, meanLengthOfInsert, standardDeviationOfInsert));
            }
            else
            {
                PairedReadType type = GetPairedReadType(pairedRead.Read1, pairedRead.Read2, meanLengthOfInsert, standardDeviationOfInsert);

                if (type == PairedReadType.Normal || type == PairedReadType.LengthAnomaly)
                {
                    int insertLength = pairedRead.InsertLength;
                    // µ + 3σ
                    float upperLimit = meanLengthOfInsert + (3 * standardDeviationOfInsert);
                    // µ - 3σ
                    float lowerLimit = meanLengthOfInsert - (3 * standardDeviationOfInsert);
                    if (insertLength > upperLimit || insertLength < lowerLimit)
                    {
                        type = PairedReadType.LengthAnomaly;
                    }
                    else
                    {
                        type = PairedReadType.Normal;
                    }
                }

                return(type);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the paired reads when DV is enabled.
        /// </summary>
        /// <param name="meanLengthOfInsert">Mean of the insert length.</param>
        /// <param name="standardDeviationOfInsert">Standard deviation of insert length.</param>
        /// <param name="calculate">If this flag is set then mean and standard deviation will
        /// be calculated from the paired reads instead of specified.</param>
        /// <returns>List of paired read.</returns>
        private IList <PairedRead> GetDVAwarePairedReads(float meanLengthOfInsert, float standardDeviationOfInsert, bool calculate = false)
        {
            // Dictionary helps to get the information at one pass of alinged sequence list.
            Dictionary <string, DVEnabledPairedRead> pairedReads = new Dictionary <string, DVEnabledPairedRead>();
            double sum   = 0;
            int    count = 0;

            for (int i = 0; i < QuerySequences.Count; i++)
            {
                DVEnabledPairedRead pairedRead;
                SAMAlignedSequence  read = QuerySequences[i];
                if ((read.Flag & SAMFlags.PairedRead) == SAMFlags.PairedRead)
                {
                    if (pairedReads.TryGetValue(read.QName, out pairedRead))
                    {
                        if (pairedRead.Index2 == -1 || pairedRead.Index1 == -1)
                        {
                            if (pairedRead.Index2 == -1)
                            {
                                pairedRead.Index2 = i;
                            }
                            else
                            {
                                pairedRead.Index1 = i;
                            }

                            // For best performace,
                            // 1. BAM/SAM file should be sorted by reads name.
                            // 2. If sorted on mapping position then give unmapped read a coordinate (generally the coordinate of the mapped mate)
                            //    for sorting/indexing purposes only.


                            pairedRead.PairedType = PairedRead.GetPairedReadType(pairedRead.Read1, pairedRead.Read2, meanLengthOfInsert, standardDeviationOfInsert);

                            if (pairedRead.PairedType == PairedReadType.Normal || pairedRead.PairedType == PairedReadType.LengthAnomaly)
                            {
                                pairedRead.InsertLength = PairedRead.GetInsertLength(pairedRead.Read1, pairedRead.Read2);

                                if (calculate)
                                {
                                    sum += pairedRead.InsertLength;
                                    count++;
                                }
                            }
                        }
                        else
                        {
                            pairedRead.InsertLength = 0;
                            if (calculate)
                            {
                                sum -= pairedRead.InsertLength;
                                count--;
                            }

                            pairedRead.ReadIndexes.Add(i);
                            pairedRead.PairedType = PairedReadType.MultipleHits;
                        }
                    }
                    else
                    {
                        pairedRead = new DVEnabledPairedRead(QuerySequences);
                        if (!string.IsNullOrEmpty(read.RName) && !read.RName.Equals("*"))
                        {
                            pairedRead.Index1 = i;
                        }
                        else
                        {
                            pairedRead.Index2 = i;
                        }

                        pairedRead.PairedType   = PairedReadType.Orphan;
                        pairedRead.InsertLength = 0;
                        pairedReads.Add(read.QName, pairedRead);
                    }
                }
            }

            List <PairedRead> allreads = pairedReads.Values.ToList <PairedRead>();

            pairedReads = null;

            if (calculate && count > 0)
            {
                UpdateType(allreads, sum, count);
            }

            return(allreads);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the paired reads when SAMAligned sequences are in memory.
        /// </summary>
        /// <param name="meanLengthOfInsert">Mean of the insert length.</param>
        /// <param name="standardDeviationOfInsert">Standard deviation of insert length.</param>
        /// <param name="calculate">If this flag is set then mean and standard deviation will
        /// be calculated from the paired reads instead of specified.</param>
        /// <returns>List of paired read.</returns>
        private IList <PairedRead> GetInMemoryPairedReads(float meanLengthOfInsert, float standardDeviationOfInsert, bool calculate = false)
        {
            // Dictionary helps to get the information at one pass of alinged sequence list.
            Dictionary <string, PairedRead> pairedReads = new Dictionary <string, PairedRead>();
            double sum   = 0;
            int    count = 0;

            for (int i = 0; i < QuerySequences.Count; i++)
            {
                PairedRead         pairedRead;
                SAMAlignedSequence read = QuerySequences[i];
                if ((read.Flag & SAMFlags.PairedRead) == SAMFlags.PairedRead)
                {
                    if (pairedReads.TryGetValue(read.QName, out pairedRead))
                    {
                        if (pairedRead.Read2 == null || pairedRead.Read1 == null)
                        {
                            if (pairedRead.Read2 == null)
                            {
                                pairedRead.Read2 = read;
                            }
                            else
                            {
                                pairedRead.Read1 = read;
                            }

                            pairedRead.PairedType = PairedRead.GetPairedReadType(pairedRead.Read1, pairedRead.Read2, meanLengthOfInsert, standardDeviationOfInsert);
                            if (pairedRead.PairedType == PairedReadType.Normal || pairedRead.PairedType == PairedReadType.LengthAnomaly)
                            {
                                pairedRead.InsertLength = PairedRead.GetInsertLength(pairedRead.Read1, pairedRead.Read2);
                                if (calculate)
                                {
                                    sum += pairedRead.InsertLength;
                                    count++;
                                }
                            }
                        }
                        else
                        {
                            pairedRead.InsertLength = 0;
                            if (calculate)
                            {
                                sum -= pairedRead.InsertLength;
                                count--;
                            }

                            pairedRead.Reads.Add(read);
                            pairedRead.PairedType = PairedReadType.MultipleHits;
                        }
                    }
                    else
                    {
                        pairedRead = new PairedRead();
                        if (!string.IsNullOrEmpty(read.RName) && !read.RName.Equals("*"))
                        {
                            pairedRead.Read1 = read;
                        }
                        else
                        {
                            pairedRead.Read2 = read;
                        }

                        pairedRead.PairedType   = PairedReadType.Orphan;
                        pairedRead.InsertLength = 0;
                        pairedReads.Add(read.QName, pairedRead);
                    }
                }
            }

            List <PairedRead> allreads = pairedReads.Values.ToList();

            pairedReads = null;
            if (calculate && count > 0)
            {
                UpdateType(allreads, sum, count);
            }


            return(allreads);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Gets the paired reads type.
 /// </summary>
 /// <param name="pairedRead">Paired read.</param>
 /// <param name="meanLengthOfInsert">Mean of the insertion length.</param>
 /// <param name="standardDeviationOfInsert">Standard deviation of insertion length.</param>
 public static PairedReadType GetPairedReadType(PairedRead pairedRead, float meanLengthOfInsert, float standardDeviationOfInsert)
 {
     return(GetPairedReadType(pairedRead, meanLengthOfInsert, standardDeviationOfInsert, false));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Gets the paired reads type.
 /// </summary>
 /// <param name="pairedRead">Paired read.</param>
 /// <param name="libraryInfo">Library information.</param>
 public static PairedReadType GetPairedReadType(PairedRead pairedRead, CloneLibraryInformation libraryInfo)
 {
     return(GetPairedReadType(pairedRead, libraryInfo, false));
 }
Exemplo n.º 8
0
 /// <summary>
 /// Gets the paired reads type.
 /// </summary>
 /// <param name="pairedRead">Paired read.</param>
 /// <param name="libraryName">library name.</param>
 public static PairedReadType GetPairedReadType(PairedRead pairedRead, string libraryName)
 {
     return(GetPairedReadType(pairedRead, libraryName, false));
 }