001package org.biopax.paxtools.pattern.miner; 002 003import org.biopax.paxtools.controller.PathAccessor; 004import org.biopax.paxtools.model.BioPAXElement; 005import org.biopax.paxtools.model.level3.*; 006import org.biopax.paxtools.pattern.Match; 007import org.biopax.paxtools.pattern.Pattern; 008import org.biopax.paxtools.pattern.PatternBox; 009 010import java.io.IOException; 011import java.io.OutputStream; 012import java.io.OutputStreamWriter; 013import java.util.HashSet; 014import java.util.List; 015import java.util.Map; 016import java.util.Set; 017 018/** 019 * Miner for the related genes (participant or controller) of interactions. 020 * @author Ozgun Babur 021 */ 022public class RelatedGenesOfInteractionsMiner extends MinerAdapter 023{ 024 /** 025 * Constructor that sets name and description. 026 */ 027 public RelatedGenesOfInteractionsMiner() 028 { 029 super("related-genes-of-interactions", "This miner finds any related gene that is a " + 030 "participant or a controller of an Interaction (Conversion or TemplateReaction). " + 031 "The output lists the ID of the interaction and the related gene symbols in a row."); 032 } 033 034 /** 035 * Constructs the pattern. 036 * @return pattern 037 */ 038 @Override 039 public Pattern constructPattern() 040 { 041 return PatternBox.relatedProteinRefOfInter( 042 Conversion.class, 043 TemplateReaction.class); 044 } 045 046 private static final PathAccessor controlAcc = new PathAccessor("Interaction/controlledOf*"); 047 048 /** 049 * Writes the IDs of interaction, then gene symbols of related proteins in a line. 050 * @param matches pattern search result 051 * @param out output stream 052 */ 053 @Override 054 public void writeResult(Map<BioPAXElement, List<Match>> matches, OutputStream out) 055 throws IOException 056 { 057 OutputStreamWriter writer = new OutputStreamWriter(out); 058 059 for (BioPAXElement ele : matches.keySet()) 060 { 061 Set<String> syms = new HashSet<String>(); 062 063 for (Match m : matches.get(ele)) 064 { 065 ProteinReference pr = (ProteinReference) m.get("PR", getPattern()); 066 067 String sym = getGeneSymbol(pr); 068 if (sym != null) syms.add(sym); 069 } 070 071 if (syms.size() > 1) 072 { 073 writer.write("\n" + ele.getRDFId()); 074 075 for (Object o : controlAcc.getValueFromBean(ele)) 076 { 077 Control ctrl = (Control) o; 078 writer.write(" " + ctrl.getRDFId()); 079 } 080 081 for (String sym : syms) 082 { 083 writer.write("\t" + sym); 084 } 085 } 086 } 087 writer.flush(); 088 } 089 090}