Skip to content

Commit

Permalink
Merged in qmarcou/igor_qprivate/dev (pull request #26)
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
qmarcou committed Nov 21, 2017
2 parents f549ba7 + 5ec3b9a commit 14386f7
Show file tree
Hide file tree
Showing 7 changed files with 3,068 additions and 213 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#Ignore generated Makefiles
Makefile

#Ignore python generated files
*.pyc
*.py~

# Ignore autoconf stuff
**/.deps
**/.libs
Expand Down
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ demo_DATA = demo/genomicVs_with_primers.fasta demo/genomicDs.fasta demo/genomicJ
man_MANS = igor.1

install-data-local:
cp -r models/ $(pkgdatadir)
mkdir $(pkgdatadir)/models
cp -r models/* $(pkgdatadir)/models

uninstall-local:
rm -rf $(pkgdatadir)/models
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ Reached using the command `-generate N` where *N* is the number of sequences to
| `--seed X` | Impose *X* as a seed for the random sequence generator. By default a random seed is obtained from the system. |

## Command examples
First as a sanity check try and run the demo code (this will run for a few minutes on all cores available):
First as a sanity after installation check try and run the demo code (this will run for a few minutes on all cores available):
```
#!bash
./igor -run_demo
igor -run_demo
```

Here we give an example with a few commands illustrating a typical workflow. In this example we assume to be executing IGoR from the directory containing the executable.
Expand All @@ -324,19 +324,19 @@ WDPATH=/path/to/your/working/directory #Let's define a shorthand for the working
#We first read the sequences contained in a text file inside the demo folder
#This will create the align folder in the working directory and the mydemo_indexed_seqs.csv file.
./igor -set_wd $WDPATH -batch foo -read_seqs ../demo/murugan_naive1_noncoding_demo_seqs.txt
igor -set_wd $WDPATH -batch foo -read_seqs ../demo/murugan_naive1_noncoding_demo_seqs.txt
#Now let's align the sequences against the provided human beta chain genomic templates with default parameters
#This will create foo_V_alignments.csv, foo_D_alignments.csv and foo_J_alignments.csv files inside the align folder.
./igor -set_wd $WDPATH -batch foo -species human -chain beta -align --all
igor -set_wd $WDPATH -batch foo -species human -chain beta -align --all
#Now use the provided beta chain model to get the 10 best scenarios per sequence
#This will create the foo_output and foo_evaluate and the corresponding files inside
./igor -set_wd $WDPATH -batch foo -species human -chain beta -evaluate -output --scenarios 10
igor -set_wd $WDPATH -batch foo -species human -chain beta -evaluate -output --scenarios 10
#Now generate 100 synthetic sequences from the provided human beta chain model
#This will create the directory bar_generate with the corresponding files containing the generated sequences and their realizations
./igor -set_wd $WDPATH -batch bar -species human -chain beta -generate 100
igor -set_wd $WDPATH -batch bar -species human -chain beta -generate 100
```
Since all these commands use several time the same arguments here is some syntactic sugar using more Bash syntax for the exact same workflow with a lighter syntax:
Expand Down Expand Up @@ -366,7 +366,9 @@ $MYCOMMANDS -batch bar -generate 100 #Generate
# Advanced usage
The set of command lines above allows to use predefined models or their topology to study a new dataset. Additionally the user can define new models directly using the model parameters file interface. For instance, in order to investigate a conditional dependence between two recombination events, the user can simply add or remove an edge in the graph following the syntax defined earlier.

In order to change the set of realizations associated with an event the user can also directly modify a recombination parameters file. Adding or removing realizations should be done with great care as IGoR will use the associated indices to read the corresponding probabilities on the probability array. These indices should be contiguous ranging from 0 to the (total number of realizations -1). Any change in these indices will make the corresponding model marginals file void, and a new one should be automatically created by passing only the model parameters filename to the `-set_custom_model` command.
In order to change the set of realizations associated with an event the user can also directly modify a recombination parameters file. Adding or removing realizations should be done with great care as IGoR will use the associated indices to read the corresponding probabilities on the probability array. These indices should be contiguous ranging from 0 to the (total number of realizations -1).

*Any change in these indices or to the graph structure will make the corresponding model marginals file void, and a new one should be automatically created by passing only the model parameters filename to the `-set_custom_model` command.*

Note that changing the GeneChoice realizations can be done automatically (without manually editing the recombination parameter file) by supplying the desired set of genomic templates to IGoR using the `-set_genomic` command. This could be used e.g to define a model for a chain in a species for which IGoR does not supply a model starting from of model for this chain from another species.

Expand Down
30 changes: 25 additions & 5 deletions igor_src/Model_marginals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,26 +1122,46 @@ void Model_marginals::write2txt_iteration(list<pair<shared_ptr<const Rec_Event>,
}

void Model_marginals::txt2marginals(string filename, const Model_Parms& parms){
ifstream infile(filename);
if(!infile){
ifstream testfilestream(filename);
if(!testfilestream){
throw runtime_error("Unknown file: "+filename);
}
string line_str;
//First count the marginals' size
int size_counter = 0;
while(getline(testfilestream,line_str)){
if(line_str[0]=='%'){
size_t semicolon_index = line_str.find(",");
++size_counter;
while(semicolon_index!=string::npos){
size_t next_comma_index = line_str.find(",", (semicolon_index+1) );
semicolon_index = next_comma_index;
++size_counter;
}
}
}
size_t current_marginals_size = this->compute_size(parms);
if(size_counter!=current_marginals_size){
throw runtime_error("Marginals contained in file \"" +filename+ "\" and supplied Model_Parms do not match in size. Make sure the Bayesian Network structure/event realizations and the marginals are coherent.");
}

//Now read the actual marginals values
ifstream infile(filename);
int index = 0;
while(getline(infile,line_str)){
if(line_str[0]=='%'){
size_t semicolon_index = line_str.find(",");
marginal_array_smart_p[index] = stod(line_str.substr(1,(semicolon_index)));
this->marginal_array_smart_p[index] = stod(line_str.substr(1,(semicolon_index)));
++index;
while(semicolon_index!=string::npos){
size_t next_comma_index = line_str.find(",", (semicolon_index+1) );
marginal_array_smart_p[index] = stod(line_str.substr( (semicolon_index+1) , (next_comma_index - semicolon_index -1) ));
this->marginal_array_smart_p[index] = stod(line_str.substr( (semicolon_index+1) , (next_comma_index - semicolon_index -1) ));
semicolon_index = next_comma_index;
++index;
}
}
}
this->marginal_arr_size = index;
//this->marginal_arr_size = index;

//Make sure marginals are normalized (deals with problem of float precision output from the text file)
queue<shared_ptr<Rec_Event>> model_queue = parms.get_model_queue();
Expand Down
12 changes: 11 additions & 1 deletion igor_src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ int terminate_IGoR_with_error_message(string error_message, exception& e){
return terminate_IGoR_with_error_message(error_messages);
}

// Output both the exception handling message and the actual exception message
int terminate_IGoR_with_error_message(forward_list<string> error_messages, exception& e){
error_messages.emplace_front(e.what());
return terminate_IGoR_with_error_message(error_messages);
}

int main(int argc , char* argv[]){

//Command line argument iterator
Expand Down Expand Up @@ -320,7 +326,11 @@ int main(int argc , char* argv[]){
cl_model_marginals.txt2marginals(string(argv[carg_i]),cl_model_parms);
}
catch(exception& e){
return terminate_IGoR_with_error_message("Exception caught while reading custom marginals after \"-set_custom_model\"", e);
forward_list<string> error_messages;
error_messages.emplace_front("If you have altered the default model structure corresponding marginals will be created if no model marginals file is passed.");
error_messages.emplace_front("Make sure file exist or that supplied Model_Parms and Model_Marginals match.");
error_messages.emplace_front("Exception caught while reading custom marginals after \"-set_custom_model\"");
return terminate_IGoR_with_error_message(error_messages, e);
}
}
else{
Expand Down
Loading

0 comments on commit 14386f7

Please sign in to comment.