Skip to content

Commit

Permalink
Code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
susiehgt committed Feb 11, 2025
1 parent 968f46e commit 92d1d41
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The PSI-MI XML Maker is a tool designed to create XML files based on the [PSI-MI
These XML files can later be used in the editor for further processing.

### How to download?
- **MacOs** : download the .dmg file
- **MacOS** : download the .dmg file
- **Windows** : download the .zip file
- **Linux** : download the .tar file

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public XmlMakerGui() {
this.fileFormaterGui = new FileFormaterGui(excelFileReader);
this.interactionWriterGui = new InteractionWriterGui(excelFileReader);
this.interactionsCreatorGui = new InteractionsCreatorGui(excelFileReader,
interactionWriterGui.getInteractionWriter(), uniprotMapperGui);
interactionWriterGui.getInteractionWriter());
excelFileReader.registerInputSelectedEventHandler(event -> setUpSheets());
}

Expand Down Expand Up @@ -284,11 +284,7 @@ public JPanel createFileFetcher() {

JTextField publicationDatabase = new JTextField("Publication database");
publicationDatabase.setEditable(true);
// JButton textValidationButton = new JButton("Submit");
// textValidationButton.addActionListener(e -> excelFileReader.setPublicationId(publicationDatabase.getText()));
pubmedInputPanel.add(publicationDatabase);
// pubmedInputPanel.add(textValidationButton);


JTextField publicationTitleField = new JTextField("Publication ID");
publicationTitleField.setEditable(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ public void checkAndInsertUniprotResultsSeparatedFormat(String idColumnName, int

String updatedOrganism = null;
String participantName = null;
String uniprotResult = null;
String uniprotResultDb = null;
String uniprotResult;
String uniprotResultDb;

if (previousId == null || previousId.isEmpty()) {
LOGGER.warning("Skipping row with null or empty ID: " + row);
Expand Down Expand Up @@ -528,7 +528,7 @@ public void checkAndInsertUniprotResultsWorkbook(String sheetSelected, String id
* @return A {@link UniprotResult} object representing the selected UniProt ID, or {@code null} if no entries exist.
*/
private UniprotResult getOneUniprotId(String previousId, String previousIdDb, String organism) {
UniprotGeneralMapperGui mapperGui = new UniprotGeneralMapperGui(uniprotGeneralMapper);
UniprotGeneralMapperGui mapperGui = new UniprotGeneralMapperGui();
ArrayList<UniprotResult> uniprotResults = uniprotGeneralMapper.fetchUniprotResult(previousId, previousIdDb, organism);
UniprotResult oneUniprotId = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public class FileFormater {
private List<Map<String, String>> preyFeatures = new ArrayList<>();

private String[] header = {"Interaction Number", "Input Participant ID", "Input Participant Name",
"Experimental role", "Input Participant ID database",
"Interaction detection method", "Participant identification method", "Experimental preparation",
"Experimental role", "Input Participant ID database", "Interaction detection method",
"Participant identification method", "Experimental preparation",
"Biological role", "Participant organism"};

private final Map<String, Integer> participantCountMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import uk.ac.ebi.intact.psi.mi.xmlmaker.utils.XmlMakerUtils;
import javax.swing.*;
import java.awt.*;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
* The {@code ParticipantAndInteractionCreatorGui} class provides a graphical user interface
Expand Down Expand Up @@ -235,11 +232,6 @@ private void updateBaitExperimentalPreparations(int count) {
int numberExperiments = baitExperimentalPanel.getComponents().length;
// baitExperimentalPreparationList.clear();

// if (numberExperiments > count) {
// baitExperimentalPanel.removeAll();
// baitExperimentalPreparationList.clear();
// }

for (int i = numberExperiments; i < count; i++) {
JComboBox<String> comboBox = new JComboBox<>();
comboBox.addItem("Experimental Preparation");
Expand Down Expand Up @@ -405,7 +397,6 @@ private void updateFeaturePanels(JPanel featureContainerPanel, int count, boolea

private JPanel createFeaturePanel(int featureNumber, boolean bait) {
Map<String, JComboBox<String>> comboBoxMap = new HashMap<>();
Map<String, Map<String, String>> featureXrefs = new HashMap<>();

JPanel featurePanel = new JPanel(new GridLayout(2, 1));
featurePanel.setBorder(BorderFactory.createTitledBorder("Create feature " + (featureNumber + 1)));
Expand All @@ -423,8 +414,7 @@ private JPanel createFeaturePanel(int featureNumber, boolean bait) {
featurePanel.add(XmlMakerUtils.setComboBoxDimension(comboBox, attribute.name));
}

featurePanel.add(featureXrefPanel(featureNumber, bait));
// featureXrefs.put(featureNumber + )
featurePanel.add(featureXrefPanel(bait));

setFeatureType(comboBoxMap.get(DataForRawFile.FEATURE_TYPE.name));
setFeatureRangeType(comboBoxMap.get(DataForRawFile.FEATURE_RANGE_TYPE.name));
Expand Down Expand Up @@ -481,7 +471,7 @@ private List<Map<String, String>> getFeaturesDataFromCombobox(List<Map<String, J
return featuresData;
}

private JPanel featureXrefPanel(int featureNumber, boolean bait) {
private JPanel featureXrefPanel(boolean bait) {
JPanel featureXrefPanel = new JPanel();
featureXrefPanel.setBorder(BorderFactory.createTitledBorder("Feature Xref"));
JSpinner numberOfXref = new JSpinner(new SpinnerNumberModel(1, 1, 10, 1));
Expand All @@ -490,17 +480,17 @@ private JPanel featureXrefPanel(int featureNumber, boolean bait) {

JPanel xrefContainerPanel = new JPanel();
xrefContainerPanel.setLayout(new BoxLayout(xrefContainerPanel, BoxLayout.Y_AXIS));
xrefContainerPanel.add(oneFeatureXrefPanel(featureNumber, bait));
xrefContainerPanel.add(oneFeatureXrefPanel(bait));

featureXrefPanel.add(xrefContainerPanel);

numberOfXref.addChangeListener(e -> updateXrefPanel(xrefContainerPanel,
(int) numberOfXref.getValue(), featureNumber, bait));
(int) numberOfXref.getValue(), bait));

return featureXrefPanel;
}

private JPanel oneFeatureXrefPanel(int featureNumber, boolean bait) {
private JPanel oneFeatureXrefPanel(boolean bait) {
JPanel xrefPanel = new JPanel();

JComboBox<String> xrefComboBox = new JComboBox<>();
Expand All @@ -524,12 +514,12 @@ private JPanel oneFeatureXrefPanel(int featureNumber, boolean bait) {
return xrefPanel;
}

private void updateXrefPanel(JPanel xrefPanel, int numberOfXref, int featureNumber, boolean bait) {
private void updateXrefPanel(JPanel xrefPanel, int numberOfXref, boolean bait) {
// xrefPanel.removeAll(); //TODO: CHECK HOW TO NOT REMOVE EVERYTHING
//todo: check for decreasing number
int length = xrefPanel.getComponents().length;
for (int i = length; i < numberOfXref; i++) {
xrefPanel.add(oneFeatureXrefPanel(featureNumber, bait));
xrefPanel.add(oneFeatureXrefPanel(bait));
}
xrefPanel.revalidate();
xrefPanel.repaint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
import uk.ac.ebi.intact.psi.mi.xmlmaker.utils.FileUtils;
import uk.ac.ebi.intact.psi.mi.xmlmaker.utils.XmlMakerUtils;
import uk.ac.ebi.intact.psi.mi.xmlmaker.file.processing.ExcelFileReader;
import uk.ac.ebi.intact.psi.mi.xmlmaker.uniprot.mapping.UniprotMapperGui;

import java.util.*;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Logger;
import java.util.stream.Collectors;
Expand All @@ -30,7 +29,7 @@ public class InteractionsCreator {
private static int MAX_INTERACTIONS_PER_FILE = 1_000;
final ExcelFileReader excelFileReader;
final InteractionWriter interactionWriter;
final UniprotMapperGui uniprotMapperGui;
// final UniprotMapperGui uniprotMapperGui;
final XmlMakerUtils utils = new XmlMakerUtils();
public final List<XmlInteractionEvidence> xmlModelledInteractions = new ArrayList<>();
public final List<Map<String, String>> dataList = new ArrayList<>();
Expand All @@ -55,13 +54,12 @@ public class InteractionsCreator {
*
* @param reader the Excel file reader for fetching data from Excel files.
* @param writer the InteractionWriter
* @param uniprotMapperGui the Uniprot mapper GUI for mapping protein data.
* @param columnAndIndex the mapping of column names to their corresponding indices in the dataset.
*/
public InteractionsCreator(ExcelFileReader reader, InteractionWriter writer, UniprotMapperGui uniprotMapperGui, Map<String, Integer> columnAndIndex) {
public InteractionsCreator(ExcelFileReader reader, InteractionWriter writer, Map<String, Integer> columnAndIndex) {
this.excelFileReader = reader;
this.interactionWriter = writer;
this.uniprotMapperGui = uniprotMapperGui;
// this.uniprotMapperGui = uniprotMapperGui;
this.columnAndIndex = columnAndIndex;
this.publicationId = excelFileReader.publicationId;
}
Expand Down Expand Up @@ -197,8 +195,7 @@ public XmlParticipantEvidence createParticipant(Map<String, String> data) {
if (numberOfFeature > 0) {
for (int i = 0; i < numberOfFeature; i++) {
XmlFeatureEvidence feature = createFeature(i, data);

participantEvidence.addFeature(feature); //todo: add feature xref here
participantEvidence.addFeature(feature);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ public class InteractionsCreatorGui extends JPanel {
*
* @param excelFileReader The Excel file reader used to read data.
* @param writer Interaction writer
* @param uniprotMapperGui The Uniprot mapper GUI for integrating with Uniprot.
*/
public InteractionsCreatorGui(ExcelFileReader excelFileReader, InteractionWriter writer, UniprotMapperGui uniprotMapperGui) {
public InteractionsCreatorGui(ExcelFileReader excelFileReader, InteractionWriter writer) {
this.excelFileReader = excelFileReader;
this.participantCreatorPanel = new JPanel(new BorderLayout());
this.interactionsCreator = new InteractionsCreator(excelFileReader, writer, uniprotMapperGui, getDataAndIndexes());
this.interactionsCreator = new InteractionsCreator(excelFileReader, writer, getDataAndIndexes());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class UniprotGeneralMapper {
*/
public ArrayList<UniprotResult> fetchUniprotResult(String protein, String previousDb, String organism){
try {
return getUniprotIds(getUniprotResponse(protein, previousDb, organism), protein, previousDb, organism);
return getUniprotIds(getUniprotResponse(protein, previousDb, organism));
} catch (Exception e) {
XmlMakerUtils.showErrorDialog("Error fetching UniProt results, please check your internet connection");
LOGGER.error("Error fetching UniProt results for protein '{}': {}", protein, e.getMessage(), e);
Expand Down Expand Up @@ -109,7 +109,7 @@ public JsonObject getUniprotResponse(String protein, String previousDb, String o
* @param results The JSON response from the UniProt API.
* @return A list of {@link UniprotResult} objects representing the UniProt entries.
*/
public ArrayList<UniprotResult> getUniprotIds(JsonObject results, String protein, String previousDb, String inputOrganism) {
public ArrayList<UniprotResult> getUniprotIds(JsonObject results) {
ArrayList<UniprotResult> uniprotResults = new ArrayList<>();

if (results.isJsonNull()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.Enumeration;

public class UniprotGeneralMapperGui {
final UniprotGeneralMapper generalMapper;
@Getter
String selectedId;
@Getter
Expand All @@ -15,8 +14,7 @@ public class UniprotGeneralMapperGui {
@Getter
private String selectedParticipantType;

public UniprotGeneralMapperGui(UniprotGeneralMapper generalMapper) {
this.generalMapper = generalMapper;
public UniprotGeneralMapperGui() {
}

public void getUniprotIdChoicePanel(ButtonGroup uniprotIdsGroup, String previousId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void setUp() {
reader = new ExcelFileReader();
UniprotMapperGui uniprotMapperGui = new UniprotMapperGui(reader, new LoadingSpinner());
interactionWriter = new InteractionWriter(reader);
interactionsCreator = new InteractionsCreator(reader, interactionWriter, uniprotMapperGui, mockColumnAndIndex());
interactionsCreator = new InteractionsCreator(reader, interactionWriter, mockColumnAndIndex());
}

@Test
Expand Down

0 comments on commit 92d1d41

Please sign in to comment.