Parse genotype call information from arrays using format array

        :param list format: List of strings with format names
        :param gt_str arr: string with genotype information values
553157
def _parse_calls_data(klass, format_, infos, gt_str):
        
        data = OrderedDict()
        # The standard is very nice to parsers, we can simply split at
        # colon characters, although I (Manuel) don't know how strict
        # programs follow this
        for key, info, value in zip(format_, infos, gt_str.split(":")):
            data[key] = parse_field_value(info, value)
        return data
1215421
def parse_line(self, line_str):
        
        line_str = line_str.rstrip()
        if not line_str:
            return None  # empty line, EOF
        arr = self._split_line(line_str)
        # CHROM
        chrom = arr[0]
        # POS
        pos = int(arr[1])
        # IDS
        if arr[2] == ".":
            ids = []
        else:
            ids = arr[2].split(";")
        # REF
        ref = arr[3]
        # ALT
        alts = []
        if arr[4] != ".":
            for alt in arr[4].split(","):
                alts.append(process_alt(self.header, ref, alt))
        # QUAL
        if arr[5] == ".":
            qual = None
        else:
            try:
                qual = int(arr[5])
            except ValueError:  # try as float
                qual = float(arr[5])
        # FILTER
        if arr[6] == ".":
            filt = []
        else:
            filt = arr[6].split(";")
        self._check_filters(filt, "FILTER")
        # INFO
        info = self._parse_info(arr[7], len(alts))
        if len(arr) == 9:
            raise exceptions.IncorrectVCFFormat("Expected 8 or 10+ columns, got 9!")
        elif len(arr) == 8:
            format_ = None
            calls = None
        else:
            # FORMAT
            format_ = arr[8].split(":")
            # sample/call columns
            calls = self._handle_calls(alts, format_, arr[8], arr)
        return record.Record(chrom, pos, ids, ref, alts, qual, filt, info, format_, calls)
1203254
def parse_args():
    """"""
    parser = argparse.ArgumentParser(
        prog="geneparse-extractor",
        description="Genotype file extractor. This tool will extract markers "
                    "according to names or to genomic locations.",
        epilog="The parser arguments (PARSER_ARGS) are the same as the one in "
               "the API. For example, the arguments for the Plink parser is "
               "'prefix:PREFIX' (where PREFIX is the prefix of the "
               "BED/BIM/FAM files).",
    )

    # The input file format
    group = parser.add_argument_group("Input Options")
    group.add_argument(
        "-f", "--format", metavar="FORMAT", required=True, type=str,
        dest="input_format", choices=set(parsers.keys()),
        help="The input file format.",
    )

    group.add_argument(
        nargs="+", dest="parser_args", type=str, metavar="PARSER_ARGS",
        help="The arguments that will be passed to the genotype parsers.",
    )

    # The extract options
    group = parser.add_argument_group("Extract Options")
    group.add_argument(
        "-e", "--extract", metavar="FILE", type=argparse.FileType("r"),
        help="The list of markers to extract (one per line, no header).",
    )
    group.add_argument(
        "-k", "--keep", metavar="FILE", type=argparse.FileType("r"),
        help="The list of samples to keep (one per line, no header).",
    )
    group.add_argument(
        "--maf", action="store_true",
        help="Check MAF and flip the allele coding if the MAF is higher "
             "than 50%%.",
    )

    # The output options
    group = parser.add_argument_group("Output Options")
    group.add_argument(
        "-o", "--output", metavar="FILE", type=str, required=True,
        help="The output file (can be '-' for STDOUT when using VCF or CSV as "
             "output format).",
    )
    group.add_argument(
        "--output-format", metavar="FORMAT", default="vcf", type=str,
        choices={"vcf", "plink", "csv"},
        help="The output file format. Note that the extension will be added "
             "if absent. Note that CSV is a long format (hence it might take "
             "more disk space).",
    )

    return parser.parse_args()
544990
private final <T> Object parseTypeArr(Converter<T> converter, Class<T> valType, String[] arr) throws Exception {
		Object objArr = Array.newInstance(valType, arr.length);
		for (int i = 0; i < arr.length; i++) {
			T item = converter.parseFromString(valType, null, null, arr[i]);
			Array.set(objArr, i, item);
		}
		return objArr;
	}
407738
def from_array(array):
        
        if array is None or not array:
            return None
        # end if
        assert_type_or_raise(array, dict, parameter_name="array")
        from pytgbot.api_types.receivable.media import PhotoSize
        

        data = {}
        data['file_id'] = u(array.get('file_id'))
        data['duration'] = int(array.get('duration'))
        data['performer'] = u(array.get('performer')) if array.get('performer') is not None else None
        data['title'] = u(array.get('title')) if array.get('title') is not None else None
        data['mime_type'] = u(array.get('mime_type')) if array.get('mime_type') is not None else None
        data['file_size'] = int(array.get('file_size')) if array.get('file_size') is not None else None
        data['thumb'] = PhotoSize.from_array(array.get('thumb')) if array.get('thumb') is not None else None
        data['_raw'] = array
        return Audio(**data)
474293
def is_array(self, data_type):
    '''
    '''

    # Split off any brackets
    data_type = data_type.split('[')[0].strip()

    return data_type.lower() in self.array_types
894404
def load_genotypes(self):
        


        if self.file_index < len(self.archives):
            self.current_file = self.archives[self.file_index]
            info_filename = self.current_file.replace(Parser.gen_ext, Parser.info_ext)
            if len(self.info_files) > 0:
                info_filename = self.info_files[self.file_index]
            self.info_file = open(info_filename)
            self.info_file.readline()   # Dump the header

            if DataParser.compressed_pedigree:
                self.freq_file = gzip.open("%s" % (self.current_file), 'rb')
            else:
                self.freq_file = open(self.current_file)
            self.current_chrom = self.chroms[self.file_index]
            self.file_index += 1
        else:
            raise StopIteration
868236
def prt_gene_aart_details(self, geneids, prt=sys.stdout):
        """"""
        _go2nt = self.sortobj.grprobj.go2nt
        patgene = self.datobj.kws["fmtgene2"]
        patgo = self.datobj.kws["fmtgo2"]
        itemid2name = self.datobj.kws.get("itemid2name")
        chr2i = self.datobj.get_chr2idx()
        for geneid in geneids:
            gos_gene = self.gene2gos[geneid]
            symbol = "" if itemid2name is None else itemid2name.get(geneid, "")
            prt.write("\n")
            prt.write(patgene.format(AART=self.gene2aart[geneid], ID=geneid, NAME=symbol))
            go2nt = {go:(_go2nt[go], "".join(self.go2chrs[go])) for go in gos_gene}
            for ntgo, abc in sorted(go2nt.values(),
                                    key=lambda t: [chr2i[t[1][:1]], t[0].NS, -1*t[0].dcnt]):
                prt.write("{ABC} ".format(ABC=abc))
                prt.write(patgo.format(**ntgo._asdict()))
1147725
function _gpfArrayFromString(array, string) {
        var length = string.length, index = 0;
        for (; index < length; ++index) {
            array.push(string.charAt(index));
        }
    }
616859
def read_gtf_line(cols, field="name"):
    """"""
    field = field.lower()
    try:
        group = cols[2]
        attrs = cols[8].split(";")
        name = [attr.strip().split(" ")[1] for attr in attrs if attr.strip().split(" ")[0].lower().endswith(field)]
        if not name:
            name = [attr.strip().split(" ")[1] for attr in attrs if attr.strip().split(" ")[0].lower().endswith("gene_id")]
        if not name:
            name = ["None"]
        biotype = [attr.strip().split(" ")[1] for attr in attrs if attr.strip().split(" ")[0].lower().endswith("biotype")]
        if biotype:
            group = biotype[0]
        c = cols[0]
        s = int(cols[3])
        e = int(cols[4])
        st = cols[6]
        return [c, s, e, st, group, name[0]]
    except(Exception, e):
        logger.error(cols)
        logger.error("File is not in correct format")
        logger.error("Expect chr source feature start end . strand attributes")
        logger.error("Attributes are 'gene_name SNCA; gene_id ENSG; '")
        logger.error("The 3rd column is used as type of small RNA (like miRNA)")
        logger.error("at least should contains '; *name NAME; '")
        logger.error(e)
        raise
439098
def _add_genotype_calls(self, variant_obj, variant_line, case_obj):
        
        variant_line = variant_line.split('\t')
        #if there is gt calls we have no individuals to add
        if len(variant_line) > 8:
            gt_format = variant_line[8].split(':')
            for individual in case_obj.individuals:
                sample_id = individual.ind_id
                index = individual.ind_index

                gt_call = variant_line[9+index].split(':')

                raw_call = dict(zip(gt_format, gt_call))

                genotype = Genotype(**raw_call)

                variant_obj.add_individual(puzzle_genotype(
                    sample_id = sample_id,
                    genotype = genotype.genotype,
                    case_id = case_obj.name,
                    phenotype = individual.phenotype,
                    ref_depth = genotype.ref_depth,
                    alt_depth = genotype.alt_depth,
                    genotype_quality = genotype.genotype_quality,
                    depth = genotype.depth_of_coverage,
                    supporting_evidence = genotype.supporting_evidence,
                    pe_support = genotype.pe_support,
                    sr_support = genotype.sr_support,
                ))
1114759
def load_genotypes(self, pheno_covar):
        

        first_genotype = 6
        pheno_col      = 5
        if not DataParser.has_sex:
            first_genotype -= 1
            pheno_col -= 1
        if not DataParser.has_parents:
            first_genotype -= 2
            pheno_col -= 2
        if not DataParser.has_pheno:
            first_genotype -= 1
        if not DataParser.has_fid:
            first_genotype -= 1
            pheno_col -= 1
        if DataParser.has_liability:
            first_genotype += 1

        sex_col = pheno_col - 1
        individual_mask = []
        self.individual_mask = []
        dropped_individuals = []

        # number of missing SNPs we can tolerate before dropping an individual
        max_missing_for_individual = numpy.sum(
                self.snp_mask[:, 0]==0) * DataParser.ind_miss_tol

        if DataParser.compressed_pedigree:
            ind_count, err = sys_call("gzip -cd %s | wc -l" %
                                      ("%s.gz" % (self.datasource)))
        else:
            ind_count, err = sys_call("wc -l %s" % (self.datasource))
        ind_count = int(ind_count[0].split()[0]) + 1

        snp_count = numpy.sum(self.snp_mask[:, 0] == 0)

        allelic_data = numpy.empty((ind_count, snp_count, 2), dtype='S1')

        valid_allele_count = 0
        if DataParser.compressed_pedigree:
            input_file = gzip.open("%s.gz" % self.datasource, 'rb')
        else:
            input_file = open(self.datasource)

        for line in input_file:
            line = line.strip()
            if len(line) > 0:
                raw_data = line.strip().split()
                alleles = numpy.ma.MaskedArray(
                        numpy.array(raw_data[first_genotype:]).reshape(-1, 2),
                        self.snp_mask).compressed().reshape(-1, 2)

                # Convert the alleles into genotypes
                indid = ":".join(raw_data[0:2])
                if not DataParser.has_fid:
                    indid = raw_data[0]

                # Ignore any subjects that are to be excluded and remove those
                # that have too much missingness
                if DataParser.valid_indid(indid):
                    missing = numpy.sum(alleles[:, 0] ==
                                        DataParser.missing_representation)

                    if missing > max_missing_for_individual:
                        individual_mask += [1, 1]
                        self.individual_mask.append(1)
                        dropped_individuals.append(indid)
                    else:
                        sex = None
                        phenotype = None
                        if DataParser.has_pheno:
                            phenotype = float(raw_data[pheno_col])
                        if DataParser.has_sex:
                            sex = int(raw_data[sex_col])
                        if pheno_covar is not None:
                            pheno_covar.add_subject(indid, sex, phenotype)
                        individual_mask += [0, 0]
                        self.individual_mask.append(0)
                        allelic_data[valid_allele_count] = alleles
                        valid_allele_count += 1

                else:
                    individual_mask += [1, 1]
                    self.individual_mask.append(1)
        self.ind_count = valid_allele_count
        allelic_data = allelic_data[0:valid_allele_count]
        self.genotypes = numpy.empty((snp_count, valid_allele_count))
        max_missing_individuals = DataParser.snp_miss_tol * ind_count
        dropped_loci = []
        valid_snps = 0
        valid_markers = []
        valid_rsids   = []
        valid_maf     = []
        valid_allele_list = []
        allele_count2s = []

        for i in xrange(0, snp_count):
            snp_geno = allelic_data[:,i]
            alleles = list(set(numpy.unique(snp_geno)) -
                           set([DataParser.missing_representation]))

            if len(alleles) > 2:
                raise TooManyAlleles(chr=self.markers[i][0],
                                     rsid=self.rsids[i],
                                     alleles=alleles)

            allele_count1 = numpy.sum(snp_geno==alleles[0])
            allele_count2 = 0
            maf = 0

            if len(alleles) > 1:
                allele_count2 = numpy.sum(snp_geno==alleles[1])
                real_allele_count2 = allele_count2

                if allele_count2 > allele_count1:
                    sorted_alleles = [alleles[1], alleles[0]]
                    alleles = sorted_alleles
                    allele_count = allele_count1
                    allele_count1 = allele_count2
                    allele_count2 = allele_count
                maf = allele_count2 / float(allele_count1 + allele_count2)
                allele_count2s.append(allele_count2)
                #genotypes = []
                major_allele       = alleles[0]
                minor_allele       = alleles[1]

                genotype_data = numpy.sum(snp_geno==alleles[1], axis=1)
                genotype_data[
                    snp_geno[:, 0]==DataParser.missing_representation] = \
                    DataParser.missing_storage
            else:
                major_allele = alleles[0]
                minor_allele = '?'

            missing = numpy.sum(genotype_data==DataParser.missing_storage)
            if maf == 0 or maf < DataParser.min_maf or \
                            maf > DataParser.max_maf or \
                            max_missing_individuals < missing:
                locus_details = self.markers[i]
                DataParser.boundary.dropped_snps[
                    locus_details[0]].add(locus_details[1])
                dropped_loci.append("%s:%s" % (locus_details[0],
                                               locus_details[1]))
                self.invalid_loci.append(i)
            else:
                self.genotypes[valid_snps, :] = genotype_data
                valid_snps += 1
                valid_markers.append(list(self.markers[i]))
                valid_rsids.append(self.rsids[i])
                valid_allele_list.append([major_allele, minor_allele])
                valid_maf.append(maf)

        self.markers = valid_markers
        self.alleles = valid_allele_list
        self.rsids   = valid_rsids
        self.locus_count = valid_snps
        self.genotypes = self.genotypes[0:self.locus_count, :]
        self.allele_count2s = allele_count2s
1192181
def rnaseq_variant_calling(samples, run_parallel):
    
    samples = run_parallel("run_rnaseq_variant_calling", samples)
    variantcaller = dd.get_variantcaller(to_single_data(samples[0]))
    if variantcaller and ("gatk-haplotype" in variantcaller):
        out = []
        for d in joint.square_off(samples, run_parallel):
            out.extend([[to_single_data(xs)] for xs in multi.split_variants_by_sample(to_single_data(d))])
        samples = out
    if variantcaller:
        samples = run_parallel("run_rnaseq_ann_filter", samples)
    if variantcaller and ("gatk-haplotype" in variantcaller):
        out = []
        for data in (to_single_data(xs) for xs in samples):
            if "variants" not in data:
                data["variants"] = []
            data["variants"].append({"variantcaller": "gatk-haplotype", "vcf": data["vrn_file_orig"],
                                     "population": {"vcf": data["vrn_file"]}})
            data["vrn_file"] = data.pop("vrn_file_orig")
            out.append([data])
        samples = out
    return samples
1118889
def parseNoise(rawArray): 
    '''
    
    '''
    nnGenes=[] 
    for i in range(0,(rawArray.shape[1])): #Checks all genes
        count0=np.asarray(np.where(rawArray[:,i]==0))
        count1=np.asarray(np.where(rawArray[:,i]==1))
        if ((count1.shape[1]+count0.shape[1])<rawArray.shape[0]):
            nnGenes=np.append(nnGenes,i)
    return nnGenes.astype(int)
142945
private List<String> calculateTranscriptHgvs(Variant variant, Transcript transcript, String geneId) {

        String mutationType = ">";

        // Populate HGVSName parse tree.
        HgvsStringBuilder hgvsStringBuilder = new HgvsStringBuilder();

        // Populate coordinates.
        // Use cDNA coordinates.
        hgvsStringBuilder.setKind(isCoding(transcript) ? HgvsStringBuilder.Kind.CODING : HgvsStringBuilder.Kind.NON_CODING);

        hgvsStringBuilder.setCdnaStart(genomicToCdnaCoord(transcript, variant.getStart()));
        hgvsStringBuilder.setCdnaEnd(hgvsStringBuilder.getCdnaStart());

        // Populate prefix.
        hgvsStringBuilder.setTranscriptId(transcript.getId());
        hgvsStringBuilder.setGeneId(geneId);

        String reference;
        String alternate;
        // Convert alleles to transcript strand.
        if (transcript.getStrand().equals("-")) {
            reference = String.valueOf(VariantAnnotationUtils.COMPLEMENTARY_NT.get(variant.getReference().charAt(0)));
            alternate = String.valueOf(VariantAnnotationUtils.COMPLEMENTARY_NT.get(variant.getAlternate().charAt(0)));
        } else {
            reference = variant.getReference();
            alternate = variant.getAlternate();
        }

        // Populate alleles.
        hgvsStringBuilder.setMutationType(mutationType);
        hgvsStringBuilder.setReference(reference);
        hgvsStringBuilder.setAlternate(alternate);

        return Collections.singletonList(hgvsStringBuilder.format());
    }
479355
def group_alleles_by_start_end_Xbp(arr, bp=28):
    
    starts = arr[:,0:bp]
    ends = arr[:,-bp:]
    starts_ends_idxs = defaultdict(list)
    l, seq_len = arr.shape
    for i in range(l):
        start_i = starts[i]
        end_i = ends[i]
        start_i_str = ''.join([str(x) for x in start_i])
        end_i_str = ''.join([str(x) for x in end_i])
        starts_ends_idxs[start_i_str + end_i_str].append(i)
    return starts_ends_idxs
74210
function formatArray(formatStr, args) {
    if (!formatStr) {
        return formatStr;
    }
    if (!args) {
        args = [];
    }
    return formatStr.replace(/{(\d+)(\:)?([^}]*)}/g, function (match, index, formatSeparator, formatExpr) {
        var resultValue = args[index];
        if (resultValue === undefined) {
            return match;
        }
        var funcDepth = 0;
        while (typeof resultValue === "function") {
            resultValue = resultValue(index, args, match, formatExpr, funcDepth++);
        }
        if (formatSeparator === ':') {
            // use format providers
            for (var i = 0; i < _formatProviders.length; i++) {
                var fp = _formatProviders[i];
                var fpCtx = new FormatProviderContext(formatExpr, resultValue);
                var fpResult;
                try {
                    fpResult = fp(fpCtx);
                }
                catch (e) {
                    continue;
                }
                if (fpCtx.handled) {
                    // handled: first wins
                    resultValue = fpResult;
                    break;
                }
            }
        }
        if (resultValue !== undefined) {
            return resultValue;
        }
        // not defined => return whole match string
        return match;
    });
}