Demo entry 3439658

transcribe

   

Submitted by anonymous on Dec 29, 2015 at 08:18
Language: Python. Code size: 960 Bytes.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os

# Transcribe is used to single out the interested rows
def transcribe(fname):
    finname = "Original/"+fname
    foutname = "Processed/Data_"+fname
    fin = open(finname,"r")
    fout = open(foutname,"w")
    line = fin.readline()
    # Find the first line of data
    while line.strip().split('\t')[0] <> 'Number':
        line = fin.readline()
    while line:
        fout.write(line.strip().split('\t')[0]+'\t'+line.strip().split('\t')[3]+"\n"),
        # line.srip().split() is used to select the desired rows separated by tab
        line = fin.readline()
    fin.close
    fout.close
    print 'Transcription of %s completed.' %finname[9:]


# Traverse all the files in the folder
currentdir = 'Original/'+os.getcwd()
directory =  os.listdir('D:/Yun/Research/20131127Dopamine/Data/Cu-64/20151223/TLC/Original')

for filename in directory:
    transcribe(filename)

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).