Parsing attributes from adf.txt files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • haobijam
    New Member
    • Oct 2010
    • 16

    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 | CompositeSequen ce 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.

    Code:
    #!/usr/bin/python
    import glob
    #import linecache
    outfile = open('out_att.txt' , 'w')
    files = glob.glob('*.adf.txt')
    for file in files:
        infile = open(file)
        #count = 0
        for line in infile:
            
            lineArray = line.rstrip()
            if not line.startswith('Composite Element Name') : continue
            #count = count + 1
            lineArray = line.split('%s\t')
            print lineArray[0]
            output = "%s\t\n"%(lineArray[0])
            outfile.write(output)
        infile.close()
    outfile.close()
    Regards,
    Haobijam
    Attached Files
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    Note that this line does nothing, i.e. is backwards (use if-->do something), and TONYJV usually produces good code:
    Code:
            if not line.startswith('Composite Element Name') : continue
    Perhaps you meant something like
    Code:
        fp = open(file)
        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.

    Comment

    Working...