Esempio n. 1
0
  private void updateFromFeature(Feature feature) {
    GridBagConstraints c = new GridBagConstraints();
    JPanel gridPanel = new JPanel(new GridBagLayout());
    gridPanel.setBackground(Color.white);

    //
    // literature & dbxref
    literatureTextArea = new QualifierTextArea();
    literatureTextArea.setBorder(BorderFactory.createLineBorder(Color.gray));
    dbxrefTextArea = new QualifierTextArea();
    dbxrefTextArea.setBorder(BorderFactory.createLineBorder(Color.gray));

    literatureTextArea
        .getDocument()
        .addDocumentListener(new TextAreaDocumentListener(literatureTextArea));

    dbxrefTextArea.getDocument().addDocumentListener(new TextAreaDocumentListener(dbxrefTextArea));

    final QualifierVector qualifiers = feature.getQualifiers().copy();
    final StringBuffer litBuffer = new StringBuffer();
    final StringBuffer dbxrefBuffer = new StringBuffer();

    for (int i = 0; i < qualifiers.size(); ++i) {
      Qualifier this_qualifier = (Qualifier) qualifiers.elementAt(i);
      if (this_qualifier.getName().equals("literature"))
        appendToBuffer(this_qualifier.getValues(), litBuffer);
      else if (this_qualifier.getName().equalsIgnoreCase("Dbxref"))
        appendToBuffer(this_qualifier.getValues(), dbxrefBuffer);
    }

    c.gridx = 0;
    c.gridy = 0;
    c.ipadx = 5;
    c.ipady = 5;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.fill = GridBagConstraints.NONE;
    gridPanel.add(new JLabel("Literature"), c);
    c.gridx = 1;
    gridPanel.add(literatureTextArea, c);

    c.gridx = 0;
    c.gridy = 1;
    gridPanel.add(new JLabel("Dbxref"), c);
    c.gridx = 1;
    gridPanel.add(dbxrefTextArea, c);

    add(gridPanel);

    literatureTextArea.setText(litBuffer.toString() + "\n");
    dbxrefTextArea.setText(dbxrefBuffer.toString() + "\n");
  }
  public QualifierPanel(Feature feature, String title) {
    super(new GridBagLayout());

    this.feature = feature;

    TitledBorder titleBorder =
        BorderFactory.createTitledBorder(
            BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), title);
    titleBorder.setTitleJustification(TitledBorder.LEFT);
    titleBorder.setTitleColor(TransferAnnotationTool.STEEL_BLUE);
    setBorder(titleBorder);

    GridBagConstraints c = new GridBagConstraints();
    c.anchor = GridBagConstraints.WEST;
    c.ipadx = 0;
    final QualifierVector qualifiers = feature.getQualifiers();

    for (int i = 0; i < qualifiers.size(); i++) {
      nrows = addQualifierComponents(qualifiers.get(i), qualifierCheckBoxes, c, nrows);
    }

    setMinimumSize(new Dimension(titleBorder.getMinimumSize(this).width, getMinimumSize().height));
  }
  /**
   * Transfer selected qualifiers to the list of features defined by the selected names.
   *
   * @param qualifierCheckBoxes - list of qualifier check boxes
   * @param geneNameTextArea - text with a list of feature names to transfer to
   * @param feature - feature to copy from
   * @param entryGroup
   * @param sameKey
   * @param overwrite
   */
  protected static int transferAnnotation(
      final Hashtable<JCheckBox, Vector<JCheckBox>> qualifierCheckBoxes,
      final Vector<JCheckBox> geneNameCheckBoxes,
      final Feature orginatingFeature,
      final EntryGroup entryGroup,
      final boolean sameKey,
      final boolean overwrite,
      final boolean setEvidenceAndWithFrom,
      final StringBuffer buff,
      final StringBuffer genesUpdated) {
    // transfer selected annotation to genes
    final QualifierVector qualifiers = orginatingFeature.getQualifiers();
    final QualifierVector qualifiersToTransfer = new QualifierVector();

    Enumeration<JCheckBox> enumQualifiers = qualifierCheckBoxes.keys();
    while (enumQualifiers.hasMoreElements()) {
      JCheckBox cb = enumQualifiers.nextElement();
      if (cb.isSelected()) {
        Vector<JCheckBox> qualifierValuesCheckBox = qualifierCheckBoxes.get(cb);
        final StringVector values = qualifiers.getQualifierByName(cb.getText()).getValues();
        StringVector valuesToTransfer = new StringVector(values);

        logger4j.debug("TRANSFER " + cb.getText());
        for (int i = 0; i < qualifierValuesCheckBox.size(); i++) {
          JCheckBox valuesCb = qualifierValuesCheckBox.get(i);
          if (!valuesCb.isSelected()) {
            valuesToTransfer.remove(valuesCb.getText());
            logger4j.debug("NOT TRANSFERING " + valuesCb.getText());
          }
        }

        if (valuesToTransfer.size() < 1) continue;

        valuesToTransfer =
            new StringVector(
                getTransferValues(
                    setEvidenceAndWithFrom, orginatingFeature, cb.getText(), valuesToTransfer));

        qualifiersToTransfer.addElement(new Qualifier(cb.getText(), valuesToTransfer));
      }
    }

    int count = 0;
    for (int i = 0; i < geneNameCheckBoxes.size(); i++) {
      if (geneNameCheckBoxes.get(i).isSelected()) count++;
    }

    if (count < 1) {
      JOptionPane.showMessageDialog(
          null, "No genes selected.", "Warning", JOptionPane.WARNING_MESSAGE);
      return -1;
    }

    String geneNames[] = new String[count];
    count = 0;
    for (int i = 0; i < geneNameCheckBoxes.size(); i++) {
      JCheckBox cb = geneNameCheckBoxes.get(i);
      if (cb.isSelected()) {
        geneNames[count] = cb.getText();
        logger4j.debug("TRANSFER ANNOTATION TO " + geneNames[count]);
        count++;
      }
    }

    final String key = orginatingFeature.getKey().getKeyString();
    final FeatureVector features = entryGroup.getAllFeatures();

    // transfer selected annotation
    entryGroup.getActionController().startAction();
    geneNames =
        transfer(
            features,
            qualifiersToTransfer,
            key,
            sameKey,
            overwrite,
            GeneUtils.isDatabaseEntry(entryGroup),
            geneNames,
            genesUpdated);
    entryGroup.getActionController().endAction();

    //
    // Commit changes to genes not in Artemis but in the database
    //
    Vector<String> genesNotFound = null;
    if (geneNames != null
        && orginatingFeature.getEntry().getEMBLEntry() instanceof DatabaseDocumentEntry) {
      DatabaseDocumentEntry db_entry =
          (DatabaseDocumentEntry) orginatingFeature.getEntry().getEMBLEntry();
      DatabaseDocument doc = (DatabaseDocument) db_entry.getDocument();

      for (int i = 0; i < geneNames.length; i++) {
        DatabaseDocumentEntry newDbEntry = GeneEdit.makeGeneEntry(null, geneNames[i], doc, null);

        if (newDbEntry == null) {
          if (genesNotFound == null) genesNotFound = new Vector<String>();
          genesNotFound.add(geneNames[i]);
          continue;
        }

        char[] c = new char[1];
        PartialSequence ps = new PartialSequence(c, 100, 0, null, null);
        newDbEntry.setPartialSequence(ps);
        Entry entry = null;
        try {
          entry = new Entry(newDbEntry);
        } catch (Exception e) {
          e.printStackTrace();
        }

        SimpleEntryGroup entry_group = new SimpleEntryGroup();
        entry_group.addElement(entry);

        ChadoTransactionManager ctm = new ChadoTransactionManager();
        entry_group.addFeatureChangeListener(ctm);
        entry_group.addEntryChangeListener(ctm);
        ctm.setEntryGroup(entry_group);

        transfer(
            entry.getAllFeatures(),
            qualifiersToTransfer,
            key,
            sameKey,
            overwrite,
            true,
            geneNames,
            genesUpdated);

        for (int j = 0; j < ctm.getTransactionCount(); j++)
          buff.append(ctm.getTransactionAt(j).getLogComment() + "\n");
        ChadoTransactionManager.commit((DatabaseDocument) newDbEntry.getDocument(), false, ctm);

        entry_group.removeFeatureChangeListener(ctm);
        entry_group.removeEntryChangeListener(ctm);
        // if(newDbEntry != null)
        // GeneEdit.showGeneEditor(null, geneNames[i], newDbEntry);
      }
    }

    if (genesNotFound != null)
      JOptionPane.showMessageDialog(
          null,
          "Gene(s) Not Found:\n" + genesNotFound.toString(),
          "Gene(s) Not Found",
          JOptionPane.WARNING_MESSAGE);
    return 0;
  }