You can code your own scripts using pergola
as a Python library.
Here we summarize some examples of how you can use it on your scripts.
Tip: This page is available as a Jupyter Notebook on /pergola/doc/notebooks under pergola GitHub repository. Should you want, you can interactively execute the code using Jupyter.
Input data¶
The two basics data inputs pergola
uses is a file with longitudinal
recordings (sequence of temporal events) in the form of a CSV
or
xlsx
file and a mapping file containing the correspondence between
the fields in this previous file and the pergola
ontology.
Sequence of temporal events¶
Pergola can process any sequence of temporal events contained in a character-separated file as in the example below:
Animal StartT EndT Behavior Value
1 137 156 eat 0.06
1 168 192 drink 0.02
1 250 281 eat 0.07
1 311 333 eat 0.08
1 457 482 drink 0.02
1 569 601 drink 0.03
Note: This example loads a sequence of eating and drinking events from a experiment where mice were used to study feeding behavior.
Mapping file¶
Pergola needs that you set the equivalences between the fields of the input data and a controled vocabular defined by Pergola ontology. The format of the mapping file is the external mapping file format from the Gene Ontology Consortium, you can see an example below:
! Mapping of behavioural fields into genome browser fields
!
behavioural_file:Animal > pergola:track
behavioural_file:StartT > pergola:chromStart
behavioural_file:EndT > pergola:chromEnd
behavioural_file:Behavior > pergola:dataTypes
behavioural_file:Value > pergola:dataValue
MappingInfo objects¶
Mappings between the input data and pergola ontology are loaded in MappingInfo objects:
To view the mappings MappingInfo objects provide the
:func:pergola.mapping.Mapping.write
method
EndT end
Nature data_types
Value data_value
StartT start
Phase chrom
CAGE track
MappingInfo objects are needed to load data into IntData objects as it will be explained in the lines below.
IntData objects¶
IntData objects load all the intervals of a file:
Input file format identified as csv
Intervals when loaded are stored in a list of tuples that can be accessed by data attribute:
[('1', 1335985232, 'food_sc', 1335985200, '0.02'),
('1', 1335986427, 'food_sc', 1335986151, '0.1'),
('1', 1335986451, 'water', 1335986420, '0.08'),
('1', 1335986553, 'water', 1335986541, '0.02'),
('1', 1335986844, 'water', 1335986832, '0.02'),
('1', 1335986947, 'food_sc', 1335986845, '0.02'),
('1', 1335987059, 'water', 1335987044, '0.02'),
('1', 1335987223, 'food_sc', 1335987089, '0.02'),
('1', 1335987495, 'food_sc', 1335987424, '0.02'),
('1', 1335987574, 'water', 1335987546, '0.04')]
IntData objects also provide some other attributes like the set of different tracks (term for IDs in pergola ontology) contained in the data:
{'food_fat', 'food_sc', 'water'}
The minimun value present in the data:
1335985200
The maximun value:
1337799586
The set of different tracks present in the data (term for different IDs in pergola ontology). In this case the different IDs for each mice:
{'1',
'10',
'11',
'12',
'13',
'14',
'15',
'16',
'17',
'18',
'2',
'3',
'4',
'5',
'7',
'8',
'9'}
And finally the dataTypes (term for different types of data in pergola ontology) that can be used to encode for example different behaviours:
EndT end
Nature data_types
Value data_value
StartT start
Phase chrom
CAGE track
'end'
Data conversion:¶
GenomicContainer is a generic class from which three subclasses derive:
Track objects¶
Data can be loaded into a Track objects by read function. This function allows to convert the intervals to relative values using the first time point as 0:
Relative coordinates set to: True
{'1',
'10',
'11',
'12',
'13',
'14',
'15',
'16',
'17',
'18',
'2',
'3',
'4',
'5',
'7',
'8',
'9'}
[0.02, 8.82]
key.......: ('12', 'food_sc')
:::::::::::::: food_sc
key.......: ('7', 'food_sc')
:::::::::::::: food_sc
key.......: ('14', 'water')
:::::::::::::: water
key.......: ('1', 'food_sc')
:::::::::::::: food_sc
key.......: ('12', 'food_fat')
:::::::::::::: food_fat
key.......: ('2', 'food_sc')
:::::::::::::: food_sc
key.......: ('10', 'food_fat')
:::::::::::::: food_fat
key.......: ('15', 'food_sc')
:::::::::::::: food_sc
key.......: ('17', 'water')
:::::::::::::: water
key.......: ('14', 'food_fat')
:::::::::::::: food_fat
key.......: ('5', 'food_sc')
:::::::::::::: food_sc
key.......: ('18', 'food_fat')
:::::::::::::: food_fat
key.......: ('2', 'water')
:::::::::::::: water
key.......: ('11', 'water')
:::::::::::::: water
key.......: ('16', 'food_fat')
:::::::::::::: food_fat
key.......: ('16', 'water')
:::::::::::::: water
key.......: ('14', 'food_sc')
:::::::::::::: food_sc
key.......: ('11', 'food_sc')
:::::::::::::: food_sc
key.......: ('4', 'water')
:::::::::::::: water
key.......: ('3', 'food_sc')
:::::::::::::: food_sc
key.......: ('2', 'food_fat')
:::::::::::::: food_fat
key.......: ('10', 'water')
:::::::::::::: water
key.......: ('9', 'water')
:::::::::::::: water
key.......: ('4', 'food_sc')
:::::::::::::: food_sc
key.......: ('8', 'water')
:::::::::::::: water
key.......: ('7', 'water')
:::::::::::::: water
key.......: ('17', 'food_sc')
:::::::::::::: food_sc
key.......: ('9', 'food_sc')
:::::::::::::: food_sc
key.......: ('12', 'water')
:::::::::::::: water
key.......: ('16', 'food_sc')
:::::::::::::: food_sc
key.......: ('5', 'water')
:::::::::::::: water
key.......: ('10', 'food_sc')
:::::::::::::: food_sc
key.......: ('13', 'water')
:::::::::::::: water
key.......: ('8', 'food_fat')
:::::::::::::: food_fat
key.......: ('1', 'water')
:::::::::::::: water
key.......: ('3', 'water')
:::::::::::::: water
key.......: ('18', 'food_sc')
:::::::::::::: food_sc
key.......: ('15', 'water')
:::::::::::::: water
key.......: ('18', 'water')
:::::::::::::: water
key.......: ('4', 'food_fat')
:::::::::::::: food_fat
key.......: ('13', 'food_sc')
:::::::::::::: food_sc
key.......: ('8', 'food_sc')
:::::::::::::: food_sc
['0.02', '0.540000000000001']
pergola.tracks.Bed
<generator object track_convert2bed at 0x1077e5550>
key.......: ('12', 'food_sc')
:::::::::::::: food_sc
key.......: ('7', 'food_sc')
:::::::::::::: food_sc
key.......: ('14', 'water')
:::::::::::::: water
key.......: ('1', 'food_sc')
:::::::::::::: food_sc
key.......: ('12', 'food_fat')
:::::::::::::: food_fat
key.......: ('2', 'food_sc')
:::::::::::::: food_sc
key.......: ('10', 'food_fat')
:::::::::::::: food_fat
key.......: ('15', 'food_sc')
:::::::::::::: food_sc
key.......: ('17', 'water')
:::::::::::::: water
key.......: ('14', 'food_fat')
:::::::::::::: food_fat
key.......: ('5', 'food_sc')
:::::::::::::: food_sc
key.......: ('18', 'food_fat')
:::::::::::::: food_fat
key.......: ('2', 'water')
:::::::::::::: water
key.......: ('11', 'water')
:::::::::::::: water
key.......: ('16', 'food_fat')
:::::::::::::: food_fat
key.......: ('16', 'water')
:::::::::::::: water
key.......: ('14', 'food_sc')
:::::::::::::: food_sc
key.......: ('11', 'food_sc')
:::::::::::::: food_sc
key.......: ('4', 'water')
:::::::::::::: water
key.......: ('3', 'food_sc')
:::::::::::::: food_sc
key.......: ('2', 'food_fat')
:::::::::::::: food_fat
key.......: ('10', 'water')
:::::::::::::: water
key.......: ('9', 'water')
:::::::::::::: water
key.......: ('4', 'food_sc')
:::::::::::::: food_sc
key.......: ('8', 'water')
:::::::::::::: water
key.......: ('7', 'water')
:::::::::::::: water
key.......: ('17', 'food_sc')
:::::::::::::: food_sc
key.......: ('9', 'food_sc')
:::::::::::::: food_sc
key.......: ('12', 'water')
:::::::::::::: water
key.......: ('16', 'food_sc')
:::::::::::::: food_sc
key.......: ('5', 'water')
:::::::::::::: water
key.......: ('10', 'food_sc')
:::::::::::::: food_sc
key.......: ('13', 'water')
:::::::::::::: water
key.......: ('8', 'food_fat')
:::::::::::::: food_fat
key.......: ('1', 'water')
:::::::::::::: water
key.......: ('3', 'water')
:::::::::::::: water
key.......: ('18', 'food_sc')
:::::::::::::: food_sc
key.......: ('15', 'water')
:::::::::::::: water
key.......: ('18', 'water')
:::::::::::::: water
key.......: ('4', 'food_fat')
:::::::::::::: food_fat
key.......: ('13', 'food_sc')
:::::::::::::: food_sc
key.......: ('8', 'food_sc')
:::::::::::::: food_sc
Track object¶
<generator object track_convert2bedGraph at 0x1081f9690>
pergola.tracks.Track
list
[0.02, 8.82]
{'1',
'10',
'11',
'12',
'13',
'14',
'15',
'16',
'17',
'18',
'2',
'3',
'4',
'5',
'7',
'8',
'9'}
('18', 1812042, 'food_fat', 1811948, '0.14')
{'food_fat', 'food_sc', 'water'}
Chromosome fasta like file will be dump into "/Users/jespinosa/git/pergola/doc/notebooks" as it has not been set using path_w
Genome fasta file created: /Users/jespinosa/git/pergola/doc/notebooks/chr1.fa
Cytoband like file will be dump into "/Users/jespinosa/git/pergola/doc/notebooks" as it has not been set using path_w
Bed files with phases will be dump into "/Users/jespinosa/git/pergola/doc/notebooks" as it has not been set using path_w
Relative coordinates set to: True
Removed data types are: water
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_12_dt_food_sc.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_14_dt_food_fat.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_1_dt_food_sc.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_2_dt_food_sc.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_15_dt_food_sc.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_5_dt_food_sc.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_16_dt_food_fat.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_14_dt_food_sc.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_11_dt_food_sc.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_3_dt_food_sc.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_2_dt_food_fat.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_10_dt_food_fat.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_4_dt_food_sc.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_17_dt_food_sc.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_9_dt_food_sc.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_12_dt_food_fat.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_16_dt_food_sc.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_10_dt_food_sc.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_8_dt_food_fat.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_7_dt_food_sc.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_18_dt_food_sc.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_18_dt_food_fat.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_4_dt_food_fat.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_13_dt_food_sc.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_8_dt_food_sc.bed generated
Output data¶
pergola
allows the conversion to several genomic formats, here we
summarize some commands and operations as an example of pergola
capabilities:
Bed file¶
track type=bed name="1_eat" description="1 eat" visibility=2 itemRgb="On" priority=20
chr1 137.0 156.0 "" 0.06 + 137.0 156.0 51,254,51
chr1 250.0 281.0 "" 0.07 + 250.0 281.0 0,254,0
chr1 311.0 333.0 "" 0.08 + 311.0 333.0 25,115,25
track type=bed name="1_eat" description="1 eat" visibility=2 itemRgb="On" priority=20
chr1 0 19 "" 0.06 + 0 19 51,254,51
chr1 113 144 "" 0.07 + 113 144 0,254,0
chr1 174 196 "" 0.08 + 174 196 25,115,25
Removed data types are: water
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_12_dt_food_sc.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_14_dt_food_fat.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_1_dt_food_sc.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_2_dt_food_sc.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_15_dt_food_sc.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_5_dt_food_sc.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_16_dt_food_fat.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_14_dt_food_sc.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_11_dt_food_sc.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_3_dt_food_sc.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_2_dt_food_fat.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_10_dt_food_fat.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_4_dt_food_sc.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_17_dt_food_sc.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_9_dt_food_sc.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_12_dt_food_fat.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_16_dt_food_sc.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_10_dt_food_sc.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_8_dt_food_fat.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_7_dt_food_sc.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_18_dt_food_sc.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_18_dt_food_fat.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_4_dt_food_fat.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_13_dt_food_sc.bedGraph generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File tr_8_dt_food_sc.bedGraph generated
bedGraph files¶
track type=bedGraph name="1_eat" description="1_eat" visibility=full color=0,254,0 altColor=25,115,25 priority=20
chr1 0 30 0.06
chr1 30 60 0
chr1 60 90 0
chr1 90 120 0.0158064516129
chr1 120 150 0.0541935483871
chr1 150 180 0.0218181818182
chr1 180 210 0.0581818181818
chr1 210 240 0
Value data_value
EndT end
StartT start
File track
NameFile data_types
Input file format identified as csv
Relative coordinates set to: True
Tracks that will be merged are: 1 3 2 5 4 7 6 9 8
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File files_data.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File files_data.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File files_data.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File files_data.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File files_data.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File files_data.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File files_data.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File files_data.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File files_data.bed generated
Input file format identified as csv
Relative coordinates set to: True
Tracks that will be merged are: 1 2
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File phase_exp.bed generated
No path selected, files dump into path: /Users/jespinosa/git/pergola/doc/notebooks
File phase_exp.bed generated
means bed file to delete
chr1 1 1801 "" 1000 + 0 1 0.06
chr1 137171 138971 "" 1000 + 132936 137171 0
chr1 397442 399242 "" 1000 + 391684 397442 0
chr1 568633 570433 "" 1000 + 563646 568633 0.125714
intermeal to delete
chr1 1 30 "" 1000 + 1 30 0
chr1 183 345 "" 1000 + 183 345 0
chr1 502 924 "" 1000 + 502 924 0