예제 #1
0
        public static ClusterRecord read_record(BinaryReader handle, int version)
        {
            /*
             * Read a cluster record from the file handle
             *
             * Args:
             *  handle(file): The file handle
             *  version(int): The cluster record version(from header)
             *
             * Returns:
             * ClusterRecord: Result will not be populated with either address or scores(read separately)
             *
             * Raises:
             * Exception: Unsupported cluster record version
             */
            List <int>   _ = ClusterFile.read_array(handle, 3, BeadArrayUtility.read_int).Cast <int>().ToList();
            int          aa_n = _[0], ab_n = _[1], bb_n = _[2];
            List <float> __ = ClusterFile.read_array(handle, 3, BeadArrayUtility.read_float).Cast <float>().ToList();
            float        aa_r_dev = __[0], ab_r_dev = __[1], bb_r_dev = __[2];

            __ = ClusterFile.read_array(handle, 3, BeadArrayUtility.read_float).Cast <float>().ToList();
            float aa_r_mean = __[0], ab_r_mean = __[1], bb_r_mean = __[2];

            __ = ClusterFile.read_array(handle, 3, BeadArrayUtility.read_float).Cast <float>().ToList();
            float aa_theta_dev = __[0], ab_theta_dev = __[1], bb_theta_dev = __[2];

            __ = ClusterFile.read_array(handle, 3, BeadArrayUtility.read_float).Cast <float>().ToList();
            float aa_theta_mean = __[0], ab_theta_mean = __[1], bb_theta_mean = __[2];

            float intensity_threshold;
            float _float;

            if (version == 9)
            {
                intensity_threshold = (float)BeadArrayUtility.read_float(handle);
            }
            else if (version == 8)
            {
                _float = (float)BeadArrayUtility.read_float(handle);
                intensity_threshold = 0;
            }
            else
            {
                throw new Exception("Unsupported cluster record version " + version);
            }


            // read through unused fields
            for (int idx = 0; idx < 14; ++idx)
            {
                _float = (float)BeadArrayUtility.read_float(handle);
            }


            ClusterStats aa_cluster_stats = new ClusterStats(
                aa_theta_mean, aa_theta_dev, aa_r_mean, aa_r_dev, aa_n);
            ClusterStats ab_cluster_stats = new ClusterStats(
                ab_theta_mean, ab_theta_dev, ab_r_mean, ab_r_dev, ab_n);
            ClusterStats bb_cluster_stats = new ClusterStats(
                bb_theta_mean, bb_theta_dev, bb_r_mean, bb_r_dev, bb_n);

            return(new ClusterRecord(aa_cluster_stats, ab_cluster_stats, bb_cluster_stats, intensity_threshold, null, null));
        }
예제 #2
0
        public static ClusterFile read_cluster_file(BinaryReader handle)
        {
            /*
             * Read a cluster file
             *
             * Args:
             *  file: EGT cluster file handle
             *
             * Returns:
             *  ClusterFile
             *
             * Raises:
             *  Exception: Incompatible cluster file format
             */
            int version = (int)BeadArrayUtility.read_int(handle);

            if (version != 3)
            {
                throw new Exception("Cluster file version " + version + " not supported");
            }

            string gencall_version       = BeadArrayUtility.read_string(handle);
            string cluster_version       = BeadArrayUtility.read_string(handle);
            string call_version          = BeadArrayUtility.read_string(handle);
            string normalization_version = BeadArrayUtility.read_string(handle);
            string date_created          = BeadArrayUtility.read_string(handle);

            bool is_wgt = ((int)BeadArrayUtility.read_byte(handle) == 1);

            if (is_wgt == false)
            {
                throw new Exception("Only WGT cluster file version supported");
            }

            string manifest_name = BeadArrayUtility.read_string(handle);

            ClusterFile result = new ClusterFile(gencall_version, cluster_version, call_version,
                                                 normalization_version, date_created, manifest_name);

            int data_block_version = (int)BeadArrayUtility.read_int(handle);

            if (!(new List <int>(new int[] { 8, 9 }).Contains(data_block_version)))
            {
                throw new Exception("Data block version in cluster file " + data_block_version + " not  supported");
            }

            // opa
            string _ = BeadArrayUtility.read_string(handle);

            int num_records = (int)BeadArrayUtility.read_int(handle);
            List <ClusterRecord> cluster_records = ClusterFile.read_array(
                handle, num_records, (BinaryReader h) => ClusterRecord.read_record(h, data_block_version)).Cast <ClusterRecord>().ToList();
            List <ClusterScore> cluster_scores = ClusterFile.read_array(
                handle, num_records, ClusterScore.read_record).Cast <ClusterScore>().ToList();

            // genotypes
            List <string> _string = ClusterFile.read_array(handle, num_records, BeadArrayUtility.read_string).Cast <string>().ToList();

            List <string> loci_names = ClusterFile.read_array(handle, num_records, BeadArrayUtility.read_string).Cast <string>().ToList();
            List <int>    addresses  = ClusterFile.read_array(handle, num_records, BeadArrayUtility.read_int).Cast <int>().ToList();

            // cluster counts
            List <List <int> > cluster_counts = new List <List <int> >();

            for (int idx = 0; idx < num_records; ++idx)
            {
                //3 corresponds to number genotypes (AA, AB, BB)
                cluster_counts.Add(ClusterFile.read_array(handle, 3, BeadArrayUtility.read_int).Cast <int>().ToList());
            }

            for (int idx = 0; idx < cluster_records.Count; ++idx)
            {
                ClusterRecord cluster_record = cluster_records[idx];
                List <int>    count_record   = cluster_counts[idx];
                System.Diagnostics.Debug.Assert(cluster_record.aa_cluster_stats.N == count_record[0]);
                System.Diagnostics.Debug.Assert(cluster_record.ab_cluster_stats.N == count_record[1]);
                System.Diagnostics.Debug.Assert(cluster_record.bb_cluster_stats.N == count_record[2]);
            }

            for (int idx = 0; idx < loci_names.Count; ++idx)
            {
                string        locus_name     = loci_names[idx];
                int           address        = addresses[idx];
                ClusterRecord cluster_record = cluster_records[idx];
                ClusterScore  cluster_score  = cluster_scores[idx];
                cluster_record.address       = address;
                cluster_record.cluster_score = cluster_score;
                result.add_record(locus_name, cluster_record);
            }

            return(result);
        }