| 1 | = Generate a MOLGENIS from existing database = |
| 2 | |
| 3 | There is legacy of existing databases, which you may inherit or get your hands on via SQL dumps/TEXT downloads. Below we will first generate a MOLGENIS for an existing database by automatically extracting the MOLGENIS data model from it. Second you will learn how to batch-load existing data sets from delimited text files. |
| 4 | |
| 5 | == Generating a MOLGENIS for an existing database == |
| 6 | 1. Edit the database connection settings in the `molgenis.properties` file to refer to an existing database. See !MolgenisPropertiesFile. In this example it is assumed you connect to the Address Book database from the !AddressBookExample. Alternatively you can download a database dump of your choice or connect to a remote database (assuming proper DatabasePermissions). |
| 7 | 1. Run !handwritten/java/!MolgenisExtractModel.java. The extraction tool will connect to your selected database and extract a model from its table structure. An example output for the Address Book Application[[BR]][[BR]]todo screenie[[BR]] |
| 8 | 1. Copy-paste the parts of XML you want to use in your *_db.xml file. Then add a suitable *_ui.xml. Then adapt the `molgenis.properties` file accordingly and generate,compile,run to view the results (as learned in the previous section). |
| 9 | |
| 10 | == Batch loading of data == |
| 11 | MOLGENIS also provides methods to quickly load large data sets from comma or tab separated data files, both in the MolgenisUserInterfaceas well as in the MolgenisJavaApi . This works if: |
| 12 | |
| 13 | * The column headers match the entity `field `definitions as defined in !MolgenisDatabaseXml file(order doesn’t matter) |
| 14 | * A special case are !XrefFields that either can use the xref_field or the xref_label. For example in the case of AddressBookExample ‘contact_id’ and ‘contact_displayname’. |
| 15 | |
| 16 | For example: Load data for Contact. Within the MOLGENIS user interface for Contacts choose ‘File’ and then ‘Add in batch’. |
| 17 | |
| 18 | In the CSV data dialog paste the following comma seperated values: |
| 19 | |
| 20 | {{{ |
| 21 | displayname,lastname,firstname,mid_initials,birthday |
| 22 | |
| 23 | Prof.dr. R Bischoff,Bischoff,Rainer,, |
| 24 | |
| 25 | Dr. R Breitling,Breitling,Rainer,, |
| 26 | |
| 27 | Prof.dr. RC Jansen,Ritsert,Jansen,C, |
| 28 | }}} |
| 29 | Load data for Address. In the dialog for Example data for Address again choose ‘File’ and then ‘Add in batch’. Set the ‘address_type’ to ‘work’ as constant for all addresses to be loaded (otherwise you get an error!). Then paste in the CSV data dialog: |
| 30 | |
| 31 | {{{ |
| 32 | phone,contact_displayname |
| 33 | |
| 34 | +31 (0)50 3633338,Prof.dr. R Bischoff |
| 35 | |
| 36 | +31 (0)50-3638088,Dr. R Breitling |
| 37 | |
| 38 | +31 (0)50-3638089,Prof.dr. RC Jansen |
| 39 | }}} |
| 40 | Notice the cross reference by ‘xref_label’ using ‘contact_displayname’! |
| 41 | |
| 42 | ---- |
| 43 | [http://gbic.target.rug.nl/#_ftnref1 "[1]"] These example data was copied from http://www.nbic.nl/nbic/network/?city=Groningen |