openmolecules.org

 
Home » DataWarrior » Cheminformatics » Create a macro to split a .dwar file into multiple .dwar files (Create a macro to split a .dwar file into multiple .dwar files based on a “compound ID” field)
Create a macro to split a .dwar file into multiple .dwar files [message #2280] Thu, 15 August 2024 14:47 Go to next message
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 Go to previous messageGo to next message
nbehrnd is currently offline  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

/forum/index.php?t=getfile&id=874&private=0

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 48 times)
  • Attachment: raw_data.dwar
    (Size: 1.40KB, Downloaded 41 times)
  • Attachment: true.dwar
    (Size: 2.26KB, Downloaded 50 times)
  • Attachment: false.dwar
    (Size: 2.38KB, Downloaded 38 times)
  • Attachment: demo.gif
    (Size: 717.47KB, Downloaded 118 times)
Re: Create a macro to split a .dwar file into multiple .dwar files [message #2282 is a reply to message #2281] Sat, 17 August 2024 15:02 Go to previous message
SM2020
Messages: 13
Registered: June 2020
Location: UK
Junior Member
Thank you for your help.

Best wishes.
Previous Topic: AllFragFp
Next Topic: Similarity Analysis query
Goto Forum:
  


Current Time: Sun Nov 24 06:23:10 CET 2024

Total time taken to generate the page: 0.03713 seconds