Perl script for rolling these filters

From GO Wiki
Jump to: navigation, search
  1. !/usr/bin/perl
=head1
This script takes a return delmited list of identifiers and generates a filter that can be usef with OBO-Edit to save out  is_a paths to root for all terms found.  It can be used with a simple shell script to find all terms with a particular ID prefix used in (dangling) relations/intersections in an OBO file:
e.g.
perl -n -e 'm/^(relationship|intersection_of)\: \s+ (idp:.+) \!/ ; print "$2\n";' ../trunk/fly_anatomy_XP.obo | sort | uniq | import_filter_roller.pl > tmp.xml
where idp is desired ID prefix
=cut
# Header:
print '<?xml version="1.0" encoding="UTF-8"?> 
<java version="1.5.0_16" class="java.beans.XMLDecoder"> 
<object class="org.obo.filters.CompoundFilterImpl"> 
 <void property="booleanOperation"> 
  <int>1</int> 
 </void>
 <void property="filters">';
# body:
chomp (@in= (<>));
foreach (@in) {
   print ' 
  <void method="add"> 
   <object class="org.obo.filters.ObjectFilterImpl"> 
    <void property="aspect"> 
     <object id="DescendantSearchAspect0" class="org.obo.filters.DescendantSearchAspect"/> 
    </void> 
    <void property="comparison"> 
     <object id="EqualsComparison0" class="org.obo.filters.EqualsComparison"/> 
    </void> 
    <void property="criterion"> 
     <object id="IDSearchCriterion0" class="org.obo.filters.IDSearchCriterion"/> 
    </void> 
    <void property="reasoner"> 
     <object id="RuleBasedReasoner0" class="org.obo.reasoner.rbr.RuleBasedReasoner"/> 
    </void> 
    <void property="traversalFilter"> 
     <object class="org.obo.filters.LinkFilterImpl"> 
      <void property="filter"> 
       <void property="comparison"> 
        <object class="org.obo.filters.EqualsComparison"/> 
       </void> 
       <void property="criterion"> 
        <object class="org.obo.filters.IDSearchCriterion"/> 
       </void> 
       <void property="value"> 
        <string>OBO_REL:is_a</string> 
       </void> 
      </void> 
     </object> 
    </void> 
    <void property="value"> 
     <string>'.$_.'</string> 
    </void> 
   </object> 
  </void> 
  <void method="add"> 
   <object class="org.obo.filters.ObjectFilterImpl"> 
    <void property="comparison"> 
     <object idref="EqualsComparison0"/> 
    </void> 
    <void property="criterion"> 
     <object idref="IDSearchCriterion0"/> 
    </void> 
    <void property="reasoner"> 
     <object idref="RuleBasedReasoner0"/> 
    </void> 
    <void property="value"> 
     <string>'.$_.'</string> 
    </void> 
   </object> 
  </void>', if $_;
}
# Footer:

print '  </void> 
</object> 
</java> ';