Create a macro to split a .dwar file into multiple .dwar files [message #2280] |
Thu, 15 August 2024 14:47 |
SM2020
Messages: 13 Registered: June 2020 Location: UK
|
Junior Member |
|
|
Hi,
I would like some help with setting up a DW macro to split a .dwar file into multiple .dwar files, please.
I am running DW version 6.0
Aim: To split a .dwar file into multiple .dwar files using a common identifier (e.g. compound ID).
Intended result: The resulting new .dwar files should have all the fields present from the original parent .dwar file but only for a subset of compounds (defined by the “compound ID” field).
I’m not sure of the syntax needed to achieve this. Not sure where to start…
If the community could provide some help, that would be appreciated.
Thank you.
|
|
|
Re: Create a macro to split a .dwar file into multiple .dwar files [message #2281 is a reply to message #2280] |
Thu, 15 August 2024 20:16 |
nbehrnd
Messages: 224 Registered: June 2019
|
Senior Member |
|
|
Hello,
for a one-at-a-time, DW very well can help you. Attached below the macro, raw data set and results, and a brief demo with DW 06.02.03
The idea is to check for the presence of a particular string in the column identifier. For this, the macro asks every line the same test question by the formula
```
if (identifier == askString("enter the identifier of interest"), "true", "false")
```
if a specific string is present at this intersection. The newly calculated column will contain an entry `true` if this is the case, or else the string `false`. (Of course you could opt-in for `active`, `inactive` to designate the two, too.) The flexibility you want is provided by DataWarrior's function `askString()` to allow to recycle the macro's function, to filter for records with an other string in this field. Watch out the pane to the right hand side: we now have a filter which allows to save the visible records per level `true`, or `false`.
While running the macro editor, a double click on `save visible rows` allows you to toggle off the question to manually define the file name (for this sub set of data). This can be useful if i) raw data and the new files to be written are every time in the same location, and ii) the output should every time the same, e.g. `positive.dwar` and `negative.dwar`.
Best regards,
Norwid
-
Attachment: filter_by_string.dwam
(Size: 0.76KB, Downloaded 46 times)
-
Attachment: raw_data.dwar
(Size: 1.40KB, Downloaded 41 times)
-
Attachment: true.dwar
(Size: 2.26KB, Downloaded 49 times)
-
Attachment: false.dwar
(Size: 2.38KB, Downloaded 38 times)
-
Attachment: demo.gif
(Size: 717.47KB, Downloaded 117 times)
|
|
|
|