示例#1
0
  private void parseHeader(String lineHeader) {
    String header = lineHeader.substring(1, lineHeader.length());
    String[] allFields = header.split("\t");

    allFields = Arrays.copyOfRange(allFields, 6, allFields.length);
    for (int i = 0; i < allFields.length; i++) {
      ped.getFields().put(allFields[i], i);
    }
  }
示例#2
0
  @Override
  public List<Pedigree> read() {
    String line;
    Individual ind, father, mother;
    String[] fields;
    String sampleId, familyId, fatherId, motherId, sex, phenotype;
    Set<Individual> family;
    String[] auxFields = null;

    try {
      while ((line = reader.readLine()) != null) {
        if (line.startsWith("#")) {
          this.parseHeader(line);
        } else {
          fields = line.split("\t", -1);
          familyId = fields[0];
          sampleId = fields[1];
          fatherId = fields[2];
          motherId = fields[3];
          sex = fields[4];
          phenotype = fields[5];

          if (fields.length > 6) {
            auxFields = Arrays.copyOfRange(fields, 6, fields.length);
          }

          family = ped.getFamily(familyId);
          if (family == null) {
            family = new TreeSet<>();
            ped.addFamily(familyId, family);
          }

          ind = new Individual(sampleId, familyId, null, null, sex, phenotype, auxFields);
          ind.setFatherId(fatherId);
          ind.setMotherId(motherId);
          ped.addIndividual(ind);
          family.add(ind);
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    for (Map.Entry<String, Individual> entry : ped.getIndividuals().entrySet()) {
      ind = entry.getValue();
      father = ped.getIndividual(ind.getFatherId());
      mother = ped.getIndividual(ind.getMotherId());

      ind.setFather(father);
      ind.setMother(mother);

      if (mother != null) {
        mother.addChild(ind);
      }
      if (father != null) {
        father.addChild(ind);
      }
    }

    return Arrays.asList(ped);
  }