Skip to content

Commit

Permalink
add word cloud for "genes and proteins" category
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouji2013 committed May 12, 2021
1 parent 286f1d0 commit 594dcf1
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@ public interface DashboardDao {
SearchResults ontologySearch(String queryString);
List<Submission> getSubmissionsForSubjectName(String subjectName);
WordCloudEntry[] getSubjectCounts();
WordCloudEntry[] getSubjectCountsForRoles(String[] roles);
}
Original file line number Diff line number Diff line change
Expand Up @@ -998,32 +998,32 @@ public List<EcoBrowse> getEcoBrowse() {
b.setNumberOfSubmissions(b.getNumberOfSubmissions() + submissionCount.intValue());
Set<Integer> centerSet = null;
switch (tier) {
case 1:
b.setNumberOfTier1Observations(b.getNumberOfTier1Observations() + tierCount.intValue());
centerSet = mapTier1centers.get(code);
if (centerSet == null) {
centerSet = new HashSet<Integer>();
mapTier1centers.put(code, centerSet);
}
break;
case 2:
b.setNumberOfTier2Observations(b.getNumberOfTier2Observations() + tierCount.intValue());
centerSet = mapTier2centers.get(code);
if (centerSet == null) {
centerSet = new HashSet<Integer>();
mapTier2centers.put(code, centerSet);
}
break;
case 3:
b.setNumberOfTier3Observations(b.getNumberOfTier3Observations() + tierCount.intValue());
centerSet = mapTier3centers.get(code);
if (centerSet == null) {
centerSet = new HashSet<Integer>();
mapTier3centers.put(code, centerSet);
}
break;
default:
log.error("unknow tier number " + tier);
case 1:
b.setNumberOfTier1Observations(b.getNumberOfTier1Observations() + tierCount.intValue());
centerSet = mapTier1centers.get(code);
if (centerSet == null) {
centerSet = new HashSet<Integer>();
mapTier1centers.put(code, centerSet);
}
break;
case 2:
b.setNumberOfTier2Observations(b.getNumberOfTier2Observations() + tierCount.intValue());
centerSet = mapTier2centers.get(code);
if (centerSet == null) {
centerSet = new HashSet<Integer>();
mapTier2centers.put(code, centerSet);
}
break;
case 3:
b.setNumberOfTier3Observations(b.getNumberOfTier3Observations() + tierCount.intValue());
centerSet = mapTier3centers.get(code);
if (centerSet == null) {
centerSet = new HashSet<Integer>();
mapTier3centers.put(code, centerSet);
}
break;
default:
log.error("unknow tier number " + tier);
}
centerSet.add(centerId);
}
Expand Down Expand Up @@ -1745,4 +1745,34 @@ public WordCloudEntry[] getSubjectCounts() {
session.close();
return list.toArray(new WordCloudEntry[0]);
}

/* this query is to emulate the explore pages */
@Override
public WordCloudEntry[] getSubjectCountsForRoles(String[] roles) {
if (roles == null || roles.length == 0)
return new WordCloudEntry[0];
StringBuffer role_list = new StringBuffer("(");
role_list.append("'" + roles[0] + "'");
for (int i = 1; i < roles.length; i++) {
role_list.append(",'" + roles[1] + "'");
}
role_list.append(")");
List<WordCloudEntry> list = new ArrayList<WordCloudEntry>();
String sql = "SELECT displayName, numberOfObservations, stableURL FROM subject_with_summaries"
+ " JOIN subject ON subject_with_summaries.subject_id=subject.id"
+ " JOIN dashboard_entity ON subject.id=dashboard_entity.id" + " WHERE score>1 AND role IN "
+ role_list.toString();
log.debug(sql);
Session session = getSession();
@SuppressWarnings("unchecked")
org.hibernate.query.Query<Object[]> query = session.createNativeQuery(sql);
for (Object[] obj : query.getResultList()) {
String subject = (String) obj[0];
Integer count = (Integer) obj[1];
String url = (String) obj[2];
list.add(new WordCloudEntry(subject, count, url));
}
session.close();
return list.toArray(new WordCloudEntry[0]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

Expand All @@ -18,7 +19,7 @@
@Controller
@RequestMapping("/wordcloud")
public class WordCloudController {
private static final Log log = LogFactory.getLog(SummaryController.class);
private static final Log log = LogFactory.getLog(WordCloudController.class);
@Autowired
private DashboardDao dashboardDao;

Expand All @@ -43,4 +44,32 @@ public ResponseEntity<String> getSubjectCounts() {
log.debug("get subject counts");
return new ResponseEntity<String>(json, headers, HttpStatus.OK);
}

@Transactional
@RequestMapping(value = "{roles}", method = { RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getSubjectCountsForRoles(@PathVariable String roles) {
log.debug("request received for roles: " + roles);
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");

String[] role_array = roles.split(",");
WordCloudEntry[] words = new WordCloudEntry[0];
if (role_array.length > 0) {
log.debug(role_array);
words = dashboardDao.getSubjectCountsForRoles(role_array);
} else {
words = dashboardDao.getSubjectCounts();
}

JSONSerializer jsonSerializer = new JSONSerializer().exclude("class");
String json = "{}";
try {
json = jsonSerializer.deepSerialize(words);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
}

return new ResponseEntity<String>(json, headers, HttpStatus.OK);
}
}
9 changes: 8 additions & 1 deletion web/src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,14 @@
<button type="button" class="btn btn-secondary" id=summary-table-label><span id=toggle-word>Show</span> Dashboard Content Summary</button>
<button type="button" class="btn btn-secondary" id=wordcloud-button><span id=wordcloud-toggle-word>Show</span> Word Cloud</button>
</div>
<div id="vis"></div>
<div id='wordcloud-container'>
<div style="text-align:center;display:block;padding:10px">
<button type="button" class="btn btn-secondary" id=wordcloud-all>All</button>
<button type="button" class="btn btn-secondary" id=wordcloud-genes>Genes and Proteins</button>
</div>
<div id="vis"></div>
<div id="vis-genes"></div>
</div>
<table id=summary-table class="table table-bordered table-sm text-center">
<thead>
<tr><th rowspan=2>Category</th><th rowspan=2>Submissions</th>
Expand Down
28 changes: 25 additions & 3 deletions web/src/main/webapp/js/ctd2.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,15 +409,32 @@
else return "Show";
});
});
$("#vis").hide();
$("#wordcloud-container").hide();
$("#wordcloud-all").prop('disabled', true);
$("#vis").show();
$("#vis-genes").hide();
$("#wordcloud-button").click(function (e) {
e.preventDefault();
$("#vis").toggle();
$("#wordcloud-container").toggle();
$("#wordcloud-toggle-word").text(function (index, content) {
if (content == "Show") return "Hide";
else return "Show";
});
});
$("#wordcloud-genes").click(function (e) {
e.preventDefault();
$("#vis").hide();
$("#vis-genes").show();
$(this).prop('disabled', true)
$("#wordcloud-all").prop('disabled', false);
});
$("#wordcloud-all").click(function (e) {
e.preventDefault();
$("#vis-genes").hide();
$("#vis").show();
$(this).prop('disabled', true)
$("#wordcloud-genes").prop('disabled', false);
});
$('#summary-table thead th').popover({
placement: "top",
trigger: 'hover',
Expand Down Expand Up @@ -525,7 +542,12 @@
});

$.ajax("wordcloud").done(function (result) {
create_wordcloud()(result);
create_wordcloud('#vis')(result);
}).fail(function (err) {
console.log(err);
});
$.ajax("wordcloud/target,biomarker").done(function (result) {
create_wordcloud('#vis-genes')(result);
}).fail(function (err) {
console.log(err);
});
Expand Down
4 changes: 2 additions & 2 deletions web/src/main/webapp/js/wordcloud.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function create_wordcloud(){/* totally 7 parameters to control the picture */
function create_wordcloud(dom_id){/* totally 7 parameters to control the picture */
const max_word_number = 250;
const angle_count = 5; // default 5
const angle_from = -60; // default -60
Expand Down Expand Up @@ -464,7 +464,7 @@ const layout = d3.layout.cloud().timeInterval(10).size([w_cloud, h_cloud]).fontS
}).text(function (t) {
return t.key
}).on("word", progress).on("end", draw);
svg = d3.select("#vis").append("svg").attr("width", w_cloud).attr("height", h_cloud);
svg = d3.select(dom_id).append("svg").attr("width", w_cloud).attr("height", h_cloud);
background = svg.append("g");

const vis = svg.append("g").attr("transform", "translate(" + [w_cloud >> 1, h_cloud >> 1] + ")");
Expand Down

0 comments on commit 594dcf1

Please sign in to comment.