问题描述:

Objective: A script that searches a directory for axograph files and performs as series of computations and returns either the values or saves it to CSV file.

Update: Data comes from Axographio raw files of intracellular recordings where each file has 4 waves of data. I seek to do the very basic ehpys calculations of properties:

input resistance,

half-width at half-maximum,

rheobase, SAG potential,

membrane time constant

afterhyperpolarisation.

I found python module "stimfit" which has useful libraries for this but it does not import properly. I´m currently troubleshooting this package.

This is my first script and first recordings, so if anyone has ideas, please share.

Problem 1. "f = axographio.read(filename)" only takes one argument with a string specific to "filename.axgd". I cant put this method alone since the resulting "file" is a list object and not the single instance of each filenames that I seek. I think that above function can work with "f=axographio.read(file)" if I can get that file object as a list or array of the filenames and extract them.

Problem 1 is now solved with f = axographio.read(os.path.join(root, file)) - it was unclear that os.path worked within the axographio module.

Problem 2. I can print all my files as list of strings but unable to extract and open each single file (even with file=open(blablabla.).

Update: I can either loop for each open file or save them to a list or array. I dont mind advice on best practice on this. axograph seems to work well with NumPy array but list is tempting since it has more flexibility. Any advice on this?

Note: its´s not necessary to make this complicated. The key point is to perform computations on multiple files at my choosing. Whether I save this into file or have more or less control is a matter of taste and time.

 -*- coding: utf-8 -*-

"""

@author: Martenzi

"""

import os,sys

import numpy as np

import matplotlib.pylab as plt

import axographio

from scipy import stats

import re

import os

from collections import defaultdict

""" Search a directory for all Axograph files """

for root, dirs, files in os.walk("."):

for file in files:

if file.endswith(".axgd"):

f = axographio.read(os.path.join(root, file))

plt.show(file)

plt.plot(f.data[0],f.data[1])

plt.plot(f.data[0],f.data[2])

plt.plot(f.data[0],f.data[3])

plt.plot(f.data[0],f.data[4])

""" Below is various code snippets that I have tried out. They are not in specific order. I have tried things and stacked it as comments """

# if(line == 'foo'):

# line = next(irofile) #BEWARE, This could raise StopIteration!

# print line

# for i in file:

# cells = [];

# cells.append(file);

# for index, w in enumerate (loopme):

# cells = array ( [i] ,dtype=complex)

# print(file)

# for k in file:

# d = defaultdict(int)

# d[k].append()

# m=self.fileFormatRegex.match(file)

# self.processFile(root, open(os.path.join(r"/", root, file)), age, inString)

# infile = open(cells,"r")

# fullpath = os.path.walk(files)

# infile = open(file, "r")

# f = open(file ["r"][buffering])

# with open(infile, mode='r'):

## f = axographio.read(file)

# print(file)

# f = axographio.read(cell)

# with open(fullpath, 'r') as f:

# f = axographio.read(file)

# data = re.sub(r'(\s*function\s+.*\s*{\s*)',

# r'\1echo "The function starts here."',

# f.read())

# with open(fullpath, 'w') as f:

# f.write(data)

相关阅读:
Top