public string SaveFiles(byte[] contents, string filename, out int fileId) { fileId = 0; var barcodeId = -1; var row = 'A'; var col = -1; ParseFileName(filename, out barcodeId, out row, out col); // invalid filename if (barcodeId == -1) { return(FileUploadErrorKeys.InvalidFileName); } // load up the barcode, from db var barcode = _repositoryFactory.BarcodeRepository.GetNullableById(barcodeId); if (barcode == null) { return(FileUploadErrorKeys.InvalidBarcode); } // check db for existing file var existingFile = _repositoryFactory.BarcodeFileRepository.Queryable.FirstOrDefault(a => a.Barcode == barcode && a.WellColumn == col && a.WellRow == row); // check the file system if (File.Exists(string.Format(@"{0}\raw\{1}\{2}", _storageLocation, barcodeId, filename)) || existingFile != null) { return(FileUploadErrorKeys.DuplicateFile); } if (WriteFile(filename, contents, string.Format(@"{0}\raw\{1}", _storageLocation, barcodeId))) { var bfile = new BarcodeFile() { Barcode = barcode, WellColumn = col, WellRow = row, Uploaded = true }; _repositoryFactory.BarcodeFileRepository.EnsurePersistent(bfile); fileId = bfile.Id; return(string.Empty); } return(FileUploadErrorKeys.WriteError); }
// run the validation, calculate the quality results private void ValidatePhred(BarcodeFile bcf) { //var files = _repositoryFactory.BarcodeFileRepository.Queryable.Where(a => a.Barcode.Id == bcf.Barcode.Id && !a.Validated).ToList(); var start = 0; var end = 0; var numbers = ReadPhredFile(bcf.Barcode.Id, bcf); FindIndexes(numbers, out start, out end); bcf.Start = start; bcf.End = end; bcf.DateTimeValidated = DateTime.Now; bcf.Validated = true; }
private int[] ReadPhredFile(int barcode, BarcodeFile barcodeFile) { var path = string.Format(@"{0}\output\{1}\{2}", _storageLocation, barcode, barcodeFile.ValidationFileName); if (File.Exists(path)) { var lines = File.ReadAllLines(path); lines[0] = string.Empty; var line = string.Join(" ", lines); var values = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); var numbers = new int[values.Count()]; for (var i = 0; i < values.Count(); i++) { numbers[i] = Convert.ToInt32(values[i].Trim()); } return(numbers); } return(new int[0]); }
/* * This is apparently the method that scans the "uploadLocation", and copies the files to * the raw directory for either PhRed processing or user download. */ public void ScanFiles() { //var uploadLocation = @"\\do-files\cgfdata"; //var uploadLocation = @"C:\Users\lai\Dropbox\Documents\Projects\Cgf\cgf\Cgf Data\data"; var re = new Regex(@"^Backup$"); foreach (var directory in Directory.EnumerateDirectories(_uploadLocation).Where(d => !re.IsMatch(Path.GetFileName(d)))) { foreach (var file in Directory.EnumerateFiles(directory)) { var start = file.LastIndexOf('\\') + 1; var filename = file.Substring(start); var barcodeId = -1; var row = 'A'; var col = -1; ParseFileName(filename, out barcodeId, out row, out col); if (barcodeId != -1) { // load up the barcode, from db var barcode = _repositoryFactory.BarcodeRepository.GetNullableById(barcodeId); if (barcode != null) { if (!Directory.Exists(string.Format(@"{0}\raw\{1}", _storageLocation, barcodeId))) { Directory.CreateDirectory(string.Format(@"{0}\raw\{1}", _storageLocation, barcodeId)); } if (File.Exists(string.Format(@"{0}\raw\{1}\{2}", _storageLocation, barcodeId, filename))) { File.Delete(string.Format(@"{0}\raw\{1}\{2}", _storageLocation, barcodeId, filename)); } // move the file into permanent storage, over write any existing files File.Move(file, string.Format(@"{0}\raw\{1}\{2}", _storageLocation, barcodeId, filename)); // This is probably the best place to add the logic that updates non-sequencing // jobs so that they can be downloaded directly by the user without any further // processing. // save the record into the database var barcodeFile = barcode.BarcodeFiles.FirstOrDefault(a => a.WellColumn == col && a.WellRow == row); if (barcodeFile == null) { barcodeFile = new BarcodeFile() { Barcode = barcode, WellColumn = col, WellRow = row, Uploaded = true }; } else { // resets all the values so that phred runs again and displays the right values barcodeFile.DateTimeValidated = null; barcodeFile.Validated = false; barcodeFile.Uploaded = true; barcodeFile.Start = 0; barcodeFile.End = 0; } _repositoryFactory.BarcodeFileRepository.EnsurePersistent(barcodeFile); /* * 2013-01-17 by kjt: Added logic to bypass need for validation * if Barcode.UserJobPlate.UserJob.JobType.HasSequencing is false, * since PhRed os only required on jobs with jobtypes that have sequencing. */ var hasSequencing = barcode.UserJobPlate.UserJob.JobType.HasSequencing; if (!hasSequencing) { //Skip Validation And Allow For Download SkipValidationAndAllowForDownload(barcode); } } // end if barcode != null // however, if the barcode was null we end up here. } // end if barcode != -1 } // end for each file in directory Directory.Delete(directory); } // end for each directory. } // end method ScanFiles().
private int[] ReadPhredFile(int barcode, BarcodeFile barcodeFile) { var path = string.Format(@"{0}\output\{1}\{2}", _storageLocation, barcode, barcodeFile.ValidationFileName); if (File.Exists(path)) { var lines = File.ReadAllLines(path); lines[0] = string.Empty; var line = string.Join(" ", lines); var values = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); var numbers = new int[values.Count()]; for (var i = 0; i < values.Count(); i++) { numbers[i] = Convert.ToInt32(values[i].Trim()); } return numbers; } return new int[0]; }
/* * This is apparently the method that scans the "uploadLocation", and copies the files to * the raw directory for either PhRed processing or user download. */ public void ScanFiles() { //var uploadLocation = @"\\do-files\cgfdata"; //var uploadLocation = @"C:\Users\lai\Dropbox\Documents\Projects\Cgf\cgf\Cgf Data\data"; var re = new Regex(@"^Backup$"); foreach(var directory in Directory.EnumerateDirectories(_uploadLocation).Where(d => !re.IsMatch(Path.GetFileName(d)))) { foreach(var file in Directory.EnumerateFiles(directory)) { var start = file.LastIndexOf('\\') + 1; var filename = file.Substring(start); var barcodeId = -1; var row = 'A'; var col = -1; ParseFileName(filename, out barcodeId, out row, out col); if (barcodeId != -1) { // load up the barcode, from db var barcode = _repositoryFactory.BarcodeRepository.GetNullableById(barcodeId); if (barcode != null) { if (!Directory.Exists(string.Format(@"{0}\raw\{1}", _storageLocation, barcodeId))) { Directory.CreateDirectory(string.Format(@"{0}\raw\{1}", _storageLocation, barcodeId)); } if (File.Exists(string.Format(@"{0}\raw\{1}\{2}", _storageLocation, barcodeId, filename))) { File.Delete(string.Format(@"{0}\raw\{1}\{2}", _storageLocation, barcodeId, filename)); } // move the file into permanent storage, over write any existing files File.Move(file, string.Format(@"{0}\raw\{1}\{2}", _storageLocation, barcodeId, filename)); // This is probably the best place to add the logic that updates non-sequencing // jobs so that they can be downloaded directly by the user without any further // processing. // save the record into the database var barcodeFile = barcode.BarcodeFiles.FirstOrDefault(a => a.WellColumn == col && a.WellRow == row); if (barcodeFile == null) { barcodeFile = new BarcodeFile() {Barcode = barcode, WellColumn = col, WellRow = row, Uploaded = true }; } else { // resets all the values so that phred runs again and displays the right values barcodeFile.DateTimeValidated = null; barcodeFile.Validated = false; barcodeFile.Uploaded = true; barcodeFile.Start = 0; barcodeFile.End = 0; } _repositoryFactory.BarcodeFileRepository.EnsurePersistent(barcodeFile); /* * 2013-01-17 by kjt: Added logic to bypass need for validation * if Barcode.UserJobPlate.UserJob.JobType.HasSequencing is false, * since PhRed os only required on jobs with jobtypes that have sequencing. */ var hasSequencing = barcode.UserJobPlate.UserJob.JobType.HasSequencing; if (!hasSequencing) { //Skip Validation And Allow For Download SkipValidationAndAllowForDownload(barcode); } } // end if barcode != null // however, if the barcode was null we end up here. } // end if barcode != -1 } // end for each file in directory Directory.Delete(directory); } // end for each directory. }
public string SaveFiles(byte[] contents, string filename, out int fileId) { fileId = 0; var barcodeId = -1; var row = 'A'; var col = -1; ParseFileName(filename, out barcodeId, out row, out col); // invalid filename if (barcodeId == -1) { return FileUploadErrorKeys.InvalidFileName; } // load up the barcode, from db var barcode = _repositoryFactory.BarcodeRepository.GetNullableById(barcodeId); if (barcode == null) { return FileUploadErrorKeys.InvalidBarcode; } // check db for existing file var existingFile = _repositoryFactory.BarcodeFileRepository.Queryable.FirstOrDefault(a => a.Barcode == barcode && a.WellColumn == col && a.WellRow == row); // check the file system if (File.Exists(string.Format(@"{0}\raw\{1}\{2}", _storageLocation, barcodeId, filename)) || existingFile != null) { return FileUploadErrorKeys.DuplicateFile; } if (WriteFile(filename, contents, string.Format(@"{0}\raw\{1}", _storageLocation, barcodeId))) { var bfile = new BarcodeFile() { Barcode = barcode, WellColumn = col, WellRow = row, Uploaded = true }; _repositoryFactory.BarcodeFileRepository.EnsurePersistent(bfile); fileId = bfile.Id; return string.Empty; } return FileUploadErrorKeys.WriteError; }