Last active
August 29, 2015 14:02
-
-
Save pewerner/f5b283caebefe3b9b874 to your computer and use it in GitHub Desktop.
Parse Spectramax reader data in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.IO; | |
namespace FileUtilities | |
{ | |
public class FileUtilities | |
{ | |
public string getMostRecentFileInDirectory(string directory, string pattern) | |
{ | |
//string pattern = "*.txt"; | |
var dirInfo = new DirectoryInfo(directory); | |
string file = (from f in dirInfo.GetFiles(pattern) orderby f.LastWriteTime descending select f).First().ToString(); | |
return file; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import os, glob, time | |
#Directory for reader data files | |
dir = "C:\\VWorks Workspace\\Scripts\\readerdata\\inputs" | |
output="C:\\VWorks Workspace\\Scripts\\readerdata\\output" | |
def getLatestFileinDirectory(root): | |
date_file_list = [] | |
for folder in glob.glob(root): | |
for file in glob.glob(folder + '/*.*'): | |
stats = os.stat(file) | |
lastmod_date = time.localtime(stats[8]) | |
date_file_tuple = lastmod_date, file | |
date_file_list.append(date_file_tuple) | |
date_file_list.sort() | |
date_file_list.reverse() # newest mod date now first | |
return date_file_list[0][1] | |
def generateInputFile(input, barcode, head): | |
file = open(input, 'r') | |
readerDataInput = file.read() | |
rd = re.search(r"\bGroup: Unknowns 1\b[\s\S]+?(~End)", readerDataInput) | |
rd = rd.group(0).split("\n") | |
outputpath = output + "\\test.csv" | |
f = open(outputpath, 'a') | |
if head == 1: | |
line = rd[1].split("\t") | |
line.insert(0, "Plate id") | |
f.write( ",".join(line) + "\n") | |
for i in range(2,98): | |
line = rd[i].split("\t") | |
line.insert(0, barcode) | |
#f.write(str(line) + "\n") | |
f.write( ",".join(line) + "\n") | |
f.close() | |
#ip = getLatestFileinDirectory(dir) | |
#print ip | |
#generateInputFile(ip, "2ewbc", 2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment