Ejemplo n.º 1
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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
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");
         }
     }
 }