示例#1
0
 private void __parse_file(BinaryReader handle)
 {
     /*
      * Helper function to initialize this object from a file handle
      *
      * Args:
      *  handle(file handle) : File handle at start of locus entry record
      *
      * Returns:
      *  None
      */
     this.version = (int)BeadArrayUtility.read_int(handle);
     if (this.version == 6)
     {
         this.__parse_locus_version_6(handle);
     }
     else if (this.version == 7)
     {
         this.__parse_locus_version_7(handle);
     }
     else if (this.version == 8)
     {
         this.__parse_locus_version_8(handle);
     }
     else
     {
         throw new Exception("Manifest format error: unknown version for locus entry (" + this.version + ")");
     }
 }
示例#2
0
 private void __parse_locus_version_8(BinaryReader handle)
 {
     /*
      * Helper function to parse version 8 locus entry
      *
      * Args:
      *  handle(file) : File handle at start of locus entry record
      *
      * Returns:
      *  None
      */
     this.__parse_locus_version_7(handle);
     this.ref_strand = RefStrand.from_string(BeadArrayUtility.read_string(handle));
 }
示例#3
0
        public static ClusterScore read_record(BinaryReader handle)
        {
            /*
             * Read a ClusterScore from a file handle
             *
             * Args:
             *  handle(file) : The file handle
             *
             * Returns:
             *  ClusterScore
             */
            float cluster_separation = (float)BeadArrayUtility.read_float(handle);
            float total_score        = (float)BeadArrayUtility.read_float(handle);
            float original_score     = (float)BeadArrayUtility.read_float(handle);
            bool  edited             = (((int)BeadArrayUtility.read_byte(handle)) != 0);

            return(new ClusterScore(cluster_separation, total_score, original_score, edited));
        }
示例#4
0
        public static ScannerData read_scanner_data(BinaryReader handle)
        {
            /*
             * Helper function to parse ScannerData object from file handle.
             *
             * Args:
             *  handle (BinaryReader): File handle
             *
             * Returns:
             *  ScannerData
             */
            string name            = BeadArrayUtility.read_string(handle);
            int    pmt_green       = (int)BeadArrayUtility.read_int(handle);
            int    pmt_red         = (int)BeadArrayUtility.read_int(handle);
            string scanner_version = BeadArrayUtility.read_string(handle);
            string imaging_user    = BeadArrayUtility.read_string(handle);

            return(new ScannerData(name, pmt_green, pmt_red, scanner_version, imaging_user));
        }
示例#5
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));
        }
示例#6
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);
        }
示例#7
0
 private void __parse_locus_version_6(BinaryReader handle)
 {
     /*
      * Helper function to parse version 6 locus entry
      *
      * Args:
      *  handle(file) : File handle at start of locus entry record
      *
      * Returns:
      *  None
      *
      * Raises:
      *  Exception: Manifest format error
      */
     this.ilmn_id       = BeadArrayUtility.read_string(handle);
     this.source_strand = SourceStrand.from_string(this.ilmn_id.Split('_')[this.ilmn_id.Split('_').Length - 2]);
     this.name          = BeadArrayUtility.read_string(handle);
     for (int idx = 0; idx < 3; ++idx)
     {
         this.after_name_string1.Add(BeadArrayUtility.read_string(handle));
     }
     this.after_name_byte = handle.ReadBytes(4);
     for (int idx = 0; idx < 2; ++idx)
     {
         this.after_name_string2.Add(BeadArrayUtility.read_string(handle));
     }
     this.snp   = BeadArrayUtility.read_string(handle);
     this.chrom = BeadArrayUtility.read_string(handle);
     for (int idx = 0; idx < 2; ++idx)
     {
         this.after_chrom_string.Add(BeadArrayUtility.read_string(handle));
     }
     this.map_info = Int32.Parse(BeadArrayUtility.read_string(handle));
     for (int idx = 0; idx < 2; ++idx)
     {
         this.after_map_info_string.Add(BeadArrayUtility.read_string(handle));
     }
     this.address_a = (int)BeadArrayUtility.read_int(handle);
     this.address_b = (int)BeadArrayUtility.read_int(handle);
     for (int idx = 0; idx < 7; ++idx)
     {
         this.after_address_string.Add(BeadArrayUtility.read_string(handle));
     }
     this.after_address_byte = handle.ReadBytes(3);
     this.assay_type         = (int)(byte)BeadArrayUtility.read_byte(handle);
     if (!(new List <int>(new int[] { 0, 1, 2 }).Contains(this.assay_type)))
     {
         throw new Exception("Format error in reading assay type from locus entry");
     }
     if (this.address_b == 0)
     {
         if (this.assay_type != 0)
         {
             throw new Exception("Manifest format error: Assay type is inconsistent with address B");
         }
     }
     else
     {
         if (this.assay_type == 0)
         {
             throw new Exception("Manifest format error: Assay type is inconsistent with address B");
         }
     }
 }