Search in sources :

Example 1 with InteractionDetail

use of gov.nih.nci.ctd2.dashboard.util.cnkb.InteractionDetail in project nci-ctd2-dashboard by CBIIT.

the class CnkbController method getCnkbObject.

@SuppressWarnings("unchecked")
@Transactional
@RequestMapping(value = "query", method = { RequestMethod.POST, RequestMethod.GET }, headers = "Accept=application/text")
public ResponseEntity<String> getCnkbObject(@RequestParam("dataType") String dataType, @RequestParam("interactome") String interactome, @RequestParam("version") String version, @RequestParam("selectedGenes") String selectedGenes, @RequestParam("interactionLimit") int interactionLimit, @RequestParam("throttle") String throttle) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    final CNKB interactionsConnection = CNKB.getInstance(getCnkbDataURL());
    CnkbObject cnkbObject = null;
    try {
        if (dataType.equals("interactome-context")) {
            cnkbObject = new InteractomeInfo();
            ((InteractomeInfo) cnkbObject).setInteractomeList(interactionsConnection.getNciDatasetAndInteractioCount());
        } else if (dataType.equals("interactome-version")) {
            cnkbObject = new InteractomeInfo();
            ((InteractomeInfo) cnkbObject).setDescription(interactionsConnection.getInteractomeDescription(interactome));
            List<VersionDescriptor> versionDescriptors = interactionsConnection.getVersionDescriptor(interactome);
            for (VersionDescriptor versionDescriptor : versionDescriptors) {
                if (versionDescriptor.getRequiresAuthentication() == false)
                    ((InteractomeInfo) cnkbObject).addVersionDescriptor(versionDescriptor);
            }
        } else if (dataType.equals("interaction-result")) {
            cnkbObject = new QueryResult();
            List<String> interactionTypes = interactionsConnection.getInteractionTypesByInteractomeVersion(interactome, version);
            ((QueryResult) cnkbObject).setInteractionTypeList(interactionTypes);
            List<InteractionDetail> interactionDetails = null;
            Short confidenceType = null;
            @SuppressWarnings("rawtypes") List<String> selectedGenesList = (List<String>) new JSONDeserializer().deserialize(selectedGenes);
            if (selectedGenesList != null && selectedGenesList.size() != 0) {
                for (String gene : selectedGenesList) {
                    CellularNetWorkElementInformation c = new CellularNetWorkElementInformation(gene.trim());
                    interactionDetails = interactionsConnection.getInteractionsByGeneSymbol(gene.trim(), interactome, version);
                    if (confidenceType == null && interactionDetails != null && interactionDetails.size() > 0)
                        confidenceType = interactionDetails.get(0).getConfidenceTypes().get(0);
                    for (int i = 0; i < interactionTypes.size(); i++) {
                        c.addInteractionNum(getInteractionNumber(interactionDetails, interactionTypes.get(i), confidenceType));
                    }
                    ((QueryResult) cnkbObject).addCnkbElement(c);
                }
            }
        } else if (dataType.equals("interaction-throttle")) {
            cnkbObject = new QueryResult();
            List<InteractionDetail> interactionDetails = null;
            List<String> selectedGenesList = convertStringToList(selectedGenes);
            List<Float> confidentList = new ArrayList<Float>();
            Short confidenceType = null;
            if (selectedGenesList != null && selectedGenesList.size() != 0) {
                for (String gene : selectedGenesList) {
                    interactionDetails = interactionsConnection.getInteractionsByGeneSymbolAndLimit(gene.trim(), interactome, version, interactionLimit);
                    if (interactionDetails != null) {
                        if (confidenceType == null && interactionDetails.size() > 0)
                            confidenceType = interactionDetails.get(0).getConfidenceTypes().get(0);
                        for (InteractionDetail interactionDetail : interactionDetails) confidentList.add(interactionDetail.getConfidenceValue(confidenceType));
                    }
                }
                // sort genes by value
                Collections.sort(confidentList, new Comparator<Float>() {

                    public int compare(Float f1, Float f2) {
                        return f2.compareTo(f1);
                    }
                });
                if (confidentList.size() > interactionLimit)
                    ((QueryResult) cnkbObject).setThreshold(confidentList.get(interactionLimit));
                else if (confidentList.size() > 0)
                    ((QueryResult) cnkbObject).setThreshold(confidentList.get(confidentList.size() - 1));
            }
        }
    } catch (UnAuthenticatedException uae) {
        uae.printStackTrace();
    } catch (ConnectException e1) {
        e1.printStackTrace();
    } catch (SocketTimeoutException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    JSONSerializer jsonSerializer = new JSONSerializer().exclude("*.class");
    return new ResponseEntity<String>(jsonSerializer.deepSerialize(cnkbObject), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) CnkbObject(gov.nih.nci.ctd2.dashboard.util.cnkb.CnkbObject) CellularNetWorkElementInformation(gov.nih.nci.ctd2.dashboard.util.cnkb.CellularNetWorkElementInformation) Comparator(java.util.Comparator) UnAuthenticatedException(gov.nih.nci.ctd2.dashboard.util.cnkb.UnAuthenticatedException) QueryResult(gov.nih.nci.ctd2.dashboard.util.cnkb.QueryResult) ArrayList(java.util.ArrayList) List(java.util.List) CNKB(gov.nih.nci.ctd2.dashboard.util.cnkb.CNKB) ConnectException(java.net.ConnectException) JSONSerializer(flexjson.JSONSerializer) JSONDeserializer(flexjson.JSONDeserializer) IOException(java.io.IOException) ResponseEntity(org.springframework.http.ResponseEntity) SocketTimeoutException(java.net.SocketTimeoutException) VersionDescriptor(gov.nih.nci.ctd2.dashboard.util.cnkb.VersionDescriptor) InteractionDetail(gov.nih.nci.ctd2.dashboard.util.cnkb.InteractionDetail) InteractomeInfo(gov.nih.nci.ctd2.dashboard.util.cnkb.InteractomeInfo) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with InteractionDetail

use of gov.nih.nci.ctd2.dashboard.util.cnkb.InteractionDetail in project nci-ctd2-dashboard by CBIIT.

the class CnkbController method getCnkbCyNetwork.

@Transactional
@RequestMapping(value = "network", method = { RequestMethod.POST, RequestMethod.GET }, headers = "Accept=application/json")
public ResponseEntity<String> getCnkbCyNetwork(@RequestParam("interactome") String interactome, @RequestParam("version") String version, @RequestParam("selectedGenes") String selectedGenes, @RequestParam("interactionLimit") int interactionLimit, @RequestParam("throttle") String throttle) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Type", "application/json; charset=utf-8");
    CNKB interactionsConnection = CNKB.getInstance(getCnkbDataURL());
    CyNetwork cyNetwork = null;
    try {
        List<InteractionDetail> interactionDetails = null;
        List<String> selectedGenesList = convertStringToList(selectedGenes);
        float throttleValue = 0;
        try {
            throttleValue = Float.valueOf(throttle);
        } catch (NumberFormatException ne) {
        // set throttleValue = 0;
        }
        List<CyEdge> edgeList = new ArrayList<CyEdge>();
        Short confidenceType = null;
        if (selectedGenesList != null && selectedGenesList.size() != 0) {
            for (String gene : selectedGenesList) {
                interactionDetails = interactionsConnection.getInteractionsByGeneSymbolAndLimit(gene.trim(), interactome, version, interactionLimit);
                if (interactionDetails != null) {
                    if (confidenceType == null && interactionDetails.size() > 0)
                        confidenceType = interactionDetails.get(0).getConfidenceTypes().get(0);
                    getCyEdgeList(interactionDetails, throttleValue, confidenceType, edgeList);
                }
            }
        }
        if (edgeList != null && edgeList.size() > 0) {
            cyNetwork = convertToCyNetwork(edgeList, interactionLimit, selectedGenesList);
        }
    } catch (UnAuthenticatedException uae) {
        uae.printStackTrace();
    } catch (ConnectException e1) {
        e1.printStackTrace();
    } catch (SocketTimeoutException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    JSONSerializer jsonSerializer = new JSONSerializer().exclude("*.class");
    return new ResponseEntity<String>(jsonSerializer.deepSerialize(cyNetwork), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ArrayList(java.util.ArrayList) CyNetwork(gov.nih.nci.ctd2.dashboard.util.cytoscape.CyNetwork) IOException(java.io.IOException) CyEdge(gov.nih.nci.ctd2.dashboard.util.cytoscape.CyEdge) UnAuthenticatedException(gov.nih.nci.ctd2.dashboard.util.cnkb.UnAuthenticatedException) ResponseEntity(org.springframework.http.ResponseEntity) SocketTimeoutException(java.net.SocketTimeoutException) InteractionDetail(gov.nih.nci.ctd2.dashboard.util.cnkb.InteractionDetail) CNKB(gov.nih.nci.ctd2.dashboard.util.cnkb.CNKB) ConnectException(java.net.ConnectException) JSONSerializer(flexjson.JSONSerializer) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with InteractionDetail

use of gov.nih.nci.ctd2.dashboard.util.cnkb.InteractionDetail in project nci-ctd2-dashboard by CBIIT.

the class CnkbController method downloadCnkbResult.

@Transactional
@RequestMapping(value = "download", method = { RequestMethod.POST })
public void downloadCnkbResult(@RequestParam("interactome") String interactome, @RequestParam("version") String version, @RequestParam("selectedGenes") String selectedGenes, @RequestParam("interactionLimit") int interactionLimit, @RequestParam("throttle") String throttle, HttpServletResponse response) {
    CNKB interactionsConnection = CNKB.getInstance(getCnkbDataURL());
    CnkbObject cnkbObject = null;
    String filename = "cnkbResult";
    response.setContentType("application/octet-stream");
    response.addHeader("Content-Disposition", "attachment; filename=\"" + filename + ".sif\"");
    response.addHeader("Content-Transfer-Encoding", "binary");
    try {
        cnkbObject = new QueryResult();
        List<String> interactionTypes = interactionsConnection.getInteractionTypesByInteractomeVersion(interactome, version);
        ((QueryResult) cnkbObject).setInteractionTypeList(interactionTypes);
        List<InteractionDetail> interactionDetails = null;
        List<String> selectedGenesList = convertStringToList(selectedGenes);
        OutputStream outputStream = response.getOutputStream();
        if (selectedGenesList.size() != 0) {
            Short confidenceType = null;
            HashMap<String, String> map = interactionsConnection.getInteractionTypeMap();
            for (String gene : selectedGenesList) {
                interactionDetails = interactionsConnection.getInteractionsByGeneSymbol(gene.trim(), interactome, version);
                if (interactionDetails == null || interactionDetails.size() == 0)
                    continue;
                if (confidenceType == null)
                    confidenceType = interactionDetails.get(0).getConfidenceTypes().get(0);
                for (int i = 0; i < interactionTypes.size(); i++) {
                    List<InteractionDetail> interactionDetailList = getSelectedInteractions(interactionDetails, interactionTypes.get(i), confidenceType);
                    if (interactionDetailList.size() == 0)
                        continue;
                    StringBuffer buf = new StringBuffer(gene + " " + map.get(interactionTypes.get(i)));
                    for (InteractionDetail interactionDetail : interactionDetailList) {
                        List<InteractionParticipant> pList = interactionDetail.getParticipantList();
                        for (int j = 0; j < pList.size(); j++) {
                            if (!pList.get(j).getGeneName().equals(gene))
                                buf.append(" " + pList.get(j).getGeneName());
                        }
                    }
                    buf.append("\n");
                    outputStream.write(buf.toString().getBytes());
                }
            }
        }
        outputStream.close();
    } catch (UnAuthenticatedException uae) {
        uae.printStackTrace();
    } catch (ConnectException e1) {
        e1.printStackTrace();
    } catch (SocketTimeoutException e1) {
        e1.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : CnkbObject(gov.nih.nci.ctd2.dashboard.util.cnkb.CnkbObject) OutputStream(java.io.OutputStream) IOException(java.io.IOException) UnAuthenticatedException(gov.nih.nci.ctd2.dashboard.util.cnkb.UnAuthenticatedException) QueryResult(gov.nih.nci.ctd2.dashboard.util.cnkb.QueryResult) SocketTimeoutException(java.net.SocketTimeoutException) InteractionParticipant(gov.nih.nci.ctd2.dashboard.util.cnkb.InteractionParticipant) InteractionDetail(gov.nih.nci.ctd2.dashboard.util.cnkb.InteractionDetail) CNKB(gov.nih.nci.ctd2.dashboard.util.cnkb.CNKB) ConnectException(java.net.ConnectException) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with InteractionDetail

use of gov.nih.nci.ctd2.dashboard.util.cnkb.InteractionDetail in project nci-ctd2-dashboard by CBIIT.

the class CnkbController method getCyEdgeList.

private void getCyEdgeList(List<InteractionDetail> interactionDetails, float throttle, Short confidenceType, List<CyEdge> edgeList) {
    CyNode source = null;
    CyNode target = null;
    for (InteractionDetail interactionDetail : interactionDetails) {
        if (!interactionDetail.getConfidenceTypes().contains(confidenceType) || interactionDetail.getConfidenceValue(confidenceType).floatValue() < throttle)
            continue;
        List<InteractionParticipant> participants = interactionDetail.getParticipantList();
        String interactionType = interactionDetail.getInteractionType();
        for (int i = 0; i < participants.size(); i++) {
            source = new CyNode();
            String sName = participants.get(i).getGeneName();
            source.setProperty(CyElement.ID, sName);
            for (int j = i + 1; j < participants.size(); j++) {
                target = new CyNode();
                String tName = participants.get(j).getGeneName();
                target.setProperty(CyElement.ID, tName);
                CyEdge cyEdge = new CyEdge();
                cyEdge.setProperty(CyElement.ID, sName + "." + getInteractionTypeMap().get(interactionType) + "." + tName);
                cyEdge.setProperty(CyElement.SOURCE, sName);
                cyEdge.setProperty(CyElement.TARGET, tName);
                cyEdge.setProperty(CyElement.WEIGHT, interactionDetail.getConfidenceValue(confidenceType));
                cyEdge.setProperty(CyElement.COLOR, colorMap.get(interactionType));
                edgeList.add(cyEdge);
            }
        }
    }
}
Also used : InteractionParticipant(gov.nih.nci.ctd2.dashboard.util.cnkb.InteractionParticipant) InteractionDetail(gov.nih.nci.ctd2.dashboard.util.cnkb.InteractionDetail) CyNode(gov.nih.nci.ctd2.dashboard.util.cytoscape.CyNode) CyEdge(gov.nih.nci.ctd2.dashboard.util.cytoscape.CyEdge)

Aggregations

InteractionDetail (gov.nih.nci.ctd2.dashboard.util.cnkb.InteractionDetail)4 CNKB (gov.nih.nci.ctd2.dashboard.util.cnkb.CNKB)3 UnAuthenticatedException (gov.nih.nci.ctd2.dashboard.util.cnkb.UnAuthenticatedException)3 IOException (java.io.IOException)3 ConnectException (java.net.ConnectException)3 SocketTimeoutException (java.net.SocketTimeoutException)3 Transactional (org.springframework.transaction.annotation.Transactional)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 JSONSerializer (flexjson.JSONSerializer)2 CnkbObject (gov.nih.nci.ctd2.dashboard.util.cnkb.CnkbObject)2 InteractionParticipant (gov.nih.nci.ctd2.dashboard.util.cnkb.InteractionParticipant)2 QueryResult (gov.nih.nci.ctd2.dashboard.util.cnkb.QueryResult)2 CyEdge (gov.nih.nci.ctd2.dashboard.util.cytoscape.CyEdge)2 ArrayList (java.util.ArrayList)2 HttpHeaders (org.springframework.http.HttpHeaders)2 ResponseEntity (org.springframework.http.ResponseEntity)2 JSONDeserializer (flexjson.JSONDeserializer)1 CellularNetWorkElementInformation (gov.nih.nci.ctd2.dashboard.util.cnkb.CellularNetWorkElementInformation)1 InteractomeInfo (gov.nih.nci.ctd2.dashboard.util.cnkb.InteractomeInfo)1 VersionDescriptor (gov.nih.nci.ctd2.dashboard.util.cnkb.VersionDescriptor)1