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

Code
Comments
Other
Rev Date Author Line
4712 22 Mar 18 nicklas 1 package net.sf.basedb.reggie.vcf;
4712 22 Mar 18 nicklas 2
4712 22 Mar 18 nicklas 3 import net.sf.basedb.core.DbControl;
4712 22 Mar 18 nicklas 4 import net.sf.basedb.core.DerivedBioAssay;
4712 22 Mar 18 nicklas 5 import net.sf.basedb.reggie.dao.Annotationtype;
4712 22 Mar 18 nicklas 6
4712 22 Mar 18 nicklas 7 /**
4712 22 Mar 18 nicklas 8   Enum for flagging an alignment as having a verified genotype. 
4712 22 Mar 18 nicklas 9   A genotype can be verified by comparing it against a separate 
4712 22 Mar 18 nicklas 10   sample. 
4712 22 Mar 18 nicklas 11
4712 22 Mar 18 nicklas 12   @author nicklas
4712 22 Mar 18 nicklas 13   @since 4.16
4712 22 Mar 18 nicklas 14 */
4712 22 Mar 18 nicklas 15 public enum VerifiedMatch 
4712 22 Mar 18 nicklas 16 {
4712 22 Mar 18 nicklas 17
4712 22 Mar 18 nicklas 18   /**
4712 22 Mar 18 nicklas 19     The genotype has been verified to match DNA from a separate sample.
4712 22 Mar 18 nicklas 20   */
4712 22 Mar 18 nicklas 21   DNA("DNA"),
4712 22 Mar 18 nicklas 22   
4712 22 Mar 18 nicklas 23   /**
4712 22 Mar 18 nicklas 24     The genotype has been verified to match RNA from a separate sample.
4712 22 Mar 18 nicklas 25   */
4712 22 Mar 18 nicklas 26   SPECIMEN("Specimen"),
4712 22 Mar 18 nicklas 27   
4712 22 Mar 18 nicklas 28   /**
4712 22 Mar 18 nicklas 29     The genotype has been verified to match RNA from a second 
4712 22 Mar 18 nicklas 30     extraction of the same specimen.
4712 22 Mar 18 nicklas 31   */
4712 22 Mar 18 nicklas 32   LYSATE("Lysate");
4712 22 Mar 18 nicklas 33   
4712 22 Mar 18 nicklas 34   
4712 22 Mar 18 nicklas 35   private final String title;
4712 22 Mar 18 nicklas 36
4712 22 Mar 18 nicklas 37   private VerifiedMatch(String title)
4712 22 Mar 18 nicklas 38   {
4712 22 Mar 18 nicklas 39     this.title = title;
4712 22 Mar 18 nicklas 40   }
4712 22 Mar 18 nicklas 41   
4712 22 Mar 18 nicklas 42   /**
4712 22 Mar 18 nicklas 43     The title to use when interacting with users.
4712 22 Mar 18 nicklas 44   */
4712 22 Mar 18 nicklas 45   public String getTitle()
4712 22 Mar 18 nicklas 46   {
4712 22 Mar 18 nicklas 47     return title;
4712 22 Mar 18 nicklas 48   }
4712 22 Mar 18 nicklas 49   
4712 22 Mar 18 nicklas 50   /**
4728 04 Apr 18 nicklas 51     Update the QC_GENOTYPE_VERIFIED annotation if this verified 
4728 04 Apr 18 nicklas 52     match is "better" than what is already set on the alignment.
4728 04 Apr 18 nicklas 53   */
4728 04 Apr 18 nicklas 54   public boolean updateIfBetter(DbControl dc, DerivedBioAssay alignment)
4728 04 Apr 18 nicklas 55   {
4728 04 Apr 18 nicklas 56     VerifiedMatch existing = VerifiedMatch.getVerifiedMatch(dc, alignment);
4728 04 Apr 18 nicklas 57     boolean updated = false;
4728 04 Apr 18 nicklas 58     if (existing == null || ordinal() < existing.ordinal())
4728 04 Apr 18 nicklas 59     {
4728 04 Apr 18 nicklas 60       updated = Annotationtype.QC_GENOTYPE_VERIFIED.setAnnotationValue(dc, alignment, getTitle());
4728 04 Apr 18 nicklas 61     }
4728 04 Apr 18 nicklas 62     return updated;
4728 04 Apr 18 nicklas 63   }
4728 04 Apr 18 nicklas 64   
4728 04 Apr 18 nicklas 65   /**
4712 22 Mar 18 nicklas 66     Get the verified match stored as an annotation on the given alignment.
4712 22 Mar 18 nicklas 67   */
4712 22 Mar 18 nicklas 68   public static VerifiedMatch getVerifiedMatch(DbControl dc, DerivedBioAssay alignment)
4712 22 Mar 18 nicklas 69   {
4712 22 Mar 18 nicklas 70     String verified = (String)Annotationtype.QC_GENOTYPE_VERIFIED.getAnnotationValue(dc, alignment);
4712 22 Mar 18 nicklas 71     if (verified != null)
4712 22 Mar 18 nicklas 72     {
4712 22 Mar 18 nicklas 73       for (VerifiedMatch match : VerifiedMatch.values())
4712 22 Mar 18 nicklas 74       {
4712 22 Mar 18 nicklas 75         if (match.getTitle().equals(verified)) return match;
4712 22 Mar 18 nicklas 76       }
4712 22 Mar 18 nicklas 77     }
4712 22 Mar 18 nicklas 78     return null;
4712 22 Mar 18 nicklas 79   }
4712 22 Mar 18 nicklas 80
4712 22 Mar 18 nicklas 81   
4712 22 Mar 18 nicklas 82   /**
4712 22 Mar 18 nicklas 83     Get the "best" verified match among the given matches. A DNA match is
4712 22 Mar 18 nicklas 84     better than a SPECIMEN match that is better than a LYSATE match.
4712 22 Mar 18 nicklas 85   */
4712 22 Mar 18 nicklas 86   public static VerifiedMatch getBest(VerifiedMatch... matches)
4712 22 Mar 18 nicklas 87   {
4712 22 Mar 18 nicklas 88     VerifiedMatch best = null;    
4712 22 Mar 18 nicklas 89     for (VerifiedMatch m : matches)
4712 22 Mar 18 nicklas 90     {
4712 22 Mar 18 nicklas 91       if (best == null || (m != null && m.ordinal() < best.ordinal()))
4712 22 Mar 18 nicklas 92       {
4712 22 Mar 18 nicklas 93         best = m;
4712 22 Mar 18 nicklas 94       }
4712 22 Mar 18 nicklas 95     }
4712 22 Mar 18 nicklas 96     return best;
4712 22 Mar 18 nicklas 97   }
4712 22 Mar 18 nicklas 98
4712 22 Mar 18 nicklas 99   
4712 22 Mar 18 nicklas 100 }