package uk.ac.ebi.spot.goci.utils;

import org.springframework.stereotype.Service;

/**
 * Created by emma on 09/05/2016.
 *
 * @author emma
 *         <p>
 *         Service class to translate headers in upload file to enum value
 */
@Service
public class TranslateUploadHeaders {

    public UploadFileHeader translateToEnumValue(String value) {

        value = value.toLowerCase();
        UploadFileHeader enumValue;

        if (value.startsWith("snp id")) {
            enumValue = UploadFileHeader.SNP_ID;
        }
        else if (value.startsWith("chr")) {
            enumValue = UploadFileHeader.CHR;
        }
        else if (value.startsWith("bp")) {
            enumValue = UploadFileHeader.BP;
        }
        else if (value.startsWith("genome")) {
            enumValue = UploadFileHeader.GENOME_BUILD;
        }
        else if (value.startsWith("effect allele")) {
            enumValue = UploadFileHeader.EFFECT_ALLELE;
        }
        else if (value.startsWith("other alleles")) {
            enumValue = UploadFileHeader.OTHER_ALLELES;
        }
        else if (value.startsWith("effect allele frequency in controls")) {
            enumValue = UploadFileHeader.EFFECT_ALLELE_FREQUENCY_IN_CONTROLS;
        }
        else if (value.startsWith("p-value mantissa")) {
            enumValue = UploadFileHeader.PVALUE_MANTISSA;
        }
        else if (value.startsWith("p-value exponent")) {
            enumValue = UploadFileHeader.PVALUE_EXPONENT;
        }
        else if (value.startsWith("or")) {
            enumValue = UploadFileHeader.OR;
        }
        else if (value.startsWith("beta")) {
            enumValue = UploadFileHeader.BETA;
        }
        else if (value.startsWith("beta unit")) {
            enumValue = UploadFileHeader.BETA_UNIT;
        }
        else if (value.startsWith("beta direction")) {
            enumValue = UploadFileHeader.BETA_DIRECTION;
        }
        else if (value.startsWith("OR/beta SE")) {
            enumValue = UploadFileHeader.STANDARD_ERROR;
        }
        else if (value.startsWith("OR/beta range")) {
            enumValue = UploadFileHeader.RANGE;
        }
        else if (value.startsWith("Association description")) {
            enumValue = UploadFileHeader.PVALUE_DESCRIPTION;
        }
        else {
            enumValue = UploadFileHeader.UNKNOWN;
        }

        return enumValue;
    }
}

@@ -438,26 +438,47 @@
 lue.
-startsWith(%22snp id
+equals(%22snp id(ideally rsid)(mandatory)
 %22)) 
@@ -565,23 +565,29 @@
 lue.
-startsWith(%22chr
+equals(%22chr(optional)
 %22)) 
@@ -671,22 +671,28 @@
 lue.
-startsWith(%22bp
+equals(%22bp(optional)
 %22)) 
@@ -775,26 +775,38 @@
 lue.
-startsWith(%22genome
+equals(%22genome build(optional)
 %22)) 
@@ -891,34 +891,30 @@
 e if (value.
-startsWith
+equals
 (%22effect all
@@ -916,16 +916,26 @@
 t allele
+(optional)
 %22)) %7B%0A  
@@ -1021,26 +1021,22 @@
  (value.
-startsWith
+equals
 (%22other 
@@ -1042,16 +1042,26 @@
  alleles
+(optional)
 %22)) %7B%0A  
@@ -1186,20 +1186,8 @@
 ency
- in controls
 %22)) 
@@ -1295,34 +1295,30 @@
 e if (value.
-startsWith
+equals
 (%22p-value ma
@@ -1323,16 +1323,27 @@
 mantissa
+(mandatory)
 %22)) %7B%0A  
@@ -1431,26 +1431,22 @@
  (value.
-startsWith
+equals
 (%22p-valu
@@ -1455,16 +1455,27 @@
 exponent
+(mandatory)
 %22)) %7B%0A  
@@ -1567,22 +1567,28 @@
 lue.
-startsWith(%22or
+equals(%22or(optional)
 %22)) 
@@ -1667,32 +1667,38 @@
  (value.
-startsWith(%22beta
+equals(%22beta(optional)
 %22)) %7B%0A  
@@ -2013,30 +2013,36 @@
 lue.
-startsWith(%22OR/beta SE
+equals(%22or/beta se(optional)
 %22)) 
@@ -2145,18 +2145,18 @@
 tsWith(%22
-OR
+or
 /beta ra
@@ -2249,21 +2249,17 @@
 lue.
-startsWith(%22A
+equals(%22a
 ssoc
@@ -2272,24 +2272,34 @@
  description
+(optional)
 %22)) %7B%0A      
@@ -2438,17 +2438,16 @@
       %7D%0A
-%0A
         
@@ -2470,10 +2470,9 @@
 ;%0A    %7D%0A
+
 %7D
-%0A

Update to deal with various flavours of headers