示例#1
0
        ///Commenting out for now as part of .NET 4 upgrade
        //public static string WriteToCSV(this IntArray x, string filename)
        //{
        //    string fullFileName = ShoUtils.GetCSVFilename(filename);
        //    ShoNS.IO.DlmWriter.dlmwrite(fullFileName, ",", x);
        //    return fullFileName;
        //}

        //public static string WriteToCSVNoDate(this IntArray x, string filename)
        //{
        //    string fullFileName = ShoUtils.GetCSVFilenameNoDate(filename);
        //    ShoNS.IO.DlmWriter.dlmwrite(fullFileName, ",", x);
        //    return fullFileName;
        //}

        /// <summary>
        /// Gives similar functionality to Matlab's [sortVal,sortIn]=sort(x), except that it is more
        /// general in that it allows one to sort any vector of values and not just those in x, by
        /// the ordering imposed by x.
        /// </summary>
        /// <param name="x">list of values to sort</param>
        /// <param name="sortedInd">Outputs the sorted values</param>
        /// <returns>The indexes of the sorted values</returns>
        public static IntArray SortWithInd(this IntArray x, out IntArray sortedInd)
        {
            Helper.CheckCondition(x.IsVector());
            x = x.ToVector();

            //ensures that if the values are all tied, the ordering does not change
            //if (x.Unique().Length == 1 && x.Unique()[0]==0)
            //{
            //    sortedInd = ShoUtils.MakeRangeInt(0, x.Length-1);
            //    return x;
            //}

            if (!x.IsEmpty())
            {
                Helper.CheckCondition(x.IsVector());
                x = x.ToVector();
                Array tmp1 = x.ToList().ToArray();
                Array tmp2 = Enumerable.Range(0, x.size1).ToArray();
                Array.Sort(tmp1, tmp2);
                sortedInd = IntArray.From(tmp2);
                IntArray sortedVals = IntArray.From(tmp1);
                return(sortedVals);
            }
            else
            {
                sortedInd = new IntArray(0);
                return(x);
            }
        }
示例#2
0
        /// <summary>
        /// Given a 1D matrix (a vector), permute it's entries
        /// </summary>
        /// <param name="x"></param>
        /// <returns></returns>
        public static IntArray RandomPermutation(this IntArray x, Random rand)
        {
            Helper.CheckCondition(x.IsVector(), "method only takes vectors not matrixes");
            List <int> xList = x.ToList();

            //Random myRand = new Random();
            xList.ShuffleInPlace(rand);
            return(IntArray.From(xList));
        }
示例#3
0
        /// <summary>
        /// Called from constructor to initialize instance values
        /// </summary>
        private void Initialize()
        {
            // Determine the read lengths of the input data and store maximum read length
            this.ReadLengths = IntArray.From(this.DetermineReadLengths());
            this.Count       = this.ReadLengths.Count;

            if (this.Count == 0)
            {
                throw new ArgumentOutOfRangeException("Zero sequence records were processed");
            }

            this.SymbolCountByPositionTable = new Dictionary <byte, int[]>();

            // Determine the alphabet of this input file
            this.Alphabet = this.Sequences.FirstOrDefault().Alphabet;

            this.GCContentByPositionArray = new DoubleArray((int)ReadLengthMax);
            this.GCContentBySequenceArray = new DoubleArray((int)Count);
        }
示例#4
0
 public static IntArray Unique(this IntArray x)
 {
     return(IntArray.From(x.Distinct().ToList()));
 }