extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/vcf/GenoTypeMessage.java

Code
Comments
Other
Rev Date Author Line
4648 15 Dec 17 nicklas 1 package net.sf.basedb.reggie.vcf;
4648 15 Dec 17 nicklas 2
4819 22 May 18 nicklas 3 import java.util.Comparator;
4819 22 May 18 nicklas 4
4648 15 Dec 17 nicklas 5 import org.json.simple.JSONObject;
4648 15 Dec 17 nicklas 6
5014 08 Oct 18 nicklas 7 import net.sf.basedb.core.DbControl;
4648 15 Dec 17 nicklas 8 import net.sf.basedb.core.DerivedBioAssay;
6588 18 Feb 22 nicklas 9 import net.sf.basedb.core.ItemSubtype;
5014 08 Oct 18 nicklas 10 import net.sf.basedb.reggie.dao.Annotationtype;
7201 25 May 23 nicklas 11 import net.sf.basedb.reggie.dao.Pipeline;
4648 15 Dec 17 nicklas 12
4648 15 Dec 17 nicklas 13 /**
4819 22 May 18 nicklas 14   For keeping track of warnings. 
4648 15 Dec 17 nicklas 15   @author nicklas
4648 15 Dec 17 nicklas 16   @since 4.14
4648 15 Dec 17 nicklas 17 */
4728 04 Apr 18 nicklas 18 public class GenoTypeMessage 
4648 15 Dec 17 nicklas 19 {
4648 15 Dec 17 nicklas 20
4819 22 May 18 nicklas 21   /**
4819 22 May 18 nicklas 22     Comparator implementation for sorting messages by category and name of alignment.
4819 22 May 18 nicklas 23     @since 4.18
4819 22 May 18 nicklas 24   */
6588 18 Feb 22 nicklas 25   public static final Comparator<GenoTypeMessage> SORT_BY_CATEGORY_AND_ASSAY = new Comparator<GenoTypeMessage>()
4819 22 May 18 nicklas 26   {
4819 22 May 18 nicklas 27
4819 22 May 18 nicklas 28     @Override
4819 22 May 18 nicklas 29     public int compare(GenoTypeMessage o1, GenoTypeMessage o2) 
4819 22 May 18 nicklas 30     {
4819 22 May 18 nicklas 31       int order = o1.category.ordinal() - o2.category.ordinal();
6588 18 Feb 22 nicklas 32       if (order == 0 && o1.otherAssay != null && o2.otherAssay != null)
4819 22 May 18 nicklas 33       {
6588 18 Feb 22 nicklas 34         order = o1.otherAssay.getName().compareTo(o2.otherAssay.getName());
4819 22 May 18 nicklas 35       }
4819 22 May 18 nicklas 36       return order;
4819 22 May 18 nicklas 37     }
4819 22 May 18 nicklas 38     
4819 22 May 18 nicklas 39   };
4819 22 May 18 nicklas 40   
6588 18 Feb 22 nicklas 41   private static AssayType getAssayType(DbControl dc, DerivedBioAssay assay)
6588 18 Feb 22 nicklas 42   {
6588 18 Feb 22 nicklas 43     ItemSubtype subtype = assay.getItemSubtype();
7201 25 May 23 nicklas 44     Pipeline pipeline = Pipeline.getByName((String)Annotationtype.PIPELINE.getAnnotationValue(dc, assay));
6588 18 Feb 22 nicklas 45     AssayType assayType = null;
7201 25 May 23 nicklas 46     if (pipeline == Pipeline.DNA_NORMAL_WGS || pipeline == Pipeline.DNA_GENOTYPING)
6588 18 Feb 22 nicklas 47     {
7201 25 May 23 nicklas 48       assayType = AssayType.NORMAL;
6588 18 Feb 22 nicklas 49     }
7201 25 May 23 nicklas 50     else
7201 25 May 23 nicklas 51     {
7201 25 May 23 nicklas 52       assayType = AssayType.TUMOR;
7201 25 May 23 nicklas 53     }
6588 18 Feb 22 nicklas 54     return assayType;
6588 18 Feb 22 nicklas 55   }
6588 18 Feb 22 nicklas 56   
4794 07 May 18 nicklas 57   private final Category category;
4728 04 Apr 18 nicklas 58   private final Level warningLevel;
4648 15 Dec 17 nicklas 59   private final String message;
6588 18 Feb 22 nicklas 60   private final DerivedBioAssay otherAssay;
6588 18 Feb 22 nicklas 61   private final AssayType assayType;
6451 22 Oct 21 nicklas 62   private final SpecimenData specimen;
4648 15 Dec 17 nicklas 63   private final VcfData vcf;
4649 20 Dec 17 nicklas 64   private final boolean flagged;
4712 22 Mar 18 nicklas 65   private final VerifiedMatch verified;
4728 04 Apr 18 nicklas 66   private final VerifiedMatch currentVerified;
5014 08 Oct 18 nicklas 67   private final String doNotUse;
5014 08 Oct 18 nicklas 68   private final String doNotUseComment;
4648 15 Dec 17 nicklas 69   
4728 04 Apr 18 nicklas 70   private String messageTooltip;
6588 18 Feb 22 nicklas 71   private String assayTooltip;
4728 04 Apr 18 nicklas 72   
4648 15 Dec 17 nicklas 73   /**
6588 18 Feb 22 nicklas 74     Create a message that is unrelated to another assay.
4648 15 Dec 17 nicklas 75   */
4794 07 May 18 nicklas 76   public GenoTypeMessage(Category category, Level warningLevel, String message)
4648 15 Dec 17 nicklas 77   {
6451 22 Oct 21 nicklas 78     this(category, warningLevel, message, null, null, null, false, null);
4648 15 Dec 17 nicklas 79   }
4648 15 Dec 17 nicklas 80   
4648 15 Dec 17 nicklas 81   /**
6588 18 Feb 22 nicklas 82     Creates a warning thiat is related to another assay.
4648 15 Dec 17 nicklas 83   */
6588 18 Feb 22 nicklas 84   public GenoTypeMessage(Category category, Level warningLevel, String message, DerivedBioAssay otherAssay, SpecimenData specimen, VcfData vcf, boolean flagged, VerifiedMatch verified)
4648 15 Dec 17 nicklas 85   {
4794 07 May 18 nicklas 86     this.category = category;
4728 04 Apr 18 nicklas 87     this.warningLevel = warningLevel;
4648 15 Dec 17 nicklas 88     this.message = message;
6588 18 Feb 22 nicklas 89     this.otherAssay = otherAssay;
6451 22 Oct 21 nicklas 90     this.specimen = specimen;
4648 15 Dec 17 nicklas 91     this.vcf = vcf;
4649 20 Dec 17 nicklas 92     this.flagged = flagged;
4712 22 Mar 18 nicklas 93     this.verified = verified;
6588 18 Feb 22 nicklas 94     if (otherAssay != null)
5014 08 Oct 18 nicklas 95     {
6588 18 Feb 22 nicklas 96       DbControl dc = otherAssay.getDbControl();
6588 18 Feb 22 nicklas 97       this.currentVerified = VerifiedMatch.getVerifiedMatch(dc, otherAssay);
6588 18 Feb 22 nicklas 98       this.doNotUse = (String)Annotationtype.DO_NOT_USE.getAnnotationValue(dc, otherAssay);
6588 18 Feb 22 nicklas 99       this.doNotUseComment = (String)Annotationtype.DO_NOT_USE_COMMENT.getAnnotationValue(dc, otherAssay);
6588 18 Feb 22 nicklas 100       this.assayType = getAssayType(dc, otherAssay);
5014 08 Oct 18 nicklas 101     }
5014 08 Oct 18 nicklas 102     else
5014 08 Oct 18 nicklas 103     {
5014 08 Oct 18 nicklas 104       this.currentVerified = null;
5014 08 Oct 18 nicklas 105       this.doNotUse = null;
5014 08 Oct 18 nicklas 106       this.doNotUseComment = null;
6588 18 Feb 22 nicklas 107       this.assayType = null;
5014 08 Oct 18 nicklas 108     }
4648 15 Dec 17 nicklas 109   }
4648 15 Dec 17 nicklas 110
4794 07 May 18 nicklas 111   public Category getCategory()
4794 07 May 18 nicklas 112   {
4794 07 May 18 nicklas 113     return category;
4794 07 May 18 nicklas 114   }
4794 07 May 18 nicklas 115   
4794 07 May 18 nicklas 116   public Level getWarningLevel()
4794 07 May 18 nicklas 117   {
4794 07 May 18 nicklas 118     return warningLevel;
4794 07 May 18 nicklas 119   }
4794 07 May 18 nicklas 120   
7216 30 May 23 nicklas 121   public String getMessage()
7216 30 May 23 nicklas 122   {
7216 30 May 23 nicklas 123     return message;
7216 30 May 23 nicklas 124   }
7216 30 May 23 nicklas 125   
6588 18 Feb 22 nicklas 126   public DerivedBioAssay getOtherAssay()
4794 07 May 18 nicklas 127   {
6588 18 Feb 22 nicklas 128     return otherAssay;
4794 07 May 18 nicklas 129   }
4794 07 May 18 nicklas 130   
6588 18 Feb 22 nicklas 131   public boolean isFlagged()
4794 07 May 18 nicklas 132   {
4794 07 May 18 nicklas 133     return flagged;
4794 07 May 18 nicklas 134   }
4794 07 May 18 nicklas 135   
6588 18 Feb 22 nicklas 136   public VerifiedMatch getVerified()
4794 07 May 18 nicklas 137   {
4794 07 May 18 nicklas 138     return currentVerified;
4794 07 May 18 nicklas 139   }
4794 07 May 18 nicklas 140   
6588 18 Feb 22 nicklas 141   public VerifiedMatch getVerifiedAssay()
4794 07 May 18 nicklas 142   {
4794 07 May 18 nicklas 143     return verified;
4794 07 May 18 nicklas 144   }
4794 07 May 18 nicklas 145   
5014 08 Oct 18 nicklas 146   public String getDoNotUse()
5014 08 Oct 18 nicklas 147   {
5014 08 Oct 18 nicklas 148     return doNotUse;
5014 08 Oct 18 nicklas 149   }
4794 07 May 18 nicklas 150   
5014 08 Oct 18 nicklas 151   public String getDoNotUseComment()
5014 08 Oct 18 nicklas 152   {
5014 08 Oct 18 nicklas 153     return doNotUseComment;
5014 08 Oct 18 nicklas 154   }
4794 07 May 18 nicklas 155   
4728 04 Apr 18 nicklas 156   public void setMessageTooltip(String tooltip)
4728 04 Apr 18 nicklas 157   {
4728 04 Apr 18 nicklas 158     this.messageTooltip = tooltip;
4728 04 Apr 18 nicklas 159   }
4728 04 Apr 18 nicklas 160   
6588 18 Feb 22 nicklas 161   public void setAssayTooltip(String tooltip)
4728 04 Apr 18 nicklas 162   {
6588 18 Feb 22 nicklas 163     this.assayTooltip = tooltip;
4728 04 Apr 18 nicklas 164   }
4728 04 Apr 18 nicklas 165   
4648 15 Dec 17 nicklas 166   public JSONObject asJSONObject()
4648 15 Dec 17 nicklas 167   {
4648 15 Dec 17 nicklas 168     JSONObject json = new JSONObject();
4794 07 May 18 nicklas 169     json.put("category", category.name());
4728 04 Apr 18 nicklas 170     json.put("warningLevel", warningLevel.name());
4648 15 Dec 17 nicklas 171     json.put("message", message);
4728 04 Apr 18 nicklas 172     json.put("messageTooltip", messageTooltip);
6588 18 Feb 22 nicklas 173     if (otherAssay != null)
4648 15 Dec 17 nicklas 174     {
6588 18 Feb 22 nicklas 175       json.put("id", otherAssay.getId());
6588 18 Feb 22 nicklas 176       json.put("otherAssay", otherAssay.getName());
6588 18 Feb 22 nicklas 177       if (assayType != null) json.put("assayType", assayType.name());
6588 18 Feb 22 nicklas 178       json.put("assayTooltip", assayTooltip);
4649 20 Dec 17 nicklas 179       json.put("flagged", flagged);
4712 22 Mar 18 nicklas 180       json.put("verifiedBy", verified == null ? null : verified.name());
4728 04 Apr 18 nicklas 181       json.put("currentVerifiedBy", currentVerified == null ? null : currentVerified.name());
5014 08 Oct 18 nicklas 182       json.put("DO_NOT_USE", doNotUse);
5014 08 Oct 18 nicklas 183       json.put("DO_NOT_USE_COMMENT", doNotUseComment);
4648 15 Dec 17 nicklas 184     }
6451 22 Oct 21 nicklas 185     if (specimen != null)
6451 22 Oct 21 nicklas 186     {
6451 22 Oct 21 nicklas 187       json.put("specimen", specimen.asJSONObject());
6451 22 Oct 21 nicklas 188     }
6451 22 Oct 21 nicklas 189     if (vcf != null) json.put("vcf", vcf.asJSONObject(false));
4648 15 Dec 17 nicklas 190     return json;
4648 15 Dec 17 nicklas 191   }
4648 15 Dec 17 nicklas 192   
4794 07 May 18 nicklas 193   
4794 07 May 18 nicklas 194   public enum Category
4794 07 May 18 nicklas 195   {
4794 07 May 18 nicklas 196     HIGH_HET(Level.HIGH, "HIGH HET", false),
4794 07 May 18 nicklas 197     LOW_DATA(Level.LOW, "LOW DATA", false),
4794 07 May 18 nicklas 198     LOW_GQ(Level.LOW, "LOW GQ", false),
4794 07 May 18 nicklas 199     LOW_GT_COUNT(Level.HIGH, "LOW GT COUNT", false),
4819 22 May 18 nicklas 200     VERIFIED_MATCH(Level.INFO, "VERIFIED MATCH", false),
4819 22 May 18 nicklas 201     GOOD_MATCH(Level.INFO, "GOOD MATCH", false),
4794 07 May 18 nicklas 202     LOW_MISMATCH(Level.HIGH, "LOW MISMATCH", true),
4794 07 May 18 nicklas 203     MEDIUM_MISMATCH(Level.LOW, "MEDIUM MISMATCH", true),
5014 08 Oct 18 nicklas 204     HIGH_MISMATCH(Level.HIGH, "HIGH MISMATCH", true),
6451 22 Oct 21 nicklas 205     DO_NOT_USE_MATCH(Level.HIGH, "DONOTUSE MATCH", false),
6452 22 Oct 21 nicklas 206     AMBIGUOUS_PATIENT(Level.HIGH, "AMBIGUOUS PATIENT", true);
4794 07 May 18 nicklas 207     
4794 07 May 18 nicklas 208     private final Level defaultLevel;
4794 07 May 18 nicklas 209     private final String messagePrefix;
4794 07 May 18 nicklas 210     private final boolean mismatch;
4794 07 May 18 nicklas 211     
4794 07 May 18 nicklas 212     private Category(Level defaultLevel, String messagePrefix, boolean mismatch)
4794 07 May 18 nicklas 213     {
4794 07 May 18 nicklas 214       this.defaultLevel = defaultLevel;
4794 07 May 18 nicklas 215       this.messagePrefix = messagePrefix;
4794 07 May 18 nicklas 216       this.mismatch = mismatch;
4794 07 May 18 nicklas 217     }
4794 07 May 18 nicklas 218     
4794 07 May 18 nicklas 219     public Level getDefaultLevel()
4794 07 May 18 nicklas 220     {
4794 07 May 18 nicklas 221       return defaultLevel;
4794 07 May 18 nicklas 222     }
4794 07 May 18 nicklas 223     
4794 07 May 18 nicklas 224     public String getMessagePrefix()
4794 07 May 18 nicklas 225     {
4794 07 May 18 nicklas 226       return messagePrefix;
4794 07 May 18 nicklas 227     }
4794 07 May 18 nicklas 228     
4794 07 May 18 nicklas 229     public boolean isMismatch()
4794 07 May 18 nicklas 230     {
4794 07 May 18 nicklas 231       return mismatch;
4794 07 May 18 nicklas 232     }
4794 07 May 18 nicklas 233     
4794 07 May 18 nicklas 234     public GenoTypeMessage message(String info)
4794 07 May 18 nicklas 235     {
4794 07 May 18 nicklas 236       return new GenoTypeMessage(this, defaultLevel, messagePrefix + info);
4794 07 May 18 nicklas 237     }
4794 07 May 18 nicklas 238     
4794 07 May 18 nicklas 239     
4794 07 May 18 nicklas 240   }
4794 07 May 18 nicklas 241   
4728 04 Apr 18 nicklas 242   public enum Level
4712 22 Mar 18 nicklas 243   {
4728 04 Apr 18 nicklas 244     INFO,
4728 04 Apr 18 nicklas 245     LOW,
4728 04 Apr 18 nicklas 246     HIGH;
4712 22 Mar 18 nicklas 247   }
4648 15 Dec 17 nicklas 248   
6588 18 Feb 22 nicklas 249   public enum AssayType
6588 18 Feb 22 nicklas 250   {
7201 25 May 23 nicklas 251     TUMOR,
7201 25 May 23 nicklas 252     NORMAL;
6588 18 Feb 22 nicklas 253   }
4648 15 Dec 17 nicklas 254 }