evanyeyeye / rainbow

Read chromatography and mass spectrometry binary files.
GNU General Public License v3.0
29 stars 15 forks source link

Parse the compound names without secondary transitions. #18

Closed OmarAshkar closed 4 months ago

OmarAshkar commented 5 months ago

This one is related to #16.

JMarvi3 commented 5 months ago

Could I suggest the following instead:

def parse_compound_names(path):
    path = os.path.join(path, '_FUNC001.CMP')
    dts = np.dtype([('compounds', 'S256'), ('transition', 'S256'), ('source', 'S512')])
    dtu = np.dtype([('compounds', 'U256'), ('transition', 'U256'), ('source', 'U512')])

    df = pd.DataFrame(np.fromfile(path, dtype=dts, offset=12).astype(dtu))
    df['measurements'] = df['compounds'] + ' ' + (df.index.values + 1).astype(str)

    return df
sardnar commented 5 months ago

Could I suggest the following instead:

def parse_compound_names(path):
    path = os.path.join(path, '_FUNC001.CMP')
    dts = np.dtype([('compounds', 'S256'), ('transition', 'S256'), ('source', 'S512')])
    dtu = np.dtype([('compounds', 'U256'), ('transition', 'U256'), ('source', 'U512')])

    df = pd.DataFrame(np.fromfile(path, dtype=dts, offset=12).astype(dtu))
    df['measurements'] = df['compounds'] + ' ' + (df.index.values + 1).astype(str)

    return df

wow! that is very neat! I'd appreciate if you contribute it in this PR. Another thing to be added is the daughter transition. However, I am not sure if it's there in this file though.

OmarAshkar commented 5 months ago

Indeed! my code is so bad in comparison :)