Changeset 5760


Ignore:
Timestamp:
Nov 26, 2019, 1:10:53 PM (3 years ago)
Author:
Nicklas Nordborg
Message:

Merged Reggie 4.24.1 to the trunk.

Location:
extensions/net.sf.basedb.reggie/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk

  • extensions/net.sf.basedb.reggie/trunk/resources/mipsprep/create_flowcells.jsp

    r5453 r5760  
    143143        <td class="input">
    144144          <select name="preset" id="preset">
    145             <option value="HiSeq2" selected>HiSeq (2 lanes)
     145            <option value="HiSeq2">HiSeq (2 lanes)
    146146            <option value="HiSeq8">HiSeq (8 lanes)
    147             <option value="NextSeq">NextSeq
     147            <option value="NextSeq" selected>NextSeq
    148148            <option value="">Custom
    149149          </select>
  • extensions/net.sf.basedb.reggie/trunk/resources/mipsprep/lib_registration.js

    r5450 r5760  
    2323    Events.addEventHandler('cleanupDate', 'blur', Wizard.validateDate);
    2424    Events.addEventHandler('libComments', 'blur', libreg.libCommentsOnChange);
     25    Events.addEventHandler('barcodeTemplate', 'change', libreg.barcodeTemplateOnChange);
    2526
    2627    // Navigation
     
    131132 
    132133    frm.barcodeTemplate.length = 0;
     134    frm.barcodeTemplate[0] = new Option('', '');
    133135    for (var i = 0; i < templates.length; i++)
    134136    {
    135137      var tmp = templates[i];
    136138      var option = new Option(tmp.name, tmp.id);
     139      option.template = tmp;
    137140      frm.barcodeTemplate[frm.barcodeTemplate.length] = option;
    138141    }
    139     if (frm.barcodeTemplate.length == 0)
     142    libreg.barcodeTemplateOnChange();
     143  }
     144 
     145  libreg.barcodeTemplateOnChange = function()
     146  {
     147    var frm = document.forms['reggie'];
     148   
     149    Wizard.setInputStatus('barcodeTemplate');
     150    Wizard.hideGoNextConfirmation();
     151    barcodeTemplateIsValid = false;
     152   
     153    if (frm.barcodeTemplate.length == 1)
    140154    {
    141155      Wizard.setInputStatus('barcodeTemplate', 'invalid', 'No available barcode templates');
     
    143157      return;
    144158    }
    145     Wizard.setInputStatus('barcodeTemplate', 'valid');
     159   
     160    if (frm.barcodeTemplate.value == '')
     161    {
     162      Wizard.setInputStatus('barcodeTemplate', 'invalid', 'A barcode template must be selected');
     163      barcodeTemplateIsValid = false;
     164      return;
     165    }
     166   
    146167    barcodeTemplateIsValid = true;
     168
     169    var template = frm.barcodeTemplate[frm.barcodeTemplate.selectedIndex].template;
     170    if (template.otherPlates && template.otherPlates.length > 0)
     171    {
     172      var msg = 'This template is also used by ' + Strings.encodeTags(template.otherPlates[0].name);
     173      if (template.otherPlates.length > 1)
     174      {
     175        msg += ' and '+(template.otherPlates.length-1)+' more plate(s)';
     176      }
     177      Wizard.setInputStatus('barcodeTemplate', 'warning', msg);
     178      Wizard.showGoNextConfirmation(true, 'Verify registration of plate with duplicate barcode template');
     179    }
     180    else
     181    {
     182      Wizard.setInputStatus('barcodeTemplate', 'valid');
     183    }
    147184  }
    148185 
  • extensions/net.sf.basedb.reggie/trunk/resources/reports/case-summary.js

    r5731 r5760  
    744744          cs.addColumn('variantCalling.donotuse', cs.asDoNotUse(vcall));
    745745          cs.addColumn('variantCalling.pipeline', vcall.pipeline);
    746           var job = raw.job;
     746          var job = vcall.job;
    747747          cs.addColumn('variantCalling.date', cs.asJob(job, truncateAt));
    748748          cs.addColumn('variantCalling.result', (vcall.result && vcall.result != 'Successful') ? cs.asFailInfo(vcall.result, 'error.png') : null);
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/Reggie.java

    r5743 r5760  
    463463  }
    464464 
     465  private static Object configLock = new Object();
    465466  private static volatile XmlConfig rootConfig;
    466467  private static volatile Map<String, XmlConfig> openGridConfig;
     
    489490    Force reload the Reggie configuration.
    490491  */
    491   public static synchronized XmlConfig reloadConfig()
    492   {
    493     loadConfig(true);
    494     ActivityLog.getInstance().reloadConfig();
    495     CounterService.getInstance().reloadConfig();
     492  public static XmlConfig reloadConfig()
     493  {
     494    synchronized (configLock)
     495    {
     496      loadConfig(true);
     497      ActivityLog.getInstance().reloadConfig();
     498      CounterService.getInstance().reloadConfig();
     499    }
    496500    return rootConfig;
    497501  }
    498502 
    499   public static synchronized void unloadConfig()
    500   {
    501     rootConfig = null;
    502     openGridConfig = null;
    503     if (reloadConfig != null)
    504     {
    505       Application.getExtensionsManager().getRegistry().unregisterEventHandler(reloadConfig);
    506       reloadConfig = null;
     503  public static void unloadConfig()
     504  {
     505    synchronized (configLock)
     506    {
     507      rootConfig = null;
     508      openGridConfig = null;
     509      if (reloadConfig != null)
     510      {
     511        Application.getExtensionsManager().getRegistry().unregisterEventHandler(reloadConfig);
     512        reloadConfig = null;
     513      }
    507514    }
    508515  }
     
    527534
    528535 
     536  private static Object sessionLock = new Object();
    529537  private static SessionControl rootSc;
    530538  /**
     
    540548    @since 3.0
    541549  */
    542   public static synchronized SessionControl getRootSessionControl(SessionControl systemSc)
    543   {
    544     if (rootSc == null || rootSc.isClosed())
    545     {
    546       SessionControl tmp = systemSc.impersonateLogin(SystemItems.getId(User.ROOT), "Reggie services");
    547       DbControl dc = tmp.newDbControl();
    548       try
    549       {
    550         ItemQuery<Project> q = Project.getQuery();
    551         q.setIncludes(Include.ALL);
    552         q.restrict(Restrictions.eq(Hql.property("name"), Expressions.string("SCAN-B")));
    553         List<Project> projects = q.list(dc);
    554         if (projects.size() == 1)
     550  public static SessionControl getRootSessionControl(SessionControl systemSc)
     551  {
     552    synchronized (sessionLock)
     553    {
     554      if (rootSc == null || rootSc.isClosed())
     555      {
     556        SessionControl tmp = systemSc.impersonateLogin(SystemItems.getId(User.ROOT), "Reggie services");
     557        DbControl dc = tmp.newDbControl();
     558        try
    555559        {
    556           tmp.setActiveProject(projects.get(0));
     560          ItemQuery<Project> q = Project.getQuery();
     561          q.setIncludes(Include.ALL);
     562          q.restrict(Restrictions.eq(Hql.property("name"), Expressions.string("SCAN-B")));
     563          List<Project> projects = q.list(dc);
     564          if (projects.size() == 1)
     565          {
     566            tmp.setActiveProject(projects.get(0));
     567          }
    557568        }
    558       }
    559       finally
    560       {
    561         if (dc != null) dc.close();
    562       }
    563      
    564       // Set active project
    565       rootSc = tmp;
    566     }
    567     else
    568     {
    569       rootSc.updateLastAccess();
     569        finally
     570        {
     571          if (dc != null) dc.close();
     572        }
     573       
     574        // Set active project
     575        rootSc = tmp;
     576      }
     577      else
     578      {
     579        rootSc.updateLastAccess();
     580      }
    570581    }
    571582    return rootSc;
     
    577588    @since 3.0
    578589  */
    579   public static synchronized void closeRootSessionControl()
    580   {
    581     if (rootSc != null)
    582     {
    583       rootSc.close();
    584       rootSc = null;
    585     }
    586   }
    587  
    588   private static synchronized void loadConfig(boolean force)
     590  public static void closeRootSessionControl()
     591  {
     592    synchronized (sessionLock)
     593    {
     594      if (rootSc != null)
     595      {
     596        rootSc.close();
     597        rootSc = null;
     598      }
     599    }
     600  }
     601 
     602  private static void loadConfig(boolean force)
    589603  {
    590604    URL configUrl = Reggie.class.getResource("/reggie-config.xml");
    591605    if (rootConfig != null && !force) return;
    592     InputStream is = null;
    593     try
    594     {
    595       logger.debug("Loading configuration from; " + configUrl);
    596       is = configUrl == null ? null : configUrl.openStream();
    597       if (is == null)
    598       {
    599         throw new ConfigurationException("Can't find the configuration file. " +
    600             "Make sure 'reggie-config.xml' is in the CLASSPATH.");
    601       }
    602      
    603       Document dom = XmlUtil2.getValidatedXml(configUrl, null);
    604       rootConfig = new XmlConfig(dom.getRootElement(), "[reggie]");
    605       openGridConfig = new HashMap<String, XmlConfig>();
    606      
    607       OpenGridService ogs = OpenGridService.getInstance();
    608       if (!ogs.isRunning()) logger.warn("Open Grid Service is no running");
    609      
    610       Element hosts = dom.getRootElement().getChild("remote-hosts");
    611       List<Element> allHosts = hosts.getChildren("host");
    612       for (Element h : allHosts)
    613       {
    614         String[] idList = h.getAttributeValue("id").split(",");
    615         for (String id : idList)
     606    synchronized (configLock)
     607    {
     608      InputStream is = null;
     609      try
     610      {
     611        logger.debug("Loading configuration from; " + configUrl);
     612        is = configUrl == null ? null : configUrl.openStream();
     613        if (is == null)
    616614        {
    617           if (!ogs.isDefined(id))
     615          throw new ConfigurationException("Can't find the configuration file. " +
     616              "Make sure 'reggie-config.xml' is in the CLASSPATH.");
     617        }
     618       
     619        Document dom = XmlUtil2.getValidatedXml(configUrl, null);
     620        rootConfig = new XmlConfig(dom.getRootElement(), "[reggie]");
     621        openGridConfig = new HashMap<String, XmlConfig>();
     622       
     623        OpenGridService ogs = OpenGridService.getInstance();
     624        if (!ogs.isRunning()) logger.warn("Open Grid Service is no running");
     625       
     626        Element hosts = dom.getRootElement().getChild("remote-hosts");
     627        List<Element> allHosts = hosts.getChildren("host");
     628        for (Element h : allHosts)
     629        {
     630          String[] idList = h.getAttributeValue("id").split(",");
     631          for (String id : idList)
    618632          {
    619             logger.warn("No cluster defined for id=" + id);
     633            if (!ogs.isDefined(id))
     634            {
     635              logger.warn("No cluster defined for id=" + id);
     636            }
     637            openGridConfig.put(id, new XmlConfig(h, "[" + id + "]"));
    620638          }
    621           openGridConfig.put(id, new XmlConfig(h, "[" + id + "]"));
    622639        }
    623       }
    624      
    625       if (reloadConfig == null)
    626       {
    627         // Create and register an event handler that re-load the Reggie configuration
    628         // whenever a SERVICE_STARTED event is sent for the Open Grid Service
    629         Registry registry = Application.getExtensionsManager().getRegistry();
    630         reloadConfig = new ReloadConfigEventHandler();
    631         EventFilter whenOpenGridServiceStarted = new ExtensionEventFilter("net.sf.basedb.opengrid.service", Services.SERVICE_STARTED);
    632         registry.registerEventHandler(reloadConfig, whenOpenGridServiceStarted, Reggie.class.getClassLoader());
    633       }
    634      
    635     }
    636     catch (Exception ex)
    637     {
    638       logger.error("Could not load configuration", ex);
    639       throw new RuntimeException(ex);
    640     }
    641     finally
    642     {
    643       FileUtil.close(is);
     640       
     641        if (reloadConfig == null)
     642        {
     643          // Create and register an event handler that re-load the Reggie configuration
     644          // whenever a SERVICE_STARTED event is sent for the Open Grid Service
     645          Registry registry = Application.getExtensionsManager().getRegistry();
     646          reloadConfig = new ReloadConfigEventHandler();
     647          EventFilter whenOpenGridServiceStarted = new ExtensionEventFilter("net.sf.basedb.opengrid.service", Services.SERVICE_STARTED);
     648          registry.registerEventHandler(reloadConfig, whenOpenGridServiceStarted, Reggie.class.getClassLoader());
     649        }
     650       
     651      }
     652      catch (Exception ex)
     653      {
     654        logger.error("Could not load configuration", ex);
     655        throw new RuntimeException(ex);
     656      }
     657      finally
     658      {
     659        FileUtil.close(is);
     660      }
    644661    }
    645662  }
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/grid/VariantCallingJobCreator.java

    r5736 r5760  
    401401        script.comment("and run that through gc_stat.py which produces a VCF file that vcfanno can use");
    402402        script.comment("to add back annotations to the VCF file from VarDict");
    403         script.cmd("awk '{OFS=\"\\t\"; if (!/^#/){print $1,$2-50,$2+50,$2,$4,$5}}' tmp/variants-raw-1.vcf > tmp/gc-50.bed");
     403        script.cmd("awk '{OFS=\"\\t\"; if (!/^#/){print $1,($2<50)?0:$2-50,$2+50,$2,$4,$5}}' tmp/variants-raw-1.vcf > tmp/gc-50.bed");
    404404        script.cmd(bedtools_path+" getfasta -fi ${Genome} -bed tmp/gc-50.bed -bedOut > tmp/gc-50-fasta.bed");
    405405        script.cmd("cat tmp/gc-50-fasta.bed | ./gc_stat.py | bgzip -c > tmp/gc-50.vcf.gz");
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/AliquotImporter.java

    r5663 r5760  
    2323import net.sf.basedb.core.query.Restrictions;
    2424import net.sf.basedb.reggie.Reggie;
     25import net.sf.basedb.reggie.converter.ValueConverter;
    2526import net.sf.basedb.reggie.dao.Annotationtype;
    2627import net.sf.basedb.reggie.dao.BioplateType;
     
    190191    Mapper patientIdMapper = getOptionalMapper(ffp, "PatientID", fileAndLine);
    191192    Mapper provnummerMapper = getOptionalMapper(ffp, "Provnummer", fileAndLine);
     193   
     194    ValueConverter<String, String> normalTumorConverter = new TranslationConverter("TUMOR", "T", "NA", null);
     195    ValueConverter<String, String> variantConverter = new TranslationConverter("0", null);
    192196   
    193197    while (ffp.hasMoreData())
     
    211215      a.poolVolume = poolVolumeMapper.getString(data);
    212216      if (commentMapper != null) a.comment = commentMapper.getString(data);
    213       if (normalTumorMapper != null) a.normalTumor = normalTumorMapper.getString(data);
     217      if (normalTumorMapper != null) a.normalTumor = normalTumorConverter.convert(normalTumorMapper.getString(data));
    214218      if (formMapper != null) a.form = formMapper.getString(data);
    215       if (variantMapper != null) a.variant = variantMapper.getString(data);
     219      if (variantMapper != null) a.variant = variantConverter.convert(variantMapper.getString(data));
    216220      if (variantListMapper != null) a.variantList = variantListMapper.getString(data);
    217221      if (screeningMapper != null) a.screening = screeningMapper.getString(data);
     
    664668   
    665669  }
     670 
     671  /**
     672    A simple converter for string values. If a value is found in the
     673    translation map the translation is returned. Otherwise the original
     674    value is returned unmodified.
     675  */
     676  public static class TranslationConverter
     677    implements ValueConverter<String, String>
     678  {
     679
     680    private final Map<String, String> translation;
     681   
     682    /**
     683      Create a new translation. Key and values are provided
     684      as a single array with pair-wise entries. Eg.
     685      mapping[0] translates to mapping[1], mapping[2] translates to
     686      mapping[3], and so on.
     687    */
     688    public TranslationConverter(String... mapping)
     689    {
     690      this.translation = new HashMap<>();
     691      for (int i = 1; i < mapping.length; i+=2)
     692      {
     693        translation.put(mapping[i-1], mapping[i]);
     694      }
     695    }
     696   
     697    @Override
     698    public String convert(String key)
     699    {
     700      return translation.containsKey(key) ? translation.get(key) : key;
     701    }
     702  }
    666703}
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/query/AnyToAnyRestriction.java

    r3051 r5760  
    22
    33import java.util.Collection;
     4import java.util.Collections;
    45
    56import net.sf.basedb.core.DbControl;
    67import net.sf.basedb.core.Item;
    78import net.sf.basedb.core.Type;
     9import net.sf.basedb.core.query.Expressions;
     10import net.sf.basedb.core.query.Hql;
    811import net.sf.basedb.core.query.Query;
    912import net.sf.basedb.core.query.QueryElement;
    1013import net.sf.basedb.core.query.Restriction;
     14import net.sf.basedb.core.query.Restrictions;
    1115import net.sf.basedb.util.EqualsHelper;
    1216
     
    2933  public static AnyToAnyRestriction exists(String linkName, Item linkedTo)
    3034  {
    31     return new AnyToAnyRestriction(linkName, linkedTo, true);
     35    Restriction link = linkedTo == null ? null :
     36      Restrictions.eq(Hql.property("at", "toType"), Expressions.integer(linkedTo.getValue()));
     37    return new AnyToAnyRestriction(linkName, link, true);
    3238  }
     39
     40  /**
     41    Create a restriction that restrict a query to return
     42    items that has a linked item with the given link name.
     43    An optional restriction can be used to limit the query
     44    to on the linked item (use "at" as prefix in the HQL).
     45    @since 4.24.1
     46  */
     47  public static AnyToAnyRestriction exists(String linkName, Restriction restriction)
     48  {
     49    return new AnyToAnyRestriction(linkName, restriction, true);
     50  }
     51
    3352 
    3453  /**
     
    3958  public static AnyToAnyRestriction missing(String linkName, Item linkedTo)
    4059  {
    41     return new AnyToAnyRestriction(linkName, linkedTo, false);
     60    Restriction link = linkedTo == null ? null :
     61        Restrictions.eq(Hql.property("at", "toType"), Expressions.integer(linkedTo.getValue()));
     62    return new AnyToAnyRestriction(linkName, link, false);
    4263  }
    4364 
    4465  private final String parameterName;
    45   private final String subQuery;
     66  private final Restriction linkRestriction;
    4667  private final String linkName;
    4768  private final boolean hasLink;
    4869 
    49   private AnyToAnyRestriction(String linkName, Item linkedTo, boolean hasLink)
     70  private AnyToAnyRestriction(String linkName, Restriction linkRestriction, boolean hasLink)
    5071  {
    5172    this.linkName = linkName;
    5273    this.hasLink = hasLink;
    5374    this.parameterName = "LN" + System.identityHashCode(this);
    54     StringBuilder sb = new StringBuilder();
    55     sb.append("(SELECT at.fromId FROM AnyToAnyData at WHERE at.name = :");
    56     sb.append(parameterName);
    57     if (linkedTo != null)
    58     {
    59       sb.append(" AND at.toType=").append(linkedTo.getValue());
    60     }
    61     sb.append(")");
    62     this.subQuery = sb.toString();
     75    this.linkRestriction = linkRestriction;
    6376  }
    6477 
     
    6780  {
    6881    query.setParameter(parameterName, linkName, Type.STRING);
    69     return query.getRootAlias() + (hasLink ? ".id = ANY" : ".id <> ALL") + subQuery;
     82    return query.getRootAlias() + (hasLink ? ".id = ANY" : ".id <> ALL") + getSubQuery(query, dc);
    7083  }
    7184
     
    7386  public Collection<? extends QueryElement> getChildren()
    7487  {
    75     return null;
     88    return linkRestriction != null ? Collections.singleton(linkRestriction) : null;
    7689  }
    7790
     91  private String getSubQuery(Query query, DbControl dc)
     92  {
     93    StringBuilder sb = new StringBuilder();
     94    sb.append("(SELECT at.fromId FROM AnyToAnyData at WHERE at.name = :");
     95    sb.append(parameterName);
     96    if (linkRestriction != null)
     97    {
     98      if (query == null)
     99      {
     100        sb.append(" AND ").append(linkRestriction.toString());
     101      }
     102      else
     103      {
     104        sb.append(" AND ").append(linkRestriction.toQl(query, dc));
     105      }
     106    }
     107    sb.append(")");
     108    return sb.toString();
     109  }
    78110 
    79111  @Override
    80112  public String toString()
    81113  {
    82     return (hasLink ? "id = ANY" : "id <> ALL") + subQuery;
     114    return (hasLink ? "id = ANY" : "id <> ALL") + getSubQuery(null, null);
    83115  }
    84116 
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/MipsServlet.java

    r5603 r5760  
    6565import net.sf.basedb.reggie.plugins.AliquotImporter;
    6666import net.sf.basedb.reggie.plugins.AliquotImporter.AliquotPlate;
     67import net.sf.basedb.reggie.query.AnyToAnyRestriction;
    6768import net.sf.basedb.util.EqualsHelper;
    6869import net.sf.basedb.util.FileUtil;
     
    348349        query.order(Orders.asc(Hql.property("name")));
    349350       
     351        // Find other MIPs plates with a given template that has not yet been pooled
     352        // We use this information to display a warning if registering more than one plate with
     353        // the same barcode template since that is typically a mistake
     354        ItemQuery<BioPlate> unpooledQuery = BioPlate.getQuery();
     355        unpooledQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
     356        // Only MIPs plates that are not destroyed
     357        BioplateType.MIPS.addFilter(dc, unpooledQuery, true);
     358        // Must have a PLATE_PROCESS_RESULT=Success annotation
     359        unpooledQuery.join(Annotations.innerJoin(null, Annotationtype.PLATE_PROCESS_RESULT.load(dc), "ppr"));
     360        unpooledQuery.restrict(Restrictions.eq(Hql.alias("ppr"), Expressions.string(ReactionPlate.PROCESS_SUCCESSFUL)));
     361        // Must NOT have a PoolDate annotation
     362        unpooledQuery.join(Annotations.leftJoin(null, Annotationtype.POOL_DATE.load(dc), "pd"));
     363        unpooledQuery.restrict(Restrictions.eq(Hql.alias("pd"), null));
     364        // Filter on BarcodeTemplate link
     365        unpooledQuery.restrict(AnyToAnyRestriction.exists("BarcodeTemplate",
     366          Restrictions.eq(Hql.property("at", "toId"), Hql.entityParameter("template", Item.BIOPLATE))));
     367        unpooledQuery.order(Orders.asc(Hql.property("name")));
     368       
    350369        List<BioPlate> result = query.list(dc);
    351370        JSONArray jsonPlates = new JSONArray();
     
    359378          jsonPlate.put("comments", plate.getDescription());
    360379          jsonPlates.add(jsonPlate);
     380         
     381          JSONArray jsonUnpooled = new JSONArray();
     382          unpooledQuery.setEntityParameter("template", plate);
     383          for (BioPlate unpooled : unpooledQuery.list(dc))
     384          {
     385            JSONObject jsonUP = new JSONObject();
     386            jsonUP.put("id", unpooled.getId());
     387            jsonUP.put("name", unpooled.getName());
     388            jsonUnpooled.add(jsonUP);
     389          }
     390          jsonPlate.put("otherPlates", jsonUnpooled);
     391         
    361392        }
    362393        json.put("templates", jsonPlates);
Note: See TracChangeset for help on using the changeset viewer.