Skip to content

Commit

Permalink
added new summary file where for a given publication the distinct set…
Browse files Browse the repository at this point in the history
… of locations are computed. Each unique location for a given publication is added to the publication/citation counts. This summary is called distinct location.

Change from the JFileChooser to Cytoscape FileUtil for file loading in the UserPanel.
  • Loading branch information
risserlin committed Nov 11, 2013
1 parent b4f2e54 commit 56873b0
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 34 deletions.
6 changes: 6 additions & 0 deletions SocialNetwork/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@
<version>${cytoscape.api.version}</version>
<type>bundle</type>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>
</dependencies>

<packaging>bundle</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.cytoscape.application.swing.CyAction;
import org.cytoscape.application.swing.CySwingApplication;
import org.cytoscape.model.CyNetworkManager;
import org.cytoscape.util.swing.FileUtil;
import org.cytoscape.util.swing.OpenBrowser;
import org.cytoscape.view.layout.CyLayoutAlgorithmManager;
import org.cytoscape.view.model.CyNetworkViewManager;
Expand Down Expand Up @@ -65,6 +66,8 @@ public void start(BundleContext bc) {

VisualStyleFactory visualStyleFactoryServiceRef = getService(bc,VisualStyleFactory.class);

FileUtil fileUtil = getService(bc, FileUtil.class);

//open browser used by about panel,
OpenBrowser openBrowserRef = getService(bc, OpenBrowser.class);

Expand Down Expand Up @@ -138,7 +141,7 @@ public void start(BundleContext bc) {
appManager.setCyAppManagerServiceRef(cyApplicationManagerServiceRef);

// Create & register new menu item (for opening /closing main app panel)
UserPanel userPanel = new UserPanel(appManager);
UserPanel userPanel = new UserPanel(appManager,fileUtil,cySwingApplicationServiceRef);

Map<String, String> serviceProperties = new HashMap<String, String>();
serviceProperties.put("inMenuBar", "true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -14,13 +15,16 @@
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JPanel;

import javax.swing.JRadioButton;
import javax.swing.JTextField;

import org.baderlab.csapps.socialnetwork.CytoscapeUtilities;
import org.baderlab.csapps.socialnetwork.model.SocialNetworkAppManager;
import org.baderlab.csapps.socialnetwork.model.academia.Incites_InstitutionLocationMap;
import org.baderlab.csapps.socialnetwork.model.academia.Scopus;
import org.cytoscape.application.swing.CySwingApplication;
import org.cytoscape.util.swing.FileChooserFilter;
import org.cytoscape.util.swing.FileUtil;


Expand Down Expand Up @@ -57,12 +61,16 @@ public class AcademiaPanel {
* A reference to the app Manager
*/
private SocialNetworkAppManager appManager = null;
private FileUtil fileUtil = null;
protected CySwingApplication cySwingAppRef = null;



public AcademiaPanel(SocialNetworkAppManager appManager) {
public AcademiaPanel(SocialNetworkAppManager appManager,FileUtil fileUtil, CySwingApplication cySwingAppRef) {
super();
this.appManager = appManager;
this.fileUtil = fileUtil;
this.cySwingAppRef = cySwingAppRef;
}

/**
Expand Down Expand Up @@ -166,24 +174,24 @@ public JButton createLoadButton() {
loadButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {
// Ask user to select the appropriate data file.
JFileChooser chooser = new JFileChooser();
// Initialize the chooser dialog box to desktop
File directory = new File(FileUtil.LAST_DIRECTORY);
chooser.setCurrentDirectory(directory);
chooser.setDialogTitle("Data Selection");
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int check = chooser.showDialog(null, "OK");
// Only attempt to read data file if user clicks "OK"
if (check == JFileChooser.APPROVE_OPTION) {
File textFile = chooser.getSelectedFile();
setDataFile(textFile);
getPathTextFieldRef().setText(textFile.getAbsolutePath());
getFacultyTextFieldRef().setText(parseFileName(textFile.getAbsolutePath()));
} else {
setDataFile(null);
getPathTextFieldRef().setText(null);
}

//Use Cytoscape File util package for the file chooser instead of Java's so
//we navigate to last cytoscape known directory.
//Filter - only enable txt, and excel files.
FileChooserFilter filter1 = new FileChooserFilter("text file","txt");
FileChooserFilter filter2 = new FileChooserFilter("excel spreadsheet","xls");
FileChooserFilter filter3 = new FileChooserFilter("excel spreadsheet","xlsx");
FileChooserFilter filter4 = new FileChooserFilter("excel spreadsheet","csv");
HashSet<FileChooserFilter> filters = new HashSet<FileChooserFilter>();
filters.add(filter1);
filters.add(filter2);
filters.add(filter3);
filters.add(filter4);
File textFile = fileUtil.getFile( cySwingAppRef.getJFrame(), "Data File Selection",FileUtil.LOAD, filters);

setDataFile(textFile);
getPathTextFieldRef().setText(textFile.getAbsolutePath());
getFacultyTextFieldRef().setText(parseFileName(textFile.getAbsolutePath()));
}
});
return loadButton;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@
import org.baderlab.csapps.socialnetwork.model.SocialNetwork;
import org.baderlab.csapps.socialnetwork.model.VisualStyles;
import org.baderlab.csapps.socialnetwork.util.GenerateReports;
import org.cytoscape.application.swing.CySwingApplication;
import org.cytoscape.application.swing.CytoPanelComponent;
import org.cytoscape.application.swing.CytoPanelName;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.util.swing.FileUtil;

import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
Expand Down Expand Up @@ -137,6 +139,8 @@ public class UserPanel extends JPanel implements CytoPanelComponent {
* Reference to the main appManager
*/
private SocialNetworkAppManager appManager = null;
private FileUtil fileUtil = null;
private CySwingApplication cySwingAppRef = null;

/*
* instance of academia panel
Expand All @@ -148,10 +152,12 @@ public class UserPanel extends JPanel implements CytoPanelComponent {
* @param null
* @return null
*/
public UserPanel(SocialNetworkAppManager appManager) {
public UserPanel(SocialNetworkAppManager appManager, FileUtil fileUtil, CySwingApplication cySwingAppRef ) {

// Save a reference to this panel object
this.appManager = appManager;
this.fileUtil = fileUtil;
this.cySwingAppRef = cySwingAppRef;
this.appManager.setUserPanelRef(this);

this.setLayout(new BorderLayout());
Expand All @@ -165,7 +171,7 @@ public UserPanel(SocialNetworkAppManager appManager) {
this.add(this.topPanelRef, BorderLayout.NORTH);

// Add the default info panel (Academia)
this.academiaPanel = new AcademiaPanel(appManager);
this.academiaPanel = new AcademiaPanel(appManager,this.fileUtil, this.cySwingAppRef);
this.setSelectedInfoPanel(this.academiaPanel.createAcademiaInfoPanel());
this.add(this.infoPanelRef, BorderLayout.CENTER);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;

import org.baderlab.csapps.socialnetwork.CytoscapeUtilities;
Expand Down Expand Up @@ -40,10 +41,16 @@ public class GenerateReports {
private HashMap<String,Integer> pubByLocation = new HashMap<String, Integer>();
//location -> number of publication (unique location for each publication
private HashMap<String,Integer> pubByLocation_unique = new HashMap<String, Integer>();
//location -> number of publication (count each distinct location for each publication once.
//i.e. publication has a total of 10 authors, 2 from US, 5 from Canada and 3 international add publication count of 1 to US, Canada and international)
private HashMap<String,Integer> pubByLocation_distinct = new HashMap<String, Integer>();
//location -> number of total citations
private HashMap<String,Integer> citationByLocation = new HashMap<String, Integer>();
private HashMap<String,Integer> citationsByLocation = new HashMap<String, Integer>();
//location -> number of total citations (unique location for each publication
private HashMap<String,Integer> citationsByLocation_unique = new HashMap<String, Integer>();
//location -> number of total citations (count each distinct location for each publication once.
//i.e. publication has a total of 10 authors, 2 from US, 5 from Canada and 3 international add publication count of 1 to US, Canada and international)
private HashMap<String,Integer> citationsByLocation_distinct = new HashMap<String, Integer>();


public GenerateReports(ArrayList<Publication> pubs, String outputDir,String networkName) {
Expand All @@ -66,22 +73,29 @@ public HashMap<String,String> createReports(){

this.calculateTotals();
this.calculateTotals_unique();
this.calculateTotals_distinct();
HashMap<String, String> filenames = new HashMap<String, String>();

String basename = this.outputDir + System.getProperty("file.separator") + this.networkName;

this.generateFiles(this.outputDir,this.networkName + "_pubByLocation_distinct", this.pubByLocation_distinct,"Publications by Location - counting publications once for every distinct location");
filenames.put("1a. Pub by location(txt) - distinct locations publication counts", basename + "_pubByLocation_distinct.txt");
filenames.put("1b. Pub by location(html) - distinct locations publication counts", basename + "_pubByLocation_distinct.html");
this.generateFiles(this.outputDir,this.networkName + "_pubByLocation", this.pubByLocation,"Publications by Location");
filenames.put("1. Pub by location(txt)", basename + "_pubByLocation.txt");
filenames.put("2. Pub by location(html)", basename + "_pubByLocation.html");
filenames.put("2a. Pub by location(txt)", basename + "_pubByLocation.txt");
filenames.put("2b. Pub by location(html)", basename + "_pubByLocation.html");
this.generateFiles(this.outputDir,this.networkName + "_pubByLocation_unique", this.pubByLocation_unique,"Publications by Location - counting publications only once");
filenames.put("3. Pub by location(txt) - unique publication counts",basename + "_pubByLocation_unique.txt");
filenames.put("4. Pub by location(html) - unique publication counts", basename + "_pubByLocation_unique.html");
this.generateFiles(this.outputDir,this.networkName + "_citationByLocation", this.citationByLocation,"Citations by Location");
filenames.put("5. Citation by location(txt)",basename + "_citationByLocation.txt");
filenames.put("6. Citation by location(html)", basename + "_citationByLocation.html");
filenames.put("3a. Pub by location(txt) - unique publication counts",basename + "_pubByLocation_unique.txt");
filenames.put("3b. Pub by location(html) - unique publication counts", basename + "_pubByLocation_unique.html");
this.generateFiles(this.outputDir,this.networkName + "_citationByLocation_distinct", this.citationsByLocation_distinct,"Citations by Location - counting citations once for every distinct location");
filenames.put("4a. Citation by location(txt) - distinct locations citation count",basename + "_citationByLocation_distinct.txt");
filenames.put("4b. Citation by location(html) - distinct locations citation counts", basename + "_citationByLocation_distinct.html");
this.generateFiles(this.outputDir,this.networkName + "_citationByLocation", this.citationsByLocation,"Citations by Location");
filenames.put("5a. Citation by location(txt)",basename + "_citationByLocation.txt");
filenames.put("5b. Citation by location(html)", basename + "_citationByLocation.html");
this.generateFiles(this.outputDir,this.networkName + "_citationByLocation_unique", this.citationsByLocation_unique,"Citations by Location - counting publications only once");
filenames.put("7. Citation by location(txt)- unique publication counts", basename + "_citationByLocation_unique.txt");
filenames.put("8. Citation by location(html)- unique publication counts", basename + "_citationByLocation_unique.html");
filenames.put("6a. Citation by location(txt)- unique publication counts", basename + "_citationByLocation_unique.txt");
filenames.put("6b. Citation by location(html)- unique publication counts", basename + "_citationByLocation_unique.html");

return filenames;
}
Expand Down Expand Up @@ -120,10 +134,54 @@ private void calculateTotals(){
}
}
}
this.citationByLocation = citations_summary;
this.citationsByLocation = citations_summary;
this.pubByLocation = pubs_summary;

}
/*
* for each publication in the set of publications for this network
* For each publication get its set of Authors. For each Author get their location
* For each unique location on the given publication add a count to that location
* (counts will be duplicated but only once per location for each publication.)
* Do the same for the times cited
* Add up the publications based on distinct locations of a given publication.
*/
private void calculateTotals_distinct(){
HashMap<String,Integer> pubs_summary = new HashMap<String, Integer>();
HashMap<String,Integer> citations_summary = new HashMap<String, Integer>();

if(this.publications != null){
for(Publication pub:this.publications){


//for each publication the set of Authors
HashSet<String> all_locations = new HashSet<String>();
for(Author author:pub.getAuthorList()){

String current_location = author.getLocation();
if(!all_locations.contains(current_location))
all_locations.add(current_location);
}

for(String current:all_locations){
if(pubs_summary.containsKey(current) && citations_summary.containsKey(current)){
Integer pub_count = pubs_summary.get(current) +1;
pubs_summary.put(current, pub_count);
Integer cit_count = citations_summary.get(current) + pub.getTimesCited();
citations_summary.put(current, cit_count);

}
else{
pubs_summary.put(current, 1);
citations_summary.put(current,pub.getTimesCited());
}
}
}
}
this.citationsByLocation_distinct = citations_summary;
this.pubByLocation_distinct = pubs_summary;

}


/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import static org.junit.Assert.*;

import static org.mockito.Mockito.mock;

import org.baderlab.csapps.socialnetwork.model.Category;
import org.baderlab.csapps.socialnetwork.model.Search;
import org.baderlab.csapps.socialnetwork.model.SocialNetworkAppManager;
import org.baderlab.csapps.socialnetwork.panels.UserPanel;
import org.cytoscape.application.swing.CySwingApplication;
import org.cytoscape.util.swing.FileUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -17,6 +20,9 @@
*/
public class TestSearch {

private FileUtil fileUtil = mock(FileUtil.class);
private CySwingApplication cySwingAppRef = mock(CySwingApplication.class);

@Before
public void setUp() throws Exception {
}
Expand All @@ -32,7 +38,7 @@ public void tearDown() throws Exception {
*/
public void testPubmedSearch() {
SocialNetworkAppManager appManager = new SocialNetworkAppManager ();
appManager.setUserPanelRef(new UserPanel(appManager));
appManager.setUserPanelRef(new UserPanel(appManager,fileUtil,cySwingAppRef));
Search search = new Search("emili a", Category.ACADEMIA,appManager);
int hits = search.getTotalHits();
int results = search.getResults().size();
Expand Down

0 comments on commit 56873b0

Please sign in to comment.