Extracting data from .rsa files
Question: I have a folder labeled cstruct with several with 20,000 .rsa files. In each
of the files I need to extract each row that contain cys values and write the
to a new file. Is there a way in python to loop through these files in this
folder and extract this information?

RES SER A 102 17.74 15.2 17.22 22.0 0.52 1.4 11.89 24.5 5.85 8.6 RES HIS A 103
17.32 9.5 16.53 11.2 0.78 2.2 12.22 12.6 5.10 5.9 **RES CYS A 104 0.00 0.0
0.00 0.0 0.00 0.0 0.00 0.0 0.00 0.0** RES LEU A 105 8.67 4.9 8.67 6.1 0.00 0.0
8.67 6.1 0.00 0.0 RES LEU A 106 5.72 3.2 5.72 4.1 0.00 0.0 5.72 4.0 0.00 0.0


Answer: Something like the following Python script should get you going in the right
direction:

    
    
    import re, glob
    
    with open("output.txt", "w") as f_output:
        for rsa_file in glob.glob(r"cstruct\*.rsa"):
            with open(rsa_file, "r") as f_input:
                f_output.write(rsa_file + "\n")
                for row in f_input:
                    for cys in re.findall(r"(RES CYS\s+\w+.*?)(?= RES|\Z)", row):
                        f_output.write(cys+"\n")
    

