예제 #1
0
  private String getEvidence() throws ObjectStoreException {

    if (evidenceRefId == null) {

      Item item = createItem("OrthologueEvidenceCode");
      item.setAttribute("abbreviation", EVIDENCE_CODE_ABBR);
      item.setAttribute("name", EVIDENCE_CODE_NAME);
      try {
        store(item);
      } catch (ObjectStoreException e) {
        throw new ObjectStoreException(e);
      }
      String refId = item.getIdentifier();

      item = createItem("OrthologueEvidence");
      item.setReference("evidenceCode", refId);
      try {
        store(item);
      } catch (ObjectStoreException e) {
        throw new ObjectStoreException(e);
      }

      evidenceRefId = item.getIdentifier();
    }
    return evidenceRefId;
  }
예제 #2
0
  private Integer createGoAnnotation(
      String productIdentifier,
      String productType,
      String termIdentifier,
      Item organism,
      String qualifier,
      String withText,
      String dataSourceCode)
      throws ObjectStoreException {
    Item goAnnotation = createItem(annotationClassName);
    goAnnotation.setReference("subject", productIdentifier);
    goAnnotation.setReference("ontologyTerm", termIdentifier);

    if (!StringUtils.isEmpty(qualifier)) {
      goAnnotation.setAttribute("qualifier", qualifier);
    }

    // with objects
    if (!StringUtils.isEmpty(withText)) {
      goAnnotation.setAttribute("withText", withText);
      List<String> with = createWithObjects(withText, organism, dataSourceCode);
      if (!with.isEmpty()) {
        goAnnotation.addCollection(new ReferenceList("with", with));
      }
    }

    goAnnotation.addToCollection("dataSets", getDataset(dataSourceCode));

    if ("gene".equals(productType)) {
      addProductCollection(productIdentifier, goAnnotation.getIdentifier());
    }
    Integer storedAnnotationId = store(goAnnotation);
    return storedAnnotationId;
  }
예제 #3
0
  private String getGene(String identifierType, String id, String taxonId)
      throws ObjectStoreException {
    String identifier = id;

    if (rslv != null && rslv.hasTaxon(taxonId)) {
      identifier = resolveGene(identifier, taxonId);
      if (identifier == null) {
        return null;
      }
    }
    String refId = identifiersToGenes.get(identifier);
    if (refId == null) {
      Item gene = createItem("Gene");
      refId = gene.getIdentifier();
      gene.setAttribute(identifierType, identifier);
      gene.setReference("organism", getOrganism(taxonId));
      identifiersToGenes.put(identifier, refId);
      try {
        store(gene);
      } catch (ObjectStoreException e) {
        throw new ObjectStoreException(e);
      }
    }
    return refId;
  }
예제 #4
0
 /**
  * Produce random data.
  *
  * <p>{@inheritDoc}
  */
 public void process(Reader inputFile) throws Exception {
   Random random = new Random();
   Set doneValues = new HashSet();
   long time = System.currentTimeMillis();
   for (int i = 0; i < count / 2; i++) {
     Item itemTo = createItem("ReferenceTo2");
     Item itemFrom = createItem("ReferenceFrom2");
     Integer firstInt;
     do {
       firstInt = new Integer(random.nextInt());
     } while (doneValues.contains(firstInt));
     doneValues.add(firstInt);
     itemTo.setAttribute("att", "" + firstInt);
     itemFrom.setReference("ref", itemTo.getIdentifier());
     getItemWriter().store(ItemHelper.convert(itemFrom));
     getItemWriter().store(ItemHelper.convert(itemTo));
   }
   long now = System.currentTimeMillis();
   LOG.info(
       "Finished generating "
           + count
           + " objects at "
           + ((60000L * count) / (now - time))
           + " objects per minute ("
           + (now - time)
           + " ms total)");
 }
예제 #5
0
 private void setImage(Item result, String img) {
   if (!imgs.containsKey(img)) {
     Item item = createItem("Image");
     item.setAttribute("url", img);
     imgs.put(img, item);
     result.addToCollection("images", item.getIdentifier());
   }
 }
예제 #6
0
 private void storeEvidenceCode(String code) throws ObjectStoreException {
   if (evidenceCodes.get(code) == null) {
     Item item = createItem("DOEvidenceCode");
     item.setAttribute("code", code);
     evidenceCodes.put(code, item.getIdentifier());
     store(item);
   }
 }
예제 #7
0
  /**
   * Create and store a BioEntity item on the first time called.
   *
   * @param type gene
   * @param primaryId the gene primaryIdentifier
   * @param symbol the gene symbol
   * @throws ObjectStoreException
   */
  private void createBioEntity(String type, String primaryId, String symbol)
      throws ObjectStoreException {
    Item bioentity = null;

    bioentity = createItem("Gene");
    bioentity.setAttribute("primaryIdentifier", primaryId);
    bioentity.setAttribute("symbol", symbol);
    store(bioentity);

    geneItems.put(primaryId, bioentity.getIdentifier());
  }
예제 #8
0
  private String makeProductKey(
      String identifier, String type, Item organism, boolean createOrganism) {
    if (type == null) {
      throw new IllegalArgumentException(
          "No type provided when creating " + organism + ": " + identifier);
    } else if (identifier == null) {
      throw new IllegalArgumentException(
          "No identifier provided when creating " + organism + ": " + type);
    }

    return identifier + type.toLowerCase() + ((createOrganism) ? organism.getIdentifier() : "");
  }
예제 #9
0
 private void setStages() throws ObjectStoreException {
   Item item = createItem("Ontology");
   item.setAttribute("name", "Fly Development");
   store(item);
   stages = new String[17];
   for (int i = 1; i <= 16; i++) {
     Item stage = createItem("DevelopmentTerm");
     stage.setAttribute("name", "embryonic stage " + i);
     stage.setReference("ontology", item);
     stages[i] = stage.getIdentifier();
     store(stage);
   }
 }
예제 #10
0
  /**
   * For a collection of items return the count of given class name.
   *
   * @param items the Item collection to count
   * @return the count for a given classname in the collection
   */
  public static int countItemByClass(Collection<Item> items, String className) {
    Map<String, List> counts = new TreeMap<String, List>();
    for (Item item : items) {
      List<String> clsItems = counts.get(item.getClassName());
      if (clsItems == null) {
        clsItems = new ArrayList<String>();
        counts.put(item.getClassName(), clsItems);
      }
      clsItems.add(item.getIdentifier());
    }

    return counts.get(className).size();
  }
  /**
   * @param proteinId
   * @param modSite
   * @param modType
   * @param source
   * @param pmid
   * @throws ObjectStoreException
   * @throws Exception
   */
  private void newProduct(
      String experiment, String proteinId, String value, String units, String pmid)
      throws ObjectStoreException, Exception {

    Item protein = getProteinItem(proteinId);

    Item pmods = getProteinHalfLife(experiment, value, units, pmid);
    protein.addToCollection("proteinHalfLife", pmods.getIdentifier());

    // Item pmods2 = getProteinHalfLife(experiment, valueMins, stringMinutes, pmid);
    // protein.addToCollection("proteinHalfLife", pmods2.getIdentifier());

  }
예제 #12
0
 private String getDataset(String code) throws ObjectStoreException {
   String dataSetIdentifier = dataSets.get(code);
   if (dataSetIdentifier == null) {
     String dataSourceName = getDataSourceName(code);
     String title = "DO Annotation from " + dataSourceName;
     Item item = createItem("DataSet");
     item.setAttribute("name", title);
     item.setReference("dataSource", getDataSource(dataSourceName));
     dataSetIdentifier = item.getIdentifier();
     dataSets.put(code, dataSetIdentifier);
     store(item);
   }
   return dataSetIdentifier;
 }
예제 #13
0
  /**
   * Constructor
   *
   * @param writer ItemWriter
   * @param seqClsName The class of the coordinate system for this GFF3 file (generally Chromosome)
   * @param orgTaxonId The taxon ID of the organism we are loading
   * @param dataSourceName name for dataSource
   * @param dataSetTitle title for dataSet
   * @param tgtModel the model to create items in
   * @param handler object to perform optional additional operations per GFF3 line
   * @param sequenceHandler the GFF3SeqHandler use to create sequence Items
   * @throws ObjectStoreException if something goes wrong
   */
  public GFF3Converter(
      ItemWriter writer,
      String seqClsName,
      String orgTaxonId,
      String dataSourceName,
      String dataSetTitle,
      Model tgtModel,
      GFF3RecordHandler handler,
      GFF3SeqHandler sequenceHandler)
      throws ObjectStoreException {
    super(writer, tgtModel);
    this.seqClsName = seqClsName;
    this.orgTaxonId = orgTaxonId;
    this.tgtModel = tgtModel;
    this.handler = handler;
    this.sequenceHandler = sequenceHandler;

    organism = getOrganism();
    dataSource = getDataSourceItem(dataSourceName);
    dataSet = getDataSetItem(dataSetTitle, null, null, dataSource);

    if (sequenceHandler == null) {
      this.sequenceHandler = new GFF3SeqHandler();
    }

    setStoreHook(
        new BioStoreHook(
            tgtModel,
            dataSet.getIdentifier(),
            dataSource.getIdentifier(),
            BioConverterUtil.getOntology(this)));

    handler.setConverter(this);
    handler.setIdentifierMap(identifierMap);
    handler.setOrganism(organism);
    readConfig();
  }
예제 #14
0
  /**
   * For a collection of items return a string containing counts of each item classname - useful for
   * degugging tests.
   *
   * @param items the Item collection to count
   * @return a formatted string with counts for each classname in the collection
   */
  public static String countItemClasses(Collection<Item> items) {
    Map<String, List> counts = new TreeMap<String, List>();
    for (Item item : items) {
      List<String> clsItems = counts.get(item.getClassName());
      if (clsItems == null) {
        clsItems = new ArrayList<String>();
        counts.put(item.getClassName(), clsItems);
      }
      clsItems.add(item.getIdentifier());
    }

    StringBuffer sb = new StringBuffer();
    for (Map.Entry<String, List> entry : counts.entrySet()) {
      sb.append(entry.getKey() + " - " + entry.getValue().size() + " " + entry.getValue() + ENDL);
    }
    return sb.toString();
  }
예제 #15
0
 private void setRefsAndCollections(List<String> parents, Item feature) {
   String clsName = feature.getClassName();
   Map<String, String> refsAndCollections = handler.getRefsAndCollections();
   if (refsAndCollections != null
       && refsAndCollections.containsKey(clsName)
       && parents != null
       && !parents.isEmpty()) {
     ClassDescriptor cld =
         tgtModel.getClassDescriptorByName(tgtModel.getPackageName() + "." + clsName);
     String refName = refsAndCollections.get(clsName);
     Iterator<String> parentIter = parents.iterator();
     if (cld.getReferenceDescriptorByName(refName, true) != null) {
       String parent = parentIter.next();
       feature.setReference(refName, getRefId(parent));
       if (parentIter.hasNext()) {
         String primaryIdent = feature.getAttribute("primaryIdentifier").getValue();
         throw new RuntimeException(
             "Feature has multiple relations for reference: "
                 + refName
                 + " for feature: "
                 + feature.getClassName()
                 + ", "
                 + feature.getIdentifier()
                 + ", "
                 + primaryIdent);
       }
     } else if (cld.getCollectionDescriptorByName(refName, true) != null) {
       List<String> refIds = new ArrayList<String>();
       while (parentIter.hasNext()) {
         refIds.add(getRefId(parentIter.next()));
       }
       feature.setCollection(refName, refIds);
     } else if (parentIter.hasNext()) {
       throw new RuntimeException(
           "No '"
               + refName
               + "' reference/collection found in "
               + "class: "
               + clsName
               + " - is map configured correctly?");
     }
   }
 }
예제 #16
0
  private void storeEvidence() throws ObjectStoreException {
    for (Set<Evidence> annotationEvidence : goTermGeneToEvidence.values()) {
      List<String> evidenceRefIds = new ArrayList<String>();
      Integer goAnnotationRefId = null;
      for (Evidence evidence : annotationEvidence) {
        Item goevidence = createItem("DOEvidence");
        goevidence.setReference("code", evidenceCodes.get(evidence.getEvidenceCode()));
        List<String> publicationEvidence = evidence.getPublications();
        if (!publicationEvidence.isEmpty()) {
          goevidence.setCollection("publications", publicationEvidence);
        }
        store(goevidence);
        evidenceRefIds.add(goevidence.getIdentifier());
        goAnnotationRefId = evidence.getStoredAnnotationId();
      }

      ReferenceList refIds = new ReferenceList("evidence", new ArrayList<String>(evidenceRefIds));
      store(refIds, goAnnotationRefId);
    }
  }
예제 #17
0
  private String newGoTerm(String identifier, String dataSourceCode) throws ObjectStoreException {

    String goId = resolveTerm(identifier);

    if (goId == null) {
      return null;
    }

    String goTermIdentifier = goTerms.get(goId);
    if (goTermIdentifier == null) {
      Item item = createItem(termClassName);
      item.setAttribute("identifier", goId);
      item.addToCollection("dataSets", getDataset(dataSourceCode));
      store(item);

      goTermIdentifier = item.getIdentifier();
      goTerms.put(goId, goTermIdentifier);
    }
    return goTermIdentifier;
  }
예제 #18
0
 private String newPublication(String codes) throws ObjectStoreException {
   String pubRefId = null;
   String[] array = codes.split("[|]");
   for (int i = 0; i < array.length; i++) {
     if (array[i].startsWith("PMID:")) {
       String pubMedId = array[i].substring(5);
       if (StringUtil.allDigits(pubMedId)) {
         pubRefId = publications.get(pubMedId);
         if (pubRefId == null) {
           Item item = createItem("Publication");
           item.setAttribute("pubMedId", pubMedId);
           pubRefId = item.getIdentifier();
           publications.put(pubMedId, pubRefId);
           store(item);
         }
         return pubRefId;
       }
     }
   }
   return null;
 }
예제 #19
0
 private Item getLocation(GFF3Record record, String refId, Item seq, ClassDescriptor cd) {
   Item location = createItem("Location");
   int start = record.getStart();
   int end = record.getEnd();
   if (record.getStart() < record.getEnd()) {
     location.setAttribute("start", String.valueOf(start));
     location.setAttribute("end", String.valueOf(end));
   } else {
     location.setAttribute("start", String.valueOf(end));
     location.setAttribute("end", String.valueOf(start));
   }
   if (record.getStrand() != null && "+".equals(record.getStrand())) {
     location.setAttribute("strand", "1");
   } else if (record.getStrand() != null && "-".equals(record.getStrand())) {
     location.setAttribute("strand", "-1");
   } else {
     location.setAttribute("strand", "0");
   }
   location.setReference("locatedOn", seq.getIdentifier());
   location.setReference("feature", refId);
   location.addToCollection("dataSets", dataSet);
   return location;
 }
예제 #20
0
  /**
   * process GFF3 record and give a xml presentation
   *
   * @param record GFF3Record
   * @throws ObjectStoreException if an error occurs storing items
   * @throws IOException
   */
  public void process(GFF3Record record) throws ObjectStoreException {
    String term = record.getType();

    if (config_exclude != null
        && !config_exclude.isEmpty()) { // don't process terms in the exclude list
      if (config_exclude.containsKey(this.orgTaxonId)) {
        if (config_exclude.get(this.orgTaxonId).contains(term)) {
          return;
        }
      }
    }

    if (config_term != null && !config_term.isEmpty()) { // otherwise all terms are processed
      if (config_term.containsKey(this.orgTaxonId)) {
        if (!config_term.get(this.orgTaxonId).contains(term)) {
          return;
        }
      }
    }

    // By default, use ID field in attributes
    String primaryIdentifier = record.getId();
    // If pid set in gff_config.propeties, look for the attribute field, e.g. locus_tag
    if (config_attr.containsKey(this.orgTaxonId)) {
      if (config_attr.get(this.orgTaxonId).containsKey("primaryIdentifier")) {
        String cls = config_attr_class.get(this.orgTaxonId).get("primaryIdentifier");
        if ("all".equals(cls) || term.equals(cls)) {
          String pidAttr = config_attr.get(this.orgTaxonId).get("primaryIdentifier");
          if (pidAttr.contains("Dbxref") && record.getDbxrefs() != null) {
            String pidAttrPrefix = pidAttr.split("\\.")[1];
            for (Iterator<?> i = record.getDbxrefs().iterator(); i.hasNext(); ) {
              String xref = (String) i.next();
              if (xref.contains(pidAttrPrefix)) {
                primaryIdentifier = xref.split(":")[1];
                break;
              }
            }
          } else {
            if (record.getAttributes().get(pidAttr) != null) {
              primaryIdentifier = record.getAttributes().get(pidAttr).get(0);
            }
          }
        }
      }
    }

    String refId = identifierMap.get(primaryIdentifier);

    // get rid of previous record Items from handler
    handler.clear();

    Item seq = getSeq(record.getSequenceID());

    String className = TypeUtil.javaiseClassName(term);
    String fullClassName = tgtModel.getPackageName() + "." + className;

    ClassDescriptor cd = tgtModel.getClassDescriptorByName(fullClassName);

    if (cd == null) {
      throw new IllegalArgumentException(
          "no class found in model for: "
              + className
              + " (original GFF record type: "
              + term
              + ") for "
              + "record: "
              + record);
    }

    Set<Item> synonymsToAdd = new HashSet<Item>();

    Item feature = null;

    // new feature
    if (refId == null) {
      feature = createItem(className);
      refId = feature.getIdentifier();
    }

    if (!"chromosome".equals(term) && seq != null) {
      boolean makeLocation =
          record.getStart() >= 1
              && record.getEnd() >= 1
              && !dontCreateLocations
              && handler.createLocations(record);
      if (makeLocation) {
        Item location = getLocation(record, refId, seq, cd);
        if (feature == null) {
          // this feature has already been created and stored
          // we only wanted the location, we're done here.
          store(location);
          return;
        }
        int length = getLength(record);
        feature.setAttribute("length", String.valueOf(length));
        handler.setLocation(location);
        if ("Chromosome".equals(seqClsName)
            && (cd.getFieldDescriptorByName("chromosome") != null)) {
          feature.setReference("chromosome", seq.getIdentifier());
          feature.setReference("chromosomeLocation", location);
        }
      }
    }

    if (feature == null) {
      // this feature has already been created and stored
      // feature with discontinous location, this location wasn't valid for some reason
      return;
    }

    if (primaryIdentifier != null) {
      feature.setAttribute("primaryIdentifier", primaryIdentifier);
    }
    handler.setFeature(feature);
    identifierMap.put(primaryIdentifier, feature.getIdentifier());

    List<?> names = record.getNames();
    String symbol = null;
    List<String> synonyms = new ArrayList<String>();

    // get the attribute set for symbol
    if (config_attr.containsKey(this.orgTaxonId)) {
      if (config_attr.get(this.orgTaxonId).containsKey("symbol")) {
        String cls = config_attr_class.get(this.orgTaxonId).get("symbol");
        if ("all".equals(cls) || term.equals(cls)) {
          String symbolAttr = config_attr.get(this.orgTaxonId).get("symbol");
          if (symbolAttr.contains("Dbxref") && record.getDbxrefs() != null) {
            String symbolAttrPrefix = symbolAttr.split("\\.")[1];
            for (Iterator<?> i = record.getDbxrefs().iterator(); i.hasNext(); ) {
              String xref = (String) i.next();
              if (xref.contains(symbolAttrPrefix)) {
                symbol = xref.split(":")[1];
                break;
              }
            }
          } else {
            if (record.getAttributes().get(symbolAttr) != null) {
              symbol = record.getAttributes().get(symbolAttr).get(0);
            }
          }
        }
      }
    }

    // get the attribute set for synonym
    if (config_attr.containsKey(this.orgTaxonId)) {
      if (config_attr.get(this.orgTaxonId).containsKey("synonym")) {
        String cls = config_attr_class.get(this.orgTaxonId).get("synonym");
        if ("all".equals(cls) || term.equals(cls)) {
          String synonymAttr = config_attr.get(this.orgTaxonId).get("synonym");
          if (synonymAttr.contains("Dbxref") && record.getDbxrefs() != null) {
            String synonymAttrPrefix = synonymAttr.split("\\.")[1];
            Set<String> synSet = new HashSet<String>();
            for (Iterator<?> i = record.getDbxrefs().iterator(); i.hasNext(); ) {
              String xref = (String) i.next();
              if (xref.contains(synonymAttrPrefix)) {
                synSet.add(xref.split(":")[1]);
              }
            }
            synonyms.addAll(synSet);
          } else {
            synonyms = record.getAttributes().get(synonymAttr);
          }
          // synonyms.removeAll(Collections.singleton(null));
        }
      }
    }

    if (names != null) {
      setNames(names, symbol, synonyms, synonymsToAdd, primaryIdentifier, feature, cd);
    }

    // Other attributes
    List<String> primeAttrList = Arrays.asList("primaryIdentifier", "symbol", "synonym");

    if (config_attr.containsKey(this.orgTaxonId)) {
      Map<String, String> attrMapOrg = config_attr.get(this.orgTaxonId);
      Map<String, String> attrMapClone = new HashMap<String, String>();
      // Deep copy of a map
      for (Entry<String, String> e : attrMapOrg.entrySet()) {
        attrMapClone.put(e.getKey(), e.getValue());
      }

      for (String pa : primeAttrList) {
        attrMapClone.remove(pa);
      }

      for (Entry<String, String> e : attrMapClone.entrySet()) {
        String cls = config_attr_class.get(this.orgTaxonId).get(e.getKey());
        if ("all".equals(cls) || term.equals(cls)) {
          String attr = e.getValue();
          if (attr.contains("Dbxref") && record.getDbxrefs() != null) {
            String attrPrefix = attr.split("\\.")[1];
            for (Iterator<?> i = record.getDbxrefs().iterator(); i.hasNext(); ) {
              String xref = (String) i.next();
              if (xref.contains(attrPrefix)) {
                if (feature.checkAttribute(e.getKey())) {
                  feature.setAttribute(e.getKey(), xref.split(":")[1]);
                }
                break;
              }
            }
          } else {
            if (record.getAttributes().get(attr) != null) {
              String attrVal = record.getAttributes().get(attr).get(0);
              if (attrVal != null) {
                if (feature.checkAttribute(e.getKey())) {
                  feature.setAttribute(e.getKey(), attrVal);
                }
              }
            }
          }
        }
      }
    }

    List<String> parents = record.getParents();
    if (parents != null && !parents.isEmpty()) {
      setRefsAndCollections(parents, feature);
    }

    feature.addReference(getOrgRef());
    feature.addToCollection("dataSets", dataSet);

    handler.addDataSet(dataSet);
    Double score = record.getScore();
    if (score != null && !"".equals(String.valueOf(score))) {
      feature.setAttribute("score", String.valueOf(score));
      feature.setAttribute("scoreType", record.getSource());
    }
    for (Item synonym : synonymsToAdd) {
      handler.addItem(synonym);
    }
    handler.process(record);
    if (handler.getDataSetReferenceList().getRefIds().size() > 0) {
      feature.addCollection(handler.getDataSetReferenceList());
    }
    handler.clearDataSetReferenceList();
    if (handler.getPublicationReferenceList().getRefIds().size() > 0) {
      feature.addCollection(handler.getPublicationReferenceList());
    }
    handler.clearPublicationReferenceList();

    try {
      Iterator<Item> iter = handler.getItems().iterator();
      while (iter.hasNext()) {
        store(iter.next());
      }
    } catch (ObjectStoreException e) {
      LOG.error("Problem writing item to the itemwriter");
      throw e;
    }
  }
예제 #21
0
  /**
   * Process the csv file
   *
   * @param reader the Reader
   * @see DataConverter#process
   * @throws Exception if something goes wrong
   */
  @Override
  public void process(Reader reader) throws Exception {
    if (rslv == null) {
      rslv = IdResolverService.getFlyIdResolver();
    }

    Iterator<String[]> it = FormattedTextParser.parseTabDelimitedReader(reader);

    while (it.hasNext()) {

      String[] lineBits = it.next();
      String geneCG = lineBits[0];

      if (!geneCG.startsWith("CG")) {
        // ignore clones for now
        continue;
      }

      // Try to create/fetch gene, if null the IdResolver failed so do nothing for this row
      Item gene = getGene(geneCG);
      if (gene == null) {
        continue;
      }

      String stage = lineBits[1];

      String resultKey = geneCG + stage;
      Item result = getResult(resultKey, gene.getIdentifier(), pub.getIdentifier(), stage);

      Integer stageNumber = null;
      try {
        stageNumber = new Integer(stage);
      } catch (NumberFormatException e) {
        // bad line in file, just keep going
        continue;
      }
      result.setAttribute("stageRange", STAGE_LABELS[stageNumber.intValue()] + " (BDGP in situ)");

      if (lineBits.length > 2) {
        String image = lineBits[2];
        if (StringUtils.isNotEmpty(image)) {
          setImage(result, URL + image);
        }
      }
      if (lineBits.length > 3) {
        String term = lineBits[3];
        Item termItem = getTerm(term);
        if (termItem != null) {
          result.addToCollection("mRNAExpressionTerms", termItem);
        }
        if ("no staining".equals(term)) {
          result.setAttribute("expressed", "false");
        }
      }
    }

    for (Item result : results.values()) {
      if (!result.hasCollection("mRNAExpressionTerms")
          || result.getCollection("mRNAExpressionTerms").getRefIds().isEmpty()) {
        result.setAttribute("expressed", "false");
      }
    }

    storeAll(imgs);
    storeAll(results);
  }
예제 #22
0
  private String newProduct(
      String identifier,
      String type,
      Item organism,
      String dataSourceCode,
      boolean createOrganism,
      String field)
      throws ObjectStoreException {
    String idField = field;
    String accession = identifier;
    String clsName = null;
    // find gene attribute first to see if organism should be part of key
    if ("gene".equalsIgnoreCase(type)) {
      clsName = "Gene";
      String taxonId = organism.getAttribute("taxonId").getValue();
      if (idField == null) {
        idField = configs.get(taxonId).identifier;
        if (idField == null) {
          throw new RuntimeException(
              "Could not find a identifier property for taxon: "
                  + taxonId
                  + " check properties file: "
                  + PROP_FILE);
        }
      }

      // if a Dmel gene we need to use FlyBaseIdResolver to find a current id
      if ("7227".equals(taxonId)) {
        IdResolver resolver = flybaseResolverFactory.getIdResolver(false);
        if (resolver != null) {
          int resCount = resolver.countResolutions(taxonId, accession);

          if (resCount != 1) {
            LOG.info(
                "RESOLVER: failed to resolve gene to one identifier, "
                    + "ignoring gene: "
                    + accession
                    + " count: "
                    + resCount
                    + " FBgn: "
                    + resolver.resolveId(taxonId, accession));
            return null;
          }
          accession = resolver.resolveId(taxonId, accession).iterator().next();
        }
      }
    } else if ("protein".equalsIgnoreCase(type)) {
      // TODO use values in config
      clsName = "Protein";
      idField = "primaryAccession";
    } else {
      String typeCls = TypeUtil.javaiseClassName(type);

      if (getModel().getClassDescriptorByName(typeCls) != null) {
        Class<?> cls = getModel().getClassDescriptorByName(typeCls).getType();
        if (BioEntity.class.isAssignableFrom(cls)) {
          clsName = typeCls;
        }
      }
      if (clsName == null) {
        throw new IllegalArgumentException("Unrecognised annotation type '" + type + "'");
      }
    }

    boolean includeOrganism;
    if ("primaryIdentifier".equals(idField) || "protein".equals(type)) {
      includeOrganism = false;
    } else {
      includeOrganism = createOrganism;
    }
    String key = makeProductKey(accession, type, organism, includeOrganism);

    // Have we already seen this product somewhere before?
    // if so, return the product rather than creating a new one...
    if (productMap.containsKey(key)) {
      return productMap.get(key);
    }

    // if a Dmel gene we need to use FlyBaseIdResolver to find a current id

    Item product = createItem(clsName);
    if (organism != null && createOrganism) {
      product.setReference("organism", organism.getIdentifier());
    }
    product.setAttribute(idField, accession);

    String dataSetIdentifier = getDataset(dataSourceCode);
    product.addToCollection("dataSets", dataSetIdentifier);

    Integer storedProductId = store(product);
    storedProductIds.put(product.getIdentifier(), storedProductId);
    productMap.put(key, product.getIdentifier());
    return product.getIdentifier();
  }
예제 #23
0
 /**
  * Create and add a synonym Item from the given information.
  *
  * @param subject the subject of the new Synonym
  * @param value the Synonym value
  * @return the new Synonym Item
  */
 public Item getSynonym(Item subject, String value) {
   Item synonym = createItem("Synonym");
   synonym.setAttribute("value", value);
   synonym.setReference("subject", subject.getIdentifier());
   return synonym;
 }
예제 #24
0
  /**
   * process GFF3 record and give a xml presentation
   *
   * @param record GFF3Record
   * @throws ObjectStoreException if an error occurs storing items
   */
  public void process(GFF3Record record) throws ObjectStoreException {
    String identifier = record.getId();
    String refId = identifierMap.get(identifier);

    // get rid of previous record Items from handler
    handler.clear();
    List<?> names = record.getNames();
    Item seq = getSeq(record.getSequenceID());

    String term = record.getType();
    String className = TypeUtil.javaiseClassName(term);
    String fullClassName = tgtModel.getPackageName() + "." + className;

    ClassDescriptor cd = tgtModel.getClassDescriptorByName(fullClassName);

    if (cd == null) {
      throw new IllegalArgumentException(
          "no class found in model for: "
              + className
              + " (original GFF record type: "
              + term
              + ") for "
              + "record: "
              + record);
    }

    Set<Item> synonymsToAdd = new HashSet<Item>();

    Item feature = null;

    // new feature
    if (refId == null) {
      feature = createItem(className);
      refId = feature.getIdentifier();
    }

    if (!"chromosome".equals(record.getType()) && seq != null) {
      boolean makeLocation =
          record.getStart() >= 1
              && record.getEnd() >= 1
              && !dontCreateLocations
              && handler.createLocations(record);
      if (makeLocation) {
        Item location = getLocation(record, refId, seq, cd);
        if (feature == null) {
          // this feature has already been created and stored
          // we only wanted the location, we're done here.
          store(location);
          return;
        }
        int length = getLength(record);
        feature.setAttribute("length", String.valueOf(length));
        handler.setLocation(location);
        if ("Chromosome".equals(seqClsName)
            && (cd.getFieldDescriptorByName("chromosome") != null)) {
          feature.setReference("chromosome", seq.getIdentifier());
          feature.setReference("chromosomeLocation", location);
        }
      }
    }

    if (feature == null) {
      // this feature has already been created and stored
      // feature with discontinous location, this location wasn't valid for some reason
      return;
    }

    if (identifier != null) {
      feature.setAttribute("primaryIdentifier", identifier);
    }
    handler.setFeature(feature);
    identifierMap.put(identifier, feature.getIdentifier());
    if (names != null) {
      setNames(names, synonymsToAdd, record.getId(), feature, cd);
    }

    List<String> parents = record.getParents();
    if (parents != null && !parents.isEmpty()) {
      setRefsAndCollections(parents, feature);
    }

    feature.addReference(getOrgRef());
    feature.addToCollection("dataSets", dataSet);

    handler.addDataSet(dataSet);
    Double score = record.getScore();
    if (score != null && !"".equals(String.valueOf(score))) {
      feature.setAttribute("score", String.valueOf(score));
      feature.setAttribute("scoreType", record.getSource());
    }
    for (Item synonym : synonymsToAdd) {
      handler.addItem(synonym);
    }
    handler.process(record);
    if (handler.getDataSetReferenceList().getRefIds().size() > 0) {
      feature.addCollection(handler.getDataSetReferenceList());
    }
    handler.clearDataSetReferenceList();
    if (handler.getPublicationReferenceList().getRefIds().size() > 0) {
      feature.addCollection(handler.getPublicationReferenceList());
    }
    handler.clearPublicationReferenceList();

    try {
      Iterator<Item> iter = handler.getItems().iterator();
      while (iter.hasNext()) {
        store(iter.next());
      }
    } catch (ObjectStoreException e) {
      LOG.error("Problem writing item to the itemwriter");
      throw e;
    }
  }