Пример #1
0
        // Gets new header with sorted SQ Fields.
        // If SQ fields are already sorted then returns the same header.
        private SAMAlignmentHeader GetHeaderWithSortedSQFields(SAMAlignmentHeader header, bool canChangeOtherTagPos)
        {
            if (IsSortedByChromosomeNames(GetSQHeaders(header.RecordFields)))
            {
                return(header);
            }

            SAMAlignmentHeader newHeader = new SAMAlignmentHeader();
            int i = 0;

            if (canChangeOtherTagPos)
            {
                List <SAMRecordField> sqHeaders = new List <SAMRecordField>();
                for (; i < header.RecordFields.Count; i++)
                {
                    SAMRecordField field = header.RecordFields[i];
                    if (field.Typecode.Equals("SQ"))
                    {
                        sqHeaders.Add(field);
                    }
                    else
                    {
                        newHeader.RecordFields.Add(field);
                    }

                    sqHeaders.Sort(CompareByChromosomeName);

                    foreach (SAMRecordField sqfield in sqHeaders)
                    {
                        newHeader.RecordFields.Add(sqfield);
                    }

                    foreach (string str in header.Comments)
                    {
                        newHeader.Comments.Add(str);
                    }
                }
            }
            else
            {
                Bio.Util.SortedList <SAMRecordField, int> map = new Bio.Util.SortedList <SAMRecordField, int>(new ComparisonWrapper <SAMRecordField>(CompareByChromosomeName));

                for (; i < header.RecordFields.Count; i++)
                {
                    SAMRecordField field = header.RecordFields[i];
                    if (field.Typecode.Equals("SQ"))
                    {
                        map.Add(field, i);
                    }

                    newHeader.RecordFields.Add(field);
                }

                i = 0;
                foreach (int index in map.Values.OrderBy(I => I))
                {
                    newHeader.RecordFields[index] = map.Keys[i++];
                }

                foreach (string str in header.Comments)
                {
                    newHeader.Comments.Add(str);
                }
            }

            return(newHeader);
        }
Пример #2
0
        // Gets new header with sorted SQ Fields.
        // If SQ fields are already sorted then returns the same header.
        private SAMAlignmentHeader GetHeaderWithSortedSQFields(SAMAlignmentHeader header, bool canChangeOtherTagPos)
        {
            if (IsSortedByChromosomeNames(GetSQHeaders(header.RecordFields)))
                return header;

            SAMAlignmentHeader newHeader = new SAMAlignmentHeader();
            int i = 0;
            if (canChangeOtherTagPos)
            {
                List<SAMRecordField> sqHeaders = new List<SAMRecordField>();
                for (; i < header.RecordFields.Count; i++)
                {
                    SAMRecordField field = header.RecordFields[i];
                    if (field.Typecode.Equals("SQ"))
                    {
                        sqHeaders.Add(field);
                    }
                    else
                    {
                        newHeader.RecordFields.Add(field);
                    }

                    sqHeaders.Sort(CompareByChromosomeName);

                    foreach (SAMRecordField sqfield in sqHeaders)
                    {
                        newHeader.RecordFields.Add(sqfield);
                    }

                    foreach (string str in header.Comments)
                    {
                        newHeader.Comments.Add(str);
                    }
                }
            }
            else
            {
                 Bio.Util.SortedList<SAMRecordField, int> map = new Bio.Util.SortedList<SAMRecordField, int>(new ComparisonWrapper<SAMRecordField>(CompareByChromosomeName));

                for (; i < header.RecordFields.Count; i++)
                {
                    SAMRecordField field = header.RecordFields[i];
                    if (field.Typecode.Equals("SQ"))
                    {
                        map.Add(field, i);
                    }

                    newHeader.RecordFields.Add(field);
                }

                i = 0;
                foreach (int index in map.Values.OrderBy(I => I))
                {
                    newHeader.RecordFields[index] = map.Keys[i++];
                }

                foreach (string str in header.Comments)
                {
                    newHeader.Comments.Add(str);
                }
            }

            return newHeader;
        }