XiaoyangSu / AccuCor

Other
16 stars 11 forks source link

Fix crash with overlapping isotoplogues #4

Open lparsons opened 4 years ago

lparsons commented 4 years ago

The application crashes without warning when isotoplogues are supplied that extend the number of atoms used for tracing. For example I have C6 but supply up to M+7. This probably doesn't happen with MAVEN but if users would use other tools. For example they usually run C-tracing experiments and extract all the possible isotopologues for C but at another point run N-tracing and just apply the same method, extract the same masses although the higher ones are empty then. As the atoms are counted anyway it would be nice to remove any overlap, otherwise it has to be done beforehand.

Reported by Matthias P via email

MPietzke commented 3 years ago

What I do is I filter the input before I save the input for Accucor. For this I added a function to extract the number of atoms of the traced element from the supplied sum formula:

   Extract_Tracer_Count = function(SumFormula, Tracer) {
     if(str_detect(SumFormula, Tracer) == TRUE) {
       Count = str_extract(SumFormula, paste0("(?<=",Tracer,")\\d*"))
       return(ifelse(Count > 1, Count, 1))
     } else return(0) # Tracer not found
   }

and then remove all the rows with a higher isotope count.

      mutate(Tracercount = as.numeric(Extract_Tracer_Count(Formula, input$Tracer_Type))) %>%
      filter(Isotope <= Tracercount) %>%   

maybe this helps? I guess you extract the numbers anyway in the function and can just drop / skip the lines?