private static int GetRowsToSkip(BioscreenFileType fileType) { //Note: Row == columns in the souorce file. Basically this skips the time and other columns and points to the OD columns. int skip = 0; switch (fileType) { case BioscreenFileType.Legacy: case BioscreenFileType.Generic: skip = 1; break; case BioscreenFileType.CSV: case BioscreenFileType.CSV2: skip = 2; break; case BioscreenFileType.Other: break; default: throw new ArgumentOutOfRangeException("fileType"); } return(skip); }
private static string[] GetHeaders(IEnumerable <string> reader, BioscreenFileType fileType) { try { switch (fileType) { case BioscreenFileType.Legacy: return(reader.Skip(6).First().Split('\t')); case BioscreenFileType.CSV: return(reader.First().SplitXP(",", "\"", true)); case BioscreenFileType.CSV2: return(reader.Skip(2).First().SplitXP(",", "\"", true)); case BioscreenFileType.Generic: return(reader.First().Split('\t')); default: throw new ArgumentOutOfRangeException("fileType"); } } catch (Exception) { switch (fileType) { case BioscreenFileType.Legacy: throw new Exception("Could not read the file headers at line 7"); case BioscreenFileType.CSV: case BioscreenFileType.Generic: throw new Exception("Could not read the file headers at line 1"); case BioscreenFileType.CSV2: throw new Exception("Could not read the file headers at line 3"); default: throw new ArgumentOutOfRangeException("fileType"); } } }
private static IEnumerable <string> GetRecords(IEnumerable <string> reader, BioscreenFileType fileType) { try { switch (fileType) { case BioscreenFileType.Legacy: return(reader.Skip(7)); case BioscreenFileType.CSV: case BioscreenFileType.Generic: return(reader.Skip(1)); case BioscreenFileType.CSV2: return(reader.Skip(3)); default: throw new ArgumentOutOfRangeException("fileType"); } } catch (Exception) { switch (fileType) { case BioscreenFileType.Legacy: throw new Exception("Could not read the rest of the file from line 8"); case BioscreenFileType.CSV: case BioscreenFileType.Generic: throw new Exception("Could not read the file headers at line 1"); case BioscreenFileType.CSV2: throw new Exception("Could not read the file headers at line 3"); default: throw new ArgumentOutOfRangeException("fileType"); } } }
private static Queue <Well> GetWellQueue(string[] headers, BioscreenFileType fileType) { var wells = new Queue <Well>(); int skip = 0; //int wellCorrect = 0; switch (fileType) { case BioscreenFileType.Legacy: case BioscreenFileType.Generic: skip = 1; break; case BioscreenFileType.CSV: skip = 2; //wellCorrect = 100; break; case BioscreenFileType.CSV2: skip = 2; break; default: throw new ArgumentOutOfRangeException("fileType"); } var count = 1; foreach (string header in headers.Skip(skip)) { var index = count; var name = header.Trim(); var well = new Well(index, name); wells.Enqueue(well); count++; } return(wells); }
private static string[] GetRowWellMeasurements(string record, BioscreenFileType fileType) { switch (fileType) { case BioscreenFileType.Legacy: case BioscreenFileType.Generic: return(record.Split('\t')); case BioscreenFileType.CSV: case BioscreenFileType.CSV2: var arr = record.SplitXP(",", "\"", true).ToList(); var retArr = arr.Select(s => s.Replace("\"", "").Replace(",", ".")).ToList(); return(retArr.ToArray()); case BioscreenFileType.Other: break; default: throw new ArgumentOutOfRangeException("fileType"); } return(new string[] {}); }
private static int GetTimeInSeconds(string item, BioscreenFileType fileType) { int time; var succeded = false; switch (fileType) { case BioscreenFileType.Legacy: //time is given in 10ths of second succeded = int.TryParse(item, NumberStyles.Number, CultureInfo.InvariantCulture, out time); time = time / 10; break; case BioscreenFileType.CSV: time = GetCVSSecondsFromTimeSpam(item, ref succeded); break; case BioscreenFileType.CSV2: time = GetCvs2SecondsFromTimeSpam(item, ref succeded); break; case BioscreenFileType.Generic: succeded = int.TryParse(item, NumberStyles.Number, CultureInfo.InvariantCulture, out time); time = succeded ? time / 10 : GetCVSSecondsFromTimeSpam(item, ref succeded); break; default: throw new ArgumentOutOfRangeException("fileType"); } if (!succeded) { throw new Exception("could not convert Time, file must be corrupted! \r\n element: " + item); } return(time); }
private static string GetRunName(IEnumerable <string> reader, BioscreenFileType fileType) { switch (fileType) { case BioscreenFileType.Legacy: try { var runNameLine = reader.Skip(1).First().Trim(); try { var runName = string.Empty; var nameDelimitor = runNameLine.IndexOf(':'); if (nameDelimitor < runNameLine.Length - 1) { runName = runNameLine.Substring(nameDelimitor + 1, runNameLine.Length - nameDelimitor - 1); } return(runName.Trim()); } catch (Exception ex) { throw new Exception("Could not parse the Experiment description"); } } catch (Exception) { throw new Exception("Could not read line 2 of the file"); } case BioscreenFileType.CSV: case BioscreenFileType.CSV2: case BioscreenFileType.Generic: return("-"); default: throw new ArgumentOutOfRangeException("fileType"); } }