Skip to content

Commit

Permalink
Merge pull request #454 from WildMeOrg/convert-kinalyzer
Browse files Browse the repository at this point in the history
Convert Individual Search Kinalyzer export to more functional genetics export
  • Loading branch information
naknomum authored Apr 10, 2024
2 parents cf877f3 + d8afa1f commit 0cc0faa
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 19 deletions.
60 changes: 43 additions & 17 deletions src/main/java/org/ecocean/servlet/export/KinalyzerExport.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@



//adds spots to a new encounter
/*
* Originally created to support allele export for kinship analysis with the University of Chicago's
* Kinalyzer tool (now gone), this export format has been modified to be a generic inividual genetics tool,
* allowing for export of individual ID, haplotype, genetic sex, and named allele pairs for any species.
*
*/
public class KinalyzerExport extends HttpServlet{


Expand All @@ -48,7 +53,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
String context="context0";
context=ServletUtilities.getContext(request);
Shepherd myShepherd = new Shepherd(context);
myShepherd.setAction("KinalyzerExport");
myShepherd.setAction("IndividualSearchGeneticsExport");

//setup data dir
String rootWebappPath = getServletContext().getRealPath("/");
Expand All @@ -58,7 +63,7 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
File encountersDir=new File(shepherdDataDir.getAbsolutePath()+"/encounters");
if(!encountersDir.exists()){encountersDir.mkdirs();}

String kinFilename = "kinalyzer_export_" + request.getRemoteUser() + ".csv";
String kinFilename = "individualSearch_genetics_export_" + request.getRemoteUser() + ".csv";
File kinFile = new File(encountersDir.getAbsolutePath()+"/" + kinFilename);


Expand All @@ -84,29 +89,47 @@ public void doPost(HttpServletRequest request, HttpServletResponse response) thr
query2Individuals = queryResult2.getResult();
int numSearch2Individuals = query2Individuals.size();

//now let's start writing output

//now let's start writing header row
String headerRow = "Individual ID, Individual Default Name, Haplotype, Genetic Sex";

//Lines 2+: write the loci
//let's calculate Fst for each of the loci
//iterate through the loci
List<String> loci=myShepherd.getAllLoci();
int numLoci=loci.size();

//List<String> haplos=myShepherd.getAllHaplotypes();
//int numHaplos=haplos.size();

//let's add loci to the header row
for(int r=0;r<numLoci;r++){
String locus=loci.get(r);
headerRow+=", "+locus+" Allele1";
headerRow+=", "+locus+" Allele2";
}

//write out header row
outp.write(headerRow+"\r\n");

//now write out POP2 for search2
for(int i=0;i<numSearch2Individuals;i++){
MarkedIndividual indie=(MarkedIndividual)query2Individuals.get(i);
boolean hasValues=false;
//outp.write("Sample_ID,Individual_ID,Latitude,Longitude,Date_Time,Region,Sex,Haplotype"+locusString.toString()+",Occurrence_ID\n");


//add individual UUID
String lociString=indie.getIndividualID()+",";
//NumberFormat myFormat = NumberFormat.getInstance();
//myFormat.setMinimumIntegerDigits(3);

//add individual default name
lociString+=indie.getDefaultName()+",";

//add individual haplotype
String haploString="";
if(indie.getHaplotype()!=null)haploString=indie.getHaplotype();
lociString+=haploString+",";

//add individualgenetic sex
String sexString="";
if(indie.getGeneticSex()!=null)sexString=indie.getGeneticSex();
lociString+=sexString+",";


for(int r=0;r<numLoci;r++){
String locus=loci.get(r);
ArrayList<Integer> values=indie.getAlleleValuesForLocus(locus);
Expand All @@ -119,15 +142,16 @@ else if(indie.getAlleleValuesForLocus(locus).size()==1){
lociString+=(values.get(0)+","+values.get(0)+",");
hasValues=true;
}
else{lociString+="-1,-1,";}
//else{lociString+="-1,-1,";}
else{lociString+=",,";}

}

int length=lociString.length();

if(hasValues)outp.write(lociString.substring(0, (length-1))+"\r\n");

//test


}

Expand Down Expand Up @@ -163,10 +187,12 @@ else if(indie.getAlleleValuesForLocus(locus).size()==1){
//out.println("<p><strong>Error encountered</strong></p>");
//out.println("<p>Please let the webmaster know you encountered an error at: KinalyzerExport servlet.</p>");
e.printStackTrace();
myShepherd.rollbackDBTransaction();
myShepherd.closeDBTransaction();

}
finally{
myShepherd.rollbackDBTransaction();
myShepherd.closeDBTransaction();
}
myShepherd=null;
//out.close();
//out=null;
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/webapp/individualSearchResultsExport.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@ Click here</a>
</p>

<p> <table border="1" bordercolor="black" cellspacing="0">
<tr><td bgcolor="#CCCCCC"><strong>Kinalyzer CSV File</strong></td></tr>
<tr><td bgcolor="#FFFFFF">Link: <a href="http://kinalyzer.cs.uic.edu">http://kinalyzer.cs.uic.edu</a></td></tr>
<tr><td bgcolor="#CCCCCC"><strong>Genetics Export CSV File</strong></td></tr>
<tr><td bgcolor="#FFFFFF">
<a href="//<%=CommonConfiguration.getURLLocation(request)%>/KinalyzerExport?<%=queryString%>">
Click here</a>
Expand Down

0 comments on commit 0cc0faa

Please sign in to comment.