Skip to content

Commit

Permalink
Merge pull request #201 from larsgw/patch-2
Browse files Browse the repository at this point in the history
Improvements to PublicationXref editing
  • Loading branch information
mkutmon authored Nov 24, 2023
2 parents abcf365 + dabde8f commit 492272b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ public void addProperty(BiopaxProperty p) {
List<BiopaxProperty> existingProps = getProperties(p.getName());
if(p.getMaxCardinality() != BiopaxProperty.UNBOUND &&
existingProps.size() >= p.getMaxCardinality()) {
//Replace the first occuring property
//Replace other properties with the same name
int first = getFirstPropertyIndex(p.getName());
properties.remove(first);
for(BiopaxProperty existingProp : existingProps) {
removeProperty(existingProp);
}
properties.add(first, p);
} else {
properties.add(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
*/
public class PublicationXref extends BiopaxNode {
static final String PUBMED_URL = "http://www.ncbi.nlm.nih.gov/pubmed/";
static final String DOI_URL = "http://doi.org/";
static final String EMPTY_VALUE_STRING = "NA";

public PublicationXref() {
super();
Expand Down Expand Up @@ -80,13 +82,22 @@ public void setYear(String year) {
setPropertyValue(PropertyType.YEAR, year);
}

public String getDb() {
String db = getPropertyValue(PropertyType.DB);
return db.equals(EMPTY_VALUE_STRING) ? "" : db;
}

public void setDb(String db) {
setPropertyValue(PropertyType.DB, Utils.isEmpty(db) ? EMPTY_VALUE_STRING : db);
}

public String getPubmedId() {
return getPropertyValue(PropertyType.ID);
String id = getPropertyValue(PropertyType.ID);
return id.equals(EMPTY_VALUE_STRING) ? "" : id;
}

public void setPubmedId(String id) {
setPropertyValue(PropertyType.ID, id);
setPropertyValue(PropertyType.DB, "PubMed");
setPropertyValue(PropertyType.ID, Utils.isEmpty(id) ? EMPTY_VALUE_STRING : id);
}

public List<String> getAuthors() {
Expand Down Expand Up @@ -188,13 +199,26 @@ public String toString() {
builder.append(year)
.append(". ");
}
String db = getDb();
String pmid = getPubmedId();
if(!Utils.isEmpty(pmid)) {
builder.append("<A href='" + PUBMED_URL)
.append(pmid)
.append("'>PubMed ")
.append(pmid)
.append("</A>.");
if (db.equals("PubMed")) {
builder.append("<A href='" + PUBMED_URL)
.append(pmid)
.append("'>PubMed ")
.append(pmid)
.append("</A>.");
} else if (db.equals("DOI")) {
builder.append("<A href='" + DOI_URL)
.append(pmid)
.append("'>doi:")
.append(pmid)
.append("</A>.");
} else {
builder.append(db)
.append(" ")
.append(pmid);
}
}
return builder.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,9 +844,6 @@ public Document createJdom(Pathway data) throws ConverterException
for (Element e : elementList) {
// make sure biopax references are sorted alphabetically by rdf-id
if(e.getName().equals("Biopax")) {
for(Element e3 : e.getChildren()) {
e3.removeChildren("AUTHORS", GpmlFormat.BIOPAX);
}
e.sortChildren(new BiopaxAttributeComparator());
}
root.addContent(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.regex.Pattern;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
Expand Down Expand Up @@ -58,14 +59,17 @@ public class PublicationXRefDialog extends OkCancelDialog {

final static String ADD = "Add";
final static String REMOVE = "Remove";
final static String PMID = "Pubmed ID";
final static String DB = "Database";
final static String PMID = "ID";
final static String TITLE = "Title";
final static String SOURCE = "Source";
final static String YEAR = "Year";
final static String AUTHORS = "Authors (separate with " + PublicationXref.AUTHOR_SEP + ")";
final static String QUERY = "Query PubMed";
final static String[] DB_OPTIONS = {"PubMed", "DOI", "ISBN"};

PublicationXref input;
JComboBox<Object> db;
JTextField pmId;
JTextField title;
JTextField source;
Expand All @@ -91,6 +95,15 @@ private void setText(String text, JTextComponent field) {
}

protected void refresh() {
String selectedDb = input.getDb();
int selectedDbIndex = java.util.Arrays.asList(DB_OPTIONS).indexOf(selectedDb);
if (selectedDb == null) {
db.setSelectedIndex(0);
} else if (selectedDbIndex > -1) {
db.setSelectedIndex(selectedDbIndex);
} else {
db.setSelectedItem(selectedDb);
}
setText(input.getPubmedId(), pmId);
setText(input.getTitle(), title);
setText(input.getSource(), source);
Expand All @@ -99,6 +112,7 @@ protected void refresh() {
}

protected void okPressed() {
input.setDb((String) db.getSelectedItem());
input.setPubmedId(pmId.getText().trim());
input.setTitle(title.getText());
input.setSource(source.getText());
Expand Down Expand Up @@ -130,6 +144,7 @@ protected Void doInBackground() throws SAXException, IOException

PubMedResult pmr = pmq.getResult();
if(pmr != null) {
db.setSelectedItem(DB_OPTIONS[0]); // set pubmed
pmId.setText(pmr.getId()); // write the trimmed pmid to the dialog
title.setText(pmr.getTitle());
year.setText(pmr.getYear());
Expand All @@ -149,12 +164,15 @@ protected Component createDialogPane() {
JPanel contents = new JPanel();
contents.setLayout(new GridBagLayout());

JLabel lblDb = new JLabel(DB);
JLabel lblPmId = new JLabel(PMID);
JLabel lblTitle = new JLabel(TITLE);
JLabel lblSource = new JLabel(SOURCE);
JLabel lblYear = new JLabel(YEAR);
JLabel lblAuthors = new JLabel(AUTHORS);

db = new JComboBox<Object>(DB_OPTIONS);
db.setEditable(true);
pmId = new JTextField();
title = new JTextField();
source = new JTextField();
Expand Down Expand Up @@ -203,6 +221,7 @@ void highlight(StyledDocument doc) {
c.gridy = GridBagConstraints.RELATIVE;
c.weightx = 0;
contents.add(lblPmId, c);
contents.add(lblDb, c);
contents.add(lblTitle, c);
contents.add(lblYear, c);
contents.add(lblSource, c);
Expand All @@ -212,6 +231,7 @@ void highlight(StyledDocument doc) {
c.fill = GridBagConstraints.HORIZONTAL;
c.weightx = 1;
contents.add(pmId, c);
contents.add(db, c);
contents.add(title, c);
contents.add(year, c);
contents.add(source, c);
Expand Down

0 comments on commit 492272b

Please sign in to comment.