/*
(non-Javadoc)

@see org.jdiameter.server.api.agent.IAgentConfiguration#parse(java.lang.String )
543689
@Override
  public IAgentConfiguration parse(String agentConfiguration) throws InternalException {
    if (agentConfiguration == null) {
      return null;
    }
    AgentConfigurationImpl conf = new AgentConfigurationImpl();
    try {

      conf.properties = new Properties();
      String[] split = agentConfiguration.split(";");
      for (String s : split) {
        String[] data = s.split("=");
        conf.properties.put(data[0], data[1]);
      }
    }
    catch (Exception e) {
      throw new InternalException(e);
    }
    return conf;
  }
802585
public Map<String, List<? extends SipApplicationRouterInfo>> parse(Properties properties) throws ParseException {
        this.properties = properties;
        return parse();
    }
1305919
public void parse(String string) {
    if (string == null) {
      throw new NullPointerException("string is null");
    }
    int bufferSize = Math.max(MIN_BUFFER_SIZE, Math.min(DEFAULT_BUFFER_SIZE, string.length()));
    try {
      parse(new StringReader(string), bufferSize);
    } catch (IOException exception) {
      // StringReader does not throw IOException
      throw new RuntimeException(exception);
    }
  }
376170
public <T> T parse(String in, Class<T> mapTo) throws ParseException {
		return getPString().parse(in, JSONValue.defaultReader.getMapper(mapTo));
	}
652596
@Override
    public String parse(final String threshold, final RangeConfig tc) throws RangeException {

        if (threshold == null) {
            throw new RangeException("Range can't be null");
        }

        Stage currentStage = this;

        String parsedThreshold = threshold;

        boolean stageParsed;

        while (parsedThreshold.length() != 0) {
            stageParsed = false;
            for (String transitionName : currentStage.getTransitionNames()) {
                Stage transition = currentStage.getTransition(transitionName);
                if (transition.canParse(parsedThreshold)) {
                    parsedThreshold = transition.parse(parsedThreshold, tc);
                    currentStage = transition;
                    stageParsed = true;
                    break;
                }
            }

            if (!stageParsed) {
                throw new InvalidRangeSyntaxException(currentStage, parsedThreshold, threshold);
            }
        }

        if (!currentStage.isLeaf()) {
            throw new PrematureEndOfRangeException(currentStage, threshold);
        }

        return parsedThreshold;
    }
1108329
private void parse() throws ParserException {
		//skip white spaces
		skipWhitespace();
		try{
			_parse();
		}catch(Exception e){
			System.out.println("\t" + this.getClass().getSimpleName() + "->" + this.toString());
			if(!(e instanceof ParserException)){
				throw new ParserException("Error parsing", e);
			}else{
				throw (ParserException)e;
			}
		}
		skipWhitespace();
	}
967745
private void parseConfiguration(String configuration) {

        Map<String, String> configOptions = CmsWidgetUtil.parsePipeSeparatedConfigString(configuration);
        if (!configOptions.isEmpty()) {
            m_category = CmsWidgetUtil.getStringOption(configOptions, CONFIGURATION_CATEGORY, m_category);
            m_isSingleValue = !("multi".equals(
                CmsWidgetUtil.getStringOption(configOptions, CONFIGURATION_SELECTIONTYPE, "single")));
            m_children = CmsWidgetUtil.getBooleanOption(configOptions, CONFIGURATION_PARENTSELECTION);
            m_collapsed = CmsWidgetUtil.getBooleanOption(configOptions, CONFIGURATION_COLLAPSED);
            m_showWithRepository = CmsWidgetUtil.getBooleanOption(configOptions, CONFIGURATION_SHOW_WITH_REPOSITORY);
            m_refPath = CmsWidgetUtil.getStringOption(configOptions, CONFIGURATION_REFPATH, m_refPath);
        }
    }
1050668
public void parse(String s) {
        Preconditions.checkNotNull(s, "s");
        if (s.length() == 0) {
            // Nothing to do.
            return;
        }

        val pairs = s.split(pairDelimiter);
        for (String pair : pairs) {
            int delimiterPos = pair.indexOf(keyValueDelimiter);
            if (delimiterPos < 0) {
                throw new IllegalArgumentException(String.format("Invalid pair '%s' (missing key-value delimiter).", pair));
            }

            String key = pair.substring(0, delimiterPos);
            String value;
            if (delimiterPos == pair.length() - 1) {
                value = "";
            } else {
                value = pair.substring(delimiterPos + 1);
            }

            Extractor<?> e = this.extractors.get(key);
            Preconditions.checkArgument(e != null, String.format("No extractor provided for key '%s'.", key));
            e.process(value);
        }
    }
1035524
@Override
    public void parse() throws IOException, InterruptedException, SQLException, ClassNotFoundException {
        Map<String, String> seqRegionMap = VariationUtils.parseSeqRegionToMap(ensemblVariationDir);
        Map<String, String> phenotypeMap = VariationUtils.parsePhenotypeToMap(ensemblVariationDir);
        Map<String, String> sourceMap = VariationUtils.parseSourceToMap(ensemblVariationDir);
        Map<String, String> studyMap = VariationUtils.parseStudyToMap(ensemblVariationDir);
        Map<String, String> attribTypeMap = VariationUtils.parseAttribTypeToMap(ensemblVariationDir);

        Map<String, Set<String>> phenotypeToGeneList = new HashMap<>(20000);

        prepare(ensemblVariationDir);
        createPhenFeatAttribTable(ensemblVariationDir);
        raf = new RandomAccessFile(ensemblVariationDir.resolve("phenotype_feature_attrib.txt").toFile(), "r");

        VariationPhenotypeAnnotation mutation;
        String seqRegion = null;
        String phenotype = null;
        String source = null;
        String study = null;
        String externalId = null;

        String clinSignificance = null;
        List<String> associatedGenes = new ArrayList<>();
        String riskAllele = null;
        float pValue = 0.0f;
        float oddsRatio = 0.0f;

        String chunkIdSuffix = CHUNK_SIZE / 1000 + "k";

        BufferedReader br = FileUtils.newBufferedReader(ensemblVariationDir.resolve("phenotype_feature.txt.gz"), Charset.defaultCharset());
        String[] fields = null;
        String[] rafFields = null;
        String line = null;
        int count = 0;
        while ((line = br.readLine()) != null) {
            fields = line.split("\t");

            if (fields[4].equals("Variation")) {
                seqRegion = seqRegionMap.get(fields[7]);
                phenotype = phenotypeMap.get(fields[1]);
                source = sourceMap.get(fields[2]).split(",")[0];
                study = studyMap.get(fields[3]);
// anyadir type: variation, SV, ...

                clinSignificance = "";
                externalId = "";
                associatedGenes = new ArrayList<>();
                riskAllele = "";
                pValue = -1f;
                oddsRatio = -1f;
                List<String> resultPhenAnnot = queryByVariationId(Integer.parseInt(fields[0]), ensemblVariationDir);
                if (++count % 10000 == 0) {
                    System.out.println(resultPhenAnnot);
//                    if(count > 200000) break;
                }
                for (String result : resultPhenAnnot) {
                    rafFields = result.split("\t", -1);
                    switch (rafFields[1]) {
                        case "10":
                            clinSignificance = rafFields[2];
                            break;
                        case "13":
                            associatedGenes = Splitter.on(",").trimResults().splitToList(rafFields[2]);
                            break;
                        case "14":  // riskAllele
                            riskAllele = rafFields[2];
                            break;
                        case "15":  // pValue
                            pValue = (rafFields[2] != null && !rafFields[2].equalsIgnoreCase("null"))
                                    ? Float.parseFloat(rafFields[2])
                                    : -1f;
                            break;
                        case "22":  // pValue
                            externalId = rafFields[2];
                            break;
                        case "23":  // pValue
                            oddsRatio = Float.parseFloat(rafFields[2]);
                            break;
                        default:
                            break;
                    }

                }

                if (!phenotypeToGeneList.containsKey(phenotype)) {
                    phenotypeToGeneList.put(phenotype, new HashSet<String>());
                }
                phenotypeToGeneList.get(phenotype).addAll(associatedGenes);

                mutation = new VariationPhenotypeAnnotation(fields[5], seqRegion, Integer.parseInt(fields[8]),
                        Integer.parseInt(fields[9]), fields[10], phenotype, source, study, clinSignificance, associatedGenes,
                        riskAllele, pValue, oddsRatio, "", externalId);
                int chunkStart = (mutation.getStart()) / CHUNK_SIZE;
                int chunkEnd = (mutation.getEnd()) / CHUNK_SIZE;

                if (mutation.getChunkIds() == null) {
                    mutation.setChunkIds(new ArrayList<String>());
                }
                for (int i = chunkStart; i <= chunkEnd; i++) {
                    mutation.getChunkIds().add(mutation.getChromosome() + "_" + i + "_" + chunkIdSuffix);
                }
                serializer.serialize(mutation);
            }
        }
        raf.close();
        br.close();

        BufferedWriter bw = Files.newBufferedWriter(Paths.get("/tmp/phenotype.json"), Charset.defaultCharset());
//        Iterator<String> iter = phenotypeToGeneList.keySet().iterator();
//        for (Object o : iter) {
//            jsonObjectWriter.writeValueAsString(phenotypeToGeneList);
//        }
        for (Map.Entry<String, Set<String>> elem : phenotypeToGeneList.entrySet()) {
            bw.write(jsonObjectWriter.writeValueAsString(elem)
                    .replace("\"key\"", "\"phenotype\"")
                    .replace("\"value\"", "\"associatedGenes\""));
            bw.newLine();
        }
        bw.close();

        clean(ensemblVariationDir);
    }
649370
public <T> T parse(byte[] in, JsonReaderI<T> mapper) throws ParseException {
		return getPBytes().parse(in, mapper);
	}
1284137
@Override
	public Object parse(String source) throws Exception {
		Source s = sources.poll();
		final char[] chars = source.toCharArray();
		if (s == null) {
			s = new Source(chars);
		} else {
			s.set(chars);
		}
		final Object result = parseNext(s);
		if (sources.size() > Config.POOL_SIZE) {
			return result;
		}
		sources.add(s);
		return result;
	}
2180
public Ast parse(byte[] serialized) throws ParseException
	{
		try {
			return parse(new String(serialized, "utf-8"));
		} catch (UnsupportedEncodingException e) {
			throw new ParseException(e.toString());
		}
	}
1213836
@Override
  public void parse(String contents) throws SourceMapParseException {
    SourceMapObject sourceMapObject = SourceMapObjectParser.parse(contents);
    parse(sourceMapObject, null);
  }
1164549
@Override
	public Object parse(FhirContext theContext, List<QualifiedParamList> theString) throws InternalErrorException, InvalidRequestException {
		return myParamBinder.parse(theContext, getName(), theString);
	}
809309
public void parse () throws JsonParseException
  {
    _readValue ();

    // Check for trailing whitespaces
    _skipSpaces ();

    final IJsonParsePosition aStartPos = m_aPos.getClone ();

    // Check for expected end of input
    final int c = _readChar ();
    if (c != EOI)
      throw _parseEx (aStartPos, "Invalid character " + _getPrintableChar (c) + " after JSON root object");
  }
1120282
private final ParseTreeNode parse() throws ParserException {
	try {
	    createActionStack();
	    return LRTokenStreamConverter.convert(getTokenStream(), getGrammar(), actionStack);
	} catch (GrammarException e) {
	    logger.error(e.getMessage(), e);
	    throw new ParserException(e.getMessage());
	}
    }
140078
public static void parse(final String str, final ShortcodeParser.Handler handler) {
      ShortcodeParser.parse(str, handler);
   }