473,387 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Parsing attributes from adf.txt files

Dear,
I would like to parse only the first line of each adf.txt files (i.e. attributes) . This python code could print individually for each file type, but i would like to run in one python code for all adf.txt files where the first line starts with only 4 different attribute terms like 'Composite Element Name | Block Column | Reporter Name | CompositeSequence Identifier' for all 35 different adf.txt files. I hereby attached only a zip file for 4 adf.txt files but for more files you may locate at this link ftp://ftp.ebi.ac.uk/pub/databases/microarray/data/array Could you please rectify this script . I would be glad for your support and cooperation.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/python
  2. import glob
  3. #import linecache
  4. outfile = open('out_att.txt' , 'w')
  5. files = glob.glob('*.adf.txt')
  6. for file in files:
  7.     infile = open(file)
  8.     #count = 0
  9.     for line in infile:
  10.  
  11.         lineArray = line.rstrip()
  12.         if not line.startswith('Composite Element Name') : continue
  13.         #count = count + 1
  14.         lineArray = line.split('%s\t')
  15.         print lineArray[0]
  16.         output = "%s\t\n"%(lineArray[0])
  17.         outfile.write(output)
  18.     infile.close()
  19. outfile.close()          
  20.  
Regards,
Haobijam
Attached Files
File Type: zip arrayexpress(2).zip (504.3 KB, 69 views)
File Type: txt out_att.txt (178 Bytes, 431 views)
Oct 19 '10 #1
1 2284
dwblas
626 Expert 512MB
Note that this line does nothing, i.e. is backwards (use if-->do something), and TONYJV usually produces good code:
Expand|Select|Wrap|Line Numbers
  1.         if not line.startswith('Composite Element Name') : continue 
Perhaps you meant something like
Expand|Select|Wrap|Line Numbers
  1.     fp = open(file)
  2.     line = fp.readline()     ## reads first rec only 
From here on you will have to produce your own code. Taking code from one forum and presenting it on another forum as your own is not ethical.
Oct 19 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Pawe³ Ga³ecki | last post by:
Are there any good libraries for parsing RTF files?? Can you recommend me some?
7
by: mike henkins | last post by:
hi, I've been looking through the various XML parsers API available and I have decided to use the SAX parser. Probably not the best of choices but I think it can do the job. What is the best way...
3
by: Kevin | last post by:
Does anyone have a suggestion for parsing large files line by line without loading the entire file into memory first? I don't want to use file() because the files I'm working with may be...
2
by: Raju | last post by:
In one of my applications,user will provide the .XSD file and i 've to parse thru the Elements and attributes and generate the XML string. Example: XSD file : ?xml version="1.0"...
0
by: firelli | last post by:
Hi, I would like to be able to read (parse) an html file into my Java program. Once I'm able to do this, I need to be able to analyse the html code. If you could offer any help in meeting for...
3
by: stéphane bard | last post by:
hello i would like to parse java files an detect class name's, attributes name's type's and visibility (and or list of methods). is there any module who can parse easily a java file without...
1
by: janakivenk | last post by:
Hello, I am running Oracle 10g R2 in our office. I created the following procedure. It is suppose to access an xml file ( family.xml). The procedure is compiled and when I try to run it, i get the...
1
by: chixor1 | last post by:
I have been charged with Parsing the data from many Abstract files, and then inputing this information into a SQL Database. The file format is rather unusual and certainly not delimited in any...
0
by: =?Utf-8?B?R2FyeSBWYXJnYQ==?= | last post by:
I am writing a DSL that adds and/or updates attributes to a project's AssemblyInfo file. What is the recommended way to parse the existing file to ensure that no attributes are lost? Is it...
13
by: haobijam | last post by:
I would like to parse tab separated .txt files separating common attribute and distinct attribute from the file. I would like to parse only the first line attributes not the values. Could you please...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.