openmolecules.org

 
Home » DataWarrior » Functionality » Renaming column
Re: Renaming column [message #2274 is a reply to message #2242] Mon, 12 August 2024 04:17 Go to previous message
yuan is currently offline  yuan
Messages: 6
Registered: May 2024
Junior Member
Hi slprakash,

I used the following SQL script to Query my SQL database and renamed some columns in it. You can modify it to fit your purpose. Besides, you can use complex SQL query to join data from different tables. Hope it can give you some help.

<macro name="QuerySQLDB">
<task name="runSQLQuery">
connect=mysql://your_database/your_query_table (e.g. mysql://sql.xxxx.com/chemicaldb)
sql=SELECT<NL> smiles,<NL> CONCAT(structure_ID) AS ID,<NL> CONCAT(weight) AS MW,<NL> CONCAT(mass,' ',mass_unit) AS mass,<NL>
</task>
<task name="selectWindow">
viewName=Custom SQL Result
</task>
<task name="closeView">
viewName=2D View
</task>
<task name="closeView">
viewName=3D View
</task>
<task name="closeView">
viewName=Structure of smiles
</task>
<task name="addCalculatedValues">
columnName=ParentID
isOverwrite=false
formula=substring(ID,1,15)
</task>
<task name="sortRows">
column=ParentID
selectedFirst=false
descending=true
</task>
</macro>



comments:
1) Save it as a .dwam file and then use "Macro-->Import Macro-->Run Macro" to run the script file.

2) CONCAT(structure_ID) AS ID ---- will rename structure_ID column in your database as ID in DataWorrior

3) CONCAT(weight) AS MW ---- will rename weight column in your database as MW in DataWorrior

4) CONCAT(mass,' ',mass_unit) AS mass ---- will merge mass and mass_unit in your database as mass in DataWorrior

5) <task name="addCalculatedValues">
columnName=ParentID
isOverwrite=false
formula=substring(ID,1,15)
</task>
---- will add calculated values (ParentID column in DataWorrior) from ID column

6) <task name="sortRows">
column=ParentID
selectedFirst=false
descending=true
</task>
---- will sort table by previously calculated ParentID

[Updated on: Mon, 12 August 2024 04:18]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Use label in Form Table
Next Topic: chemical complexity calculation
Goto Forum:
  


Current Time: Mon Nov 25 02:17:21 CET 2024

Total time taken to generate the page: 0.03492 seconds