diff --git a/Source/mesquite/chromaseq/ExportFastaDNAForGenBank/ExportFastaDNAForGenBank.java b/Source/mesquite/chromaseq/ExportFastaDNAForGenBank/ExportFastaDNAForGenBank.java
deleted file mode 100644
index 0e4c425e..00000000
--- a/Source/mesquite/chromaseq/ExportFastaDNAForGenBank/ExportFastaDNAForGenBank.java
+++ /dev/null
@@ -1 +0,0 @@
-/* Mesquite Chromaseq source code. Copyright 2005-2011 David Maddison and Wayne Maddison.
Version 1.0 December 2011
Disclaimer: The Mesquite source code is lengthy and we are few. There are no doubt inefficiencies and goofs in this code.
The commenting leaves much to be desired. Please approach this source code with the spirit of helping out.
Perhaps with your help we can be more than a few, and make Mesquite better.
Mesquite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
Mesquite's web site is http://mesquiteproject.org
This source code and its compiled class files are free and modifiable under the terms of
GNU Lesser General Public License. (http://www.gnu.org/copyleft/lesser.html)
*/
package mesquite.chromaseq.ExportFastaDNAForGenBank;
/*~~ */
import java.awt.*;
import java.util.Vector;
import mesquite.lib.*;
import mesquite.lib.characters.*;
import mesquite.lib.duties.*;
import mesquite.categ.lib.*;
import mesquite.chromaseq.lib.ChromaseqUtil;
import mesquite.io.lib.*;
/* ============ a file interpreter for DNA/RNA Fasta files ============*/
public class ExportFastaDNAForGenBank extends InterpretFasta {
protected String addendum = "";
protected static String codeLabel = "Voucher";
protected boolean addVoucherNumberToDescription = false;
protected boolean featureAnnotation = false;
public void getEmployeeNeeds(){ //This gets called on startup to harvest information; override this and inside, call registerEmployeeNeed
EmployeeNeed e = registerEmployeeNeed(OTUIDCodeInfoCoord.class, "Voucher information is needed for FASTA export for Genbank submissions.",
"This is activated automatically when you choose this exporter.");
}
OTUIDCodeInfoCoord voucherInfoTask;
/*.................................................................................................................*/
public boolean startJob(String arguments, Object condition, boolean hiredByName) {
voucherInfoTask = (OTUIDCodeInfoCoord)hireEmployee(OTUIDCodeInfoCoord.class, null);
loadPreferences();
return voucherInfoTask != null && super.startJob(arguments, condition, hiredByName);
}
/*.................................................................................................................*/
public void processSingleXMLPreference (String tag, String content) {
if ("codeLabel".equalsIgnoreCase(tag))
codeLabel= content;
if ("addVoucherNumberToDescription".equalsIgnoreCase(tag))
addVoucherNumberToDescription=MesquiteBoolean.fromTrueFalseString(content);
if ("featureAnnotation".equalsIgnoreCase(tag))
featureAnnotation=MesquiteBoolean.fromTrueFalseString(content);
}
/*.................................................................................................................*/
public String preparePreferencesForXML () {
StringBuffer buffer = new StringBuffer(60);
StringUtil.appendXMLTag(buffer, 2, "codeLabel",codeLabel);
StringUtil.appendXMLTag(buffer, 2, "addVoucherNumberToDescription",addVoucherNumberToDescription);
StringUtil.appendXMLTag(buffer, 2, "featureAnnotation",featureAnnotation);
return buffer.toString();
}
/*.................................................................................................................*/
public boolean canImport() {
return false; //
}
public boolean canImport(String arguments){
return false;
}
protected int taxonNameLengthLimit() {
return 15;
}
/*.................................................................................................................*/
public boolean getExportOptions(CharacterData data, boolean dataSelected, boolean taxaSelected){
MesquiteInteger buttonPressed = new MesquiteInteger(1);
ExporterDialog exportDialog = new ExporterDialog(this,containerOfModule(), "Export FASTA for GenBank Options", buttonPressed);
exportDialog.appendToHelpString("Choose the options for exporting the matrix as a FASTA file prepared for processing by NCBI's Sequin.");
exportDialog.appendToHelpString("
SeqID Suffix: this will be added to each taxon name to form the unique SeqID.");
exportDialog.appendToHelpString(" Description of gene fragment: this will be added to each sequence's DEFINITION.");
exportDialog.appendToHelpString(" Text before OTU (Specimen) ID Code in DEFINITION: this will be inserted between the organism name and the OTU (Specimen) ID Code in the DEFINITION.");
exportDialog.appendToHelpString(" Features Annotation Tables: A table will be written for each sequence (see Genbank submission instructions). Group name will become Feature's Product name. Assumes first site in sequence in group will be representative; if has codon position, whole group will be considered CDs.");
String matrixName = "";
if (data!=null){
matrixName = data.getName();
exportDialog.addLabel("(Matrix: " + matrixName+ ")",Label.CENTER);
}
SingleLineTextField uniqueSuffixField = exportDialog.addTextField("SeqID Suffix", matrixName, 20);
TextArea fsText =null;
exportDialog.addLabel("Description of gene fragment:",Label.LEFT);
fsText =exportDialog.addTextAreaSmallFont(addendum,4);
Checkbox addVoucherNumberBox = exportDialog.addCheckBox("add OTU (Specimen) ID Code to DEFINITION", addVoucherNumberToDescription);
SingleLineTextField codeLabelField = exportDialog.addTextField("Text before OTU (Specimen) ID Code in DEFINITION", codeLabel, 20);
Checkbox includeGapsCheckBox = exportDialog.addCheckBox("include gaps", includeGaps);
//added WPM may 2012
Checkbox featureAnnotationCheckBox = exportDialog.addCheckBox("if gaps NOT included, save Genbank Features Annotation tables? \n(requires characters partitioned into groups)", featureAnnotation);
exportDialog.completeAndShowDialog(dataSelected, taxaSelected);
addendum = fsText.getText();
codeLabel = codeLabelField.getText();
uniqueSuffix = uniqueSuffixField.getText();
addVoucherNumberToDescription = addVoucherNumberBox.getState();
boolean ok = (exportDialog.query(dataSelected, taxaSelected)==0);
includeGaps = includeGapsCheckBox.getState();
featureAnnotation = featureAnnotationCheckBox.getState();
exportDialog.dispose();
return ok;
}
/*.................................................................................................................*/
public int getPartials(String nameOfPart){ //00 = not partial; 01 = partial end; 10 = partial start; 11 = partial both
MesquiteInteger buttonPressed = new MesquiteInteger(1);
ExtensibleDialog partialDialog = new ExtensibleDialog(containerOfModule(), "Partial?", buttonPressed);
TextArea uniqueSuffixField = partialDialog.addLargeTextLabel("Is the partition \"" + nameOfPart + "\" partial on either end?");
Checkbox start = partialDialog.addCheckBox("5' Partial", false);
Checkbox end = partialDialog.addCheckBox("3' Partial", false);
partialDialog.completeAndShowDialog();
int result = 0;
if (start.getState())
result += 2;
if (end.getState())
result += 1;
partialDialog.dispose();
return result;
}
/*.................................................................................................................*/
public boolean canExportEver() {
return true; //
}
/*.................................................................................................................*/
public boolean canExportProject(MesquiteProject project) {
return project.getNumberCharMatrices(DNAState.class) > 0; //
}
/*.................................................................................................................*/
public boolean canExportData(Class dataClass) {
return (dataClass==DNAState.class);
}
/*.................................................................................................................*/
public CharacterData createData(CharactersManager charTask, Taxa taxa) {
return charTask.newCharacterData(taxa, 0, DNAData.DATATYPENAME); //
}
protected String getSupplementForTaxon(Taxa taxa, int it){
if (taxa!=null && voucherInfoTask != null) {
String s = " ";
String voucherID = ChromaseqUtil.getStringAssociated(taxa, VoucherInfoFromOTUIDDB.voucherCodeRef, it);
VoucherInfoFromOTUIDDB vi= voucherInfoTask.getVoucherInfo(ChromaseqUtil.getStringAssociated(taxa, VoucherInfoFromOTUIDDB.voucherDBRef, it), voucherID);
if (vi != null) {
String gbs = vi.toGenBankString();
if (StringUtil.blank(gbs))
MesquiteMessage.println("Taxon with no Genbank information: " + taxa.getTaxonName(it) + "; OTU (specimen) ID code: " + voucherID);
s += gbs;
if (addVoucherNumberToDescription)
return s + " " + codeLabel + " " + voucherID + " " + addendum;
else
return s + " " + addendum;
}
else
MesquiteMessage.println("Taxon with no Genbank information: " + taxa.getTaxonName(it) + "; OTU (specimen) ID code: " + voucherID);
}
return null;
}
static int taxonNameLengthLimit = 32;
/*.................................................................................................................*/
protected String getTaxonName(Taxa taxa, int it){
String s = StringUtil.cleanseStringOfFancyChars(taxa.getTaxonName(it),false,true);
String suffix = StringUtil.cleanseStringOfFancyChars(uniqueSuffix,false,true);
if (taxonNameLengthLimit>0) {
String taxnum = MesquiteInteger.toString(it);
int reduction = s.length() + suffix.length() - taxonNameLengthLimit;
if (reduction>0) {
reduction += taxnum.length();
String note = "\nSeqID (\"" + s + suffix + "\") too long; renamed as ";
if (s.length()-reduction <1)
s = taxnum;
else {
s = s.substring(0,4) + "_" + s.substring(5+reduction,s.length())+"_" + taxnum;
}
logln(note + "\"" + s + suffix+"\"");
}
}
return s+suffix;
}
int getSequencePosition(int column, int it, DNAData data){
int count = 0;
for (int ic=0; ic<=column; ic++){
if (!data.isInapplicable(ic, it))
count++;
}
return count;
}
int getCodonPositionOfFirstSiteOfPartition(Listable[] listArray, Object obj, DNAData data, int it){
for (int i=0; i0) {
if (lastWritten != i-1) {
s += (getSequencePosition(i-1, it, data));
v.addElement(s);
s = "";
lastWritten = i-1;
}
else {
s += "\t" + (getSequencePosition(lastWritten, it, data));
v.addElement(s);
s = "";
lastWritten = -1;
}
continuing = 0;
}
}
}
if (continuing>1){
if (partialEnd)
s += ">";
s += (getSequencePosition(listArray.length-1, it, data));
v.addElement(s);
s = "";
}
if (found)
return v;
else
return null;
}
/*.................................................................................................................*/
protected void saveExtraFiles(CharacterData cata){
if (!(cata instanceof DNAData))
return;
DNAData data = (DNAData)cata;
if (featureAnnotation && !includeGaps){
CharactersGroup[] parts =null;
boolean hasCDs = data.someCoding();
boolean hasParts = false;
CharacterPartition characterPartition = (CharacterPartition)data.getCurrentSpecsSet(CharacterPartition.class);
if (characterPartition!=null) {
parts = characterPartition.getGroups();
hasParts = parts!=null;
}
if (!hasParts) {
return;
}
boolean[][] partial = new boolean[2][parts.length];
for (int ip = 0; ipFeatures " + getTaxonName(data.getTaxa(), it) + "\t\t\t\t");
buffer.append("\n");
for (int i=0; i=1 && cp<=3)
buffer.append(s + "\t" + "CDS\t\t");
else if (StringUtil.indexOfIgnoreCase(parts[i].getName(), "intron")>=0)
buffer.append(s + "\t" + "intron\t\t");
else
buffer.append(s + "\t" + "misc_feature\t\t");
}
else
buffer.append(s + "\t\t\t");
buffer.append("\n");
}
buffer.append("\t\t\tproduct\t" + parts[i].getName());
buffer.append("\n");
int cp = getCodonPositionOfFirstSiteOfPartition((Listable[])characterPartition.getProperties(), parts[i], data, it);
if (cp>=1 && cp <=3){
/*Genbank has this strange convention where the codon start is the offset until the next full codon,
* but starting counting at 1, so that if the start of the feature is at codon position 1, offset is treated as 1 (not 0!):
* If first codon position is 2, then start of the next codon is treated as offset 3
* If first codon position is 3, then start of the next codon is treated as offset 2
* Go figure. I can see using offsets, but then it should be 0 based.
*/
int genbankOffset = 0;
if (cp ==1)
genbankOffset = 1;
else if (cp == 2)
genbankOffset = 3;
else if (cp == 3)
genbankOffset = 2;
buffer.append("\t\t\tcodon_start\t" + genbankOffset);
buffer.append("\n");
}
}
}
MesquiteFile.putFileContents(directory + MesquiteFile.fileSeparator + (it+1) + "-features_" + getTaxonName(data.getTaxa(), it) + ".txt", buffer.toString(), true);
}
}
}
}
/*.................................................................................................................*/
public CharacterData findDataToExport(MesquiteFile file, String arguments) {
return getProject().chooseData(containerOfModule(), file, null, DNAState.class, "Select data to export");
}
/*.................................................................................................................*/
public void setFastaState(CharacterData data, int ic, int it, char c) {
if ((c=='U')||(c=='u')) {
((DNAData)data).setDisplayAsRNA(true);
}
((DNAData)data).setState(ic,it,c);
}
/*.................................................................................................................*/
public String getUnassignedSymbol(){
return "N";
}
/*.................................................................................................................*/
public String getName() {
return "FASTA (DNA/RNA) for GenBank Deposition";
}
/*.................................................................................................................*/
/** returns an explanation of what the module does.*/
public String getExplanation() {
return "Exports FASTA files for GenBank deposition." ;
}
}
\ No newline at end of file
diff --git a/Source/mesquite/chromaseq/ExportFastaDNAForGenBankTbl2Asn/ExportFastaDNAForGenBankTbl2Asn.java b/Source/mesquite/chromaseq/ExportFastaDNAForGenBankTbl2Asn/ExportFastaDNAForGenBankTbl2Asn.java
new file mode 100644
index 00000000..62cbc398
--- /dev/null
+++ b/Source/mesquite/chromaseq/ExportFastaDNAForGenBankTbl2Asn/ExportFastaDNAForGenBankTbl2Asn.java
@@ -0,0 +1 @@
+/* Mesquite Chromaseq source code. Copyright 2005-2011 David Maddison and Wayne Maddison.
Version 1.0 December 2011
Disclaimer: The Mesquite source code is lengthy and we are few. There are no doubt inefficiencies and goofs in this code.
The commenting leaves much to be desired. Please approach this source code with the spirit of helping out.
Perhaps with your help we can be more than a few, and make Mesquite better.
Mesquite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
Mesquite's web site is http://mesquiteproject.org
This source code and its compiled class files are free and modifiable under the terms of
GNU Lesser General Public License. (http://www.gnu.org/copyleft/lesser.html)
*/
package mesquite.chromaseq.ExportFastaDNAForGenBankTbl2Asn;
/*~~ */
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import mesquite.lib.*;
import mesquite.lib.characters.*;
import mesquite.lib.duties.*;
import mesquite.categ.lib.*;
import mesquite.chromaseq.lib.*;
import mesquite.io.lib.*;
//tbl2asn -t template.sbt.txt -p submission -a s2 -V v -k m
/* ============ a file interpreter for DNA/RNA Fasta files ============*/
public class ExportFastaDNAForGenBankTbl2Asn extends InterpretFasta implements ActionListener {
protected String addendum = "";
protected static String codeLabel = "Voucher";
protected boolean addVoucherNumberToDescription = false;
protected boolean featureAnnotation = false;
protected boolean saveFeatureTableEvenIfNoParts = true;
protected boolean useGroupNameAsProductName = false;
SequenceProfileManager specificationManager;
SequenceProfile sequenceProfile = null;
OTUIDCodeInfoCoord voucherInfoTask;
String sequenceProfileName;
boolean shortenInMiddle=false;
String executablePath;
public void getEmployeeNeeds(){ //This gets called on startup to harvest information; override this and inside, call registerEmployeeNeed
EmployeeNeed e = registerEmployeeNeed(OTUIDCodeInfoCoord.class, "Voucher information is needed for FASTA export for Genbank submissions.",
"This is activated automatically when you choose this exporter.");
EmployeeNeed e3 = registerEmployeeNeed(SequenceProfileManager.class, "A specifier of the nature of sequences is required.", "This is activated automatically.");
}
/*.................................................................................................................*/
public boolean startJob(String arguments, Object condition, boolean hiredByName) {
voucherInfoTask = (OTUIDCodeInfoCoord)hireEmployee(OTUIDCodeInfoCoord.class, null);
loadPreferences();
if (specificationManager == null)
specificationManager= (SequenceProfileManager)MesquiteTrunk.mesquiteTrunk.hireEmployee(SequenceProfileManager.class, "Supplier of sequence specifications.");
if (specificationManager == null) {
return false;
}
return voucherInfoTask != null && super.startJob(arguments, condition, hiredByName);
}
/*.................................................................................................................*/
public void processSingleXMLPreference (String tag, String content) {
if ("codeLabel".equalsIgnoreCase(tag))
codeLabel= content;
if ("addVoucherNumberToDescription".equalsIgnoreCase(tag))
addVoucherNumberToDescription=MesquiteBoolean.fromTrueFalseString(content);
if ("featureAnnotation".equalsIgnoreCase(tag))
featureAnnotation=MesquiteBoolean.fromTrueFalseString(content);
if ("sequenceProfileName".equalsIgnoreCase(tag))
sequenceProfileName=content;
if ("executablePath".equalsIgnoreCase(tag)){ // it is one with the flavor attribute
executablePath = StringUtil.cleanXMLEscapeCharacters(content);
}
if ("useGroupNameAsProductName".equalsIgnoreCase(tag)){
useGroupNameAsProductName = MesquiteBoolean.fromTrueFalseString(content);
}
}
/*.................................................................................................................*/
public String preparePreferencesForXML () {
StringBuffer buffer = new StringBuffer(60);
StringUtil.appendXMLTag(buffer, 2, "codeLabel",codeLabel);
StringUtil.appendXMLTag(buffer, 2, "addVoucherNumberToDescription",addVoucherNumberToDescription);
StringUtil.appendXMLTag(buffer, 2, "useGroupNameAsProductName",useGroupNameAsProductName);
StringUtil.appendXMLTag(buffer, 2, "featureAnnotation",featureAnnotation);
if (StringUtil.notEmpty(sequenceProfileName))
StringUtil.appendXMLTag(buffer, 2, "sequenceProfileName",sequenceProfileName);
StringUtil.appendXMLTag(buffer, 2, "executablePath", executablePath);
return buffer.toString();
}
/*.................................................................................................................*/
public boolean canImport() {
return false; //
}
public boolean canImport(String arguments){
return false;
}
protected int taxonNameLengthLimit() {
return 15;
}
Choice sequenceSpecificationChoice;
ExporterDialog exportDialog;
SingleLineTextField executablePathField = null;
/*.................................................................................................................*/
public boolean getExportOptions(CharacterData data, boolean dataSelected, boolean taxaSelected){
String[] specifications = specificationManager.getListOfProfiles();
if (specifications==null)
// if (!specificationManager.optionsSpecified())
if (!specificationManager.queryOptions())
return false;
MesquiteInteger buttonPressed = new MesquiteInteger(1);
exportDialog = new ExporterDialog(this,containerOfModule(), "Export FASTA for GenBank via tbl2asn", buttonPressed);
exportDialog.appendToHelpString("Choose the options for exporting the matrix as a FASTA file prepared for processing by NCBI's tbl2asn.");
exportDialog.appendToHelpString("
SeqID Suffix: this will be added to each taxon name to form the unique SeqID.");
exportDialog.appendToHelpString(" Text before OTU (Specimen) ID Code in DEFINITION: this will be inserted between the organism name and the OTU (Specimen) ID Code in the DEFINITION.");
exportDialog.appendToHelpString(" Features Annotation Tables: A table will be written for each sequence (see Genbank submission instructions). Group name will become Feature's Product name. Assumes first site in sequence in group will be representative; if has codon position, whole group will be considered CDs.");
String matrixName = "";
if (data!=null){
matrixName = data.getName();
exportDialog.addLabel("(Matrix: " + matrixName+ ")",Label.CENTER);
}
// SingleLineTextField uniqueSuffixField = exportDialog.addTextField("SeqID Suffix", matrixName, 20);
int index = specificationManager.findSpecificationIndex(sequenceProfileName);
if (index<0) index=0;
sequenceSpecificationChoice = exportDialog.addPopUpMenu("Sequence Profile", specificationManager.getListOfProfiles(), index);
final Button manageSpecificationsButton = exportDialog.addAListenedButton("Manage...",null, this);
manageSpecificationsButton.setActionCommand("ManageSpecifications");
Checkbox addVoucherNumberBox = exportDialog.addCheckBox("add OTU (Specimen) ID Code to DEFINITION", addVoucherNumberToDescription);
SingleLineTextField codeLabelField = exportDialog.addTextField("Text before OTU (Specimen) ID Code in DEFINITION", codeLabel, 20);
Checkbox shortenInMiddleBox = exportDialog.addCheckBox("if seqID is too long, shorten in middle (as opposed to end)", shortenInMiddle);
Checkbox useGroupNameAsProductNameCheckBox = exportDialog.addCheckBox("use character group name as product name for coding regions", useGroupNameAsProductName);
exportDialog.addHorizontalLine(1);
//Checkbox includeGapsCheckBox = exportDialog.addCheckBox("include gaps", includeGaps);
//added WPM may 2012
// Checkbox featureAnnotationCheckBox = exportDialog.addCheckBox("if gaps NOT included, save Genbank Features Annotation tables? \n(requires characters partitioned into groups)", featureAnnotation);
// exportDialog.addHorizontalLine(1);
// executablePathField = exportDialog.addTextField("Path to tbl2asn:", executablePath, 40);
// Button browseButton = exportDialog.addAListenedButton("Browse...",null, this);
// browseButton.setActionCommand("browse");
exportDialog.completeAndShowDialog(dataSelected, taxaSelected);
codeLabel = codeLabelField.getText();
// uniqueSuffix = uniqueSuffixField.getText();
addVoucherNumberToDescription = addVoucherNumberBox.getState();
boolean ok = (exportDialog.query(dataSelected, taxaSelected)==0);
includeGaps=false; // for tbl2asn, gaps will be excluded
//includeGaps = includeGapsCheckBox.getState();
useGroupNameAsProductName = useGroupNameAsProductNameCheckBox.getState();
//featureAnnotation = featureAnnotationCheckBox.getState();
featureAnnotation = true; // always true for tbl2asn
shortenInMiddle = shortenInMiddleBox.getState();
int sequenceProfileIndex = sequenceSpecificationChoice.getSelectedIndex();
sequenceProfile = specificationManager.getSequenceProfile(sequenceProfileIndex);
sequenceProfileName = sequenceProfile.getName();
uniqueSuffix = sequenceProfile.getSeqIDSuffix();
if (executablePathField!=null)
executablePath = executablePathField.getText();
exportDialog.dispose();
if (ok) {
storePreferences();
}
return ok;
}
/*.................................................................................................................*/
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equalsIgnoreCase("ManageSpecifications")) {
int currentSequenceProfileIndex = sequenceSpecificationChoice.getSelectedIndex();
SequenceProfile currentSequenceProfile = specificationManager.getSequenceProfile(currentSequenceProfileIndex);
String currentSequenceProfileName = currentSequenceProfile.getName();
if (specificationManager.manageSequenceProfiles()) {
int count2 = sequenceSpecificationChoice.getItemCount();
while (sequenceSpecificationChoice.getItemCount()>0)
sequenceSpecificationChoice.remove(0);
String[] specList = specificationManager.getListOfProfiles();
if (specList!=null && specList.length>0)
for (int i=0; i 0; //
}
/*.................................................................................................................*/
public boolean canExportData(Class dataClass) {
return (dataClass==DNAState.class);
}
/*.................................................................................................................*/
public CharacterData createData(CharactersManager charTask, Taxa taxa) {
return charTask.newCharacterData(taxa, 0, DNAData.DATATYPENAME); //
}
protected String getSupplementForTaxon(Taxa taxa, int it){
if (taxa!=null && voucherInfoTask != null) {
String s = " ";
String voucherID = ChromaseqUtil.getStringAssociated(taxa, VoucherInfoFromOTUIDDB.voucherCodeRef, it);
VoucherInfoFromOTUIDDB vi= voucherInfoTask.getVoucherInfo(ChromaseqUtil.getStringAssociated(taxa, VoucherInfoFromOTUIDDB.voucherDBRef, it), voucherID);
if (vi != null) {
if (sequenceProfile!=null)
s+= sequenceProfile.getFASTASourceModifiers()+ " ";
String gbs = vi.toGenBankString();
if (StringUtil.blank(gbs))
MesquiteMessage.println("Taxon with no Genbank information: " + taxa.getTaxonName(it) + "; OTU (specimen) ID code: " + voucherID);
s += gbs;
addendum = sequenceProfile.getDescription();
if (addVoucherNumberToDescription)
s+= " " + codeLabel + voucherID + " " + addendum;
else
s+= " " + addendum;
return s;
}
else
MesquiteMessage.println("Taxon with no Genbank information: " + taxa.getTaxonName(it) + "; OTU (specimen) ID code: " + voucherID);
}
return null;
}
static int taxonNameLengthLimit = 32;
/*.................................................................................................................*/
protected String getTaxonName(Taxa taxa, int it){
String s = StringUtil.cleanseStringOfFancyChars(taxa.getTaxonName(it),false,true);
String suffix = StringUtil.cleanseStringOfFancyChars(uniqueSuffix,false,true);
if (taxonNameLengthLimit>0) {
String taxnum = MesquiteInteger.toString(it);
int reduction = s.length() + suffix.length() - taxonNameLengthLimit;
if (reduction>0) {
reduction += taxnum.length();
String note = "\nSeqID (\"" + s + suffix + "\") too long; renamed as ";
if (s.length()-reduction <1)
s = taxnum;
else {
if (shortenInMiddle)
s = s.substring(0,4) + "_" + s.substring(5+reduction,s.length())+"_" + taxnum;
else
s = s.substring(0,s.length()-reduction-3) + "_"+taxnum;
}
logln(note + "\"" + s + "_"+suffix+"\"");
}
}
return s+"_"+suffix;
}
int getSequencePosition(int column, int it, DNAData data){
int count = 0;
for (int ic=0; ic<=column; ic++){
if (!data.isInapplicable(ic, it))
count++;
}
return count;
}
int getCodonPositionOfFirstSiteOfPartition(Listable[] listArray, Object obj, DNAData data, int it){
for (int i=0; i0) { // we've already found one, AND this one is not one of this group, AND it is not a gap
if (lastWritten != i-1) {
if (partialEnd) //DRM added
s += ">";
s += (getSequencePosition(i-1, it, data));
if (!returnStartingCodonPosition)
v.addElement(s);
s = "";
lastWritten = i-1;
}
else {
s += "\t" + (getSequencePosition(lastWritten, it, data));
if (!returnStartingCodonPosition)
v.addElement(s);
s = "";
lastWritten = -1;
}
continuing = 0;
}
}
} // end for loop
if (continuing>1){
if (partialEnd)
s += ">";
s += (getSequencePosition(characterObjectArray.length-1, it, data));
if (!returnStartingCodonPosition)
v.addElement(s);
s = "";
}
if (found)
return v;
else
return null;
}
/*.................................................................................................................*/
public String preferredDataFileExtension() {
return "fsa";
}
int getGenBankOffset (int cp) {
/*Genbank has this strange convention where the codon start is the offset until the next full codon,
* but starting counting at 1, so that if the start of the feature is at codon position 1, offset is treated as 1 (not 0!):
* If first codon position is 2, then start of the next codon is treated as offset 3
* If first codon position is 3, then start of the next codon is treated as offset 2
* Go figure. I can see using offsets, but then it should be 0 based.
*/
int genbankOffset = 0;
if (cp ==1)
genbankOffset = 1;
else if (cp == 2)
genbankOffset = 3;
else if (cp == 3)
genbankOffset = 2;
return genbankOffset;
}
/*.................................................................................................................*/
protected void saveExtraFiles(CharacterData cata){
if (!(cata instanceof DNAData))
return;
String extraFilePath = StringUtil.getAllButLastItem(filePath, ".")+".tbl";
DNAData data = (DNAData)cata;
if (featureAnnotation && !includeGaps){
CharactersGroup[] parts =null;
boolean hasCDs = data.someCoding();
boolean hasParts = false;
CharacterPartition characterPartition = (CharacterPartition)data.getCurrentSpecsSet(CharacterPartition.class);
if (characterPartition!=null) {
parts = characterPartition.getGroups();
hasParts = parts!=null;
}
if (!hasParts && !saveFeatureTableEvenIfNoParts) {
return;
}
boolean[][] partial=null;
if (hasParts) {
partial = new boolean[2][parts.length];
for (int ip = 0; ipFeatures " + getTaxonName(data.getTaxa(), it) + "\t\t\t\t");
buffer.append("\n");
if (!hasParts) {
int cp = getCodonPositionOfFirstSite(data, it);
String s = "<1\t>"+data.getNumberApplicableInTaxon(it, true);
if (cp>=1 && cp<=3) {
buffer.append(s + "\t" + "CDS\t\t\n");
buffer.append("\t\t\tproduct\t" + sequenceProfile.getProductName()+"\n");
int genbankOffset = getGenBankOffset(cp);
buffer.append("\t\t\tcodon_start\t" + genbankOffset);
buffer.append("\n");
} else {
buffer.append(s + "\t" + "misc_feature\t\t\n");
buffer.append("\t\t\tproduct\t" + sequenceProfile.getProductName()+"\n");
buffer.append("\n");
}
} else {
for (int i=0; i=1 && cp<=3) {
buffer.append(s + "\t" + "CDS\t\t\n");
if (useGroupNameAsProductName)
buffer.append("\t\t\tproduct\t" + parts[i].getName()+"\n");
else
buffer.append("\t\t\tproduct\t" + sequenceProfile.getProductName()+"\n");
int genbankOffset = getGenBankOffset(cp);
buffer.append("\t\t\tcodon_start\t" + genbankOffset+"\n");
nonCoding=false;
}
else if (StringUtil.indexOfIgnoreCase(parts[i].getName(), "intron")>=0) {
buffer.append(s + "\t" + "intron\t\t"+"\n");
nonCoding=true;
}
else
buffer.append(s + "\t" + "misc_feature\t\t"+"\n");
//}
//else
// buffer.append(s + "\t\t\t");
buffer.append("\n");
}
}
}
}
// single MesquiteFile.putFileContents(directory + MesquiteFile.fileSeparator + (it+1) + "-features_" + getTaxonName(data.getTaxa(), it) + ".tbl", buffer.toString(), true);
}
}
MesquiteFile.putFileContents(extraFilePath, buffer.toString(), true);
}
}
/*.................................................................................................................*/
public CharacterData findDataToExport(MesquiteFile file, String arguments) {
return getProject().chooseData(containerOfModule(), file, null, DNAState.class, "Select data to export");
}
/*.................................................................................................................*/
public void setFastaState(CharacterData data, int ic, int it, char c) {
if ((c=='U')||(c=='u')) {
((DNAData)data).setDisplayAsRNA(true);
}
((DNAData)data).setState(ic,it,c);
}
/*.................................................................................................................*/
public String getUnassignedSymbol(){
return "N";
}
/*.................................................................................................................*/
public String getName() {
return "FASTA (DNA/RNA) for GenBank (via tbl2asn)";
}
/*.................................................................................................................*/
/** returns an explanation of what the module does.*/
public String getExplanation() {
return "Exports FASTA files for use in tbl2asn for GenBank deposition." ;
}
/*.................................................................................................................*/
/** returns the version number at which this module was first released. If 0, then no version number is claimed. If a POSITIVE integer
* then the number refers to the Mesquite version. This should be used only by modules part of the core release of Mesquite.
* If a NEGATIVE integer, then the number refers to the local version of the package, e.g. a third party package*/
public int getVersionOfFirstRelease(){
return -1500;
}
}
\ No newline at end of file
diff --git a/Source/mesquite/chromaseq/ExportFastaDNAForSequin/ExportFastaDNAForSequin.java b/Source/mesquite/chromaseq/ExportFastaDNAForSequin/ExportFastaDNAForSequin.java
new file mode 100644
index 00000000..dac129ca
--- /dev/null
+++ b/Source/mesquite/chromaseq/ExportFastaDNAForSequin/ExportFastaDNAForSequin.java
@@ -0,0 +1 @@
+/* Mesquite Chromaseq source code. Copyright 2005-2011 David Maddison and Wayne Maddison.
Version 1.0 December 2011
Disclaimer: The Mesquite source code is lengthy and we are few. There are no doubt inefficiencies and goofs in this code.
The commenting leaves much to be desired. Please approach this source code with the spirit of helping out.
Perhaps with your help we can be more than a few, and make Mesquite better.
Mesquite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
Mesquite's web site is http://mesquiteproject.org
This source code and its compiled class files are free and modifiable under the terms of
GNU Lesser General Public License. (http://www.gnu.org/copyleft/lesser.html)
*/
package mesquite.chromaseq.ExportFastaDNAForSequin;
/*~~ */
import java.awt.*;
import java.util.Vector;
import mesquite.lib.*;
import mesquite.lib.characters.*;
import mesquite.lib.duties.*;
import mesquite.categ.lib.*;
import mesquite.chromaseq.lib.ChromaseqUtil;
import mesquite.io.lib.*;
/* ============ a file interpreter for DNA/RNA Fasta files ============*/
public class ExportFastaDNAForSequin extends InterpretFasta {
protected String addendum = "";
protected static String codeLabel = "Voucher";
protected boolean addVoucherNumberToDescription = false;
protected boolean featureAnnotation = false;
public void getEmployeeNeeds(){ //This gets called on startup to harvest information; override this and inside, call registerEmployeeNeed
EmployeeNeed e = registerEmployeeNeed(OTUIDCodeInfoCoord.class, "Voucher information is needed for FASTA export for Genbank submissions.",
"This is activated automatically when you choose this exporter.");
}
OTUIDCodeInfoCoord voucherInfoTask;
/*.................................................................................................................*/
public boolean startJob(String arguments, Object condition, boolean hiredByName) {
voucherInfoTask = (OTUIDCodeInfoCoord)hireEmployee(OTUIDCodeInfoCoord.class, null);
loadPreferences();
return voucherInfoTask != null && super.startJob(arguments, condition, hiredByName);
}
/*.................................................................................................................*/
/** returns whether this module is requesting to appear as a primary choice */
public boolean requestPrimaryChoice(){
return false;
}
/*.................................................................................................................*/
public void processSingleXMLPreference (String tag, String content) {
if ("codeLabel".equalsIgnoreCase(tag))
codeLabel= content;
if ("addVoucherNumberToDescription".equalsIgnoreCase(tag))
addVoucherNumberToDescription=MesquiteBoolean.fromTrueFalseString(content);
if ("featureAnnotation".equalsIgnoreCase(tag))
featureAnnotation=MesquiteBoolean.fromTrueFalseString(content);
}
/*.................................................................................................................*/
public String preparePreferencesForXML () {
StringBuffer buffer = new StringBuffer(60);
StringUtil.appendXMLTag(buffer, 2, "codeLabel",codeLabel);
StringUtil.appendXMLTag(buffer, 2, "addVoucherNumberToDescription",addVoucherNumberToDescription);
StringUtil.appendXMLTag(buffer, 2, "featureAnnotation",featureAnnotation);
return buffer.toString();
}
/*.................................................................................................................*/
public boolean canImport() {
return false; //
}
public boolean canImport(String arguments){
return false;
}
protected int taxonNameLengthLimit() {
return 15;
}
/*.................................................................................................................*/
public boolean getExportOptions(CharacterData data, boolean dataSelected, boolean taxaSelected){
MesquiteInteger buttonPressed = new MesquiteInteger(1);
ExporterDialog exportDialog = new ExporterDialog(this,containerOfModule(), "Export FASTA for GenBank Options", buttonPressed);
exportDialog.appendToHelpString("Choose the options for exporting the matrix as a FASTA file prepared for processing by NCBI's Sequin.");
exportDialog.appendToHelpString("
SeqID Suffix: this will be added to each taxon name to form the unique SeqID.");
exportDialog.appendToHelpString(" Description of gene fragment: this will be added to each sequence's DEFINITION.");
exportDialog.appendToHelpString(" Text before OTU (Specimen) ID Code in DEFINITION: this will be inserted between the organism name and the OTU (Specimen) ID Code in the DEFINITION.");
exportDialog.appendToHelpString(" Features Annotation Tables: A table will be written for each sequence (see Genbank submission instructions). Group name will become Feature's Product name. Assumes first site in sequence in group will be representative; if has codon position, whole group will be considered CDs.");
String matrixName = "";
if (data!=null){
matrixName = data.getName();
exportDialog.addLabel("(Matrix: " + matrixName+ ")",Label.CENTER);
}
SingleLineTextField uniqueSuffixField = exportDialog.addTextField("SeqID Suffix", matrixName, 20);
TextArea fsText =null;
exportDialog.addLabel("Description of gene fragment:",Label.LEFT);
fsText =exportDialog.addTextAreaSmallFont(addendum,4);
Checkbox addVoucherNumberBox = exportDialog.addCheckBox("add OTU (Specimen) ID Code to DEFINITION", addVoucherNumberToDescription);
SingleLineTextField codeLabelField = exportDialog.addTextField("Text before OTU (Specimen) ID Code in DEFINITION", codeLabel, 20);
Checkbox includeGapsCheckBox = exportDialog.addCheckBox("include gaps", includeGaps);
//added WPM may 2012
Checkbox featureAnnotationCheckBox = exportDialog.addCheckBox("if gaps NOT included, save Genbank Features Annotation tables? \n(requires characters partitioned into groups)", featureAnnotation);
exportDialog.completeAndShowDialog(dataSelected, taxaSelected);
addendum = fsText.getText();
codeLabel = codeLabelField.getText();
uniqueSuffix = uniqueSuffixField.getText();
addVoucherNumberToDescription = addVoucherNumberBox.getState();
boolean ok = (exportDialog.query(dataSelected, taxaSelected)==0);
includeGaps = includeGapsCheckBox.getState();
featureAnnotation = featureAnnotationCheckBox.getState();
exportDialog.dispose();
return ok;
}
/*.................................................................................................................*/
public int getPartials(String nameOfPart){ //00 = not partial; 01 = partial end; 10 = partial start; 11 = partial both
MesquiteInteger buttonPressed = new MesquiteInteger(1);
ExtensibleDialog partialDialog = new ExtensibleDialog(containerOfModule(), "Partial?", buttonPressed);
TextArea uniqueSuffixField = partialDialog.addLargeTextLabel("Is the partition \"" + nameOfPart + "\" partial on either end?");
Checkbox start = partialDialog.addCheckBox("5' Partial", false);
Checkbox end = partialDialog.addCheckBox("3' Partial", false);
partialDialog.completeAndShowDialog();
int result = 0;
if (start.getState())
result += 2;
if (end.getState())
result += 1;
partialDialog.dispose();
return result;
}
/*.................................................................................................................*/
public boolean canExportEver() {
return true; //
}
/*.................................................................................................................*/
public boolean canExportProject(MesquiteProject project) {
return project.getNumberCharMatrices(DNAState.class) > 0; //
}
/*.................................................................................................................*/
public boolean canExportData(Class dataClass) {
return (dataClass==DNAState.class);
}
/*.................................................................................................................*/
public CharacterData createData(CharactersManager charTask, Taxa taxa) {
return charTask.newCharacterData(taxa, 0, DNAData.DATATYPENAME); //
}
protected String getSupplementForTaxon(Taxa taxa, int it){
if (taxa!=null && voucherInfoTask != null) {
String s = " ";
String voucherID = ChromaseqUtil.getStringAssociated(taxa, VoucherInfoFromOTUIDDB.voucherCodeRef, it);
VoucherInfoFromOTUIDDB vi= voucherInfoTask.getVoucherInfo(ChromaseqUtil.getStringAssociated(taxa, VoucherInfoFromOTUIDDB.voucherDBRef, it), voucherID);
if (vi != null) {
String gbs = vi.toGenBankString();
if (StringUtil.blank(gbs))
MesquiteMessage.println("Taxon with no Genbank information: " + taxa.getTaxonName(it) + "; OTU (specimen) ID code: " + voucherID);
s += gbs;
if (addVoucherNumberToDescription)
return s + " " + codeLabel + " " + voucherID + " " + addendum;
else
return s + " " + addendum;
}
else
MesquiteMessage.println("Taxon with no Genbank information: " + taxa.getTaxonName(it) + "; OTU (specimen) ID code: " + voucherID);
}
return null;
}
static int taxonNameLengthLimit = 32;
/*.................................................................................................................*/
protected String getTaxonName(Taxa taxa, int it){
String s = StringUtil.cleanseStringOfFancyChars(taxa.getTaxonName(it),false,true);
String suffix = StringUtil.cleanseStringOfFancyChars(uniqueSuffix,false,true);
if (taxonNameLengthLimit>0) {
String taxnum = MesquiteInteger.toString(it);
int reduction = s.length() + suffix.length() - taxonNameLengthLimit;
if (reduction>0) {
reduction += taxnum.length();
String note = "\nSeqID (\"" + s + suffix + "\") too long; renamed as ";
if (s.length()-reduction <1)
s = taxnum;
else {
s = s.substring(0,4) + "_" + s.substring(5+reduction,s.length())+"_" + taxnum;
}
logln(note + "\"" + s + suffix+"\"");
}
}
return s+suffix;
}
int getSequencePosition(int column, int it, DNAData data){
int count = 0;
for (int ic=0; ic<=column; ic++){
if (!data.isInapplicable(ic, it))
count++;
}
return count;
}
int getCodonPositionOfFirstSiteOfPartition(Listable[] listArray, Object obj, DNAData data, int it){
for (int i=0; i0) {
if (lastWritten != i-1) {
s += (getSequencePosition(i-1, it, data));
v.addElement(s);
s = "";
lastWritten = i-1;
}
else {
s += "\t" + (getSequencePosition(lastWritten, it, data));
v.addElement(s);
s = "";
lastWritten = -1;
}
continuing = 0;
}
}
}
if (continuing>1){
if (partialEnd)
s += ">";
s += (getSequencePosition(listArray.length-1, it, data));
v.addElement(s);
s = "";
}
if (found)
return v;
else
return null;
}
/*.................................................................................................................*/
protected void saveExtraFiles(CharacterData cata){
if (!(cata instanceof DNAData))
return;
DNAData data = (DNAData)cata;
if (featureAnnotation && !includeGaps){
CharactersGroup[] parts =null;
boolean hasCDs = data.someCoding();
boolean hasParts = false;
CharacterPartition characterPartition = (CharacterPartition)data.getCurrentSpecsSet(CharacterPartition.class);
if (characterPartition!=null) {
parts = characterPartition.getGroups();
hasParts = parts!=null;
}
if (!hasParts) {
return;
}
boolean[][] partial = new boolean[2][parts.length];
for (int ip = 0; ipFeatures " + getTaxonName(data.getTaxa(), it) + "\t\t\t\t");
buffer.append("\n");
for (int i=0; i=1 && cp<=3)
buffer.append(s + "\t" + "CDS\t\t");
else if (StringUtil.indexOfIgnoreCase(parts[i].getName(), "intron")>=0)
buffer.append(s + "\t" + "intron\t\t");
else
buffer.append(s + "\t" + "misc_feature\t\t");
}
else
buffer.append(s + "\t\t\t");
buffer.append("\n");
}
buffer.append("\t\t\tproduct\t" + parts[i].getName());
buffer.append("\n");
int cp = getCodonPositionOfFirstSiteOfPartition((Listable[])characterPartition.getProperties(), parts[i], data, it);
if (cp>=1 && cp <=3){
/*Genbank has this strange convention where the codon start is the offset until the next full codon,
* but starting counting at 1, so that if the start of the feature is at codon position 1, offset is treated as 1 (not 0!):
* If first codon position is 2, then start of the next codon is treated as offset 3
* If first codon position is 3, then start of the next codon is treated as offset 2
* Go figure. I can see using offsets, but then it should be 0 based.
*/
int genbankOffset = 0;
if (cp ==1)
genbankOffset = 1;
else if (cp == 2)
genbankOffset = 3;
else if (cp == 3)
genbankOffset = 2;
buffer.append("\t\t\tcodon_start\t" + genbankOffset);
buffer.append("\n");
}
}
}
MesquiteFile.putFileContents(directory + MesquiteFile.fileSeparator + (it+1) + "-features_" + getTaxonName(data.getTaxa(), it) + ".txt", buffer.toString(), true);
}
}
}
}
/*.................................................................................................................*/
public CharacterData findDataToExport(MesquiteFile file, String arguments) {
return getProject().chooseData(containerOfModule(), file, null, DNAState.class, "Select data to export");
}
/*.................................................................................................................*/
public void setFastaState(CharacterData data, int ic, int it, char c) {
if ((c=='U')||(c=='u')) {
((DNAData)data).setDisplayAsRNA(true);
}
((DNAData)data).setState(ic,it,c);
}
/*.................................................................................................................*/
public String getUnassignedSymbol(){
return "N";
}
/*.................................................................................................................*/
public String getName() {
return "FASTA (DNA/RNA) for Sequin";
}
/*.................................................................................................................*/
/** returns an explanation of what the module does.*/
public String getExplanation() {
return "Exports FASTA files for GenBank deposition using Sequin." ;
}
}
\ No newline at end of file
diff --git a/Source/mesquite/chromaseq/ExportSeparateSequenceFASTA/ExportSeparateSequenceFASTA.java b/Source/mesquite/chromaseq/ExportSeparateSequenceFASTA/ExportSeparateSequenceFASTA.java
index 95a9c935..509078ae 100644
--- a/Source/mesquite/chromaseq/ExportSeparateSequenceFASTA/ExportSeparateSequenceFASTA.java
+++ b/Source/mesquite/chromaseq/ExportSeparateSequenceFASTA/ExportSeparateSequenceFASTA.java
@@ -70,7 +70,7 @@ public boolean canExportData(Class dataClass){
}
protected int taxonNameLengthLimit() {
- return 15;
+ return 50;
}
/* ============================ exporting ============================*/
diff --git a/Source/mesquite/chromaseq/PhredPhrap/PhredPhrap.java b/Source/mesquite/chromaseq/PhredPhrap/PhredPhrap.java
index a4fd4551..5847ddad 100644
--- a/Source/mesquite/chromaseq/PhredPhrap/PhredPhrap.java
+++ b/Source/mesquite/chromaseq/PhredPhrap/PhredPhrap.java
@@ -1 +1 @@
-/* Mesquite Chromaseq source code. Copyright 2005-2011 David Maddison and Wayne Maddison.
Version 1.0 December 2011
Disclaimer: The Mesquite source code is lengthy and we are few. There are no doubt inefficiencies and goofs in this code.
The commenting leaves much to be desired. Please approach this source code with the spirit of helping out.
Perhaps with your help we can be more than a few, and make Mesquite better.
Mesquite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
Mesquite's web site is http://mesquiteproject.org
This source code and its compiled class files are free and modifiable under the terms of
GNU Lesser General Public License. (http://www.gnu.org/copyleft/lesser.html)
*/
package mesquite.chromaseq.PhredPhrap;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JLabel;
import org.dom4j.*;
import mesquite.lib.*;
import mesquite.lib.duties.*;
import mesquite.tol.lib.MesquiteXMLToLUtilities;
import mesquite.categ.lib.*;
import mesquite.cont.lib.*;
import mesquite.meristic.lib.*;
import mesquite.molec.lib.DNADatabaseURLSource;
import mesquite.chromaseq.ChromaseqAuthorDefaults.ChromaseqAuthorDefaults;
import mesquite.chromaseq.lib.*;
/* ======================================================================== */
public class PhredPhrap extends ChromatogramProcessor implements ActionListener, OutputFileProcessor, ShellScriptWatcher {
protected DNADatabaseURLSource databaseURLSource = null;
private boolean uploadResultsToDatabase = false;
private ChromaseqAuthorDefaults authorDefaults;
ChromatogramFileNameParser nameParserManager;
StringBuffer logBuffer;
boolean scriptBased = true; // Note: turning this off will require Java 7 because of Process.isAlive()
ShellScriptRunner scriptRunner;
ExternalProcessManager externalRunner;
ProgressIndicator progIndicator = null;
boolean importing = true;
String[][] fileNameTranslation;
//for importing sequences
//MesquiteProject project = null;
FileCoordinator coord = null;
MesquiteFile file = null;
Taxa taxa = null;
DNAData data = null;
DNAData originalData = null;
ContinuousData qualityData = null;
// CategoricalData addedBaseData = null;
MeristicData registrationData = null;
MesquiteInteger maxChar = new MesquiteInteger(0);
static String previousDirectory = null;
int preDNANumberLength = 10;
final String processedFolder = "processed";
final String originalFolder = "originals";
// final String fastaFolder = "fasta";
final String processedACEFolder = "processedACE";
final String sequencesFolder = "sequences";
String fastaDirectory = null;
String processedFastaDirectory = null;
String processedACEDirectory = null;
final static String VERSION_FILE = "fileToDetermineVersion";
boolean preferencesSet = false;
String phredParamPath;
String phredPath;
String phrapOptions = "-qual_show 20 -vector_bound 0 ";
String phredOptions = "";
String fileExtension = "";
boolean requiresExtension=true;
final static boolean runPhredPhrap = true;
boolean processPolymorphisms = true;
boolean verbose = true;
boolean singleTaxaBlock = false;
boolean addPhrapFailures = true;
boolean showBirdsEye = true;
double polyThreshold = 0.3;
ExtensibleDialog dialog = null;
SingleLineTextField cygwinPathField = null;
SingleLineTextField phredPathField = null;
SingleLineTextField paramPathField = null;
int qualThresholdForTrim = 20;
int qualThresholdForLowerCase = 49;
boolean truncateMixedEnds = true;
int mixedEndWindow = 10;
int mixedEndThreshold = 5;
boolean renameContigsInAceFiles = true;
boolean addFragName = false;
// boolean unTrimAceReads = true;
boolean backupOriginals = true;
SequenceNameSource sequenceNameTask = null;
PrimerInfoSource primerInfoTask = null;
public void getEmployeeNeeds(){ //This gets called on startup to harvest information; override this and inside, call registerEmployeeNeed
EmployeeNeed e1 = registerEmployeeNeed(SequenceNameSource.class, "Phred/Phrap processing requires a source of sequence names; choose the one that appropriately determines the sequence names from the sample codes.", "This is activated automatically.");
EmployeeNeed e2 = registerEmployeeNeed(PrimerInfoSource.class, "Phred/Phrap processing requires a source of information about primers, including their names, direction, and sequence, as well as the gene fragments to which they correspond.", "This is activated automatically.");
EmployeeNeed e3 = registerEmployeeNeed(ChromatogramFileNameParser.class, "Phred/Phrap processing requires a means to determine the sample code and primer name.", "This is activated automatically.");
}
/*.................................................................................................................*/
public boolean startJob(String arguments, Object condition, boolean hiredByName){
/* don't know if your structure permits this but: if was set previously, could use prefs to have these modules start up and hire according
* to prefs before dialog shows up. Then in composing dialog use getParameters() of all these employees to report on current settings,
* and put report in a little text area at top of dialog to indicate current settings, and a button that says "change". Would require
* that getParameters of these modules return text with this in mind, and that modules that hire other modules would have to put
* the latter's text embedded in own getParameters text returned. */
loadPreferences();
if (authorDefaults == null) {
authorDefaults = (ChromaseqAuthorDefaults)MesquiteTrunk.mesquiteTrunk.findEmployeeWithName("#ChromaseqAuthorDefaults");
}
if (nameParserManager == null)
nameParserManager= (ChromatogramFileNameParser)MesquiteTrunk.mesquiteTrunk.hireEmployee(ChromatogramFileNameParser.class, "Supplier of sample code and primer name from the chromatogram file name.");
if (nameParserManager == null || authorDefaults == null) {
return false;
} else {
if (!nameParserManager.optionsSpecified())
if (!nameParserManager.queryOptions())
return false;
}
if (sequenceNameTask==null)
sequenceNameTask = (SequenceNameSource)hireEmployee(SequenceNameSource.class, "Supplier of sequence names from sample codes");
if (sequenceNameTask==null)
return false;
else {
if (!sequenceNameTask.optionsSpecified())
if (!sequenceNameTask.queryOptions())
return false;
}
// primerInfoTask = (PrimerInfoSource)hireCompatibleEmployee(PrimerInfoSource.class, new MesquiteString("alwaysAsk"), "Supplier of information about primers and gene fragments");
if (primerInfoTask==null)
primerInfoTask = (PrimerInfoSource)hireEmployee(PrimerInfoSource.class, "Supplier of information about primers and gene fragments");
if (primerInfoTask==null)
return false;
else {
if (!primerInfoTask.optionsSpecified())
if (!primerInfoTask.queryOptions())
return false;
}
logBuffer = new StringBuffer(200);
return true;
}
/*.................................................................................................................*/
public boolean processChromatograms(MesquiteProject project, boolean appendIfPossible) {
return processChromatograms(project, appendIfPossible, null);
}
public boolean userAborted(){
return false;
}
/*.................................................................................................................*/
public boolean processChromatograms(MesquiteProject project, boolean appendIfPossible, String outputDirectory) {
importing = project !=null;
if (queryOptions()) {
// if they want to upload the results to the database, they need to ensure that
// they have selected their username
if (uploadResultsToDatabase) {
boolean results = authorDefaults.verifyAuthorIsntDefault();
if (!results) {
return false;
}
}
if (project != null) project.incrementProjectWindowSuppression();
boolean success = prepareAndRunPhredPhrap(project, appendIfPossible, outputDirectory);
postBean();
if (project !=null) getProject().decrementProjectWindowSuppression();
return success;
}
return false;
}
/*.................................................................................................................*/
public void processSingleXMLPreference (String tag, String content) {
if ("requiresExtension".equalsIgnoreCase(tag))
requiresExtension = MesquiteBoolean.fromTrueFalseString(content);
else if ("phredParamPath".equalsIgnoreCase(tag))
phredParamPath = StringUtil.cleanXMLEscapeCharacters(content);
else if ("phredPath".equalsIgnoreCase(tag))
phredPath = StringUtil.cleanXMLEscapeCharacters(content);
else if ("previousDirectory".equalsIgnoreCase(tag))
previousDirectory = StringUtil.cleanXMLEscapeCharacters(content);
else if ("phrapOptions".equalsIgnoreCase(tag))
phrapOptions = StringUtil.cleanXMLEscapeCharacters(content);
else if ("fileExtension".equalsIgnoreCase(tag))
fileExtension = StringUtil.cleanXMLEscapeCharacters(content);
else if ("phredOptions".equalsIgnoreCase(tag))
phredOptions = StringUtil.cleanXMLEscapeCharacters(content);
else if ("processPolymorphisms".equalsIgnoreCase(tag))
processPolymorphisms = MesquiteBoolean.fromTrueFalseString(content);
else if ("showBirdsEye".equalsIgnoreCase(tag))
showBirdsEye = MesquiteBoolean.fromTrueFalseString(content);
else if ("singleTaxaBlock".equalsIgnoreCase(tag))
singleTaxaBlock = MesquiteBoolean.fromTrueFalseString(content);
else if ("truncateMixedEnds".equalsIgnoreCase(tag))
truncateMixedEnds = MesquiteBoolean.fromTrueFalseString(content);
else if ("renameContigsInAceFiles".equalsIgnoreCase(tag))
renameContigsInAceFiles = MesquiteBoolean.fromTrueFalseString(content);
else if ("addFragName".equalsIgnoreCase(tag))
addFragName = MesquiteBoolean.fromTrueFalseString(content);
else if ("backupOriginals".equalsIgnoreCase(tag))
backupOriginals = MesquiteBoolean.fromTrueFalseString(content);
else if ("polyThreshold".equalsIgnoreCase(tag))
polyThreshold = MesquiteDouble.fromString(content);
else if ("qualThresholdForTrim".equalsIgnoreCase(tag))
qualThresholdForTrim = MesquiteInteger.fromString(content);
else if ("qualThresholdForLowerCase".equalsIgnoreCase(tag))
qualThresholdForLowerCase = MesquiteInteger.fromString(content);
else if ("mixedEndWindow".equalsIgnoreCase(tag))
mixedEndWindow = MesquiteInteger.fromString(content);
else if ("mixedEndThreshold".equalsIgnoreCase(tag))
mixedEndThreshold = MesquiteInteger.fromString(content);
else if ("uploadResultsToDatabase".equalsIgnoreCase(tag)) {
uploadResultsToDatabase = MesquiteBoolean.fromTrueFalseString(content);
}
else if ("setPrimerInfoSource".equalsIgnoreCase(tag)) {
replacePrimerInfoSource(content);
}
else if ("setSequenceNameSource".equalsIgnoreCase(tag)) {
replaceSequenceNameSource(content);
}
preferencesSet = true;
}
/*.................................................................................................................*/
public String preparePreferencesForXML () {
StringBuffer buffer = new StringBuffer(200);
StringUtil.appendXMLTag(buffer, 2, "requiresExtension", requiresExtension);
StringUtil.appendXMLTag(buffer, 2, "phredParamPath", phredParamPath);
StringUtil.appendXMLTag(buffer, 2, "phredPath", phredPath);
StringUtil.appendXMLTag(buffer, 2, "processPolymorphisms", processPolymorphisms);
StringUtil.appendXMLTag(buffer, 2, "polyThreshold", polyThreshold);
StringUtil.appendXMLTag(buffer, 2, "previousDirectory", previousDirectory);
StringUtil.appendXMLTag(buffer, 2, "singleTaxaBlock", singleTaxaBlock);
StringUtil.appendXMLTag(buffer, 2, "qualThresholdForTrim", qualThresholdForTrim);
StringUtil.appendXMLTag(buffer, 2, "qualThresholdForLowerCase", qualThresholdForLowerCase);
StringUtil.appendXMLTag(buffer, 2, "mixedEndWindow", mixedEndWindow);
StringUtil.appendXMLTag(buffer, 2, "mixedEndThreshold", mixedEndThreshold);
StringUtil.appendXMLTag(buffer, 2, "truncateMixedEnds", truncateMixedEnds);
StringUtil.appendXMLTag(buffer, 2, "renameContigsInAceFiles", renameContigsInAceFiles);
StringUtil.appendXMLTag(buffer, 2, "addFragName", addFragName);
StringUtil.appendXMLTag(buffer, 2, "backupOriginals", backupOriginals);
StringUtil.appendXMLTag(buffer, 2, "phrapOptions", phrapOptions);
StringUtil.appendXMLTag(buffer, 2, "fileExtension", fileExtension);
StringUtil.appendXMLTag(buffer, 2, "phredOptions", phredOptions);
StringUtil.appendXMLTag(buffer, 2, "showBirdsEye", showBirdsEye);
StringUtil.appendXMLTag(buffer, 2, "uploadResultsToDatabase", uploadResultsToDatabase);
if (primerInfoTask!=null)
StringUtil.appendXMLTag(buffer, 2, "setPrimerInfoSource",primerInfoTask);
if (sequenceNameTask!=null)
StringUtil.appendXMLTag(buffer, 2, "setSequenceNameSource",sequenceNameTask);
preferencesSet = true;
return buffer.toString();
}
/*.................................................................................................................*/
/** returns whether this module is requesting to appear as a primary choice */
public boolean requestPrimaryChoice(){
return true;
}
/*.................................................................................................................*/
public boolean isPrerelease(){
return false;
}
/*.................................................................................................................*/
public boolean isSubstantive(){
return true;
}
/*.................................................................................................................*/
public boolean queryFileLocations() {
MesquiteInteger buttonPressed = new MesquiteInteger(1);
ExtensibleDialog queryFilesDialog = new ExtensibleDialog(MesquiteTrunk.mesquiteTrunk.containerOfModule(), "Phred Phrap Locations & Options",buttonPressed); //MesquiteTrunk.mesquiteTrunk.containerOfModule()
queryFilesDialog.addLabel("Phred & Phrap - File Locations & Options");
phredPathField = queryFilesDialog.addTextField("Phred, Phrap, & Phd2Fasta path:", phredPath, 40);
Button phredBrowseButton = queryFilesDialog.addAListenedButton("Browse...",null, this);
phredBrowseButton.setActionCommand("phBrowse");
paramPathField = queryFilesDialog.addTextField("Phred parameter file:", phredParamPath, 40);
Button paramBrowseButton = queryFilesDialog.addAListenedButton("Browse...",null, this);
paramBrowseButton.setActionCommand("paramBrowse");
SingleLineTextField phredOptionsField = queryFilesDialog.addTextField("Phred command-line arguments:", phredOptions, 26, true);
SingleLineTextField phrapOptionsField = queryFilesDialog.addTextField("Phrap command-line arguments:", phrapOptions, 26, true);
queryFilesDialog.completeAndShowDialog(true);
if (buttonPressed.getValue()==0) {
phredParamPath = paramPathField.getText();
phredPath = phredPathField.getText();
phredPath = StringUtil.stripTrailingWhitespace(phredPath);
if (!phredPath.endsWith(MesquiteFile.fileSeparator))
phredPath+=MesquiteFile.fileSeparator;
phrapOptions = phrapOptionsField.getText();
phredOptions = phredOptionsField.getText();
}
queryFilesDialog.dispose();
return (buttonPressed.getValue()==0);
}
/*.................................................................................................................*/
public boolean queryPostOptions() {
MesquiteInteger buttonPressed = new MesquiteInteger(1);
ExtensibleDialog queryPostDialog = new ExtensibleDialog(MesquiteTrunk.mesquiteTrunk.containerOfModule(), "Post-Phrap Sequence Processing Options",buttonPressed); //MesquiteTrunk.mesquiteTrunk.containerOfModule()
queryPostDialog.addLabel("Post-Phrap Processing by Chromaseq");
IntegerField lowerCaseQualityField = queryPostDialog.addIntegerField("Quality threshold for lower case:", qualThresholdForLowerCase, 3);
Checkbox polyBox = queryPostDialog.addCheckBox("Convert multiple-peaks sites to ambiguity codes",processPolymorphisms);
DoubleField polyThresholdField = queryPostDialog.addDoubleField("Minimum secondary peak fraction for ambiguity:", polyThreshold, 6);
Checkbox truncateEndsBox = queryPostDialog.addCheckBox("Trim low quality regions from ends (FASTA & import)",truncateMixedEnds);
IntegerField trimQualityField = queryPostDialog.addIntegerField("Quality threshold for trim:", qualThresholdForTrim, 3);
IntegerField trimWindowField = queryPostDialog.addIntegerField("Trim window length:", mixedEndWindow, 3);
IntegerField trimThresholdField = queryPostDialog.addIntegerField("Trim window threshold:", mixedEndThreshold, 3);
// Checkbox unTrimAceReadsField = queryPostDialog.addCheckBox("reset quality regions in reads in .ace files",unTrimAceReads);
Checkbox renameContigsField = queryPostDialog.addCheckBox("rename contigs in .ace files",renameContigsInAceFiles);
Checkbox addFragNameField = queryPostDialog.addCheckBox("add fragment name to contig name",addFragName);
queryPostDialog.addHorizontalLine(2);
// Checkbox openAceField = queryPostDialog.addCheckBox("open directory with .ace file links",openAceDirectory);
// Checkbox importSequencesField = queryPostDialog.addCheckBox("import sequences into Mesquite",importSequencesIntoMesquite);
String s = "After Phrap finishes assembling contigs, Mesquite will process the files produced. It will change upper case nucleotides to lower case if the quality score falls below the specified quality threshold.\n\n";
s+= "Mesquite will also trim low quality ends of sequences, if you so choose. This trimming is done by removing regions of leading or trailing nucleotides with quality values less than the specified quality threshold. ";
s+= "If the ends have a mixture of lower and higher quality nucleotides, then Mesquite will trim until if finds a window of nucleotides of specified length which have fewer than the \"Trim window threshold\" ";
s+= "of nucleotides below the quality score. To put it another way, it will trim leading and trailing windows of nucleotides which have as many or more poor-quality nucleotides than specified; ";
s+= "it trims high-quality nucleotides only if they are external to low-quality nucleotides that are to be trimmed by this criterion.";
queryPostDialog.appendToHelpString(s);
queryPostDialog.completeAndShowDialog(true);
if (buttonPressed.getValue()==0) {
qualThresholdForLowerCase = lowerCaseQualityField.getValue();
truncateMixedEnds = truncateEndsBox.getState();
qualThresholdForTrim = trimQualityField.getValue();
processPolymorphisms = polyBox.getState();
polyThreshold = polyThresholdField.getValue();
mixedEndWindow = trimWindowField.getValue();
mixedEndThreshold = trimThresholdField.getValue();
renameContigsInAceFiles = renameContigsField.getState();
// unTrimAceReads = unTrimAceReadsField.getState();
addFragName = addFragNameField.getState();
// openAceDirectory = openAceField.getState();
// importSequencesIntoMesquite = importSequencesField.getState();
}
queryPostDialog.dispose();
return (buttonPressed.getValue()==0);
}
JLabel nameParserLabel = null;
JLabel sequenceNameTaskLabel = null;
JLabel primerInfoTaskLabel = null;
MesquiteTextCanvas nameParserTextCanvas = null;
MesquiteTextCanvas sequenceNameTaskTextCanvas = null;
MesquiteTextCanvas primerInfoTaskTextCanvas = null;
Button sequenceNameTaskButton = null;
Button nameParserButton = null;
Button primerInfoTaskButton = null;
/*.................................................................................................................*/
private String getModuleText(MesquiteModule mod) {
return mod.getName() + "\n" + mod.getParameters();
}
/*.................................................................................................................*/
public boolean queryOptions() {
MesquiteInteger buttonPressed = new MesquiteInteger(ExtensibleDialog.defaultCANCEL);
ExtensibleDialog dialog = new ExtensibleDialog(containerOfModule(), "Phred/Phrap/Chromaseq Options",buttonPressed); //MesquiteTrunk.mesquiteTrunk.containerOfModule()
dialog.addLabel("Phred/Phrap/Chromaseq Options");
dialog.setHelpURL(this, "manual/preparation.html#processing");
TextCanvasWithButtons textCanvasWithButtons;
//section for name parser
dialog.addHorizontalLine(1);
dialog.addLabel("Chromatogram File Name Parser");
dialog.forceNewPanel();
String s = getModuleText(nameParserManager);
if (MesquiteTrunk.mesquiteTrunk.numModulesAvailable(ChromatogramFileNameParser.class)>1){
textCanvasWithButtons = dialog.addATextCanvasWithButtons(s,"File Name Parser...", "nameParserReplace", "Options...", "nameParserButton",this);
nameParserButton = textCanvasWithButtons.getButton2();
}
else {
textCanvasWithButtons = dialog.addATextCanvasWithButtons(s, "Options...", "nameParserButton",this);
nameParserButton = textCanvasWithButtons.getButton();
}
nameParserButton.setEnabled (nameParserManager.hasOptions());
nameParserTextCanvas = textCanvasWithButtons.getTextCanvas();
//section for SequenceNameSource
dialog.addHorizontalLine(1);
dialog.addLabel("Source of Sequence Names");
dialog.forceNewPanel();
s = getModuleText(sequenceNameTask);
if (MesquiteTrunk.mesquiteTrunk.numModulesAvailable(SequenceNameSource.class)>1){
textCanvasWithButtons = dialog.addATextCanvasWithButtons(s,"Sequence Name Source...", "sequenceNameTaskReplace", "Options...", "sequenceNameTaskButton",this);
sequenceNameTaskButton = textCanvasWithButtons.getButton2();
}
else {
textCanvasWithButtons = dialog.addATextCanvasWithButtons(s, "Options...", "sequenceNameTaskButton",this);
sequenceNameTaskButton = textCanvasWithButtons.getButton();
}
sequenceNameTaskButton.setEnabled (sequenceNameTask.hasOptions());
sequenceNameTaskTextCanvas = textCanvasWithButtons.getTextCanvas();
//section for PrimerInfoSource
dialog.addHorizontalLine(1);
dialog.addLabel("Source of Primer Information");
dialog.forceNewPanel();
s = getModuleText(primerInfoTask);
if (MesquiteTrunk.mesquiteTrunk.numModulesAvailable(PrimerInfoSource.class)>1){
textCanvasWithButtons = dialog.addATextCanvasWithButtons(s,"Primer Info Source...", "primerInfoTaskReplace", "Options...", "primerInfoTaskButton",this);
primerInfoTaskButton = textCanvasWithButtons.getButton2();
}
else {
textCanvasWithButtons = dialog.addATextCanvasWithButtons(s, "Options...", "primerInfoTaskButton",this);
primerInfoTaskButton = textCanvasWithButtons.getButton();
}
nameParserButton.setEnabled (primerInfoTask.hasOptions());
primerInfoTaskTextCanvas = textCanvasWithButtons.getTextCanvas();
dialog.addHorizontalLine(2);
dialog.setDefaultButton("Process");
Checkbox requiresExtensionBox = dialog.addCheckBox("process only files with standard extensions (ab1,abi,ab,CRO,scf)", requiresExtension);
SingleLineTextField fileExtensionField = dialog.addTextField("uniform file extension for organized chromatograms (if desired):", fileExtension, 8, true);
Checkbox backupOriginalsBox = dialog.addCheckBox("save backups of original chromatograms", backupOriginals);
Panel buttonPanel = dialog.addNewDialogPanel();
Button fileLocationsButton = dialog.addAButton("Phred Phrap Locations & Options...",buttonPanel);
fileLocationsButton.addActionListener(this);
fileLocationsButton.setActionCommand("phLocations");
dialog.addHorizontalLine(2);
Panel buttonPanel2 = dialog.addNewDialogPanel();
Button postProcessingButton = dialog.addAButton("Post-Phrap Sequence Processing Options...",buttonPanel2);
postProcessingButton.addActionListener(this);
postProcessingButton.setActionCommand("postOptions");
Checkbox singleTaxaBlockBox=null;
if (importing) {
singleTaxaBlockBox = dialog.addCheckBox("import as single taxon block",singleTaxaBlock);
}
Checkbox uploadResultsBox = null;
if (MesquiteTrunk.mesquiteTrunk.numModulesAvailable(DNADatabaseURLSource.class)>=1)
uploadResultsBox = dialog.addCheckBox("upload results to database", uploadResultsToDatabase);
Checkbox showBirdsEyeBox=null;
if (importing) {
showBirdsEyeBox = dialog.addCheckBox("display matrix in bird's eye view",showBirdsEye);
}
dialog.addHorizontalLine(2);
dialog.completeAndShowDialog(true);
boolean success=(buttonPressed.getValue()== dialog.defaultOK);
if (success) {
fileExtension = fileExtensionField.getText();
requiresExtension = requiresExtensionBox.getState();
backupOriginals = backupOriginalsBox.getState();
if (uploadResultsBox!=null)
uploadResultsToDatabase = uploadResultsBox.getState();
if (importing) {
singleTaxaBlock = singleTaxaBlockBox.getState();
showBirdsEye = showBirdsEyeBox.getState();
}
}
storePreferences(); // do this here even if Cancel pressed as the File Locations subdialog box might have been used
nameParserTextCanvas = null;
sequenceNameTaskTextCanvas = null;
primerInfoTaskTextCanvas = null;
dialog.dispose();
return success;
}
/*.................................................................................................................*/
boolean makeDirectoriesForFragment(String fragmentDirPath){
File newDir = new File(fragmentDirPath);
try { newDir.mkdir(); //make folder for this gene
processedFastaDirectory = fragmentDirPath + MesquiteFile.fileSeparator + ChromaseqUtil.processedFastaFolder;
newDir = new File(processedFastaDirectory);
newDir.mkdir(); //make processed fastaFolder
String sequencesDirectory = fragmentDirPath + MesquiteFile.fileSeparator + sequencesFolder;
newDir = new File(sequencesDirectory);
newDir.mkdir(); //make sequences folder for holding all of the sequences and files produces by phred and phrap
}
catch (SecurityException e) {
logln("Couldn't make directory.");
return false;
}
return true;
}
/*.................................................................................................................*/
String getPhredCommand(){
if (MesquiteTrunk.isWindows())
return StringUtil.protectFilePathForWindows(phredPath + "phred.exe");
else
return StringUtil.protectFilePathForUnix(phredPath + "phred");
}
/*.................................................................................................................*/
String getPhrapCommand(){
if (MesquiteTrunk.isWindows())
return StringUtil.protectFilePathForWindows(phredPath + "phrap.exe");
else
return StringUtil.protectFilePathForUnix(phredPath + "phrap");
}
/*.................................................................................................................*/
String getPhd2FastaCommand(){
if (MesquiteTrunk.isWindows())
return StringUtil.protectFilePathForWindows(phredPath + "phd2fasta.exe");
else
return StringUtil.protectFilePathForUnix(phredPath + "phd2fasta");
}
int sequenceCount = 0;
String importedDirectoryPath, importedDirectoryName;
public boolean prepareAndRunPhredPhrap(MesquiteProject project, boolean appendIfPossible){
return prepareAndRunPhredPhrap(project, appendIfPossible, null);
}
/*.................................................................................................................*/
public boolean queryForPaths(MesquiteBoolean pleaseStorePrefs) {
if (!preferencesSet || StringUtil.blank(phredPath)) {
phredPath = MesquiteFile.chooseDirectory("Choose directory containing phred, phrap, and phd2fasta: ");
if (StringUtil.blank(phredPath))
return false;
if (!phredPath.endsWith(MesquiteFile.fileSeparator))
phredPath+=MesquiteFile.fileSeparator;
if (pleaseStorePrefs!=null)
pleaseStorePrefs.setValue(true);
}
if (!preferencesSet || StringUtil.blank(phredParamPath)) {
MesquiteString paramDir = new MesquiteString();
MesquiteString paramFile = new MesquiteString();
phredParamPath = MesquiteFile.openFileDialog("Choose phred parameter file: ", paramDir, paramFile);
if (StringUtil.blank(phredParamPath))
return false;
if (pleaseStorePrefs!=null)
pleaseStorePrefs.setValue(true);
}
return true;
}
/*.................................................................................................................*/
public void prepareShellScriptForDirectory(StringBuffer shellScript, StringBuffer postShellScript, String statusFilePath, String phphLogFilePath, String fragmentDirPath, String seqFileName, String fullSeqName, String directoryPath){
shellScript.append(ShellScriptUtil.getChangeDirectoryCommand(directoryPath));
if (runPhredPhrap)
shellScript.append(ShellScriptUtil.getAppendStringAsFile(phphLogFilePath, "" + sequenceCount + ". " + fullSeqName + " (directory changed)"));
shellScript.append(getPhredCommand() + " -V -log -id . -pd . -d " + StringUtil.blankIfNull(phredOptions) + " "+ StringUtil.lineEnding());
if (runPhredPhrap) {
shellScript.append(ShellScriptUtil.getWriteStringAsFile(statusFilePath, "" + sequenceCount + ". " + fullSeqName + " (Phred)"));
shellScript.append(ShellScriptUtil.getAppendStringAsFile(phphLogFilePath, "" + sequenceCount + ". " + fullSeqName + " (Phred completed)"));
}
shellScript.append(getPhd2FastaCommand() + " -id . -os '" + seqFileName + "' -oq '" + seqFileName + ".qual'"+ StringUtil.lineEnding());
if (runPhredPhrap) {
shellScript.append(ShellScriptUtil.getWriteStringAsFile(statusFilePath, "" + sequenceCount + ". " + fullSeqName + " (Phd2Fasta)"));
shellScript.append(ShellScriptUtil.getAppendStringAsFile(phphLogFilePath, "" + sequenceCount + ". " + fullSeqName + " (Phd2Fasta completed)"));
}
shellScript.append(getPhrapCommand() + " '" + seqFileName + "' -screen -new_ace " + StringUtil.blankIfNull(phrapOptions) + " "+ StringUtil.lineEnding());
if (runPhredPhrap) {
shellScript.append(ShellScriptUtil.getWriteStringAsFile(statusFilePath, "" + sequenceCount + ". " + fullSeqName + " (Phrap)"));
shellScript.append(ShellScriptUtil.getAppendStringAsFile(phphLogFilePath, "" + sequenceCount + ". " + fullSeqName + " (Phrap completed)"));
}
shellScript.append(ShellScriptUtil.getSetFileTypeCommand(directoryPath + MesquiteFile.fileSeparator + "" + seqFileName + ".ace"));
//postShellScript.append(getSetFileTypeCommand(sequenceDirPath + MesquiteFile.fileSeparator + "" + seqName + processedACESuffix + ".ace"));
}
/*.................................................................................................................*/
private void assignStLouisString(MesquiteString stLouisString, boolean isForward) {
if (isForward)
stLouisString.setValue("b.");
else
stLouisString.setValue("g.");
}
/*.................................................................................................................*/
/** returns the next token in a string AFTER a particular substring; returns empty string if substring not present*/
public static String getNextTokenAfterSubStringIgnoreCase(String line, String subString) {
if (line==null)
return null;
else if (line.equals(""))
return "";
int loc=line.toLowerCase().indexOf(subString.toLowerCase());
if (loc<0)
return "";
loc += subString.length();
Parser parser = new Parser(line);
parser.setPosition(loc);
String token = parser.getNextToken();
return token;
}
/*.................................................................................................................*/
public String getAnalysisParameters() {
StringBuffer sb = new StringBuffer();
sb.append("Phred Options: " + " -id . -pd . -d " + StringUtil.blankIfNull(phredOptions) + "\n");
sb.append("Phrap Options: " + " -new_ace " + StringUtil.blankIfNull(phrapOptions) + "\n");
sb.append("Chromaseq Options: \n");
sb.append(" Quality threshold for lower case: " + qualThresholdForLowerCase + "\n");
sb.append(" Convert multiple-peaks sites to ambiguity codes: " + processPolymorphisms + "\n");
sb.append(" Minimum secondary peak fraction for ambiguity: " + polyThreshold + "\n");
sb.append(" Trim low quality regions from ends: " + truncateMixedEnds + "\n");
sb.append(" Quality threshold for trim: " + qualThresholdForTrim + "\n");
sb.append(" Trim window length: " + mixedEndWindow + "\n");
sb.append(" Trim window threshold: " + mixedEndThreshold + "\n");
return sb.toString();
}
int sectionNumber=1;
/*.................................................................................................................*/
// starting the run
public boolean startExecution(String scriptPath, String runningFilePath){ //do we assume these are disconnectable?
if (scriptBased) {
scriptRunner = new ShellScriptRunner(scriptPath, runningFilePath, null, false, "Phred and Phrap", null, this, this, true); //scriptPath, runningFilePath, null, true, name, outputFilePaths, outputFileProcessor, watcher, true
return scriptRunner.executeInShell();
} else {
return executeProgramsInScriptFile(scriptPath);
}
/*Process proc = ShellScriptUtil.executeScript(scriptPath, true);
if (proc==null) {
if (progIndicator!=null) progIndicator.goAway();
return false;
}
return true;
*/
}
/*.................................................................................................................*/
// not fully implemented; not currently used. Will require Java 8
public boolean executeProgramsInScriptFile(String scriptPath){
String contents = MesquiteFile.getFileContentsAsString(scriptPath);
Parser parser = new Parser(contents);
String line = parser.getRawNextDarkLine();
Parser subParser = new Parser();
boolean overallSuccess = true;
while (StringUtil.notEmpty(line) && overallSuccess) {
subParser.setString(line);
String programCommand = subParser.getFirstItem(line, "\t");
String options = subParser.getRemaining();
//externalRunner = new ExternalProcessManager(this, rootDir, getPhredCommand(), arguments, getExecutableName(), outputFilePaths, this, this, false);
boolean success = externalRunner.executeInShell();
if (!success)
overallSuccess = false;
line = parser.getRawNextDarkLine();
}
return overallSuccess;
}
/*.................................................................................................................*/
public boolean prepareAndRunPhredPhrap(MesquiteProject project, boolean appendIfPossible, String directoryPath){
MesquiteBoolean pleaseStorePrefs = new MesquiteBoolean(false);
if (!queryForPaths(pleaseStorePrefs))
return false;
if (pleaseStorePrefs.getValue())
storePreferences();
// ============ getting primer info ===========
// PrimerList primers = getPrimers();
// if not passed-in, then ask
if (StringUtil.blank(directoryPath)) {
directoryPath = MesquiteFile.chooseDirectory("Choose directory containing ABI files:", previousDirectory); //MesquiteFile.saveFileAsDialog("Base name for files (files will be named 1.nex, 2.nex, etc.)", baseName);
}
if (StringUtil.blank(directoryPath))
return false;
File directory = new File(directoryPath);
importedDirectoryPath = directoryPath + MesquiteFile.fileSeparator;
importedDirectoryName = directory.getName();
previousDirectory = directory.getParent();
storePreferences();
if (directory.exists() && directory.isDirectory()) {
logBuffer.setLength(0);
progIndicator = new ProgressIndicator(getProject(),"Preparing for Phred/Phrap");
progIndicator.setStopButtonName("Stop");
progIndicator.start();
boolean abort = false;
/* Thread mt = Thread.currentThread();
boolean piMine = false;
if (mt instanceof MesquiteThread)
progIndicator = ((MesquiteThread)mt).getProgressIndicator();
if (progIndicator ==null) {
progIndicator = new ProgressIndicator(getProject(),"Running Phred & Phrap", 0);
piMine = true;
if (mt instanceof MesquiteThread)
((MesquiteThread)mt).setProgressIndicator(progIndicator);
}
progIndicator.setButtonMode(ProgressIndicator.FLAG_AND_HIDE);
progIndicator.start();
boolean abort = false;
*/
String cPath;
String seqFileName;
String fullSeqName;
String fragName = "";
StringBuffer shellScript = new StringBuffer(6000);
StringBuffer postShellScript = new StringBuffer(6000);
sequenceCount = 0;
if (MesquiteTrunk.isWindows()) {
shellScript.append("set PHRED_PARAMETER_FILE="+phredParamPath+ StringUtil.lineEnding());
} else {
// shellScript.append("setenv PHRED_PARAMETER_FILE "+StringUtil.protectForUnix(phredParamPath)+"\n");
shellScript.append("#!/bin/csh -v\nsetenv PHRED_PARAMETER_FILE "+StringUtil.protectFilePathForUnix(phredParamPath)+StringUtil.lineEnding());
}
// shellScript.append(getAliasCommand ("phred", phredPath + "phred"));
// shellScript.append(getAliasCommand ("phd2fasta",phredPath+"phd2fasta"));
// shellScript.append(getAliasCommand ("phrap",phredPath+"phrap"));
//set path = ( $path /usr/bin /usr/sbin /phredPhrap/ph/)
int loc = 0;
String[] files = directory.list();
StringBuffer renameBuffer = new StringBuffer(1000);
String processedDirPath = directoryPath + MesquiteFile.fileSeparator + processedFolder; // directory into which processed files go
String originalsDirPath = directoryPath + MesquiteFile.fileSeparator + originalFolder; // directory for copies of original files
loglnEchoToStringBuffer("\nPhred Phrap processing of chromatograms as scripted by Mesquite", logBuffer);
loglnEchoToStringBuffer(StringUtil.getDateTime(), logBuffer);
loglnEchoToStringBuffer(StringUtil.lineEnding()+"Mesquite "+ MesquiteTrunk.getMesquiteVersion() + MesquiteTrunk.getBuildVersion(), logBuffer);
loglnEchoToStringBuffer("Chromaseq "+ getVersion() + " (build " + getBuildNumberOfPackage()+")", logBuffer);
loglnEchoToStringBuffer(StringUtil.lineEnding()+" Processing directory: ", logBuffer);
loglnEchoToStringBuffer(" "+directoryPath+"\n", logBuffer);
if (sequenceNameTask!=null)
sequenceNameTask.echoParametersToFile(logBuffer);
if (primerInfoTask!=null)
primerInfoTask.echoParametersToFile(logBuffer);
loglnEchoToStringBuffer("Parameters: " + getAnalysisParameters()+"\n", logBuffer);
String rootDir = processedDirPath;
String fragmentDirPath = "";
File newDir;
int numPrepared = 0;
shellScript.append(ShellScriptUtil.getChangeDirectoryCommand(rootDir));
shellScript.append(getPhredCommand() + " -V -log"+StringUtil.lineEnding());
//shellScript.append("("+getPhrapCommand() + ") >& phrapFileToDetermineVersion\n");
shellScript.append(getPhrapCommand() + " > "+VERSION_FILE+StringUtil.lineEnding());
newDir = new File(processedDirPath);
try {
newDir.mkdir();
if (backupOriginals) {
newDir = new File(originalsDirPath);
newDir.mkdir();
}
}
catch (SecurityException e) {
logln("Couldn't make directory.");
if (progIndicator!=null) progIndicator.goAway();
return false;
}
String runningFilePath = rootDir + MesquiteFile.fileSeparator + "running";
String contigPropertiesFilePath = rootDir + MesquiteFile.fileSeparator + "contigProperties.txt";
String statusFilePath = rootDir + MesquiteFile.fileSeparator + "status";
String phphLogFilePath = rootDir + MesquiteFile.fileSeparator + "phPhPh.log";
String phredLogFilePath = rootDir + MesquiteFile.fileSeparator + "phred.log";
String phrapStdErrFilePath = rootDir + MesquiteFile.fileSeparator + VERSION_FILE;
if (runPhredPhrap)
MesquiteFile.putFileContents(runningFilePath, "Phred Phrap are running...", true);
fileNameTranslation= new String[5][files.length];
Vector infoFiles = new Vector();
loglnEchoToStringBuffer("---------------------------------------------------", logBuffer);
loglnEchoToStringBuffer("Section " +(sectionNumber++) + ": Examining chromatogram files and preparing directories ", logBuffer);
loglnEchoToStringBuffer("", logBuffer);
for (int i=0; i0)
oldExtension = "."+ StringUtil.getLastItem(chromFileName, ".");
String extension = fileExtension;
if (StringUtil.blank(extension))
extension=oldExtension;
if (backupOriginals) {
try {
String pathInOriginalFolder = originalsDirPath + MesquiteFile.fileSeparator + chromFileName; // path to where original will be stored
File originalFile = new File(pathInOriginalFolder); //
MesquiteFile.copy(cFile, originalFile);
}
catch (IOException e) {
logln( "Can't copy: " + seqFileName);
}
}
//now move and rename the original to this sequence's directory
//writeInfoFile(infoFilePath, fullSeqName);
try {
String newFileName = startTokenResult + sampleCode.getValue()+"." + stLouisString.getValue()+primerName+extension;
String newFilePath = sequenceDirPath + MesquiteFile.fileSeparator + newFileName;
File newFile = new File(newFilePath); //
int count=1;
while (newFile.exists()) {
newFileName = startTokenResult + sampleCode.getValue()+"_"+count + "." + stLouisString.getValue()+primerName+extension;
newFilePath = sequenceDirPath + MesquiteFile.fileSeparator + newFileName;
newFile = new File(newFilePath);
count++;
}
if (verbose)
renameBuffer.append(" " + chromFileName + " renamed to " + newFileName + "\n");
fileNameTranslation[0][i] = newFileName;
fileNameTranslation[1][i] = chromFileName;
fileNameTranslation[2][i] = primerName.toString();
fileNameTranslation[3][i] = startTokenResult.getValue();
fileNameTranslation[4][i] = sampleCode.getValue();
ChromaseqInfoFile infoFile = ChromaseqInfoFile.getInfoFile(infoFiles,sequenceDirPath);
if (infoFile!=null)
infoFile.addChromatogramInfo(chromFileName, newFileName, primerName.toString());
cFile.renameTo(newFile);
}
catch (SecurityException e) {
logln( "Can't rename: " + seqFileName);
}
}
catch (SecurityException e) {
logln( "Can't make directory: " + seqFileName);
}
}
}
}
}
if (infoFiles!=null){
loglnEchoToStringBuffer("Writing info.xml files...", logBuffer);
ChromaseqInfoFile.writeInfoFiles(infoFiles, progIndicator);
ChromaseqInfoFile.dispose(infoFiles);
}
loglnEchoToStringBuffer("", logBuffer);
loglnEchoToStringBuffer("Number of files prepared: " + numPrepared, logBuffer);
loglnEchoToStringBuffer("", logBuffer);
loglnEchoToStringBuffer("---------------------------------------------------", logBuffer);
loglnEchoToStringBuffer("Section " +(sectionNumber++) + ": Renaming chromatograms for Phred and Phrap", logBuffer);
if (verbose)
loglnEchoToStringBuffer("\n" + renameBuffer.toString()+"\n", logBuffer);
if (!abort) {
if (runPhredPhrap) {
shellScript.append(ShellScriptUtil.getRemoveCommand(runningFilePath));
shellScript.append(ShellScriptUtil.getRemoveCommand(statusFilePath));
}
progIndicator.spin();
if (shellScript.length()>0){
//note name of file should end in .command for Terminal in OS X to run it; on other OS's we may be able to get the script to run directly from Runtime.exec
String scriptPath = rootDir + MesquiteFile.fileSeparator + "ppscript.bat";
MesquiteFile.putFileContents(scriptPath, shellScript.toString(), true);
if (runPhredPhrap) {
try {
//String scriptPath = StringUtil.protectForUnix(rootDir + MesquiteFile.fileSeparator + "ppscript.command");
ShellScriptUtil.setScriptFileToBeExecutable(scriptPath);
//logln("Request to change permissions of file \"ppscript.bat\" given");
if (!startExecution(scriptPath, runningFilePath))
return false;
//Process proc = ShellScriptUtil.executeScript(scriptPath);
//if (proc==null) {
// if (progIndicator!=null) progIndicator.goAway();
// return false;
//}
if (progIndicator!=null)
progIndicator.setTitle("Running Phred & Phrap");
loglnEchoToStringBuffer("", logBuffer);
loglnEchoToStringBuffer("---------------------------------------------------", logBuffer);
loglnEchoToStringBuffer("Section " +(sectionNumber++) + ": Execution of Phred-Phrap command file begun", logBuffer);
/*On OS X at this point the script operates asyncronously, so if we wanted to immediately go into the post processing we'd have to listen for some file showing up or such
When runtime.exec runs the script directly, proc.waitFor() can be used to force this thread to hang until the script finishes*/
/* the following does nothing on OS X, but will be useful on other OS's if previous statement executes script directly so as to show processing in log window
InputStream stream = proc.getInputStream();
int c = 0;
while ((c=stream.read())!=-1){
log("" + (char)c);
}
/**/
}
catch (IOException e){
logln("IOE error: " + e);
abort =true;
}
}
}
}
boolean findPhredVersion = true;
String phredVersion = null;
boolean findPhrapVersion = true;
String phrapVersion = null;
if (runPhredPhrap && !abort) {
try {
String oldStatus = "";
int equalStatusCount = 0;
int count=-3;
logln("");
//if (progIndicator!=null) progIndicator.setTotalValue(sequenceCount);
while (MesquiteFile.fileExists(runningFilePath) && !abort){
if (findPhredVersion && MesquiteFile.fileExists(phredLogFilePath)) { // get phredVersion
String phredLog = MesquiteFile.getFileContentsAsString(phredLogFilePath);
phredVersion = getNextTokenAfterSubStringIgnoreCase(phredLog, "PHRED version");
findPhredVersion = false;
}
if (findPhrapVersion && MesquiteFile.fileExists(phrapStdErrFilePath)) { // get phredVersion
String phrapStdErr = MesquiteFile.getFileContentsAsString(phrapStdErrFilePath);
phrapVersion = getNextTokenAfterSubStringIgnoreCase(phrapStdErr, "phrap version");
findPhrapVersion = false;
}
String status = "";
if (MesquiteFile.fileExists(statusFilePath)) {
status = MesquiteFile.getFileContentsAsString(statusFilePath);
}
if (!StringUtil.blank(status)) {
if (progIndicator!=null) {
if (progIndicator.getTotalValue()==0) {
progIndicator.setTotalValue(sequenceCount);
//progIndicator.repaintBar();
}
progIndicator.setText(status);
String s = StringUtil.getFirstItem(status,".");
int num = MesquiteInteger.fromString(s);
progIndicator.setCurrentValue(num);
}
if (status.equalsIgnoreCase(oldStatus))
equalStatusCount++;
else {
equalStatusCount = 0;
log(status);
}
if (equalStatusCount>25) {
logln("There may be a problem: Phred and Phrap do not seem to be actively analyzing files.");
if (equalStatusCount>35)
abort=true;
}
oldStatus = status;
}
else {
log(".");
if (progIndicator!=null) progIndicator.spin();
}
count = 1;
//}
if (progIndicator.isAborted())
abort = true;
Thread.sleep(200);
count++;
}
logln("");
if (abort)
loglnEchoToStringBuffer("Mesquite processing stopped.", logBuffer);
else
loglnEchoToStringBuffer("Phred & Phrap analyses completed.", logBuffer);
}
catch (InterruptedException e){
Thread.currentThread().interrupt();
}
//PostPhrap pPhrap = (PostPhrap)hireEmployee(PostPhrap.class, "Post Phrap Processing");
if (!abort) {
loglnEchoToStringBuffer("", logBuffer);
loglnEchoToStringBuffer("---------------------------------------------------", logBuffer);
loglnEchoToStringBuffer("Section " +(sectionNumber++) + ": Mesquite processing of Phrap results", logBuffer);
contigPropertiesFileBuffer = new StringBuffer();
postPhrapOnDirectory( project,appendIfPossible, rootDir);
MesquiteFile.putFileContents(contigPropertiesFilePath, contigPropertiesFileBuffer.toString(), true);
}
}
if (progIndicator!=null)
progIndicator.goAway();
loglnEchoToStringBuffer(StringUtil.getDateTime(), logBuffer);
logBuffer.append("Mesquite version: " + MesquiteTrunk.mesquiteTrunk.getVersion()+", build number " + MesquiteTrunk.mesquiteTrunk.getBuildNumber()+"\n");
loglnEchoToStringBuffer("Chromaseq version: " + getVersion(), logBuffer);
if (StringUtil.notEmpty(phredVersion))
loglnEchoToStringBuffer("Phred version: " + phredVersion, logBuffer);
if (StringUtil.notEmpty(phrapVersion))
loglnEchoToStringBuffer("Phrap version: " + phrapVersion, logBuffer);
loglnEchoToStringBuffer("", logBuffer);
loglnEchoToStringBuffer("========================", logBuffer);
loglnEchoToStringBuffer("", logBuffer);
MesquiteFile.putFileContents(rootDir + MesquiteFile.fileSeparator + "phredPhrapLog.txt", logBuffer.toString(), true);
MesquiteFile.deleteFile(phredLogFilePath);
if (project != null) {
//project.getCoordinatorModule().saveFile(project.getHomeFile());
if (originalData != null)
originalData.setDirty(true); //so that user will prompted; seems to be needed for annotations to be saved
}
}
return true;
}
/*.................................................................................................................*/
private void addWindowsHeaderOLD(StringBuffer shellScript) {
// TODO: Issues with new-ish Windows/Cygwin. Oliver.July.30.2015
// original implementation has these two lines
shellScript.append("REGEDIT /E %Temp%.\\tmp-cygwin.reg \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2\\/\"> nul"+ StringUtil.lineEnding());
shellScript.append("FOR /F \"tokens=1* delims==\" %%A IN ('TYPE %Temp%.\\tmp-cygwin.reg ^| FIND \"native\"') DO SET CYGWIN_ROOT=%%B> nul"+ StringUtil.lineEnding());
// For newer (?) installations of Cygwin, replace those two lines ^^ with these two lines vv
// shellScript.append("REGEDIT /E %Temp%.\\tmp-cygwin.reg \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygwin\\setup\"> nul\n");
// shellScript.append("FOR /F \"tokens=1* delims==\" %%A IN ('TYPE %Temp%.\\tmp-cygwin.reg ^| FIND \"rootdir\"') DO SET CYGWIN_ROOT=%%B> nul\n");
// An alternative approach would be to shift the entire burden to the Windows user,
// Asking where cygwin is installed; it is often in the root, C:\cygwin64
shellScript.append("SET CYGWIN_ROOT=%CYGWIN_ROOT:\"=%> nul"+ StringUtil.lineEnding());
shellScript.append("if exist %Temp%.\\tmp-cygwin.reg del %Temp%.\\tmp-cygwin.reg"+ StringUtil.lineEnding());
shellScript.append("SET PATH=.;%CYGWIN_ROOT%\\bin;%CYGWIN_ROOT%\\opt\\elinos\\bin;%PATH%"+ StringUtil.lineEnding());
shellScript.append("set PHRED_PARAMETER_FILE="+phredParamPath+ StringUtil.lineEnding());
}
int aceFileCount = 0;
boolean processFolderAborted = false;
Vector goodNews = new Vector();
Vector badNews = new Vector();
/*.................................................................................................................*/
public void writeInfoFile(String infoFilePath, String fullName){
StringBuffer infoFileBuffer = new StringBuffer();
infoFileBuffer.append(fullName); //here write the XML info file
MesquiteFile.putFileContents(infoFilePath, infoFileBuffer.toString(), true);
}
StringBuffer contigPropertiesFileBuffer;
/*.................................................................................................................*/
public void processAceFileWithContig(MesquiteProject project, String processedAceFilePath, String fragmentDirPath, AceFile ace, SequenceUploader uploader, String geneName, MesquiteString fullName, String baseName, MesquiteString voucherCode) {
ace.setNameTranslation(fileNameTranslation);
log(ace.contigListForLog()+StringUtil.lineEnding());
if (processPolymorphisms)
ace.processPolys(); //creates an additional CO that has polys in it
if (renameContigsInAceFiles)
ace.renameContigs(fullName.toString(), addFragName, geneName);
ace.setLowQualityToLowerCase(qualThresholdForLowerCase);
ace.writeToPropertiesFile(contigPropertiesFileBuffer, fullName.toString());
if (truncateMixedEnds)
ace.trimMixedEnds(mixedEndThreshold, mixedEndWindow, qualThresholdForTrim, addPhrapFailures);
if (uploadResultsToDatabase && uploader!=null && databaseURLSource!=null) {
// note: this should really be abstracted, and become a job for a module to do; we shouldn't see the raw reference to getTOLPageDatabaseURL in here
uploader.uploadAceFileToServer(MesquiteXMLToLUtilities.getTOLPageDatabaseURL(databaseURLSource.getBaseURL()), ace, processPolymorphisms, qualThresholdForTrim);
}
System.out.println("\n\nfasta file name: " + baseName + " ace file: " + ace);
MesquiteFile.putFileContents(fragmentDirPath + MesquiteFile.fileSeparator + ChromaseqUtil.processedFastaFolder + MesquiteFile.fileSeparator + baseName+".fas", ace.toFASTAString(processPolymorphisms, qualThresholdForTrim), true);
MesquiteFile.putFileContents(processedAceFilePath, ace.toString(processPolymorphisms), true);
if (project != null) {
ace.importSequence(taxa, data, MesquiteInteger.unassigned, originalData, qualityData, registrationData, singleTaxaBlock, processPolymorphisms, maxChar," contig ", false, voucherCode);
}
}
/*.................................................................................................................*/
public void processAceFileWithoutContig(String processedAceFilePath, AceFile ace, String geneName, MesquiteString fullName, MesquiteString voucherCode) {
ace.processFailedContig(polyThreshold);
ace.setNameTranslation(fileNameTranslation);
if (renameContigsInAceFiles)
ace.renameContigs(fullName.toString(), addFragName, geneName);
ace.setLowQualityToLowerCase(qualThresholdForLowerCase);
ace.writeToPropertiesFile(contigPropertiesFileBuffer, fullName.toString());
if (truncateMixedEnds)
ace.trimMixedEnds(mixedEndThreshold, mixedEndWindow, qualThresholdForTrim, addPhrapFailures);
MesquiteFile.putFileContents(processedAceFilePath, ace.toString(processPolymorphisms), true);
ace.importSequence(taxa, data, MesquiteInteger.unassigned, originalData, qualityData, registrationData, singleTaxaBlock, processPolymorphisms, maxChar,"", true, voucherCode);
}
/*.................................................................................................................*/
public boolean processAceFileDirectory(MesquiteProject project, boolean appendIfPossible, File directory, String directoryPath, String enclosingDirName, String geneName, String dataFilePath, int level){
boolean addingPhrapFailures = false;
String[] files = directory.list();
String processedAceFilePath = null;
AceFile ace = null;
int currentRead = -1;
if (uploadResultsToDatabase)
checkDatabaseSource();
SequenceUploader uploader = new SequenceUploader(databaseURLSource);
MesquiteString fullName = null;
MesquiteString voucherCode = new MesquiteString();
for (int i=0; i=1) {
processAceFileWithContig(project, processedAceFilePath, fragmentDirPath, ace, uploader, geneName, fullName, baseName, voucherCode);
}
else {
loglnEchoToStringBuffer(" ACE file contains no contigs!", logBuffer);
badNews.addElement(" (" + geneName + ") -- " + baseName);
if (addPhrapFailures && project !=null) {
addingPhrapFailures = true;
i=-1;
ace.createEmptyContigs(MesquiteFile.numFilesEndingWith(directoryPath,files,".phd.1")); //create an empty contig
if (renameContigsInAceFiles)
ace.renameContigs(fullName.toString(), addFragName, geneName);
}
}
if (!addingPhrapFailures)
ace.dispose();
}
else if (files[i].endsWith(".phd.1") && addingPhrapFailures) {
loglnEchoToStringBuffer(" Importing single-read Phred file "+files[i], logBuffer);
currentRead++;
ace.addPhdFileAsSingleReadInContig(currentRead, directoryPath, files[i], processPolymorphisms, polyThreshold);
}
}
}
}
}
if (addingPhrapFailures && ace !=null ) { // have to process AceFile that we have manually made
MesquiteFile.putFileContents(processedAceFilePath, ace.toString(processPolymorphisms), true);
if (project != null){
processAceFileWithoutContig( processedAceFilePath, ace, geneName, fullName, voucherCode);
}
ace.dispose();
}
return false;
}
/*.................................................................................................................*/
public boolean processFolderAfterPhrap(MesquiteProject project, boolean appendIfPossible, File directory, String directoryPath, String enclosingDirName, String geneName, String dataFilePath, int level, MesquiteInteger numAceFiles){
boolean addingPhrapFailures = false;
if (processFolderAborted)
return false;
String[] files = directory.list();
String sequenceName = geneName;
String originalDataFilePath = dataFilePath;
if (project!=null){
originalDataFilePath= project.getHomeFile().getPath();
originalDataFilePath=MesquiteFile.getDirectoryPathFromFilePath(originalDataFilePath);
}
boolean rename = false;
if (level == 1)
sequenceName = directory.getName();
if (level == 1 && project!=null) {
project.virginProject=false;
taxa = null; //making sure nothing old is remembered accidentally
//getting ready to import; making matrices to be filled
if (appendIfPossible && project != null){
data = (DNAData)project.getCharacterMatrixByReference(null, directory.getName() + " (from Phred/Phrap)");
originalData = (DNAData)project.getCharacterMatrixByReference(null, directory.getName() + " (ORIGINAL from Phred/Phrap)");
qualityData = (ContinuousData)project.getCharacterMatrixByReference(null, "Quality Scores for " + directory.getName() + " from Phred/Phrap");
// addedBaseData = (CategoricalData)project.getCharacterMatrixByReference(null, "Bases added for " + directory.getName() + " from Phred/Phrap");
registrationData = (MeristicData)project.getCharacterMatrixByReference(null, "Registration of " + directory.getName() + " from Phred/Phrap");//DAVID: if change name here have to change elsewhere
if (data !=null && (qualityData==null || originalData==null || registrationData==null)){
//discreetAlert("Cannot append chromatogram information to the matrix \"" + data.getName() + "\" that does not contain Chromaseq data");
data = null;
rename = true;
}
if (originalData != null)
originalData.saveChangeHistory = false;
if (qualityData != null)
qualityData.saveChangeHistory = false;
// if (addedBaseData != null)
// addedBaseData.saveChangeHistory = false;
if (data != null){
taxa = data.getTaxa();
data.saveChangeHistory = false;
}
}
if (taxa == null){
if (singleTaxaBlock) {
if (project.getNumberTaxas()>0)
taxa = project.getTaxa(0);
if (taxa == null) {
taxa = project.createTaxaBlock(0);
taxa.setName("Sequences");
}
}
else {
taxa = project.createTaxaBlock(0);
String taxaBlockName = directory.getName() + " Sequences";
if (rename) {
ListableVector taxas = getProject().getTaxas();
taxaBlockName = taxas.getUniqueName(taxaBlockName);
}
taxa.setName(taxaBlockName);
}
}
CharactersManager manageCharacters = (CharactersManager)coord.findElementManager(mesquite.lib.characters.CharacterData.class);
MesquiteString uid = new MesquiteString(ChromaseqUtil.PHPHIMPORTIDREF, MesquiteTrunk.getUniqueIDBase());
MesquiteString gN = new MesquiteString(ChromaseqUtil.GENENAMEREF, directory.getName());
if (data == null){
data = (DNAData)manageCharacters.newCharacterData(taxa, 0, DNAData.DATATYPENAME); //
data.saveChangeHistory = false;
data.addToFile(file, project, manageCharacters);
String matrixName = directory.getName() + " (from Phred/Phrap)";
if (rename) {
ListableVector datas = getProject().getCharacterMatrices();
matrixName = datas.getUniqueName(matrixName);
}
data.setName(matrixName);
ChromaseqUtil.attachStringToMatrix(data,uid);
ChromaseqUtil.attachStringToMatrix(data,gN);
ChromaseqUtil.attachStringToMatrix(data,new MesquiteString(ChromaseqUtil.PHPHMQVERSIONREF, ChromaseqUtil.PHPHMQVERSION));
ChromaseqUtil.attachStringToMatrix(data,new MesquiteString(ChromaseqUtil.PHPHIMPORTMATRIXTYPEREF, ChromaseqUtil.EDITEDREF));
}
if (originalData == null){
originalData = (DNAData)manageCharacters.newCharacterData(taxa, 0, DNAData.DATATYPENAME); //
originalData.saveChangeHistory = false;
originalData.incrementEditInhibition();
originalData.setUserVisible(ChromaseqUtil.isChromaseqDevelopment());
originalData.addToFile(file, project, manageCharacters);
originalData.setName(directory.getName() + " (ORIGINAL from Phred/Phrap)");
//data.addToLinkageGroup(originalData); //link matrices! //DAVID: uncomment this to reverse new registration system
originalData.setResourcePanelIsOpen(false);
ChromaseqUtil.attachStringToMatrix(originalData,uid);
ChromaseqUtil.attachStringToMatrix(originalData,gN);
ChromaseqUtil.attachStringToMatrix(originalData,new MesquiteString(ChromaseqUtil.PHPHIMPORTMATRIXTYPEREF, ChromaseqUtil.ORIGINALREF));
originalData.incrementEditInhibition();
}
if (qualityData == null){
qualityData = (ContinuousData)manageCharacters.newCharacterData(taxa, 0, ContinuousData.DATATYPENAME); //
qualityData.saveChangeHistory = false;
qualityData.addToFile(file, project, manageCharacters);
//data.addToLinkageGroup(qualityData); //link matrices! //DAVID: uncomment this to reverse new registration system
qualityData.setName("Quality Scores for " + directory.getName() + " from Phred/Phrap");
qualityData.setResourcePanelIsOpen(false);
qualityData.setUserVisible(ChromaseqUtil.isChromaseqDevelopment());
ChromaseqUtil.attachStringToMatrix(qualityData,uid);
ChromaseqUtil.attachStringToMatrix(qualityData,gN);
ChromaseqUtil.attachStringToMatrix(qualityData,new MesquiteString(ChromaseqUtil.PHPHIMPORTMATRIXTYPEREF, ChromaseqUtil.QUALITYREF));
qualityData.incrementEditInhibition();
qualityData.setUseDiagonalCharacterNames(false);
}
/* if (addedBaseData == null){
addedBaseData = (CategoricalData)manageCharacters.newCharacterData(taxa, 0, CategoricalData.DATATYPENAME); //
addedBaseData.addToFile(file, project, manageCharacters);
addedBaseData.setUserVisible(ChromaseqUtil.isChromaseqDevelopment());
// ChromaseqUtil.setAddedBaseDataValues(addedBaseData, data, directory.getName(), uid, gN);
}
*/ if (registrationData == null){
registrationData = (MeristicData)manageCharacters.newCharacterData(taxa, 0, MeristicData.DATATYPENAME); //
registrationData.setUserVisible(ChromaseqUtil.isChromaseqDevelopment());
registrationData.addToFile(file, project, manageCharacters);
ChromaseqUtil.setRegistryDataValues(registrationData, data, directory.getName() , uid, gN);
}
ChromaseqUtil.setChromaseqRegistrationBuildOfMatrix(data,ChromaseqUtil.ChromaseqRegistrationBuild);
if (appendIfPossible && project != null)
maxChar.setValue(data.getNumChars()); // DRM 8.Nov.2013 Added this to fix the bug whereby existing data could be truncated.
else
maxChar.setValue(0);
//qualityData.attachIf UniqueName(new MesquiteString(ChromaseqUtil.PHPHIMPORTMATRIXTYPEREF, "quality")); use method in ChromaseqUtil instead
}
String processedAceFilePath = null;
AceFile ace = null;
int currentRead = -1;
if (uploadResultsToDatabase)
checkDatabaseSource();
SequenceUploader uploader = new SequenceUploader(databaseURLSource);
MesquiteString fullName = null;
MesquiteString voucherCode = null;
for (int i=0; i=1) {
processAceFileWithContig(project, processedAceFilePath, fragmentDirPath, ace, uploader, geneName, fullName, baseName, voucherCode);
goodNews.addElement(" (" + geneName + ") -- " + fullName);
}
else {
loglnEchoToStringBuffer(" ACE file contains no contigs!", logBuffer);
badNews.addElement(" (" + geneName + ") -- " + baseName);
if (addPhrapFailures && project !=null) {
addingPhrapFailures = true;
i=-1; // 24 Feb 2O18: set to -1 as wasn't getting first file in directory if set to 0 as loop was setting it then to 1
ace.createEmptyContigs(MesquiteFile.numFilesEndingWith(directoryPath,files,".phd.1")); //create an empty contig
if (renameContigsInAceFiles)
ace.renameContigs(fullName.toString(), addFragName, geneName);
}
}
if (!addingPhrapFailures)
ace.dispose();
}
else if (files[i].endsWith(".phd.1") && addingPhrapFailures) {
loglnEchoToStringBuffer(" Importing single-read Phred file "+files[i], logBuffer);
currentRead++;
ace.addPhdFileAsSingleReadInContig(currentRead, directoryPath, files[i], processPolymorphisms, polyThreshold);
}
}
}
}
}
if (addingPhrapFailures && ace !=null ) { // have to process AceFile that we have manually made
MesquiteFile.putFileContents(processedAceFilePath, ace.toString(processPolymorphisms), true);
if (project != null){
processAceFileWithoutContig(processedAceFilePath, ace, geneName, fullName, voucherCode);
}
ace.dispose();
}
if (taxa!=null)
taxa.notifyListeners(this, new Notification(PARTS_ADDED));
if (level ==1 && project !=null){
//Wayne: cleaning up and showing matrix
if (maxChar.getValue()0){
loglnEchoToStringBuffer("Multi-read sequences obtained from the following genes and samples:", logBuffer);
for (int i=0; i0){
loglnEchoToStringBuffer("Multi-read sequences FAILED to be obtained from the following genes and samples:", logBuffer);
for (int i=0; i1){
textCanvasWithButtons = dialog.addATextCanvasWithButtons(s,"File Name Parser...", "nameParserReplace", "Options...", "nameParserButton",this);
nameParserButton = textCanvasWithButtons.getButton2();
}
else {
textCanvasWithButtons = dialog.addATextCanvasWithButtons(s, "Options...", "nameParserButton",this);
nameParserButton = textCanvasWithButtons.getButton();
}
nameParserButton.setEnabled (nameParserManager.hasOptions());
nameParserTextCanvas = textCanvasWithButtons.getTextCanvas();
//section for SequenceNameSource
dialog.addHorizontalLine(1);
dialog.addLabel("Source of Sequence Names");
dialog.forceNewPanel();
s = getModuleText(sequenceNameTask);
if (MesquiteTrunk.mesquiteTrunk.numModulesAvailable(SequenceNameSource.class)>1){
textCanvasWithButtons = dialog.addATextCanvasWithButtons(s,"Sequence Name Source...", "sequenceNameTaskReplace", "Options...", "sequenceNameTaskButton",this);
sequenceNameTaskButton = textCanvasWithButtons.getButton2();
}
else {
textCanvasWithButtons = dialog.addATextCanvasWithButtons(s, "Options...", "sequenceNameTaskButton",this);
sequenceNameTaskButton = textCanvasWithButtons.getButton();
}
sequenceNameTaskButton.setEnabled (sequenceNameTask.hasOptions());
sequenceNameTaskTextCanvas = textCanvasWithButtons.getTextCanvas();
//section for PrimerInfoSource
dialog.addHorizontalLine(1);
dialog.addLabel("Source of Primer Information");
dialog.forceNewPanel();
s = getModuleText(primerInfoTask);
if (MesquiteTrunk.mesquiteTrunk.numModulesAvailable(PrimerInfoSource.class)>1){
textCanvasWithButtons = dialog.addATextCanvasWithButtons(s,"Primer Info Source...", "primerInfoTaskReplace", "Options...", "primerInfoTaskButton",this);
primerInfoTaskButton = textCanvasWithButtons.getButton2();
}
else {
textCanvasWithButtons = dialog.addATextCanvasWithButtons(s, "Options...", "primerInfoTaskButton",this);
primerInfoTaskButton = textCanvasWithButtons.getButton();
}
nameParserButton.setEnabled (primerInfoTask.hasOptions());
primerInfoTaskTextCanvas = textCanvasWithButtons.getTextCanvas();
dialog.addHorizontalLine(2);
dialog.setDefaultButton("Process");
Checkbox requiresExtensionBox = dialog.addCheckBox("process only files with standard extensions (ab1,abi,ab,CRO,scf)", requiresExtension);
SingleLineTextField fileExtensionField = dialog.addTextField("uniform file extension for organized chromatograms (if desired):", fileExtension, 8, true);
Checkbox backupOriginalsBox = dialog.addCheckBox("save backups of original chromatograms", backupOriginals);
Panel buttonPanel = dialog.addNewDialogPanel();
Button fileLocationsButton = dialog.addAButton("Phred Phrap Locations & Options...",buttonPanel);
fileLocationsButton.addActionListener(this);
fileLocationsButton.setActionCommand("phLocations");
dialog.addHorizontalLine(2);
Panel buttonPanel2 = dialog.addNewDialogPanel();
Button postProcessingButton = dialog.addAButton("Post-Phrap Sequence Processing Options...",buttonPanel2);
postProcessingButton.addActionListener(this);
postProcessingButton.setActionCommand("postOptions");
Checkbox singleTaxaBlockBox=null;
if (importing) {
singleTaxaBlockBox = dialog.addCheckBox("import as single taxon block",singleTaxaBlock);
}
Checkbox uploadResultsBox = null;
if (MesquiteTrunk.mesquiteTrunk.numModulesAvailable(DNADatabaseURLSource.class)>=1)
uploadResultsBox = dialog.addCheckBox("upload results to database", uploadResultsToDatabase);
Checkbox showBirdsEyeBox=null;
if (importing) {
showBirdsEyeBox = dialog.addCheckBox("display matrix in bird's eye view",showBirdsEye);
}
dialog.addHorizontalLine(2);
dialog.completeAndShowDialog(true);
boolean success=(buttonPressed.getValue()== dialog.defaultOK);
if (success) {
fileExtension = fileExtensionField.getText();
requiresExtension = requiresExtensionBox.getState();
backupOriginals = backupOriginalsBox.getState();
if (uploadResultsBox!=null)
uploadResultsToDatabase = uploadResultsBox.getState();
if (importing) {
singleTaxaBlock = singleTaxaBlockBox.getState();
showBirdsEye = showBirdsEyeBox.getState();
}
}
storePreferences(); // do this here even if Cancel pressed as the File Locations subdialog box might have been used
nameParserTextCanvas = null;
sequenceNameTaskTextCanvas = null;
primerInfoTaskTextCanvas = null;
dialog.dispose();
return success;
}
/*.................................................................................................................*/
boolean makeDirectoriesForFragment(String fragmentDirPath){
File newDir = new File(fragmentDirPath);
try { newDir.mkdir(); //make folder for this gene
processedFastaDirectory = fragmentDirPath + MesquiteFile.fileSeparator + ChromaseqUtil.processedFastaFolder;
newDir = new File(processedFastaDirectory);
newDir.mkdir(); //make processed fastaFolder
String sequencesDirectory = fragmentDirPath + MesquiteFile.fileSeparator + sequencesFolder;
newDir = new File(sequencesDirectory);
newDir.mkdir(); //make sequences folder for holding all of the sequences and files produces by phred and phrap
}
catch (SecurityException e) {
logln("Couldn't make directory.");
return false;
}
return true;
}
/*.................................................................................................................*/
String getPhredCommand(){
if (MesquiteTrunk.isWindows())
return StringUtil.protectFilePathForWindows(phredPath + "phred.exe");
else
return StringUtil.protectFilePathForUnix(phredPath + "phred");
}
/*.................................................................................................................*/
String getPhrapCommand(){
if (MesquiteTrunk.isWindows())
return StringUtil.protectFilePathForWindows(phredPath + "phrap.exe");
else
return StringUtil.protectFilePathForUnix(phredPath + "phrap");
}
/*.................................................................................................................*/
String getPhd2FastaCommand(){
if (MesquiteTrunk.isWindows())
return StringUtil.protectFilePathForWindows(phredPath + "phd2fasta.exe");
else
return StringUtil.protectFilePathForUnix(phredPath + "phd2fasta");
}
int sequenceCount = 0;
String importedDirectoryPath, importedDirectoryName;
public boolean prepareAndRunPhredPhrap(MesquiteProject project, boolean appendIfPossible){
return prepareAndRunPhredPhrap(project, appendIfPossible, null);
}
/*.................................................................................................................*/
public boolean queryForPaths(MesquiteBoolean pleaseStorePrefs) {
if (!preferencesSet || StringUtil.blank(phredPath)) {
phredPath = MesquiteFile.chooseDirectory("Choose directory containing phred, phrap, and phd2fasta: ");
if (StringUtil.blank(phredPath))
return false;
if (!phredPath.endsWith(MesquiteFile.fileSeparator))
phredPath+=MesquiteFile.fileSeparator;
if (pleaseStorePrefs!=null)
pleaseStorePrefs.setValue(true);
}
if (!preferencesSet || StringUtil.blank(phredParamPath)) {
MesquiteString paramDir = new MesquiteString();
MesquiteString paramFile = new MesquiteString();
phredParamPath = MesquiteFile.openFileDialog("Choose phred parameter file: ", paramDir, paramFile);
if (StringUtil.blank(phredParamPath))
return false;
if (pleaseStorePrefs!=null)
pleaseStorePrefs.setValue(true);
}
return true;
}
/*.................................................................................................................*/
public void prepareShellScriptForDirectory(StringBuffer shellScript, StringBuffer postShellScript, String statusFilePath, String phphLogFilePath, String fragmentDirPath, String seqFileName, String fullSeqName, String directoryPath){
shellScript.append(ShellScriptUtil.getChangeDirectoryCommand(MesquiteTrunk.isWindows(), directoryPath));
if (runPhredPhrap)
shellScript.append(ShellScriptUtil.getAppendStringAsFile(phphLogFilePath, "" + sequenceCount + ". " + fullSeqName + " (directory changed)"));
shellScript.append(getPhredCommand() + " -V -log -id . -pd . -d " + StringUtil.blankIfNull(phredOptions) + " "+ StringUtil.lineEnding());
if (runPhredPhrap) {
shellScript.append(ShellScriptUtil.getWriteStringAsFile(statusFilePath, "" + sequenceCount + ". " + fullSeqName + " (Phred)"));
shellScript.append(ShellScriptUtil.getAppendStringAsFile(phphLogFilePath, "" + sequenceCount + ". " + fullSeqName + " (Phred completed)"));
}
shellScript.append(getPhd2FastaCommand() + " -id . -os '" + seqFileName + "' -oq '" + seqFileName + ".qual'"+ StringUtil.lineEnding());
if (runPhredPhrap) {
shellScript.append(ShellScriptUtil.getWriteStringAsFile(statusFilePath, "" + sequenceCount + ". " + fullSeqName + " (Phd2Fasta)"));
shellScript.append(ShellScriptUtil.getAppendStringAsFile(phphLogFilePath, "" + sequenceCount + ". " + fullSeqName + " (Phd2Fasta completed)"));
}
shellScript.append(getPhrapCommand() + " '" + seqFileName + "' -screen -new_ace " + StringUtil.blankIfNull(phrapOptions) + " "+ StringUtil.lineEnding());
if (runPhredPhrap) {
shellScript.append(ShellScriptUtil.getWriteStringAsFile(statusFilePath, "" + sequenceCount + ". " + fullSeqName + " (Phrap)"));
shellScript.append(ShellScriptUtil.getAppendStringAsFile(phphLogFilePath, "" + sequenceCount + ". " + fullSeqName + " (Phrap completed)"));
}
shellScript.append(ShellScriptUtil.getSetFileTypeCommand(directoryPath + MesquiteFile.fileSeparator + "" + seqFileName + ".ace"));
//postShellScript.append(getSetFileTypeCommand(sequenceDirPath + MesquiteFile.fileSeparator + "" + seqName + processedACESuffix + ".ace"));
}
/*.................................................................................................................*/
private void assignStLouisString(MesquiteString stLouisString, boolean isForward) {
if (isForward)
stLouisString.setValue("b.");
else
stLouisString.setValue("g.");
}
/*.................................................................................................................*/
/** returns the next token in a string AFTER a particular substring; returns empty string if substring not present*/
public static String getNextTokenAfterSubStringIgnoreCase(String line, String subString) {
if (line==null)
return null;
else if (line.equals(""))
return "";
int loc=line.toLowerCase().indexOf(subString.toLowerCase());
if (loc<0)
return "";
loc += subString.length();
Parser parser = new Parser(line);
parser.setPosition(loc);
String token = parser.getNextToken();
return token;
}
/*.................................................................................................................*/
public String getAnalysisParameters() {
StringBuffer sb = new StringBuffer();
sb.append("Phred Options: " + " -id . -pd . -d " + StringUtil.blankIfNull(phredOptions) + "\n");
sb.append("Phrap Options: " + " -new_ace " + StringUtil.blankIfNull(phrapOptions) + "\n");
sb.append("Chromaseq Options: \n");
sb.append(" Quality threshold for lower case: " + qualThresholdForLowerCase + "\n");
sb.append(" Convert multiple-peaks sites to ambiguity codes: " + processPolymorphisms + "\n");
sb.append(" Minimum secondary peak fraction for ambiguity: " + polyThreshold + "\n");
sb.append(" Trim low quality regions from ends: " + truncateMixedEnds + "\n");
sb.append(" Quality threshold for trim: " + qualThresholdForTrim + "\n");
sb.append(" Trim window length: " + mixedEndWindow + "\n");
sb.append(" Trim window threshold: " + mixedEndThreshold + "\n");
return sb.toString();
}
int sectionNumber=1;
/*.................................................................................................................*/
// starting the run
public boolean startExecution(String scriptPath, String runningFilePath){ //do we assume these are disconnectable?
if (scriptBased) {
scriptRunner = new ShellScriptRunner(scriptPath, runningFilePath, null, false, "Phred and Phrap", null, this, this, true); //scriptPath, runningFilePath, null, true, name, outputFilePaths, outputFileProcessor, watcher, true
return scriptRunner.executeInShell();
} else {
return executeProgramsInScriptFile(scriptPath);
}
/*Process proc = ShellScriptUtil.executeScript(scriptPath, true);
if (proc==null) {
if (progIndicator!=null) progIndicator.goAway();
return false;
}
return true;
*/
}
/*.................................................................................................................*/
// not fully implemented; not currently used. Will require Java 8
public boolean executeProgramsInScriptFile(String scriptPath){
String contents = MesquiteFile.getFileContentsAsString(scriptPath);
Parser parser = new Parser(contents);
String line = parser.getRawNextDarkLine();
Parser subParser = new Parser();
boolean overallSuccess = true;
while (StringUtil.notEmpty(line) && overallSuccess) {
subParser.setString(line);
String programCommand = subParser.getFirstItem(line, "\t");
String options = subParser.getRemaining();
//externalRunner = new ExternalProcessManager(this, rootDir, getPhredCommand(), arguments, getExecutableName(), outputFilePaths, this, this, false);
boolean success = externalRunner.executeInShell();
if (!success)
overallSuccess = false;
line = parser.getRawNextDarkLine();
}
return overallSuccess;
}
/*.................................................................................................................*/
public boolean prepareAndRunPhredPhrap(MesquiteProject project, boolean appendIfPossible, String directoryPath){
MesquiteBoolean pleaseStorePrefs = new MesquiteBoolean(false);
if (!queryForPaths(pleaseStorePrefs))
return false;
if (pleaseStorePrefs.getValue())
storePreferences();
// ============ getting primer info ===========
// PrimerList primers = getPrimers();
// if not passed-in, then ask
if (StringUtil.blank(directoryPath)) {
directoryPath = MesquiteFile.chooseDirectory("Choose directory containing ABI files:", previousDirectory); //MesquiteFile.saveFileAsDialog("Base name for files (files will be named 1.nex, 2.nex, etc.)", baseName);
}
if (StringUtil.blank(directoryPath))
return false;
File directory = new File(directoryPath);
importedDirectoryPath = directoryPath + MesquiteFile.fileSeparator;
importedDirectoryName = directory.getName();
previousDirectory = directory.getParent();
storePreferences();
if (directory.exists() && directory.isDirectory()) {
logBuffer.setLength(0);
progIndicator = new ProgressIndicator(getProject(),"Preparing for Phred/Phrap");
progIndicator.setStopButtonName("Stop");
progIndicator.start();
boolean abort = false;
/* Thread mt = Thread.currentThread();
boolean piMine = false;
if (mt instanceof MesquiteThread)
progIndicator = ((MesquiteThread)mt).getProgressIndicator();
if (progIndicator ==null) {
progIndicator = new ProgressIndicator(getProject(),"Running Phred & Phrap", 0);
piMine = true;
if (mt instanceof MesquiteThread)
((MesquiteThread)mt).setProgressIndicator(progIndicator);
}
progIndicator.setButtonMode(ProgressIndicator.FLAG_AND_HIDE);
progIndicator.start();
boolean abort = false;
*/
String cPath;
String seqFileName;
String fullSeqName;
String fragName = "";
StringBuffer shellScript = new StringBuffer(6000);
StringBuffer postShellScript = new StringBuffer(6000);
sequenceCount = 0;
if (MesquiteTrunk.isWindows()) {
shellScript.append("set PHRED_PARAMETER_FILE="+phredParamPath+ StringUtil.lineEnding());
} else {
// shellScript.append("setenv PHRED_PARAMETER_FILE "+StringUtil.protectForUnix(phredParamPath)+"\n");
shellScript.append("#!/bin/csh -v\nsetenv PHRED_PARAMETER_FILE "+StringUtil.protectFilePathForUnix(phredParamPath)+StringUtil.lineEnding());
}
// shellScript.append(getAliasCommand ("phred", phredPath + "phred"));
// shellScript.append(getAliasCommand ("phd2fasta",phredPath+"phd2fasta"));
// shellScript.append(getAliasCommand ("phrap",phredPath+"phrap"));
//set path = ( $path /usr/bin /usr/sbin /phredPhrap/ph/)
int loc = 0;
String[] files = directory.list();
StringBuffer renameBuffer = new StringBuffer(1000);
String processedDirPath = directoryPath + MesquiteFile.fileSeparator + processedFolder; // directory into which processed files go
String originalsDirPath = directoryPath + MesquiteFile.fileSeparator + originalFolder; // directory for copies of original files
loglnEchoToStringBuffer("\nPhred Phrap processing of chromatograms as scripted by Mesquite", logBuffer);
loglnEchoToStringBuffer(StringUtil.getDateTime(), logBuffer);
loglnEchoToStringBuffer(StringUtil.lineEnding()+"Mesquite "+ MesquiteTrunk.getMesquiteVersion() + MesquiteTrunk.getBuildVersion(), logBuffer);
loglnEchoToStringBuffer("Chromaseq "+ getVersion() + " (build " + getBuildNumberOfPackage()+")", logBuffer);
loglnEchoToStringBuffer(StringUtil.lineEnding()+" Processing directory: ", logBuffer);
loglnEchoToStringBuffer(" "+directoryPath+"\n", logBuffer);
if (sequenceNameTask!=null)
sequenceNameTask.echoParametersToFile(logBuffer);
if (primerInfoTask!=null)
primerInfoTask.echoParametersToFile(logBuffer);
loglnEchoToStringBuffer("Parameters: " + getAnalysisParameters()+"\n", logBuffer);
String rootDir = processedDirPath;
String fragmentDirPath = "";
File newDir;
int numPrepared = 0;
shellScript.append(ShellScriptUtil.getChangeDirectoryCommand(MesquiteTrunk.isWindows(), rootDir));
shellScript.append(getPhredCommand() + " -V -log"+StringUtil.lineEnding());
//shellScript.append("("+getPhrapCommand() + ") >& phrapFileToDetermineVersion\n");
shellScript.append(getPhrapCommand() + " > "+VERSION_FILE+StringUtil.lineEnding());
newDir = new File(processedDirPath);
try {
newDir.mkdir();
if (backupOriginals) {
newDir = new File(originalsDirPath);
newDir.mkdir();
}
}
catch (SecurityException e) {
logln("Couldn't make directory.");
if (progIndicator!=null) progIndicator.goAway();
return false;
}
String runningFilePath = rootDir + MesquiteFile.fileSeparator + "running";
String contigPropertiesFilePath = rootDir + MesquiteFile.fileSeparator + "contigProperties.txt";
String statusFilePath = rootDir + MesquiteFile.fileSeparator + "status";
String phphLogFilePath = rootDir + MesquiteFile.fileSeparator + "phPhPh.log";
String phredLogFilePath = rootDir + MesquiteFile.fileSeparator + "phred.log";
String phrapStdErrFilePath = rootDir + MesquiteFile.fileSeparator + VERSION_FILE;
if (runPhredPhrap)
MesquiteFile.putFileContents(runningFilePath, "Phred Phrap are running...", true);
fileNameTranslation= new String[5][files.length];
Vector infoFiles = new Vector();
loglnEchoToStringBuffer("---------------------------------------------------", logBuffer);
loglnEchoToStringBuffer("Section " +(sectionNumber++) + ": Examining chromatogram files and preparing directories ", logBuffer);
loglnEchoToStringBuffer("", logBuffer);
for (int i=0; i0)
oldExtension = "."+ StringUtil.getLastItem(chromFileName, ".");
String extension = fileExtension;
if (StringUtil.blank(extension))
extension=oldExtension;
if (backupOriginals) {
try {
String pathInOriginalFolder = originalsDirPath + MesquiteFile.fileSeparator + chromFileName; // path to where original will be stored
File originalFile = new File(pathInOriginalFolder); //
MesquiteFile.copy(cFile, originalFile);
}
catch (IOException e) {
logln( "Can't copy: " + seqFileName);
}
}
//now move and rename the original to this sequence's directory
//writeInfoFile(infoFilePath, fullSeqName);
try {
String newFileName = startTokenResult + sampleCode.getValue()+"." + stLouisString.getValue()+primerName+extension;
String newFilePath = sequenceDirPath + MesquiteFile.fileSeparator + newFileName;
File newFile = new File(newFilePath); //
int count=1;
while (newFile.exists()) {
newFileName = startTokenResult + sampleCode.getValue()+"_"+count + "." + stLouisString.getValue()+primerName+extension;
newFilePath = sequenceDirPath + MesquiteFile.fileSeparator + newFileName;
newFile = new File(newFilePath);
count++;
}
if (verbose)
renameBuffer.append(" " + chromFileName + " renamed to " + newFileName + "\n");
fileNameTranslation[0][i] = newFileName;
fileNameTranslation[1][i] = chromFileName;
fileNameTranslation[2][i] = primerName.toString();
fileNameTranslation[3][i] = startTokenResult.getValue();
fileNameTranslation[4][i] = sampleCode.getValue();
ChromaseqInfoFile infoFile = ChromaseqInfoFile.getInfoFile(infoFiles,sequenceDirPath);
if (infoFile!=null)
infoFile.addChromatogramInfo(chromFileName, newFileName, primerName.toString());
cFile.renameTo(newFile);
}
catch (SecurityException e) {
logln( "Can't rename: " + seqFileName);
}
}
catch (SecurityException e) {
logln( "Can't make directory: " + seqFileName);
}
}
}
}
}
if (infoFiles!=null){
loglnEchoToStringBuffer("Writing info.xml files...", logBuffer);
ChromaseqInfoFile.writeInfoFiles(infoFiles, progIndicator);
ChromaseqInfoFile.dispose(infoFiles);
}
loglnEchoToStringBuffer("", logBuffer);
loglnEchoToStringBuffer("Number of files prepared: " + numPrepared, logBuffer);
loglnEchoToStringBuffer("", logBuffer);
loglnEchoToStringBuffer("---------------------------------------------------", logBuffer);
loglnEchoToStringBuffer("Section " +(sectionNumber++) + ": Renaming chromatograms for Phred and Phrap", logBuffer);
if (verbose)
loglnEchoToStringBuffer("\n" + renameBuffer.toString()+"\n", logBuffer);
if (!abort) {
if (runPhredPhrap) {
shellScript.append(ShellScriptUtil.getRemoveCommand(MesquiteTrunk.isWindows(), runningFilePath));
shellScript.append(ShellScriptUtil.getRemoveCommand(MesquiteTrunk.isWindows(), statusFilePath));
}
progIndicator.spin();
if (shellScript.length()>0){
//note name of file should end in .command for Terminal in OS X to run it; on other OS's we may be able to get the script to run directly from Runtime.exec
String scriptPath = rootDir + MesquiteFile.fileSeparator + "ppscript.bat";
MesquiteFile.putFileContents(scriptPath, shellScript.toString(), true);
if (runPhredPhrap) {
try {
//String scriptPath = StringUtil.protectForUnix(rootDir + MesquiteFile.fileSeparator + "ppscript.command");
ShellScriptUtil.setScriptFileToBeExecutable(scriptPath);
//logln("Request to change permissions of file \"ppscript.bat\" given");
if (!startExecution(scriptPath, runningFilePath))
return false;
//Process proc = ShellScriptUtil.executeScript(scriptPath);
//if (proc==null) {
// if (progIndicator!=null) progIndicator.goAway();
// return false;
//}
if (progIndicator!=null)
progIndicator.setTitle("Running Phred & Phrap");
loglnEchoToStringBuffer("", logBuffer);
loglnEchoToStringBuffer("---------------------------------------------------", logBuffer);
loglnEchoToStringBuffer("Section " +(sectionNumber++) + ": Execution of Phred-Phrap command file begun", logBuffer);
/*On OS X at this point the script operates asyncronously, so if we wanted to immediately go into the post processing we'd have to listen for some file showing up or such
When runtime.exec runs the script directly, proc.waitFor() can be used to force this thread to hang until the script finishes*/
/* the following does nothing on OS X, but will be useful on other OS's if previous statement executes script directly so as to show processing in log window
InputStream stream = proc.getInputStream();
int c = 0;
while ((c=stream.read())!=-1){
log("" + (char)c);
}
/**/
}
catch (IOException e){
logln("IOE error: " + e);
abort =true;
}
}
}
}
boolean findPhredVersion = true;
String phredVersion = null;
boolean findPhrapVersion = true;
String phrapVersion = null;
if (runPhredPhrap && !abort) {
try {
String oldStatus = "";
int equalStatusCount = 0;
int count=-3;
logln("");
//if (progIndicator!=null) progIndicator.setTotalValue(sequenceCount);
while (MesquiteFile.fileExists(runningFilePath) && !abort){
if (findPhredVersion && MesquiteFile.fileExists(phredLogFilePath)) { // get phredVersion
String phredLog = MesquiteFile.getFileContentsAsString(phredLogFilePath);
phredVersion = getNextTokenAfterSubStringIgnoreCase(phredLog, "PHRED version");
findPhredVersion = false;
}
if (findPhrapVersion && MesquiteFile.fileExists(phrapStdErrFilePath)) { // get phredVersion
String phrapStdErr = MesquiteFile.getFileContentsAsString(phrapStdErrFilePath);
phrapVersion = getNextTokenAfterSubStringIgnoreCase(phrapStdErr, "phrap version");
findPhrapVersion = false;
}
String status = "";
if (MesquiteFile.fileExists(statusFilePath)) {
status = MesquiteFile.getFileContentsAsString(statusFilePath);
}
if (!StringUtil.blank(status)) {
if (progIndicator!=null) {
if (progIndicator.getTotalValue()==0) {
progIndicator.setTotalValue(sequenceCount);
//progIndicator.repaintBar();
}
progIndicator.setText(status);
String s = StringUtil.getFirstItem(status,".");
int num = MesquiteInteger.fromString(s);
progIndicator.setCurrentValue(num);
}
if (status.equalsIgnoreCase(oldStatus))
equalStatusCount++;
else {
equalStatusCount = 0;
log(status);
}
if (equalStatusCount>25) {
logln("There may be a problem: Phred and Phrap do not seem to be actively analyzing files.");
if (equalStatusCount>35)
abort=true;
}
oldStatus = status;
}
else {
log(".");
if (progIndicator!=null) progIndicator.spin();
}
count = 1;
//}
if (progIndicator.isAborted())
abort = true;
Thread.sleep(200);
count++;
}
logln("");
if (abort)
loglnEchoToStringBuffer("Mesquite processing stopped.", logBuffer);
else
loglnEchoToStringBuffer("Phred & Phrap analyses completed.", logBuffer);
}
catch (InterruptedException e){
Thread.currentThread().interrupt();
}
//PostPhrap pPhrap = (PostPhrap)hireEmployee(PostPhrap.class, "Post Phrap Processing");
if (!abort) {
loglnEchoToStringBuffer("", logBuffer);
loglnEchoToStringBuffer("---------------------------------------------------", logBuffer);
loglnEchoToStringBuffer("Section " +(sectionNumber++) + ": Mesquite processing of Phrap results", logBuffer);
contigPropertiesFileBuffer = new StringBuffer();
postPhrapOnDirectory( project,appendIfPossible, rootDir);
MesquiteFile.putFileContents(contigPropertiesFilePath, contigPropertiesFileBuffer.toString(), true);
}
}
if (progIndicator!=null)
progIndicator.goAway();
loglnEchoToStringBuffer(StringUtil.getDateTime(), logBuffer);
logBuffer.append("Mesquite version: " + MesquiteTrunk.mesquiteTrunk.getVersion()+", build number " + MesquiteTrunk.mesquiteTrunk.getBuildNumber()+"\n");
loglnEchoToStringBuffer("Chromaseq version: " + getVersion(), logBuffer);
if (StringUtil.notEmpty(phredVersion))
loglnEchoToStringBuffer("Phred version: " + phredVersion, logBuffer);
if (StringUtil.notEmpty(phrapVersion))
loglnEchoToStringBuffer("Phrap version: " + phrapVersion, logBuffer);
loglnEchoToStringBuffer("", logBuffer);
loglnEchoToStringBuffer("========================", logBuffer);
loglnEchoToStringBuffer("", logBuffer);
MesquiteFile.putFileContents(rootDir + MesquiteFile.fileSeparator + "phredPhrapLog.txt", logBuffer.toString(), true);
MesquiteFile.deleteFile(phredLogFilePath);
if (project != null) {
//project.getCoordinatorModule().saveFile(project.getHomeFile());
if (originalData != null)
originalData.setDirty(true); //so that user will prompted; seems to be needed for annotations to be saved
}
}
return true;
}
/*.................................................................................................................*/
private void addWindowsHeaderOLD(StringBuffer shellScript) {
// TODO: Issues with new-ish Windows/Cygwin. Oliver.July.30.2015
// original implementation has these two lines
shellScript.append("REGEDIT /E %Temp%.\\tmp-cygwin.reg \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2\\/\"> nul"+ StringUtil.lineEnding());
shellScript.append("FOR /F \"tokens=1* delims==\" %%A IN ('TYPE %Temp%.\\tmp-cygwin.reg ^| FIND \"native\"') DO SET CYGWIN_ROOT=%%B> nul"+ StringUtil.lineEnding());
// For newer (?) installations of Cygwin, replace those two lines ^^ with these two lines vv
// shellScript.append("REGEDIT /E %Temp%.\\tmp-cygwin.reg \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Cygwin\\setup\"> nul\n");
// shellScript.append("FOR /F \"tokens=1* delims==\" %%A IN ('TYPE %Temp%.\\tmp-cygwin.reg ^| FIND \"rootdir\"') DO SET CYGWIN_ROOT=%%B> nul\n");
// An alternative approach would be to shift the entire burden to the Windows user,
// Asking where cygwin is installed; it is often in the root, C:\cygwin64
shellScript.append("SET CYGWIN_ROOT=%CYGWIN_ROOT:\"=%> nul"+ StringUtil.lineEnding());
shellScript.append("if exist %Temp%.\\tmp-cygwin.reg del %Temp%.\\tmp-cygwin.reg"+ StringUtil.lineEnding());
shellScript.append("SET PATH=.;%CYGWIN_ROOT%\\bin;%CYGWIN_ROOT%\\opt\\elinos\\bin;%PATH%"+ StringUtil.lineEnding());
shellScript.append("set PHRED_PARAMETER_FILE="+phredParamPath+ StringUtil.lineEnding());
}
int aceFileCount = 0;
boolean processFolderAborted = false;
Vector goodNews = new Vector();
Vector badNews = new Vector();
/*.................................................................................................................*/
public void writeInfoFile(String infoFilePath, String fullName){
StringBuffer infoFileBuffer = new StringBuffer();
infoFileBuffer.append(fullName); //here write the XML info file
MesquiteFile.putFileContents(infoFilePath, infoFileBuffer.toString(), true);
}
StringBuffer contigPropertiesFileBuffer;
/*.................................................................................................................*/
public void processAceFileWithContig(MesquiteProject project, String processedAceFilePath, String fragmentDirPath, AceFile ace, SequenceUploader uploader, String geneName, MesquiteString fullName, String baseName, MesquiteString voucherCode) {
ace.setNameTranslation(fileNameTranslation);
log(ace.contigListForLog()+StringUtil.lineEnding());
if (processPolymorphisms)
ace.processPolys(); //creates an additional CO that has polys in it
if (renameContigsInAceFiles)
ace.renameContigs(fullName.toString(), addFragName, geneName);
ace.setLowQualityToLowerCase(qualThresholdForLowerCase);
ace.writeToPropertiesFile(contigPropertiesFileBuffer, fullName.toString());
if (truncateMixedEnds)
ace.trimMixedEnds(mixedEndThreshold, mixedEndWindow, qualThresholdForTrim, addPhrapFailures);
if (uploadResultsToDatabase && uploader!=null && databaseURLSource!=null) {
// note: this should really be abstracted, and become a job for a module to do; we shouldn't see the raw reference to getTOLPageDatabaseURL in here
uploader.uploadAceFileToServer(MesquiteXMLToLUtilities.getTOLPageDatabaseURL(databaseURLSource.getBaseURL()), ace, processPolymorphisms, qualThresholdForTrim);
}
System.out.println("\n\nfasta file name: " + baseName + " ace file: " + ace);
MesquiteFile.putFileContents(fragmentDirPath + MesquiteFile.fileSeparator + ChromaseqUtil.processedFastaFolder + MesquiteFile.fileSeparator + baseName+".fas", ace.toFASTAString(processPolymorphisms, qualThresholdForTrim), true);
MesquiteFile.putFileContents(processedAceFilePath, ace.toString(processPolymorphisms), true);
if (project != null) {
ace.importSequence(taxa, data, MesquiteInteger.unassigned, originalData, qualityData, registrationData, singleTaxaBlock, processPolymorphisms, maxChar," contig ", false, voucherCode);
}
}
/*.................................................................................................................*/
public void processAceFileWithoutContig(String processedAceFilePath, AceFile ace, String geneName, MesquiteString fullName, MesquiteString voucherCode) {
ace.processFailedContig(polyThreshold);
ace.setNameTranslation(fileNameTranslation);
if (renameContigsInAceFiles)
ace.renameContigs(fullName.toString(), addFragName, geneName);
ace.setLowQualityToLowerCase(qualThresholdForLowerCase);
ace.writeToPropertiesFile(contigPropertiesFileBuffer, fullName.toString());
if (truncateMixedEnds)
ace.trimMixedEnds(mixedEndThreshold, mixedEndWindow, qualThresholdForTrim, addPhrapFailures);
MesquiteFile.putFileContents(processedAceFilePath, ace.toString(processPolymorphisms), true);
ace.importSequence(taxa, data, MesquiteInteger.unassigned, originalData, qualityData, registrationData, singleTaxaBlock, processPolymorphisms, maxChar,"", true, voucherCode);
}
/*.................................................................................................................*/
public boolean processAceFileDirectory(MesquiteProject project, boolean appendIfPossible, File directory, String directoryPath, String enclosingDirName, String geneName, String dataFilePath, int level){
boolean addingPhrapFailures = false;
String[] files = directory.list();
String processedAceFilePath = null;
AceFile ace = null;
int currentRead = -1;
if (uploadResultsToDatabase)
checkDatabaseSource();
SequenceUploader uploader = new SequenceUploader(databaseURLSource);
MesquiteString fullName = null;
MesquiteString voucherCode = new MesquiteString();
for (int i=0; i=1) {
processAceFileWithContig(project, processedAceFilePath, fragmentDirPath, ace, uploader, geneName, fullName, baseName, voucherCode);
}
else {
loglnEchoToStringBuffer(" ACE file contains no contigs!", logBuffer);
badNews.addElement(" (" + geneName + ") -- " + baseName);
if (addPhrapFailures && project !=null) {
addingPhrapFailures = true;
i=-1;
ace.createEmptyContigs(MesquiteFile.numFilesEndingWith(directoryPath,files,".phd.1")); //create an empty contig
if (renameContigsInAceFiles)
ace.renameContigs(fullName.toString(), addFragName, geneName);
}
}
if (!addingPhrapFailures)
ace.dispose();
}
else if (files[i].endsWith(".phd.1") && addingPhrapFailures) {
loglnEchoToStringBuffer(" Importing single-read Phred file "+files[i], logBuffer);
currentRead++;
ace.addPhdFileAsSingleReadInContig(currentRead, directoryPath, files[i], processPolymorphisms, polyThreshold);
}
}
}
}
}
if (addingPhrapFailures && ace !=null ) { // have to process AceFile that we have manually made
MesquiteFile.putFileContents(processedAceFilePath, ace.toString(processPolymorphisms), true);
if (project != null){
processAceFileWithoutContig( processedAceFilePath, ace, geneName, fullName, voucherCode);
}
ace.dispose();
}
return false;
}
/*.................................................................................................................*/
public boolean processFolderAfterPhrap(MesquiteProject project, boolean appendIfPossible, File directory, String directoryPath, String enclosingDirName, String geneName, String dataFilePath, int level, MesquiteInteger numAceFiles){
boolean addingPhrapFailures = false;
if (processFolderAborted)
return false;
String[] files = directory.list();
String sequenceName = geneName;
String originalDataFilePath = dataFilePath;
if (project!=null){
originalDataFilePath= project.getHomeFile().getPath();
originalDataFilePath=MesquiteFile.getDirectoryPathFromFilePath(originalDataFilePath);
}
boolean rename = false;
if (level == 1)
sequenceName = directory.getName();
if (level == 1 && project!=null) {
project.virginProject=false;
taxa = null; //making sure nothing old is remembered accidentally
//getting ready to import; making matrices to be filled
if (appendIfPossible && project != null){
data = (DNAData)project.getCharacterMatrixByReference(null, directory.getName() + " (from Phred/Phrap)");
originalData = (DNAData)project.getCharacterMatrixByReference(null, directory.getName() + " (ORIGINAL from Phred/Phrap)");
qualityData = (ContinuousData)project.getCharacterMatrixByReference(null, "Quality Scores for " + directory.getName() + " from Phred/Phrap");
// addedBaseData = (CategoricalData)project.getCharacterMatrixByReference(null, "Bases added for " + directory.getName() + " from Phred/Phrap");
registrationData = (MeristicData)project.getCharacterMatrixByReference(null, "Registration of " + directory.getName() + " from Phred/Phrap");//DAVID: if change name here have to change elsewhere
if (data !=null && (qualityData==null || originalData==null || registrationData==null)){
//discreetAlert("Cannot append chromatogram information to the matrix \"" + data.getName() + "\" that does not contain Chromaseq data");
data = null;
rename = true;
}
if (originalData != null)
originalData.saveChangeHistory = false;
if (qualityData != null)
qualityData.saveChangeHistory = false;
// if (addedBaseData != null)
// addedBaseData.saveChangeHistory = false;
if (data != null){
taxa = data.getTaxa();
data.saveChangeHistory = false;
}
}
if (taxa == null){
if (singleTaxaBlock) {
if (project.getNumberTaxas()>0)
taxa = project.getTaxa(0);
if (taxa == null) {
taxa = project.createTaxaBlock(0);
taxa.setName("Sequences");
}
}
else {
taxa = project.createTaxaBlock(0);
String taxaBlockName = directory.getName() + " Sequences";
if (rename) {
ListableVector taxas = getProject().getTaxas();
taxaBlockName = taxas.getUniqueName(taxaBlockName);
}
taxa.setName(taxaBlockName);
}
}
CharactersManager manageCharacters = (CharactersManager)coord.findElementManager(mesquite.lib.characters.CharacterData.class);
MesquiteString uid = new MesquiteString(ChromaseqUtil.PHPHIMPORTIDREF, MesquiteTrunk.getUniqueIDBase());
MesquiteString gN = new MesquiteString(ChromaseqUtil.GENENAMEREF, directory.getName());
if (data == null){
data = (DNAData)manageCharacters.newCharacterData(taxa, 0, DNAData.DATATYPENAME); //
data.saveChangeHistory = false;
data.addToFile(file, project, manageCharacters);
String matrixName = directory.getName() + " (from Phred/Phrap)";
if (rename) {
ListableVector datas = getProject().getCharacterMatrices();
matrixName = datas.getUniqueName(matrixName);
}
data.setName(matrixName);
ChromaseqUtil.attachStringToMatrix(data,uid);
ChromaseqUtil.attachStringToMatrix(data,gN);
ChromaseqUtil.attachStringToMatrix(data,new MesquiteString(ChromaseqUtil.PHPHMQVERSIONREF, ChromaseqUtil.PHPHMQVERSION));
ChromaseqUtil.attachStringToMatrix(data,new MesquiteString(ChromaseqUtil.PHPHIMPORTMATRIXTYPEREF, ChromaseqUtil.EDITEDREF));
}
if (originalData == null){
originalData = (DNAData)manageCharacters.newCharacterData(taxa, 0, DNAData.DATATYPENAME); //
originalData.saveChangeHistory = false;
originalData.incrementEditInhibition();
originalData.setUserVisible(ChromaseqUtil.isChromaseqDevelopment());
originalData.addToFile(file, project, manageCharacters);
originalData.setName(directory.getName() + " (ORIGINAL from Phred/Phrap)");
//data.addToLinkageGroup(originalData); //link matrices! //DAVID: uncomment this to reverse new registration system
originalData.setResourcePanelIsOpen(false);
ChromaseqUtil.attachStringToMatrix(originalData,uid);
ChromaseqUtil.attachStringToMatrix(originalData,gN);
ChromaseqUtil.attachStringToMatrix(originalData,new MesquiteString(ChromaseqUtil.PHPHIMPORTMATRIXTYPEREF, ChromaseqUtil.ORIGINALREF));
originalData.incrementEditInhibition();
}
if (qualityData == null){
qualityData = (ContinuousData)manageCharacters.newCharacterData(taxa, 0, ContinuousData.DATATYPENAME); //
qualityData.saveChangeHistory = false;
qualityData.addToFile(file, project, manageCharacters);
//data.addToLinkageGroup(qualityData); //link matrices! //DAVID: uncomment this to reverse new registration system
qualityData.setName("Quality Scores for " + directory.getName() + " from Phred/Phrap");
qualityData.setResourcePanelIsOpen(false);
qualityData.setUserVisible(ChromaseqUtil.isChromaseqDevelopment());
ChromaseqUtil.attachStringToMatrix(qualityData,uid);
ChromaseqUtil.attachStringToMatrix(qualityData,gN);
ChromaseqUtil.attachStringToMatrix(qualityData,new MesquiteString(ChromaseqUtil.PHPHIMPORTMATRIXTYPEREF, ChromaseqUtil.QUALITYREF));
qualityData.incrementEditInhibition();
qualityData.setUseDiagonalCharacterNames(false);
}
/* if (addedBaseData == null){
addedBaseData = (CategoricalData)manageCharacters.newCharacterData(taxa, 0, CategoricalData.DATATYPENAME); //
addedBaseData.addToFile(file, project, manageCharacters);
addedBaseData.setUserVisible(ChromaseqUtil.isChromaseqDevelopment());
// ChromaseqUtil.setAddedBaseDataValues(addedBaseData, data, directory.getName(), uid, gN);
}
*/ if (registrationData == null){
registrationData = (MeristicData)manageCharacters.newCharacterData(taxa, 0, MeristicData.DATATYPENAME); //
registrationData.setUserVisible(ChromaseqUtil.isChromaseqDevelopment());
registrationData.addToFile(file, project, manageCharacters);
ChromaseqUtil.setRegistryDataValues(registrationData, data, directory.getName() , uid, gN);
}
ChromaseqUtil.setChromaseqRegistrationBuildOfMatrix(data,ChromaseqUtil.ChromaseqRegistrationBuild);
if (appendIfPossible && project != null)
maxChar.setValue(data.getNumChars()); // DRM 8.Nov.2013 Added this to fix the bug whereby existing data could be truncated.
else
maxChar.setValue(0);
//qualityData.attachIf UniqueName(new MesquiteString(ChromaseqUtil.PHPHIMPORTMATRIXTYPEREF, "quality")); use method in ChromaseqUtil instead
}
String processedAceFilePath = null;
AceFile ace = null;
int currentRead = -1;
if (uploadResultsToDatabase)
checkDatabaseSource();
SequenceUploader uploader = new SequenceUploader(databaseURLSource);
MesquiteString fullName = null;
MesquiteString voucherCode = null;
for (int i=0; i=1) {
processAceFileWithContig(project, processedAceFilePath, fragmentDirPath, ace, uploader, geneName, fullName, baseName, voucherCode);
goodNews.addElement(" (" + geneName + ") -- " + fullName);
}
else {
loglnEchoToStringBuffer(" ACE file contains no contigs!", logBuffer);
badNews.addElement(" (" + geneName + ") -- " + baseName);
if (addPhrapFailures && project !=null) {
addingPhrapFailures = true;
i=-1; // 24 Feb 2O18: set to -1 as wasn't getting first file in directory if set to 0 as loop was setting it then to 1
ace.createEmptyContigs(MesquiteFile.numFilesEndingWith(directoryPath,files,".phd.1")); //create an empty contig
if (renameContigsInAceFiles)
ace.renameContigs(fullName.toString(), addFragName, geneName);
}
}
if (!addingPhrapFailures)
ace.dispose();
}
else if (files[i].endsWith(".phd.1") && addingPhrapFailures) {
loglnEchoToStringBuffer(" Importing single-read Phred file "+files[i], logBuffer);
currentRead++;
ace.addPhdFileAsSingleReadInContig(currentRead, directoryPath, files[i], processPolymorphisms, polyThreshold);
}
}
}
}
}
if (addingPhrapFailures && ace !=null ) { // have to process AceFile that we have manually made
MesquiteFile.putFileContents(processedAceFilePath, ace.toString(processPolymorphisms), true);
if (project != null){
processAceFileWithoutContig(processedAceFilePath, ace, geneName, fullName, voucherCode);
}
ace.dispose();
}
if (taxa!=null)
taxa.notifyListeners(this, new Notification(PARTS_ADDED));
if (level ==1 && project !=null){
//Wayne: cleaning up and showing matrix
if (maxChar.getValue()0){
loglnEchoToStringBuffer("Multi-read sequences obtained from the following genes and samples:", logBuffer);
for (int i=0; i0){
loglnEchoToStringBuffer("Multi-read sequences FAILED to be obtained from the following genes and samples:", logBuffer);
for (int i=0; i=0)
+ sequenceProfile = (SequenceProfile)(sequenceProfileVector.elementAt(ruleNumber));
+ return true;
+ }
+ /*.................................................................................................................*/
+
+ public boolean optionsSpecified(){
+ boolean db = StringUtil.notEmpty(sequenceProfileName);
+ db = sequenceProfile!=null;
+ int ruleNumber = sequenceProfileVector.indexOfByNameIgnoreCase(sequenceProfileName);
+
+ return (StringUtil.notEmpty(sequenceProfileName) && sequenceProfile!=null) ;
+ }
+ public boolean hasOptions(){
+ return true;
+ }
+
+ public String getSequenceModifiers(int sequenceType) {
+ return "";
+ }
+ /*.................................................................................................................*/
+ public String[] getListOfProfiles(){
+ if (sequenceProfileVector==null || sequenceProfileVector.size()<1)
+ return null;
+ return sequenceProfileVector.getStringArrayList();
+ }
+
+ /*.................................................................................................................*/
+ public boolean queryOptions() {
+ MesquiteInteger buttonPressed = new MesquiteInteger(ExtensibleDialog.defaultCANCEL);
+ SequenceProfileDialog dialog = new SequenceProfileDialog(MesquiteTrunk.mesquiteTrunk.containerOfModule(), "Choose the sequence profile", buttonPressed, this, sequenceProfileName);
+
+
+ String s = "In preparing sequences for GenBank submission, Mesquite saves data about the sequence (e.g., gene name, genetic code, etc.). ";
+ dialog.appendToHelpString(s);
+
+ dialog.completeAndShowDialog(true);
+ boolean success=(buttonPressed.getValue()== dialog.defaultOK);
+ if (success) {
+ sequenceProfile = dialog.getNameParsingRule();
+ sequenceProfileName = sequenceProfile.getName();
+ }
+ storePreferences(); // do this here even if Cancel pressed as the File Locations subdialog box might have been used
+ dialog.dispose();
+ return success;
+ }
+ /*.................................................................................................................*/
+ public String preparePreferencesForXML () {
+ StringBuffer buffer = new StringBuffer();
+ StringUtil.appendXMLTag(buffer, 2, "sequenceSpecificationName", sequenceProfileName);
+ return buffer.toString();
+ }
+ /*.................................................................................................................*/
+ public String getParameters () {
+ if (StringUtil.blank(sequenceProfileName))
+ return "Sequence profile: not chosen.";
+ return "Sequence profile: " + sequenceProfileName;
+ }
+
+ /*.................................................................................................................*/
+ public void processSingleXMLPreference (String tag, String content) {
+ if ("sequenceSpecificationName".equalsIgnoreCase(tag))
+ sequenceProfileName = StringUtil.cleanXMLEscapeCharacters(content);
+ }
+ /*.................................................................................................................*/
+ public SequenceProfile loadSequenceSpecificationFile(String cPath, String fileName, boolean requiresEnding, boolean userDef) {
+ File cFile = new File(cPath);
+ if (cFile.exists() && !cFile.isDirectory() && (!requiresEnding || fileName.endsWith("xml"))) {
+ String contents = MesquiteFile.getFileContentsAsString(cPath);
+ if (!StringUtil.blank(contents)) {
+ SequenceProfile localSequenceSpecification = new SequenceProfile();
+ localSequenceSpecification.path = cPath;
+ if (localSequenceSpecification.readXML(contents)){
+ sequenceProfileVector.addElement(localSequenceSpecification, false);
+ return localSequenceSpecification;
+ }
+ return null;
+ }
+ }
+ return null;
+ }
+
+
+ public void setChoice (Choice choice) {
+ this.choice = choice;
+ }
+ public Choice getChoice() {
+ return choice;
+ }
+ public int getNumRules() {
+ return sequenceProfileVector.getNumberOfParts();
+ }
+
+ /*.................................................................................................................*/
+ private void loadSequenceSpecifications(String path, File storageDir, boolean userDef){
+ if (storageDir.exists() && storageDir.isDirectory()) {
+ String[] fileNames = storageDir.list();
+ StringArray.sort(fileNames);
+ for (int i=0; i=0 && sL < sequenceProfileVector.size()) {
+ sequenceSpecification = (SequenceProfile)sequenceProfileVector.elementAt(sL);
+ }
+ storePreferences();
+ }
+ chooseSequenceProfileDialog.dispose();
+ chooseSequenceProfileDialog = null;
+ return sequenceSpecification;
+ }
+ /*.................................................................................................................*/
+ public boolean manageSequenceProfiles() {
+
+ MesquiteInteger buttonPressed = new MesquiteInteger(1);
+ chooseSequenceProfileDialog = new ManageGeneProfileDLOG(this, sequenceProfileName, buttonPressed);
+
+ if (choice !=null) {
+ sequenceProfileName = choice.getSelectedItem();
+ int sL = sequenceProfileVector.indexOfByName(sequenceProfileName);
+ if (sL >=0 && sL < sequenceProfileVector.size()) {
+ sequenceProfile = (SequenceProfile)sequenceProfileVector.elementAt(sL);
+ }
+ storePreferences();
+ }
+ chooseSequenceProfileDialog.dispose();
+ chooseSequenceProfileDialog = null;
+ return true;
+ }
+
+
+ /*.................................................................................................................*/
+ public int numSpecifications(){
+ return sequenceProfileVector.size();
+ }
+ /*.................................................................................................................*/
+ public MesquiteString getSpecification(String name){
+ int i = sequenceProfileVector.indexOfByName(name);
+ if (i<0)
+ return null;
+ Listable listable = sequenceProfileVector.elementAt(i);
+ if (listable!=null)
+ return new MesquiteString(listable.getName());
+ else
+ return null;
+ }
+ /*.................................................................................................................*/
+ public int findSpecificationIndex(String name){
+ return sequenceProfileVector.indexOfByName(name);
+ }
+ /*.................................................................................................................*/
+ public SequenceProfile getSequenceProfile(int index){
+ return (SequenceProfile)(sequenceProfileVector.elementAt(index));
+
+ }
+ /*.................................................................................................................*/
+ public MesquiteString getSpecification(int i){
+ if (i<0 || i>= sequenceProfileVector.size())
+ return null;
+ Listable listable = sequenceProfileVector.elementAt(i);
+ if (listable!=null)
+ return new MesquiteString(listable.getName());
+ else
+ return null;
+ }
+ /*.................................................................................................................*/
+ private String newSpecificationPath(String name){
+ String base = MesquiteModule.prefsDirectory+ MesquiteFile.fileSeparator + prefDirectoryName;
+ if (!MesquiteFile.fileExists(base)) {
+ File f = new File(base);
+ f.mkdir();
+ }
+ String candidate = base + MesquiteFile.fileSeparator + StringUtil.punctuationToUnderline(name)+ ".xml";
+ if (!MesquiteFile.fileExists(candidate))
+ return candidate;
+ candidate = base + MesquiteFile.fileSeparator + "specification1.xml";
+ int count = 2;
+ while (MesquiteFile.fileExists(candidate)){
+ candidate = base + MesquiteFile.fileSeparator + "specification" + (count++) + ".xml";
+ }
+ return candidate;
+ }
+ /*.................................................................................................................*/
+ public void addSpecification(SequenceProfile sequenceSpecification, String name){
+ sequenceSpecification.save(newSpecificationPath(name), name);
+ sequenceProfileVector.addElement(sequenceSpecification, false);
+ choice.add(name);
+ sequenceProfileName = name;
+ // return s;
+ }
+ /*.................................................................................................................*/
+ public SequenceProfile duplicateNameRule(SequenceProfile sequenceSpecification, String name){
+ SequenceProfile specification = new SequenceProfile(sequenceSpecification);
+ specification.setName(name);
+ specification.setPath(newSpecificationPath(name));
+ specification.save();
+ sequenceProfileVector.addElement(specification, false);
+ choice.add(name);
+ sequenceProfileName = name;
+ return specification;
+ // return s;
+ }
+ /*.................................................................................................................*/
+ void renameSpecification(int i, String name){
+ SequenceProfile specification = (SequenceProfile)sequenceProfileVector.elementAt(i);
+ specification.setName(name);
+ specification.save();
+ choice.remove(i);
+ choice.insert(name,i);
+ sequenceProfileName=name;
+ }
+ /*.................................................................................................................*/
+ void deleteSpecification(int i){
+ SequenceProfile specification = (SequenceProfile)sequenceProfileVector.elementAt(i);
+ if (specification!=null) {
+ String oldTemplateName = specification.getName();
+ File f = new File(specification.path);
+ f.delete();
+ //MesquiteString s = getNameRule(i);
+ //if (s !=null)
+ sequenceProfileVector.removeElement(specification, false); //deletes it from the vector
+ choice.remove(i);
+ }
+ }
+ /*.................................................................................................................*/
+ public String getName() {
+ return "Sequence Profile for GenBank";
+ }
+
+}
+
+
+
+/*=======================================================================*/
+class ManageGeneProfileDLOG extends ExtensibleListDialog {
+ SequenceProfileForGenBank ownerModule;
+ boolean editLastItem = false;
+
+ public ManageGeneProfileDLOG (SequenceProfileForGenBank ownerModule, String nameParsingRulesName, MesquiteInteger buttonPressed){
+ super(ownerModule.containerOfModule(), "Sequence Profile Manager", "Sequence Profile", buttonPressed, ownerModule.sequenceProfileVector);
+ this.ownerModule = ownerModule;
+ completeAndShowDialog("Done", null, true, null);
+
+ }
+ /*.................................................................................................................*/
+ public void windowOpened(WindowEvent e){
+ if (editLastItem)
+ editNumberedElement(getLastItem());
+ editLastItem = false;
+ super.windowOpened(e);
+ }
+ /*.................................................................................................................*/
+ /** this is the name of the class of objects */
+ public String objectName(){
+ return "Sequence Profile";
+ }
+ /*.................................................................................................................*/
+ /** this is the name of the class of objects */
+ public String pluralObjectName(){
+ return "Sequence Profiles";
+ }
+
+ /*.................................................................................................................*/
+ public Listable createNewElement(String name, MesquiteBoolean success){
+ hide();
+ SequenceProfile sequenceSpecification = new SequenceProfile();
+ if (sequenceSpecification.queryOptions(name)) {
+ addNewElement(sequenceSpecification,name); //add name to list
+ ownerModule.addSpecification(sequenceSpecification, name);
+ if (success!=null) success.setValue(true);
+ setVisible(true);
+ return sequenceSpecification;
+
+ }
+ else {
+ if (success!=null) success.setValue(false);
+ setVisible(true);
+ return null;
+ }
+ }
+ /*.................................................................................................................*/
+ public void deleteElement(int item, int newSelectedItem){
+ hide();
+ ownerModule.deleteSpecification(item);
+ setVisible(true);
+ }
+ /*.................................................................................................................*/
+ public void renameElement(int item, Listable element, String newName){
+ ownerModule.renameSpecification(item,newName);
+ }
+ /*.................................................................................................................*/
+ public Listable duplicateElement(String name){
+ SequenceProfile sequenceSpecification = ownerModule.duplicateNameRule((SequenceProfile)currentElement, name);
+ return sequenceSpecification;
+ }
+ /*.................................................................................................................*/
+ public boolean getEditable(int item){
+ return true;
+ }
+ /*.................................................................................................................*/
+ public void editElement(int item){
+ //hide();
+ SequenceProfile sequenceSpecification = ((SequenceProfile)ownerModule.sequenceProfileVector.elementAt(item));
+ if (sequenceSpecification.queryOptions(sequenceSpecification.getName()))
+ sequenceSpecification.save();
+ setVisible(true);
+ }
+
+
+
+
+}
+
diff --git a/Source/mesquite/chromaseq/SuffixTaxNameWCode/SuffixTaxNameWCode.java b/Source/mesquite/chromaseq/SuffixTaxNameWCode/SuffixTaxNameWCode.java
index 9e88d32d..21fa73ad 100644
--- a/Source/mesquite/chromaseq/SuffixTaxNameWCode/SuffixTaxNameWCode.java
+++ b/Source/mesquite/chromaseq/SuffixTaxNameWCode/SuffixTaxNameWCode.java
@@ -1 +1 @@
-/* Mesquite source code. Copyright 1997-2009 W. Maddison and D. Maddison.
Version 2.72, December 2009.
Disclaimer: The Mesquite source code is lengthy and we are few. There are no doubt inefficiencies and goofs in this code.
The commenting leaves much to be desired. Please approach this source code with the spirit of helping out.
Perhaps with your help we can be more than a few, and make Mesquite better.
Mesquite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
Mesquite's web site is http://mesquiteproject.org
This source code and its compiled class files are free and modifiable under the terms of
GNU Lesser General Public License. (http://www.gnu.org/copyleft/lesser.html)
*/
package mesquite.chromaseq.SuffixTaxNameWCode;
import java.util.*;
import java.awt.*;
import mesquite.chromaseq.lib.ChromaseqUtil;
import mesquite.lib.*;
import mesquite.lib.duties.*;
import mesquite.lib.table.*;
/* ======================================================================== */
public class SuffixTaxNameWCode extends TaxonNameAlterer {
/*.................................................................................................................*/
public boolean startJob(String arguments, Object condition, boolean hiredByName){
return true;
}
/*.................................................................................................................*/
/**Returns true if the module is to appear in menus and other places in which users can choose, and if can be selected in any way other than by direct request*/
public boolean getUserChooseable(){
return true;
}
/*.................................................................................................................*/
/** Called to alter the taxon name in a single cell. If you use the alterContentOfCells method of this class,
then you must supply a real method for this, not just this stub. */
public boolean alterName(Taxa taxa, int it){
boolean nameChanged = false;
String name = taxa.getTaxonName(it);
if (name!=null){
String vc = getVoucherCode(taxa, it);
if (vc != null){
if (!name.contains(vc))
taxa.setTaxonName(it, name + "." + vc, false);
}
nameChanged = true;
}
return nameChanged;
}
public String getVoucherCode(Taxa taxa, int ic){
if (taxa!=null) {
Object n = ChromaseqUtil.getStringAssociated(taxa, VoucherInfoFromOTUIDDB.voucherCodeRef, ic);
if (n !=null)
return ((String)n);
}
return null;
}
/*.................................................................................................................*/
public Object doCommand(String commandName, String arguments, CommandChecker checker) {
if (checker.compare(this.getClass(), "Appends numbers to taxon names", "[length]", commandName, "appendNumbers")) {
if (taxa !=null){
alterTaxonNames(taxa,table);
}
}
else
return super.doCommand(commandName, arguments, checker);
return null;
}
/*.................................................................................................................*/
public String getNameForMenuItem() {
return "Suffix With OTU ID Code";
}
/*.................................................................................................................*/
public String getName() {
return "Suffix With OTU ID Code";
}
/*.................................................................................................................*/
public String getExplanation() {
return "Suffixes the taxon name with the OTU ID Code.";
}
}
\ No newline at end of file
+/* Mesquite source code. Copyright 1997-2009 W. Maddison and D. Maddison.
Version 2.72, December 2009.
Disclaimer: The Mesquite source code is lengthy and we are few. There are no doubt inefficiencies and goofs in this code.
The commenting leaves much to be desired. Please approach this source code with the spirit of helping out.
Perhaps with your help we can be more than a few, and make Mesquite better.
Mesquite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
Mesquite's web site is http://mesquiteproject.org
This source code and its compiled class files are free and modifiable under the terms of
GNU Lesser General Public License. (http://www.gnu.org/copyleft/lesser.html)
*/
package mesquite.chromaseq.SuffixTaxNameWCode;
import java.util.*;
import java.awt.*;
import mesquite.chromaseq.lib.ChromaseqUtil;
import mesquite.lib.*;
import mesquite.lib.duties.*;
import mesquite.lib.table.*;
/* ======================================================================== */
public class SuffixTaxNameWCode extends TaxonNameAlterer {
/*.................................................................................................................*/
public boolean startJob(String arguments, Object condition, boolean hiredByName){
return true;
}
/*.................................................................................................................*/
/**Returns true if the module is to appear in menus and other places in which users can choose, and if can be selected in any way other than by direct request*/
public boolean getUserChooseable(){
return true;
}
/*.................................................................................................................*/
/** Called to alter the taxon name in a single cell. If you use the alterContentOfCells method of this class,
then you must supply a real method for this, not just this stub. */
public boolean alterName(Taxa taxa, int it){
boolean nameChanged = false;
String name = taxa.getTaxonName(it);
if (name!=null){
String vc = getVoucherCode(taxa, it);
if (vc != null){
if (!name.contains(vc)) {
taxa.setTaxonName(it, name + "." + vc, false);
nameChanged = true;
}
}
}
return nameChanged;
}
public String getVoucherCode(Taxa taxa, int ic){
if (taxa!=null) {
Object n = ChromaseqUtil.getStringAssociated(taxa, VoucherInfoFromOTUIDDB.voucherCodeRef, ic);
if (n !=null)
return ((String)n);
}
return null;
}
/*.................................................................................................................*/
public Object doCommand(String commandName, String arguments, CommandChecker checker) {
if (checker.compare(this.getClass(), "Appends numbers to taxon names", "[length]", commandName, "appendNumbers")) {
if (taxa !=null){
alterTaxonNames(taxa,table);
}
}
else
return super.doCommand(commandName, arguments, checker);
return null;
}
/*.................................................................................................................*/
public String getNameForMenuItem() {
return "Suffix With OTU ID Code";
}
/*.................................................................................................................*/
public String getName() {
return "Suffix With OTU ID Code";
}
/*.................................................................................................................*/
public String getExplanation() {
return "Suffixes the taxon name with the OTU ID Code.";
}
}
\ No newline at end of file
diff --git a/Source/mesquite/chromaseq/TaxonNameRootWCode/TaxonNameRootWCode.java b/Source/mesquite/chromaseq/TaxonNameRootWCode/TaxonNameRootWCode.java
new file mode 100644
index 00000000..16c92840
--- /dev/null
+++ b/Source/mesquite/chromaseq/TaxonNameRootWCode/TaxonNameRootWCode.java
@@ -0,0 +1 @@
+/* Mesquite source code. Copyright 1997-2009 W. Maddison and D. Maddison.
Version 2.72, December 2009.
Disclaimer: The Mesquite source code is lengthy and we are few. There are no doubt inefficiencies and goofs in this code.
The commenting leaves much to be desired. Please approach this source code with the spirit of helping out.
Perhaps with your help we can be more than a few, and make Mesquite better.
Mesquite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
Mesquite's web site is http://mesquiteproject.org
This source code and its compiled class files are free and modifiable under the terms of
GNU Lesser General Public License. (http://www.gnu.org/copyleft/lesser.html)
*/
package mesquite.chromaseq.TaxonNameRootWCode;
import java.util.*;
import java.awt.*;
import mesquite.chromaseq.lib.ChromaseqUtil;
import mesquite.lib.*;
import mesquite.lib.duties.*;
import mesquite.lib.table.*;
/* ======================================================================== */
public class TaxonNameRootWCode extends TaxonNameAlterer {
String startOfName = "";
/*.................................................................................................................*/
public boolean startJob(String arguments, Object condition, boolean hiredByName){
return true;
}
/*.................................................................................................................*/
/**Returns true if the module is to appear in menus and other places in which users can choose, and if can be selected in any way other than by direct request*/
public boolean getUserChooseable(){
return true;
}
/*.................................................................................................................*/
public boolean getOptions(Taxa taxa, int firstSelected){
if (MesquiteThread.isScripting())
return true;
MesquiteInteger buttonPressed = new MesquiteInteger(1);
ExtensibleDialog queryDialog = new ExtensibleDialog(containerOfModule(), "Taxon name from root + OTU ID Code", buttonPressed);
queryDialog.addLabel("Taxon name from root + OTU ID Code", Label.CENTER);
SingleLineTextField prefixField = queryDialog.addTextField("Root of name", startOfName, 12);
queryDialog.completeAndShowDialog(true);
boolean ok = (queryDialog.query()==0);
if (ok) {
startOfName = prefixField.getText();
}
queryDialog.dispose();
return ok;
}
/*.................................................................................................................*/
/** Called to alter the taxon name in a single cell. If you use the alterContentOfCells method of this class,
then you must supply a real method for this, not just this stub. */
public boolean alterName(Taxa taxa, int it){
boolean nameChanged = false;
String vc = getVoucherCode(taxa, it);
if (vc != null){
taxa.setTaxonName(it, startOfName + vc, false);
nameChanged = true;
}
return nameChanged;
}
public String getVoucherCode(Taxa taxa, int ic){
if (taxa!=null) {
Object n = ChromaseqUtil.getStringAssociated(taxa, VoucherInfoFromOTUIDDB.voucherCodeRef, ic);
if (n !=null)
return ((String)n);
}
return null;
}
/*.................................................................................................................*/
public Object doCommand(String commandName, String arguments, CommandChecker checker) {
if (checker.compare(this.getClass(), "Alters taxon names", "[length]", commandName, "appendNumbers")) {
if (taxa !=null){
alterTaxonNames(taxa,table);
}
}
else
return super.doCommand(commandName, arguments, checker);
return null;
}
/*.................................................................................................................*/
public String getNameForMenuItem() {
return "Root Text + OTU ID Code";
}
/*.................................................................................................................*/
public String getName() {
return "Root Text + OTU ID Code";
}
/*.................................................................................................................*/
public String getExplanation() {
return "Changes the taxon name to be a root text + OTU ID Code";
}
}
\ No newline at end of file
diff --git a/Source/mesquite/chromaseq/aChromaseqIntro/aChromaseqIntro.java b/Source/mesquite/chromaseq/aChromaseqIntro/aChromaseqIntro.java
index a765a594..4275dc23 100644
--- a/Source/mesquite/chromaseq/aChromaseqIntro/aChromaseqIntro.java
+++ b/Source/mesquite/chromaseq/aChromaseqIntro/aChromaseqIntro.java
@@ -1 +1 @@
-/* Mesquite Chromaseq source code. Copyright 2005-2011 David Maddison and Wayne Maddison.
Version 1.0 December 2011
Disclaimer: The Mesquite source code is lengthy and we are few. There are no doubt inefficiencies and goofs in this code.
The commenting leaves much to be desired. Please approach this source code with the spirit of helping out.
Perhaps with your help we can be more than a few, and make Mesquite better.
Mesquite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
Mesquite's web site is http://mesquiteproject.org
This source code and its compiled class files are free and modifiable under the terms of
GNU Lesser General Public License. (http://www.gnu.org/copyleft/lesser.html)
*/
package mesquite.chromaseq.aChromaseqIntro;
import mesquite.lib.duties.*;
import mesquite.lib.*;
/* ======================================================================== */
public class aChromaseqIntro extends PackageIntro {
/*.................................................................................................................*/
public boolean startJob(String arguments, Object condition, boolean hiredByName) {
return true;
}
public Class getDutyClass(){
return aChromaseqIntro.class;
}
/*.................................................................................................................*/
public String getManualPath(){
return getPackagePath() +"docs/index.html";
}
/** returns the URL of the notices file for this module so that it can phone home and check for messages */
/*.................................................................................................................*/
public String getHomePhoneNumber(){
if (MesquiteTrunk.debugMode)
return "http://chromaseq.mesquiteproject.org/noticesAndUpdates/noticesDev.xml";
else if (isPrerelease())
return "http://chromaseq.mesquiteproject.org/noticesAndUpdates/noticesPrerelease.xml";
else
return "http://chromaseq.mesquiteproject.org/noticesAndUpdates/notices.xml";
/* version 1.3 and before:
if (MesquiteTrunk.debugMode)
return "http://mesquiteproject.org/packages/chromaseq/noticesDev.xml";
else if (isPrerelease())
return "http://mesquiteproject.org/packages/chromaseq/noticesPrerelease.xml";
else
return "http://mesquiteproject.org/packages/chromaseq/notices.xml";
*/
}
/*.................................................................................................................*/
public String getExplanation() {
return "Chromaseq is a package of Mesquite modules providing tools for processing and displaying chromatograms and sequence data.";
}
/*.................................................................................................................*/
public String getName() {
return "Chromaseq Package";
}
/*.................................................................................................................*/
/** Returns the name of the package of modules (e.g., "Basic Mesquite Package", "Rhetenor")*/
public String getPackageName(){
return "Chromaseq Package";
}
/*.................................................................................................................*/
public boolean isPrerelease(){
return false;
}
/*.................................................................................................................*/
/** Returns citation for a package of modules*/
public String getPackageCitation(){
if (isPrerelease())
return "Maddison, D.R., & W.P. Maddison. 2018. Chromaseq. A package for processing chromatograms and sequence data in Mesquite. Prerelease version " + getPackageVersion() + " (build " + getBuildVersion() + ").";
return "Maddison, D.R., & W.P. Maddison. 2018. Chromaseq. A package for processing chromatograms and sequence data in Mesquite. Version " + getPackageVersion() + ".";
}
/*.................................................................................................................*/
/** Returns version for a package of modules*/
public String getPackageVersion(){
return "1.31";
}
/*.................................................................................................................*/
/** Returns version for a package of modules as an integer*/
public int getPackageVersionInt(){
return 1310;
}
/*.................................................................................................................*/
public String getPackageDateReleased(){
return "4 May 2018 ";
}
/*.................................................................................................................*/
/** Returns build number for a package of modules as an integer*/
public int getPackageBuildNumber(){
return 53;
}
/* release history:
0.981, build 12 25 July 2010 - first beta release
0.982, build 15 14 August 2010 - second beta
0.983, build 18 21 September 2010
0.984, build 19 3 October 2010
0.986, build 21 1 June 2011 - third beta
0.990, build 25 4 October 2011 - first public release, fourth beta
1.0, build 28 23 December 2011
1.01 10 December 2013
1.1 19 August 2014
1.11 (build 35) 29 August 2014
1.12 (build 36) 2 September 2014
1.2 (build 40) 27 June 2016
1.3 (build 48) 12 September 2017
1.31 (build 53) 4 May 2018
*/
/*.................................................................................................................*/
public String getPackageURL(){
return "http://chromaseq.mesquiteproject.org";
}
/*.................................................................................................................*/
/** Returns whether there is a splash banner*/
public boolean hasSplash(){
return true;
}
/*.................................................................................................................*/
public int getVersionOfFirstRelease(){
return 275;
}
}
\ No newline at end of file
+/* Mesquite Chromaseq source code. Copyright 2005-2011 David Maddison and Wayne Maddison.
Version 1.0 December 2011
Disclaimer: The Mesquite source code is lengthy and we are few. There are no doubt inefficiencies and goofs in this code.
The commenting leaves much to be desired. Please approach this source code with the spirit of helping out.
Perhaps with your help we can be more than a few, and make Mesquite better.
Mesquite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
Mesquite's web site is http://mesquiteproject.org
This source code and its compiled class files are free and modifiable under the terms of
GNU Lesser General Public License. (http://www.gnu.org/copyleft/lesser.html)
*/
package mesquite.chromaseq.aChromaseqIntro;
import mesquite.lib.duties.*;
import mesquite.lib.*;
/* ======================================================================== */
public class aChromaseqIntro extends PackageIntro {
/*.................................................................................................................*/
public boolean startJob(String arguments, Object condition, boolean hiredByName) {
return true;
}
public Class getDutyClass(){
return aChromaseqIntro.class;
}
/*.................................................................................................................*/
public String getManualPath(){
return getPackagePath() +"docs/index.html";
}
/** returns the URL of the notices file for this module so that it can phone home and check for messages */
/*.................................................................................................................*/
public String getHomePhoneNumber(){
if (MesquiteTrunk.debugMode)
return "http://chromaseq.mesquiteproject.org/noticesAndUpdates/noticesDev.xml";
else if (isPrerelease())
return "http://chromaseq.mesquiteproject.org/noticesAndUpdates/noticesPrerelease.xml";
else
return "http://chromaseq.mesquiteproject.org/noticesAndUpdates/notices.xml";
/* version 1.3 and before:
if (MesquiteTrunk.debugMode)
return "http://mesquiteproject.org/packages/chromaseq/noticesDev.xml";
else if (isPrerelease())
return "http://mesquiteproject.org/packages/chromaseq/noticesPrerelease.xml";
else
return "http://mesquiteproject.org/packages/chromaseq/notices.xml";
*/
}
/*.................................................................................................................*/
public String getExplanation() {
return "Chromaseq is a package of Mesquite modules providing tools for processing and displaying chromatograms and sequence data.";
}
/*.................................................................................................................*/
public String getName() {
return "Chromaseq Package";
}
/*.................................................................................................................*/
/** Returns the name of the package of modules (e.g., "Basic Mesquite Package", "Rhetenor")*/
public String getPackageName(){
return "Chromaseq Package";
}
/*.................................................................................................................*/
public boolean isPrerelease(){
return false;
}
/*.................................................................................................................*/
/** Returns citation for a package of modules*/
public String getPackageCitation(){
if (isPrerelease())
return "Maddison, D.R., & W.P. Maddison. 2018. Chromaseq. A package for processing chromatograms and sequence data in Mesquite. Prerelease version " + getPackageVersion() + " (build " + getBuildVersion() + ").";
return "Maddison, D.R., & W.P. Maddison. 2018. Chromaseq. A package for processing chromatograms and sequence data in Mesquite. Version " + getPackageVersion() + ".";
}
/*.................................................................................................................*/
/** Returns version for a package of modules*/
public String getPackageVersion(){
return "1.5";
}
/*.................................................................................................................*/
/** Returns version for a package of modules as an integer*/
public int getPackageVersionInt(){
return 1500;
}
/*.................................................................................................................*/
public String getPackageDateReleased(){
return "27 December 2018 ";
}
/*.................................................................................................................*/
/** Returns build number for a package of modules as an integer*/
public int getPackageBuildNumber(){
return 61;
}
/* release history:
0.981, build 12 25 July 2010 - first beta release
0.982, build 15 14 August 2010 - second beta
0.983, build 18 21 September 2010
0.984, build 19 3 October 2010
0.986, build 21 1 June 2011 - third beta
0.990, build 25 4 October 2011 - first public release, fourth beta
1.0, build 28 23 December 2011
1.01 10 December 2013
1.1 19 August 2014
1.11 (build 35) 29 August 2014
1.12 (build 36) 2 September 2014
1.2 (build 40) 27 June 2016
1.3 (build 48) 12 September 2017
1.31 (build 53) 4 May 2018
1.5 (build 61) 27 December 2018
*/
/*.................................................................................................................*/
/** Returns the integer version of the MesquiteCore version that this package requires to function*/
public int getMinimumMesquiteVersionRequiredInt(){
return 360;
}
/*.................................................................................................................*/
/** Returns the String version of the MesquiteCore version number that this package requires to function*/
public String getMinimumMesquiteVersionRequired(){
return "3.6";
}
/*.................................................................................................................*/
public String getPackageURL(){
return "http://chromaseq.mesquiteproject.org";
}
/*.................................................................................................................*/
/** Returns whether there is a splash banner*/
public boolean hasSplash(){
return true;
}
/*.................................................................................................................*/
public int getVersionOfFirstRelease(){
return 275;
}
}
\ No newline at end of file
diff --git a/Source/mesquite/chromaseq/lib/Read.java b/Source/mesquite/chromaseq/lib/Read.java
index d99585c6..f1a1ac46 100755
--- a/Source/mesquite/chromaseq/lib/Read.java
+++ b/Source/mesquite/chromaseq/lib/Read.java
@@ -1 +1 @@
-/* Mesquite Chromaseq source code. Copyright 2005-2011 David Maddison and Wayne Maddison.
Version 1.0 December 2011
Disclaimer: The Mesquite source code is lengthy and we are few. There are no doubt inefficiencies and goofs in this code.
The commenting leaves much to be desired. Please approach this source code with the spirit of helping out.
Perhaps with your help we can be more than a few, and make Mesquite better.
Mesquite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
Mesquite's web site is http://mesquiteproject.org
This source code and its compiled class files are free and modifiable under the terms of
GNU Lesser General Public License. (http://www.gnu.org/copyleft/lesser.html)
*/
package mesquite.chromaseq.lib;
import mesquite.lib.*;
import mesquite.categ.lib.*;
public class Read implements Listable {
public static final char SAMPLECODEDELIMITER = '/';
String readName;
String originalName;
String primerName;
String sampleCode;
String sampleCodeSource;
String primerToShow;
public boolean complemented;
boolean originalDirection=true;
int frameStart;
int numPaddedBases;
double averageQuality=0.0;
int numBasesHighQuality=0;
int numBasesHighQualityThreshold = 30;
String bases="";
int qualClipStart;
int qualClipEnd;
int alignClipStart;
int alignClipEnd;
String abiFile, phdFile, DSRemainder, abiFilePath;
String polyFilePath = "";
boolean polyExists;
long[] polyBases = null; // the base at this position within the RD, but in the same orientation as the contig
// padded bases are given the value of -1
boolean[] baseIsStrongDoublePeak = null;
double [] secondaryPeakFraction = null;
String phdBases = null;
int[] unpaddedBase;
int[] paddingBefore;
int[] paddingAfter;
int[] phdQuality;
int[] phdLocation;
int[] phdBoundary;
int[] locationQuality;
int pads = 0;
Contig contig;
// RegistryCoordinator registries;
/*.................................................................................................................*/
public Read (Contig contig, String readName, boolean complemented, int frameStart){
this.readName = readName;
this.complemented = complemented;
this.frameStart = frameStart;
this.contig = contig;
// this.registries = registries;
}
/*.................................................................................................................*/
public boolean getComplemented() {
return (complemented && originalDirection) || (!complemented && !originalDirection);
}
/*.................................................................................................................*/
public void setPrimerToShow(String primerName) {
this.primerToShow = primerName;
}
/*.................................................................................................................*/
public String getPrimerToShow() {
return primerToShow;
}
/*.................................................................................................................*/
public void setPrimerName(String primerName) {
this.primerName = primerName;
}
/*.................................................................................................................*/
public String getPrimerName() {
return primerName;
}
/*.................................................................................................................*/
public void setSampleCodeSource(String sampleCodeSource) {
this.sampleCodeSource = sampleCodeSource;
}
/*.................................................................................................................*/
public String getSampleCodeSource() {
return sampleCodeSource;
}
/*.................................................................................................................*/
public void setSampleCode(String sampleCode) {
this.sampleCode = sampleCode;
}
/*.................................................................................................................*/
public String getSampleCode() {
return sampleCode;
}
/*.................................................................................................................*/
public String getOriginalName() {
return originalName;
}
/*.................................................................................................................*/
public void setOriginalName(String originalName) {
this.originalName = originalName;
}
/*.................................................................................................................*/
public String getName() {
return readName;
}
/*.................................................................................................................*/
public boolean getPolyExists() {
return polyExists;
}
/*.................................................................................................................*/
public String getABIFile() {
return abiFile;
}
/*.................................................................................................................*/
public String getABIFilePath() {
return abiFilePath;
}
/*.................................................................................................................*/
public boolean isPadded(int i) { // i is the position, zero-based, in the padded consensus sequence
return polyBases[i]==-1;
}
/*.................................................................................................................*/
public long getPolyBase(int i) { // i is the position, zero-based, in the padded consensus sequence
if (polyBases!=null) {
int iBase;
/* The position within this read would be iBase = i - frameStart +1 IF this read had the same pads in it that the contig does.
If the pads don't match, then we need to adjust.
So, this means that within the RD itself, we want to get iBase=i-frameStart+1. The problem is the correspondence between
the bases in the read and the bases in the .poly file.
if read is uncomplemented:
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCC // this is the contig
RRRRRRRRRRRRRRRRRRRRRRRRRRR // for this read, framestart is -3.
Therefore, the 0'th base in the contig corresponds to the
-frameStart+1 base in the read. If there are pads in the read, then
to get to the right element in the poly file, you just count number of unpadded bases
*/
iBase = unpaddedBase[i - frameStart+1] ;
if (iBase>=0 && iBase=0 && readBase=0 && iBase=secondaryPeakFraction.length)
return 0.0;
else
return secondaryPeakFraction[i];
}
/*.................................................................................................................*/
public boolean getStrongDoublePeak(int i) { // i is the position, zero-based, in the padded consensus sequence
if (baseIsStrongDoublePeak!=null) {
int iBase;
int pos = i - frameStart+1;
if (pos<0 || pos>unpaddedBase.length-1)
return false;
iBase = unpaddedBase[i - frameStart+1] ;
if (iBase>=0 && iBase=phdBases.length())
return ' ';
else
return phdBases.charAt(i);
}
/*.................................................................................................................*/
public int getPhdBaseQuality(int i) { // i is the position, zero-based, in the padded consensus sequence
if (i<0 || phdQuality==null || i>=phdQuality.length)
return -1;
else
return phdQuality[i];
}
/*.................................................................................................................*/
public char getPolyBaseChar(int i) { // i is the position, zero-based, in the padded consensus sequence
if (i<0 || i>=polyBases.length)
return getPhdBaseChar(i);
else {
int polyBasePos = i;
if (i=polyBases.length)
return "";
else
return DNAData.getIUPACSymbol(polyBases[i]);
}
/*.................................................................................................................*/
public int getPhdLocation(int i, ContigDisplay window, boolean calcAverageIfZero) { // i is the position, zero-based, in the padded consensus sequence; returns location
if (phdLocation==null)
return -(int)(window.getApproximateNumberOfPeaksVisible()*window.getAveragePeakDistance());
if (i<0)
return (int)(i*window.getAveragePeakDistance()); //approximate
else if (i>=phdLocation.length)
return phdLocation[phdLocation.length-1]+(int)((i-phdLocation.length+1)*window.getAveragePeakDistance()); //approximate
else if (phdLocation[i]==0 && i>0 && i=0; j--) {
if (phdLocation[j]>0) {
leftNeighbor = j;
break;
}
}
for (int j = i+1; j0) {
rightNeighbor = j;
break;
}
}
if (leftNeighbor==rightNeighbor) return 0;
return phdLocation[leftNeighbor]+(phdLocation[rightNeighbor]-phdLocation[leftNeighbor])/2;
}
else
return phdLocation[i];
}
/*.................................................................................................................*/
public int getPhdLeftBoundary(int i, ContigDisplay window, boolean calcAverageIfZero) { // i is the position, zero-based, in the padded consensus sequence; returns location
int loc = getPhdLocation(i,window,calcAverageIfZero);
if (i>0)
return loc-(loc-getPhdLocation(i-1,window,calcAverageIfZero))/2;
else
return loc/2;
}
/*.................................................................................................................*/
public int getPhdRightBoundary(int i, ContigDisplay window, boolean calcAverageIfZero) { // i is the position, zero-based, in the padded consensus sequence; returns location
int loc = getPhdLocation(i,window,calcAverageIfZero);
if ( i=locationQuality.length)
return -1;
else
return locationQuality[location];
}
/*.................................................................................................................*/
public int getNumBasesHighQualityThreshold(){
return numBasesHighQualityThreshold;
}
/*.................................................................................................................*/
public int getNumBasesHighQuality(){
return numBasesHighQuality;
}
/*.................................................................................................................*/
public double getAverageQuality(){
return averageQuality;
}
/*.................................................................................................................*/
public String toString (){
StringBuffer sb = new StringBuffer(numPaddedBases+20);
sb.append("RD ");
sb.append(StringUtil.blanksToUnderline(readName));
sb.append(" " + bases.length() + " 0 0"+StringUtil.lineEnding()); //DRM don't use 0 0
for (int i = 0; i=0; i--) {
if (bases.charAt(i)=='*')
pads++;
paddingAfter[i] = pads;
}
}
/*.................................................................................................................*/
public long getPolyFileLineState(Parser lineParser, int i,double polyThreshold, MesquiteDouble secondaryFraction) {
String s = lineParser.getFirstToken();
long stateSet = DNAState.fromCharStatic(s.charAt(0));
String originalBase = s;
String position = lineParser.getNextToken(); //position
double mainHeight = MesquiteDouble.fromString(lineParser.getNextToken());
s = lineParser.getNextToken(); //?number
s = lineParser.getNextToken(); //nextState
long state2;
if (secondaryFraction!=null)
secondaryFraction.setValue(0.0);
if (!s.equalsIgnoreCase("N") && !s.equalsIgnoreCase(originalBase)) {
state2 = DNAState.fromCharStatic(s.charAt(0));
position = lineParser.getNextToken(); //position
double height2 = MesquiteDouble.fromString(lineParser.getNextToken());
if (height2>=polyThreshold*mainHeight) {
stateSet |= state2;
stateSet = CategoricalState.setUncertainty(stateSet, true);
}
if (secondaryFraction!=null)
secondaryFraction.setValue(height2/mainHeight);
}
if (complemented)
stateSet = DNAState.complement(stateSet);
return stateSet;
}
/*.................................................................................................................*/
public int numBasesInPhdFile(String directoryPath, String phdFile, StringBuffer basesBuffer){
int count=0;
String phdFilePath = directoryPath + phdFile;
boolean phdExists = MesquiteFile.fileExists(phdFilePath);
if (phdExists) {
String phdFileContents = MesquiteFile.getFileContentsAsString(phdFilePath,-1,10000);
Parser phdParser = new Parser(phdFileContents);
Parser lineParser = new Parser();
phdParser.setPosition(0);
String line="";
while (!phdParser.atEnd() && !"BEGIN_DNA".equalsIgnoreCase(line)) {
line = phdParser.getRawNextLine();
}
lineParser.setString(line);
while (!phdParser.atEnd() && !"END DNA".equalsIgnoreCase(lineParser.getFirstToken())) {
line = phdParser.getRawNextLine();
lineParser.setString(line);
if (basesBuffer!=null && !"END DNA".equalsIgnoreCase(lineParser.getFirstToken())) {
basesBuffer.append(line.charAt(0));
count++;
}
}
}
qualClipEnd = count;
alignClipEnd = count;
return count;
}
/*.................................................................................................................*/
public void processDS(String abiFile, String directoryPath, String phdFile, String DSRemainder, boolean processPolymorphisms, double polyThreshold){
boolean acquireDataFromPhDFile = StringUtil.blank(abiFile);
this.abiFile = abiFile;
this.abiFilePath = directoryPath;
this.phdFile = phdFile;
this.DSRemainder = DSRemainder;
MesquiteInteger pos = new MesquiteInteger(0);
StringBuffer phdBuffer;
if (bases==null)
phdBuffer=new StringBuffer(0);
else
phdBuffer = new StringBuffer(bases);
String phdFilePath = directoryPath + phdFile;
boolean phdExists = MesquiteFile.fileExists(phdFilePath);
if (phdExists && phdBuffer!=null) {
String phdFileContents = MesquiteFile.getFileContentsAsString(phdFilePath,-1,10000);
Parser phdParser = new Parser(phdFileContents);
phdParser.setPosition(0);
Parser lineParser = new Parser();
lineParser.setPunctuationString(":");
int maxIndex = 0;
String line="";
while (!phdParser.atEnd()) {
lineParser.setString(line);
String ds = lineParser.getFirstToken();
if ("TRACE ARRAY MAX INDEX".equalsIgnoreCase(lineParser.getFirstToken())) {
lineParser.getNextToken(); // the :
maxIndex = MesquiteInteger.fromString(lineParser.getNextToken()); // the maximum index value
locationQuality = new int[maxIndex];
break;
}
else if ("BEGIN SEQUENCE".equalsIgnoreCase(lineParser.getFirstToken())) {
if (acquireDataFromPhDFile) { //then we didn't get the abiFile info previously, so have to set some values
this.abiFile = lineParser.getNextToken();
readName = StringUtil.blanksToUnderline(this.abiFile);
complemented = readName.indexOf(".g.")>0;
StringBuffer basesBuffer = new StringBuffer();
numPaddedBases = numBasesInPhdFile(directoryPath, phdFile, basesBuffer);
bases = basesBuffer.toString();
phdBuffer = new StringBuffer(bases);
createArrays(numPaddedBases);
int baseCount=0;
for (int i=0; i=0 && !phdParser.atEnd() && (!"END_DNA".equalsIgnoreCase(line)); i--) {
if (polyBases[i] != -1) { // this is not a padded position, process
if (!StringUtil.blank(line)) {
String base = lineParser.getFirstToken();
if (base!=null) {
phdBuffer.setCharAt(i,base.charAt(0));
phdQuality[i] = MesquiteInteger.fromString(lineParser.getNextToken());
phdLocation[i] = maxIndex-MesquiteInteger.fromString(lineParser.getNextToken()); // as will be reverse complemented
}
}
line = phdParser.getRawNextLine(); // get next line
lineParser.setString(line);
}
else {
phdBuffer.setCharAt(i,'*');
phdQuality[i] = 0;
phdLocation[i] = 0;
}
}
}
else for (int i=0; i=numBasesHighQualityThreshold)
numBasesHighQuality++;
totalQuality+= qual;
int startLoc;
if (i<=0)
startLoc = 0;
else
startLoc = phdLocation[i]-(phdLocation[i]-phdLocation[i-1])/2;
int endLoc;
if (i>=phdLocation.length-1)
endLoc = maxIndex-1;
else
endLoc = phdLocation[i]+(phdLocation[i+1]-phdLocation[i])/2;
for (int j=startLoc; j<=endLoc && j>=0 && j <= maxIndex-1 ; j++)
locationQuality[j] = qual;
}
averageQuality=0.0;
if (phdLocation.length>0)
averageQuality = totalQuality/phdLocation.length;
}
}
}
phdBases = phdBuffer.toString();
if (complemented)
phdBases = DNAData.complementString(phdBases);
phdBases = phdBases.toUpperCase();
if (processPolymorphisms) {
polyFilePath = directoryPath + abiFile + ".poly";
polyExists = MesquiteFile.fileExists(polyFilePath);
if (polyExists && polyBases!=null) {
String polyFile = MesquiteFile.getFileContentsAsString(polyFilePath,-1,10000);
if (polyFile!=null) {
Parser polyParser = new Parser(polyFile);
polyParser.setPosition(0);
String line="";
while (StringUtil.blank(line))
line = polyParser.getRawNextLine(); // get first line, ignore
line = polyParser.getRawNextLine(); // get first line of data
Parser lineParser = new Parser();
lineParser.setPunctuationString("");
MesquiteBoolean isDoublePeak = new MesquiteBoolean(false);
MesquiteDouble secondaryFraction = new MesquiteDouble();
if (complemented) {
for (int i=polyBases.length-1-pads; i>=0 && !polyParser.atEnd(); i--) {
if (!StringUtil.blank(line)) {
lineParser.setString(line);
long polyBase= getPolyFileLineState(lineParser, i, polyThreshold, secondaryFraction);
if (polyBases[i] != -1) {
polyBases[i] = polyBase;
baseIsStrongDoublePeak[i] = secondaryFraction.getValue()>0.5 && getPhdBaseQuality(i)>10;
secondaryPeakFraction[i] = secondaryFraction.getValue();
}
}
line = polyParser.getRawNextLine(); // get next line
//polyBases[i] = getPolyFileLineState(lineParser, i, polyThreshold, secondaryFraction);
}
}
else for (int i=0; i0.5 && getPhdBaseQuality(i)>10;
secondaryPeakFraction[i] = secondaryFraction.getValue();
}
}
line = polyParser.getRawNextLine(); // get next line
}
}
}
}
}
public String getSequence(){
return phdBases;
}
/*.................................................................................................................*/
public void unTrimQA(){
if (qualClipStart>alignClipStart)
qualClipStart = alignClipStart;
// if (alignClipStart>qualClipStart)
// alignClipStart = qualClipStart;
if (qualClipEnd = 1 and = 1 (not zero). If the entire read is low quality, then and will both be -1.
*/
}
/*.................................................................................................................*/
public String getAFString() {
if (complemented)
return "AF "+StringUtil.blanksToUnderline(readName) + " C " + frameStart + StringUtil.lineEnding();
else
return "AF "+StringUtil.blanksToUnderline(readName) + " U " + frameStart + StringUtil.lineEnding();
}
/*.................................................................................................................*/
public int getEndLocation() {
if (phdLocation==null)
return 0;
for (int i=phdLocation.length-1; i>=0; i--)
if (MesquiteInteger.isCombinable(phdLocation[i]))
return phdLocation[i];
return 0;
}
/*.................................................................................................................*/
public void reverseComplement(int numBasesInContig){
frameStart= numBasesInContig - (frameStart+numPaddedBases);
int temp = qualClipStart;
qualClipStart=qualClipEnd;
qualClipEnd = temp;
temp = alignClipStart;
alignClipStart = alignClipEnd;
alignClipEnd = temp;
originalDirection = !originalDirection;
int[] tempArray = new int[paddingBefore.length];
tempArray = paddingBefore;
paddingBefore= IntegerArray.reverse(paddingAfter);
paddingAfter = IntegerArray.reverse(tempArray);
unpaddedBase = IntegerArray.reverse(unpaddedBase);
phdQuality = IntegerArray.reverse(phdQuality);
phdLocation = IntegerArray.reverse(phdLocation);
phdBoundary = IntegerArray.reverse(phdBoundary);
locationQuality = IntegerArray.reverse(locationQuality);
phdBases=DNAData.complementString(StringUtil.reverse(phdBases));
bases = DNAData.complementString(StringUtil.reverse(bases));
//need to adjust frameStart
}
/*.................................................................................................................*
public void createRegistries() {
contig.getRegistrationCoordinator().createPhdRegistry(numPaddedBases, readName);
}
/*.................................................................................................................*/
public void dispose() {
}
/*======== Following section is about registration ==========*/
/*.................................................................................................................*/
public int getFrameStart(){
return frameStart;
}
/*.................................................................................................................*/
/*This returns for read position i, what is the position in the consensus. */
public int getContigBaseFromReadBase(int i){
return i+frameStart-1; // - contig.getNumBasesAddedToStart();
}
/*.................................................................................................................*/
/*This returns for consensus position i, what is the position in the read. */
public int getReadBaseFromContigBase(int i){
return i-frameStart+1;// + contig.getNumBasesAddedToStart();
}
/*.................................................................................................................*/
public int getContigPositionOfLastBase(){
return getContigBaseFromReadBase(bases.length());
}
}
\ No newline at end of file
+/* Mesquite Chromaseq source code. Copyright 2005-2011 David Maddison and Wayne Maddison.
Version 1.0 December 2011
Disclaimer: The Mesquite source code is lengthy and we are few. There are no doubt inefficiencies and goofs in this code.
The commenting leaves much to be desired. Please approach this source code with the spirit of helping out.
Perhaps with your help we can be more than a few, and make Mesquite better.
Mesquite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
Mesquite's web site is http://mesquiteproject.org
This source code and its compiled class files are free and modifiable under the terms of
GNU Lesser General Public License. (http://www.gnu.org/copyleft/lesser.html)
*/
package mesquite.chromaseq.lib;
import mesquite.lib.*;
import mesquite.categ.lib.*;
public class Read implements Listable {
public static final char SAMPLECODEDELIMITER = '/';
String readName;
String originalName;
String primerName;
String sampleCode;
String sampleCodeSource;
String primerToShow;
public boolean complemented;
boolean originalDirection=true;
int frameStart;
int numPaddedBases;
double averageQuality=0.0;
int numBasesHighQuality=0;
int numBasesHighQualityThreshold = 30;
String bases="";
int qualClipStart;
int qualClipEnd;
int alignClipStart;
int alignClipEnd;
String abiFile, phdFile, DSRemainder, abiFilePath;
String polyFilePath = "";
boolean polyExists;
long[] polyBases = null; // the base at this position within the RD, but in the same orientation as the contig
// padded bases are given the value of -1
boolean[] baseIsStrongDoublePeak = null;
double [] secondaryPeakFraction = null;
String phdBases = null;
int[] unpaddedBase;
int[] paddingBefore;
int[] paddingAfter;
int[] phdQuality;
int[] phdLocation;
int[] phdBoundary;
int[] locationQuality;
int pads = 0;
Contig contig;
// RegistryCoordinator registries;
/*.................................................................................................................*/
public Read (Contig contig, String readName, boolean complemented, int frameStart){
this.readName = readName;
this.complemented = complemented;
this.frameStart = frameStart;
this.contig = contig;
// this.registries = registries;
}
/*.................................................................................................................*/
public boolean getComplemented() {
return (complemented && originalDirection) || (!complemented && !originalDirection);
}
/*.................................................................................................................*/
public void setPrimerToShow(String primerName) {
this.primerToShow = primerName;
}
/*.................................................................................................................*/
public String getPrimerToShow() {
return primerToShow;
}
/*.................................................................................................................*/
public void setPrimerName(String primerName) {
this.primerName = primerName;
}
/*.................................................................................................................*/
public String getPrimerName() {
return primerName;
}
/*.................................................................................................................*/
public void setSampleCodeSource(String sampleCodeSource) {
this.sampleCodeSource = sampleCodeSource;
}
/*.................................................................................................................*/
public String getSampleCodeSource() {
return sampleCodeSource;
}
/*.................................................................................................................*/
public void setSampleCode(String sampleCode) {
this.sampleCode = sampleCode;
}
/*.................................................................................................................*/
public String getSampleCode() {
return sampleCode;
}
/*.................................................................................................................*/
public String getOriginalName() {
return originalName;
}
/*.................................................................................................................*/
public void setOriginalName(String originalName) {
this.originalName = originalName;
}
/*.................................................................................................................*/
public String getName() {
return readName;
}
/*.................................................................................................................*/
public boolean getPolyExists() {
return polyExists;
}
/*.................................................................................................................*/
public String getABIFile() {
return abiFile;
}
/*.................................................................................................................*/
public String getABIFilePath() {
return abiFilePath;
}
/*.................................................................................................................*/
public boolean isPadded(int i) { // i is the position, zero-based, in the padded consensus sequence
return polyBases[i]==-1;
}
/*.................................................................................................................*/
public long getPolyBase(int i) { // i is the position, zero-based, in the padded consensus sequence
if (polyBases!=null) {
int iBase;
/* The position within this read would be iBase = i - frameStart +1 IF this read had the same pads in it that the contig does.
If the pads don't match, then we need to adjust.
So, this means that within the RD itself, we want to get iBase=i-frameStart+1. The problem is the correspondence between
the bases in the read and the bases in the .poly file.
if read is uncomplemented:
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCC // this is the contig
RRRRRRRRRRRRRRRRRRRRRRRRRRR // for this read, framestart is -3.
Therefore, the 0'th base in the contig corresponds to the
-frameStart+1 base in the read. If there are pads in the read, then
to get to the right element in the poly file, you just count number of unpadded bases
*/
iBase = unpaddedBase[i - frameStart+1] ;
if (iBase>=0 && iBase=0 && readBase=0 && iBase=secondaryPeakFraction.length)
return 0.0;
else
return secondaryPeakFraction[i];
}
/*.................................................................................................................*/
public boolean getStrongDoublePeak(int i) { // i is the position, zero-based, in the padded consensus sequence
if (baseIsStrongDoublePeak!=null) {
int iBase;
int pos = i - frameStart+1;
if (pos<0 || pos>unpaddedBase.length-1)
return false;
iBase = unpaddedBase[i - frameStart+1] ;
if (iBase>=0 && iBase=phdBases.length())
return ' ';
else
return phdBases.charAt(i);
}
/*.................................................................................................................*/
public int getPhdBaseQuality(int i) { // i is the position, zero-based, in the padded consensus sequence
if (i<0 || phdQuality==null || i>=phdQuality.length)
return -1;
else
return phdQuality[i];
}
/*.................................................................................................................*/
public char getPolyBaseChar(int i) { // i is the position, zero-based, in the padded consensus sequence
if (i<0 || i>=polyBases.length)
return getPhdBaseChar(i);
else {
int polyBasePos = i;
if (i=polyBases.length)
return "";
else
return DNAData.getIUPACSymbol(polyBases[i]);
}
/*.................................................................................................................*/
public int getPhdLocation(int i, ContigDisplay window, boolean calcAverageIfZero) { // i is the position, zero-based, in the padded consensus sequence; returns location
if (phdLocation==null)
return -(int)(window.getApproximateNumberOfPeaksVisible()*window.getAveragePeakDistance());
if (i<0)
return (int)(i*window.getAveragePeakDistance()); //approximate
else if (i>=phdLocation.length)
return phdLocation[phdLocation.length-1]+(int)((i-phdLocation.length+1)*window.getAveragePeakDistance()); //approximate
else if (phdLocation[i]==0 && i>0 && i=0; j--) {
if (phdLocation[j]>0) {
leftNeighbor = j;
break;
}
}
for (int j = i+1; j0) {
rightNeighbor = j;
break;
}
}
if (leftNeighbor==rightNeighbor) return 0;
return phdLocation[leftNeighbor]+(phdLocation[rightNeighbor]-phdLocation[leftNeighbor])/2;
}
else
return phdLocation[i];
}
/*.................................................................................................................*/
public int getPhdLeftBoundary(int i, ContigDisplay window, boolean calcAverageIfZero) { // i is the position, zero-based, in the padded consensus sequence; returns location
int loc = getPhdLocation(i,window,calcAverageIfZero);
if (i>0)
return loc-(loc-getPhdLocation(i-1,window,calcAverageIfZero))/2;
else
return loc/2;
}
/*.................................................................................................................*/
public int getPhdRightBoundary(int i, ContigDisplay window, boolean calcAverageIfZero) { // i is the position, zero-based, in the padded consensus sequence; returns location
int loc = getPhdLocation(i,window,calcAverageIfZero);
if ( i=locationQuality.length)
return -1;
else
return locationQuality[location];
}
/*.................................................................................................................*/
public int getNumBasesHighQualityThreshold(){
return numBasesHighQualityThreshold;
}
/*.................................................................................................................*/
public int getNumBasesHighQuality(){
return numBasesHighQuality;
}
/*.................................................................................................................*/
public double getAverageQuality(){
return averageQuality;
}
/*.................................................................................................................*/
public String toString (){
StringBuffer sb = new StringBuffer(numPaddedBases+20);
sb.append("RD ");
sb.append(StringUtil.blanksToUnderline(readName));
sb.append(" " + bases.length() + " 0 0"+StringUtil.lineEnding()); //DRM don't use 0 0
for (int i = 0; i=0; i--) {
if (bases.charAt(i)=='*')
pads++;
paddingAfter[i] = pads;
}
}
/*.................................................................................................................*/
public long getPolyFileLineState(Parser lineParser, int i,double polyThreshold, MesquiteDouble secondaryFraction) {
String s = lineParser.getFirstToken();
if (StringUtil.blank(s))
return 0; //TODO: check if this is correct value
long stateSet = DNAState.fromCharStatic(s.charAt(0));
String originalBase = s;
String position = lineParser.getNextToken(); //position
double mainHeight = MesquiteDouble.fromString(lineParser.getNextToken());
s = lineParser.getNextToken(); //?number
s = lineParser.getNextToken(); //nextState
long state2;
if (secondaryFraction!=null)
secondaryFraction.setValue(0.0);
if (s!=null && !s.equalsIgnoreCase("N") && !s.equalsIgnoreCase(originalBase)) {
state2 = DNAState.fromCharStatic(s.charAt(0));
position = lineParser.getNextToken(); //position
double height2 = MesquiteDouble.fromString(lineParser.getNextToken());
if (height2>=polyThreshold*mainHeight) {
stateSet |= state2;
stateSet = CategoricalState.setUncertainty(stateSet, true);
}
if (secondaryFraction!=null)
secondaryFraction.setValue(height2/mainHeight);
}
if (complemented)
stateSet = DNAState.complement(stateSet);
return stateSet;
}
/*.................................................................................................................*/
public int numBasesInPhdFile(String directoryPath, String phdFile, StringBuffer basesBuffer){
int count=0;
String phdFilePath = directoryPath + phdFile;
boolean phdExists = MesquiteFile.fileExists(phdFilePath);
if (phdExists) {
String phdFileContents = MesquiteFile.getFileContentsAsString(phdFilePath,-1,10000);
Parser phdParser = new Parser(phdFileContents);
Parser lineParser = new Parser();
phdParser.setPosition(0);
String line="";
while (!phdParser.atEnd() && !"BEGIN_DNA".equalsIgnoreCase(line)) {
line = phdParser.getRawNextLine();
}
lineParser.setString(line);
while (!phdParser.atEnd() && !"END DNA".equalsIgnoreCase(lineParser.getFirstToken())) {
line = phdParser.getRawNextLine();
lineParser.setString(line);
if (basesBuffer!=null && !"END DNA".equalsIgnoreCase(lineParser.getFirstToken())) {
basesBuffer.append(line.charAt(0));
count++;
}
}
}
qualClipEnd = count;
alignClipEnd = count;
return count;
}
/*.................................................................................................................*/
public void processDS(String abiFile, String directoryPath, String phdFile, String DSRemainder, boolean processPolymorphisms, double polyThreshold){
boolean acquireDataFromPhDFile = StringUtil.blank(abiFile);
this.abiFile = abiFile;
this.abiFilePath = directoryPath;
this.phdFile = phdFile;
this.DSRemainder = DSRemainder;
MesquiteInteger pos = new MesquiteInteger(0);
StringBuffer phdBuffer;
if (bases==null)
phdBuffer=new StringBuffer(0);
else
phdBuffer = new StringBuffer(bases);
String phdFilePath = directoryPath + phdFile;
boolean phdExists = MesquiteFile.fileExists(phdFilePath);
if (phdExists && phdBuffer!=null) {
String phdFileContents = MesquiteFile.getFileContentsAsString(phdFilePath,-1,10000);
Parser phdParser = new Parser(phdFileContents);
phdParser.setPosition(0);
Parser lineParser = new Parser();
lineParser.setPunctuationString(":");
int maxIndex = 0;
String line="";
while (!phdParser.atEnd()) {
lineParser.setString(line);
String ds = lineParser.getFirstToken();
if ("TRACE ARRAY MAX INDEX".equalsIgnoreCase(lineParser.getFirstToken())) {
lineParser.getNextToken(); // the :
maxIndex = MesquiteInteger.fromString(lineParser.getNextToken()); // the maximum index value
locationQuality = new int[maxIndex];
break;
}
else if ("BEGIN SEQUENCE".equalsIgnoreCase(lineParser.getFirstToken())) {
if (acquireDataFromPhDFile) { //then we didn't get the abiFile info previously, so have to set some values
this.abiFile = lineParser.getNextToken();
readName = StringUtil.blanksToUnderline(this.abiFile);
complemented = readName.indexOf(".g.")>0;
StringBuffer basesBuffer = new StringBuffer();
numPaddedBases = numBasesInPhdFile(directoryPath, phdFile, basesBuffer);
bases = basesBuffer.toString();
phdBuffer = new StringBuffer(bases);
createArrays(numPaddedBases);
int baseCount=0;
for (int i=0; i=0 && !phdParser.atEnd() && (!"END_DNA".equalsIgnoreCase(line)); i--) {
if (polyBases[i] != -1) { // this is not a padded position, process
if (!StringUtil.blank(line)) {
String base = lineParser.getFirstToken();
if (base!=null) {
phdBuffer.setCharAt(i,base.charAt(0));
phdQuality[i] = MesquiteInteger.fromString(lineParser.getNextToken());
phdLocation[i] = maxIndex-MesquiteInteger.fromString(lineParser.getNextToken()); // as will be reverse complemented
}
}
line = phdParser.getRawNextLine(); // get next line
lineParser.setString(line);
}
else {
phdBuffer.setCharAt(i,'*');
phdQuality[i] = 0;
phdLocation[i] = 0;
}
}
}
else for (int i=0; i=numBasesHighQualityThreshold)
numBasesHighQuality++;
totalQuality+= qual;
int startLoc;
if (i<=0)
startLoc = 0;
else
startLoc = phdLocation[i]-(phdLocation[i]-phdLocation[i-1])/2;
int endLoc;
if (i>=phdLocation.length-1)
endLoc = maxIndex-1;
else
endLoc = phdLocation[i]+(phdLocation[i+1]-phdLocation[i])/2;
for (int j=startLoc; j<=endLoc && j>=0 && j <= maxIndex-1 ; j++)
locationQuality[j] = qual;
}
averageQuality=0.0;
if (phdLocation.length>0)
averageQuality = totalQuality/phdLocation.length;
}
}
}
phdBases = phdBuffer.toString();
if (complemented)
phdBases = DNAData.complementString(phdBases);
phdBases = phdBases.toUpperCase();
if (processPolymorphisms) {
polyFilePath = directoryPath + abiFile + ".poly";
polyExists = MesquiteFile.fileExists(polyFilePath);
if (polyExists && polyBases!=null) {
String polyFile = MesquiteFile.getFileContentsAsString(polyFilePath,-1,10000);
if (polyFile!=null) {
Parser polyParser = new Parser(polyFile);
polyParser.setPosition(0);
String line="";
while (StringUtil.blank(line))
line = polyParser.getRawNextLine(); // get first line, ignore
line = polyParser.getRawNextLine(); // get first line of data
Parser lineParser = new Parser();
lineParser.setPunctuationString("");
MesquiteBoolean isDoublePeak = new MesquiteBoolean(false);
MesquiteDouble secondaryFraction = new MesquiteDouble();
if (complemented) {
for (int i=polyBases.length-1-pads; i>=0 && !polyParser.atEnd(); i--) {
if (!StringUtil.blank(line)) {
lineParser.setString(line);
long polyBase= getPolyFileLineState(lineParser, i, polyThreshold, secondaryFraction);
if (polyBases[i] != -1) {
polyBases[i] = polyBase;
baseIsStrongDoublePeak[i] = secondaryFraction.getValue()>0.5 && getPhdBaseQuality(i)>10;
secondaryPeakFraction[i] = secondaryFraction.getValue();
}
}
line = polyParser.getRawNextLine(); // get next line
//polyBases[i] = getPolyFileLineState(lineParser, i, polyThreshold, secondaryFraction);
}
}
else for (int i=0; i0.5 && getPhdBaseQuality(i)>10;
secondaryPeakFraction[i] = secondaryFraction.getValue();
}
}
line = polyParser.getRawNextLine(); // get next line
}
}
}
}
}
public String getSequence(){
return phdBases;
}
/*.................................................................................................................*/
public void unTrimQA(){
if (qualClipStart>alignClipStart)
qualClipStart = alignClipStart;
// if (alignClipStart>qualClipStart)
// alignClipStart = qualClipStart;
if (qualClipEnd = 1 and = 1 (not zero). If the entire read is low quality, then and will both be -1.
*/
}
/*.................................................................................................................*/
public String getAFString() {
if (complemented)
return "AF "+StringUtil.blanksToUnderline(readName) + " C " + frameStart + StringUtil.lineEnding();
else
return "AF "+StringUtil.blanksToUnderline(readName) + " U " + frameStart + StringUtil.lineEnding();
}
/*.................................................................................................................*/
public int getEndLocation() {
if (phdLocation==null)
return 0;
for (int i=phdLocation.length-1; i>=0; i--)
if (MesquiteInteger.isCombinable(phdLocation[i]))
return phdLocation[i];
return 0;
}
/*.................................................................................................................*/
public void reverseComplement(int numBasesInContig){
frameStart= numBasesInContig - (frameStart+numPaddedBases);
int temp = qualClipStart;
qualClipStart=qualClipEnd;
qualClipEnd = temp;
temp = alignClipStart;
alignClipStart = alignClipEnd;
alignClipEnd = temp;
originalDirection = !originalDirection;
int[] tempArray = new int[paddingBefore.length];
tempArray = paddingBefore;
paddingBefore= IntegerArray.reverse(paddingAfter);
paddingAfter = IntegerArray.reverse(tempArray);
unpaddedBase = IntegerArray.reverse(unpaddedBase);
phdQuality = IntegerArray.reverse(phdQuality);
phdLocation = IntegerArray.reverse(phdLocation);
phdBoundary = IntegerArray.reverse(phdBoundary);
locationQuality = IntegerArray.reverse(locationQuality);
phdBases=DNAData.complementString(StringUtil.reverse(phdBases));
bases = DNAData.complementString(StringUtil.reverse(bases));
//need to adjust frameStart
}
/*.................................................................................................................*
public void createRegistries() {
contig.getRegistrationCoordinator().createPhdRegistry(numPaddedBases, readName);
}
/*.................................................................................................................*/
public void dispose() {
}
/*======== Following section is about registration ==========*/
/*.................................................................................................................*/
public int getFrameStart(){
return frameStart;
}
/*.................................................................................................................*/
/*This returns for read position i, what is the position in the consensus. */
public int getContigBaseFromReadBase(int i){
return i+frameStart-1; // - contig.getNumBasesAddedToStart();
}
/*.................................................................................................................*/
/*This returns for consensus position i, what is the position in the read. */
public int getReadBaseFromContigBase(int i){
return i-frameStart+1;// + contig.getNumBasesAddedToStart();
}
/*.................................................................................................................*/
public int getContigPositionOfLastBase(){
return getContigBaseFromReadBase(bases.length());
}
}
\ No newline at end of file
diff --git a/Source/mesquite/chromaseq/lib/SequenceProfile.java b/Source/mesquite/chromaseq/lib/SequenceProfile.java
new file mode 100644
index 00000000..690e3ff2
--- /dev/null
+++ b/Source/mesquite/chromaseq/lib/SequenceProfile.java
@@ -0,0 +1,340 @@
+/* Mesquite Chromaseq source code. Copyright 2005-2011 David Maddison and Wayne Maddison.
+Version 1.0 December 2011
+Disclaimer: The Mesquite source code is lengthy and we are few. There are no doubt inefficiencies and goofs in this code.
+The commenting leaves much to be desired. Please approach this source code with the spirit of helping out.
+Perhaps with your help we can be more than a few, and make Mesquite better.
+
+Mesquite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
+Mesquite's web site is http://mesquiteproject.org
+
+This source code and its compiled class files are free and modifiable under the terms of
+GNU Lesser General Public License. (http://www.gnu.org/copyleft/lesser.html)
+ */
+
+
+package mesquite.chromaseq.lib;
+
+import java.awt.*;
+import java.util.regex.*;
+
+import org.dom4j.*;
+
+import mesquite.lib.*;
+
+public class SequenceProfile implements Listable, Explainable {
+
+ public String location = "genome";
+ public String moltype = "DNA";
+ public String description = "";
+ public String productName = "";
+ public String seqIDSuffix = "";
+ public String note = "";
+ //public boolean CDS = true;
+ int gcode= 1;
+
+ public String path;
+
+ public String name = "default";
+ public String explanation;
+
+ public SequenceProfile() {
+ }
+
+ public SequenceProfile(SequenceProfile spec) {
+ if (spec!=null) {
+ description = spec.description;
+ location = spec.location;
+ moltype = spec.moltype;
+ productName = spec.productName;
+ seqIDSuffix = spec.seqIDSuffix;
+ note = spec.note;
+ gcode = spec.gcode;
+ name = spec.name;
+// CDS = spec.CDS;
+ }
+ }
+
+ public void setPath(String path){
+ this.path = path;
+ }
+ public void setNote(String note){
+ this.note = note;
+ }
+ public String getNote(){
+ return note;
+ }
+ public void setName(String name){
+ this.name = name;
+ }
+ public String getName(){
+ return name;
+ }
+ public String getProductName(){
+ return productName;
+ }
+ public String getDescription(){
+ return description;
+ }
+/* public boolean isCDS(){
+ return CDS;
+ }
+ */
+ public String getLocation(){
+ return location;
+ }
+ public int getTranslationTable(){
+ return gcode;
+ }
+ public String getExplanation(){
+ return explanation;
+ }
+ String getProcessedTokenForWrite(String s) {
+ if (" ".equals(s))
+ return "\\ ";
+ else if (StringUtil.blank(s))
+ return " ";
+ else
+ return s;
+ }
+ public String getXML(){
+ Element mesquiteElement = DocumentHelper.createElement("mesquite");
+ Document doc = DocumentHelper.createDocument(mesquiteElement);
+ Element sequenceProfileElement = DocumentHelper.createElement("sequenceProfile");
+ mesquiteElement.add(sequenceProfileElement);
+ XMLUtil.addFilledElement(sequenceProfileElement, "version","1");
+ Element boundedByTokensElement = DocumentHelper.createElement("boundedByTokens");
+ sequenceProfileElement.add(boundedByTokensElement);
+ XMLUtil.addFilledElement(boundedByTokensElement, "name",name);
+ XMLUtil.addFilledElement(boundedByTokensElement, "description",DocumentHelper.createCDATA(description));
+ XMLUtil.addFilledElement(boundedByTokensElement, "location",DocumentHelper.createCDATA(location));
+ XMLUtil.addFilledElement(boundedByTokensElement, "moltype",DocumentHelper.createCDATA(moltype));
+ XMLUtil.addFilledElement(boundedByTokensElement, "productName",DocumentHelper.createCDATA(productName));
+ XMLUtil.addFilledElement(boundedByTokensElement, "seqIDSuffix",DocumentHelper.createCDATA(seqIDSuffix));
+ XMLUtil.addFilledElement(boundedByTokensElement, "gcode",DocumentHelper.createCDATA(""+gcode));
+ XMLUtil.addFilledElement(boundedByTokensElement, "note",DocumentHelper.createCDATA(""+note));
+// XMLUtil.addFilledElement(boundedByTokensElement, "CDS",DocumentHelper.createCDATA(MesquiteBoolean.toTrueFalseString(CDS)));
+ return XMLUtil.getDocumentAsXMLString(doc);
+ }
+ public void save(String path, String name){
+ this.name = name;
+ this.path = path;
+ MesquiteFile.putFileContents(path, getXML(), true);
+ }
+
+ public void save(){
+ if (path!=null)
+ MesquiteFile.putFileContents(path, getXML(), true);
+ }
+
+ /*.................................................................................................................*/
+ public boolean readXML(String contents) {
+ Element root = XMLUtil.getRootXMLElementFromString("mesquite", contents);
+ if (root==null)
+ return false;
+
+ Element sequenceProfileElement = root.element("sequenceProfile");
+ if (sequenceProfileElement != null) {
+ Element versionElement = sequenceProfileElement.element("version");
+ if (versionElement == null || !versionElement.getText().equals("1")) {
+ return false;
+ }
+ Element boundedByTokens = sequenceProfileElement.element("boundedByTokens");
+ if (boundedByTokens == null) {
+ return false;
+ }
+ name = boundedByTokens.elementText("name");
+ description = boundedByTokens.elementText("description");
+ location = boundedByTokens.elementText("location");
+ moltype = boundedByTokens.elementText("moltype");
+ productName = boundedByTokens.elementText("productName");
+ seqIDSuffix = boundedByTokens.elementText("seqIDSuffix");
+ note = boundedByTokens.elementText("note");
+ gcode = MesquiteInteger.fromString(boundedByTokens.elementText("gcode"));
+// CDS = MesquiteBoolean.fromTrueFalseString(boundedByTokens.elementText("CDS"));
+ //translateSampleCodes = MesquiteBoolean.fromTrueFalseString(boundedByTokens.elementTextTrim("translateSampleCodes"));
+ } else {
+ return false;
+ }
+ return true;
+ }
+
+ /*.................................................................................................................*/
+ public String getFASTASourceModifiers() {
+ StringBuffer sb = new StringBuffer();
+ // sb.append("[productName = " + productName + "] ");
+ // sb.append("[description = " + description + "] ");
+ sb.append("[location = " + location + "] ");
+ if (location.equalsIgnoreCase("Mitochondrion"))
+ sb.append("[mgcode = " + gcode + "] ");
+ else
+ sb.append("[gcode = " + gcode + "] ");
+ sb.append("[moltype = " + moltype + "] ");
+ if (StringUtil.notEmpty(note))
+ sb.append("[note = " + note + "] ");
+ return sb.toString();
+ }
+ /*.................................................................................................................*/
+ public String getSeqIDSuffix() {
+ return seqIDSuffix;
+ }
+
+ /*.................................................................................................................*
+ public String processTokenAfterRead(String s) {
+ if ("\\ ".equals(s))
+ return " ";
+ else if (StringUtil.blank(s))
+ return "";
+ else
+ return s;
+ }
+ /*.................................................................................................................*/
+ public String[] moltypeStrings() { // from http://www.insdc.org/controlled-vocabulary-moltype-qualifier
+ return new String[] {
+ "genomic DNA",
+ "genomic RNA",
+ "mRNA",
+ "tRNA",
+ "rRNA",
+ "other RNA",
+ "other DNA",
+ "transcribed RNA",
+ "viral cRNA",
+ "unassigned DNA",
+ "unassigned RNA"
+ };
+ }
+ /*.................................................................................................................*/
+ public String[] organelleStrings() { // from http://www.insdc.org/controlled-vocabulary-organelle-qualifier
+ return new String[] {
+ "chromatophore",
+ "hydrogenosome",
+ "mitochondrion",
+ "nucleomorph",
+ "plastid",
+ "mitochondrion:kinetoplast",
+ "plastid:chloroplast",
+ "plastid:apicoplast",
+ "plastid:chromoplast",
+ "plastid:cyanelle",
+ "plastid:leucoplast",
+ "plastid:proplastid"
+ };
+ }
+ /*.................................................................................................................*/
+ public String[] locationStrings() { // from https://www.ncbi.nlm.nih.gov/projects/Sequin/sequin.hlp.html#Location
+ return new String[] {
+ "Genomic",
+ "Mitochondrion",
+ "Chloroplast",
+ "Apicoplast",
+ "Chromatophore",
+ "Chromoplast",
+ "Cyanelle",
+ "Endogenous_virus",
+ "Extrachromosomal",
+ "Hydrogenosome",
+ "Kinetoplast",
+ "Leucoplast",
+ "Macronuclear",
+ "Nucleomorph",
+ "Plasmid",
+ "Plastid",
+ "Proplastid",
+ "Proviral"
+ };
+ }
+ /*.................................................................................................................*/
+ public String[] molecularStrings() {
+ return new String[] {
+ "DNA",
+ "RNA"
+ };
+ }
+
+ /*.................................................................................................................*/
+ public String[] gCodeStrings() {
+ return new String[] {
+ "The Standard Code",
+ "The Vertebrate Mitochondrial Code",
+ "The Yeast Mitochondrial Code",
+ "The Mold, Protozoan, and Coelenterate Mitochondrial Code and the Mycoplasma/Spiroplasma Code",
+ "The Invertebrate Mitochondrial Code",
+ "The Ciliate, Dasycladacean and Hexamita Nuclear Code",
+ "The Echinoderm and Flatworm Mitochondrial Code",
+ "The Euplotid Nuclear Code",
+ "The Bacterial, Archaeal and Plant Plastid Code",
+ "The Alternative Yeast Nuclear Code",
+ "The Ascidian Mitochondrial Code",
+ "The Alternative Flatworm Mitochondrial Code",
+ "Chlorophycean Mitochondrial Code",
+ "Trematode Mitochondrial Code",
+ "Scenedesmus obliquus Mitochondrial Code",
+ "Thraustochytrium Mitochondrial Code",
+ "Pterobranchia Mitochondrial Code",
+ "Candidate Division SR1 and Gracilibacteria Code",
+ "Pachysolen tannophilus Nuclear Code",
+ "Karyorelict Nuclear",
+ "Condylostoma Nuclear",
+ "Mesodinium Nuclear",
+ "Peritrich Nuclear",
+ "Blastocrithidia Nuclear"
+ };
+ }
+
+ /*.................................................................................................................*/
+ public boolean queryOptions(String name) {
+ MesquiteInteger buttonPressed = new MesquiteInteger(1);
+ ExtensibleDialog dialog = new ExtensibleDialog(MesquiteTrunk.mesquiteTrunk.containerOfModule(), "Sequence Profile",buttonPressed); //MesquiteTrunk.mesquiteTrunk.containerOfModule()
+ if (!StringUtil.blank(name))
+ dialog.addLabel("Sequence Profile: "+name);
+ else
+ dialog.addLabel("Sequence Profile");
+
+ SingleLineTextField descriptionField = dialog.addTextField("Description of sequence*:", description,80, true);
+ SingleLineTextField productNameField = dialog.addTextField("Product name:", productName, 80, true);
+ int item = StringArray.indexOfIgnoreCase(locationStrings(), location);
+ if (item<0) item=0;
+ Choice locationChoice = dialog.addPopUpMenu("Location*", locationStrings(), item);
+ item = StringArray.indexOfIgnoreCase(moltypeStrings(), moltype);
+ Choice geneticCodeChoice = dialog.addPopUpMenu("Genetic Code*", gCodeStrings(), gcode-1);
+ if (item<0) item=0;
+ Choice moltypeChoice = dialog.addPopUpMenu("Molecular type*", moltypeStrings(), item);
+ SingleLineTextField noteField = dialog.addTextField("Note:", note,80, true);
+ SingleLineTextField seqIDSuffixField = dialog.addTextField("SeqID suffix*:", seqIDSuffix,30, true);
+ //Checkbox CDSbox = dialog.addCheckBox("CDS", CDS);
+
+ dialog.addHorizontalLine(2);
+
+
+ // Checkbox requiresExtensionBox = dialog.addCheckBox("only process files with standard extensions (ab1,abi,ab,CRO,scf)", requiresExtension);
+
+
+ String s = "For each gene, gene fragment, or type of sequence data, this allows you to create a profile for that gene; the information in this profile "
+ + "is then included in your submission to GenBank .\n";
+ dialog.appendToHelpString(s);
+
+ dialog.completeAndShowDialog(true);
+ if (buttonPressed.getValue()==0) {
+ description = descriptionField.getText();
+ location = locationChoice.getSelectedItem();
+ moltype = moltypeChoice.getSelectedItem();
+ productName = productNameField.getText();
+ seqIDSuffix = seqIDSuffixField.getText();
+ note = noteField.getText();
+ gcode = geneticCodeChoice.getSelectedIndex()+1;
+// CDS =CDSbox.getState();
+ // translateSampleCodes = translateCodesBox.getState();
+ }
+ //storePreferences(); // do this here even if Cancel pressed as the File Locations subdialog box might have been used
+ dialog.dispose();
+ return (buttonPressed.getValue()==0);
+ }
+
+ /*.................................................................................................................*/
+ public String getDefinitions (MesquiteModule ownerModule){
+ return "";
+
+ }
+
+
+}
diff --git a/Source/mesquite/chromaseq/lib/SequenceProfileManager.java b/Source/mesquite/chromaseq/lib/SequenceProfileManager.java
new file mode 100644
index 00000000..ee552c79
--- /dev/null
+++ b/Source/mesquite/chromaseq/lib/SequenceProfileManager.java
@@ -0,0 +1,56 @@
+/* Mesquite Chromaseq source code. Copyright 2005-2011 David Maddison and Wayne Maddison.
+Version 1.0 December 2011
+Disclaimer: The Mesquite source code is lengthy and we are few. There are no doubt inefficiencies and goofs in this code.
+The commenting leaves much to be desired. Please approach this source code with the spirit of helping out.
+Perhaps with your help we can be more than a few, and make Mesquite better.
+
+Mesquite is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
+Mesquite's web site is http://mesquiteproject.org
+
+This source code and its compiled class files are free and modifiable under the terms of
+GNU Lesser General Public License. (http://www.gnu.org/copyleft/lesser.html)
+ */
+
+package mesquite.chromaseq.lib;
+
+
+import mesquite.lib.*;
+import mesquite.lib.duties.*;
+import java.awt.*;
+
+/* Modules of this duty class are responsible for being able to supply the sample code and primer name given the chromatogram file name */
+public abstract class SequenceProfileManager extends MesquiteInit {
+
+ public Class getDutyClass(){
+ return SequenceProfileManager.class;
+ }
+
+ public abstract String getSequenceModifiers(int sequenceType);
+
+ public abstract String[] getListOfProfiles();
+
+ public abstract boolean manageSequenceProfiles();
+
+ public boolean queryOptions(){
+ return true;
+ }
+
+ public boolean optionsSpecified(){
+ return false;
+ }
+
+ /*.................................................................................................................*/
+ public abstract SequenceProfile getSequenceProfile(int index);
+
+ /*.................................................................................................................*/
+ public abstract int findSpecificationIndex(String name);
+
+
+ public boolean hasOptions(){
+ return false;
+ }
+
+
+}
+
+
diff --git a/docs/Templates/ChromaseqTemplate.dwt b/docs/Templates/ChromaseqTemplate.dwt
index cb1a4b9b..4a6a4c56 100644
--- a/docs/Templates/ChromaseqTemplate.dwt
+++ b/docs/Templates/ChromaseqTemplate.dwt
@@ -41,8 +41,10 @@
Maddison, D.R., & W.P. Maddison. 2018. Chromaseq: a Mesquite
- package for analyzing sequence chromatograms. Version 1.31. http://chromaseq.mesquiteproject.org
-
If your analysis involved Phred and Phrap (which virtually all uses of Chromaseq would), then you must also cite Phred and Phrap (see the Phred and Phrap documentation for details).
+ package for analyzing sequence chromatograms. Version 1.5. http://chromaseq.mesquiteproject.org
+
If your analysis involved Phred and Phrap (which many uses of Chromaseq would), then you must also cite Phred and Phrap (see the Phred and Phrap documentation for details).
@@ -216,6 +227,7 @@
var PreparingDataPanel = null;
var CreditPanel = null;
var HelpPanel = null;
+var GenBankPanel = null;
var OtherFeaturesPanel = null;
var TechnicalPanel = null;
@@ -249,6 +261,11 @@
else
HelpPanel = new Spry.Widget.CollapsiblePanel("HelpPanel", {contentIsOpen: false});
+if (qsParm['GenBankPanel']=='open')
+ GenBankPanel = new Spry.Widget.CollapsiblePanel("GenBankPanel", {contentIsOpen: true});
+else
+ GenBankPanel = new Spry.Widget.CollapsiblePanel("GenBankPanel", {contentIsOpen: false});
+
if (qsParm['OtherFeaturesPanel']=='open')
OtherFeaturesPanel = new Spry.Widget.CollapsiblePanel("OtherFeaturesPanel", {contentIsOpen: true});
else
diff --git a/docs/conflicts.html b/docs/conflicts.html
index e26f559d..8b792653 100644
--- a/docs/conflicts.html
+++ b/docs/conflicts.html
@@ -41,8 +41,10 @@
Conflicts between a read and the ba
var PreparingDataPanel = null;
var CreditPanel = null;
var HelpPanel = null;
+var GenBankPanel = null;
var OtherFeaturesPanel = null;
var TechnicalPanel = null;
@@ -270,6 +282,11 @@
Conflicts between a read and the ba
else
HelpPanel = new Spry.Widget.CollapsiblePanel("HelpPanel", {contentIsOpen: false});
+if (qsParm['GenBankPanel']=='open')
+ GenBankPanel = new Spry.Widget.CollapsiblePanel("GenBankPanel", {contentIsOpen: true});
+else
+ GenBankPanel = new Spry.Widget.CollapsiblePanel("GenBankPanel", {contentIsOpen: false});
+
if (qsParm['OtherFeaturesPanel']=='open')
OtherFeaturesPanel = new Spry.Widget.CollapsiblePanel("OtherFeaturesPanel", {contentIsOpen: true});
else
diff --git a/docs/display.html b/docs/display.html
index 488edf1e..b1261cd5 100644
--- a/docs/display.html
+++ b/docs/display.html
@@ -43,8 +43,10 @@
You can download and install Chromaseq in one of two ways:
-
Start Mesquite 3.4 or later. Choose File>Check Now for Notices/Installs. In the dialog box that is presented, enter http://chromaseq.mesquiteproject.org/noticesAndUpdates/install.xml, and press OK.
+
Start Mesquite 3.6 or later. Choose File>Check Now for Notices/Installs. In the dialog box that is presented, enter http://chromaseq.mesquiteproject.org/noticesAndUpdates/install.xml, and press OK.
Download the package from this page from the Chromaseq Github release page, and download the latest release by pressing the appropriate green button. We suggest you download the zip version if you have MacOSX or Windows, and the tgz version if you have a Linux system. To install Cartographer, open up the
downloaded file, find the directory contained therein
called "chromaseq",
@@ -236,6 +247,7 @@
var PreparingDataPanel = null;
var CreditPanel = null;
var HelpPanel = null;
+var GenBankPanel = null;
var OtherFeaturesPanel = null;
var TechnicalPanel = null;
@@ -269,6 +281,11 @@
else
HelpPanel = new Spry.Widget.CollapsiblePanel("HelpPanel", {contentIsOpen: false});
+if (qsParm['GenBankPanel']=='open')
+ GenBankPanel = new Spry.Widget.CollapsiblePanel("GenBankPanel", {contentIsOpen: true});
+else
+ GenBankPanel = new Spry.Widget.CollapsiblePanel("GenBankPanel", {contentIsOpen: false});
+
if (qsParm['OtherFeaturesPanel']=='open')
OtherFeaturesPanel = new Spry.Widget.CollapsiblePanel("OtherFeaturesPanel", {contentIsOpen: true});
else
diff --git a/docs/extraSequences.html b/docs/extraSequences.html
index 923e3a21..a4f45016 100644
--- a/docs/extraSequences.html
+++ b/docs/extraSequences.html
@@ -41,8 +41,10 @@
-Chromaseq has one feature designed to aid submitting sequences contained in a Mesquite file to GenBank.
-
-
Preparation of files for submission by Sequin
-
-
This system is built to submit sequences from one gene at a time.
+
Preparation of files for submission using tbl2asn
+
Chromaseq has two features designed to aid submitting sequences contained in a Mesquite file to GenBank. The primary tool, described here, allows for preparing files for use by tbl2asn. There is also a legacy tool for submitting sequences via Sequin.
+
This system is built to submit sequences from one matrix at a time.
To prepare
- files for submission by Sequin, you will need the following:
+ files for submission by tbl2asn, you will need the following:
-
A Mesquite file containing your sequences from one gene.
-
A tab-delimited text file containing information about each sequence to
- be submitted. This file contains organism's name, authority, locality data,
+
A tab-delimited text file containing information about each sample whose data will be submitted. This file contains organism's name, authority, locality data,
etc. This is called the "OTU ID code Database" or "OTU ID code DB" file in Mesquite.
+
A Mesquite file containing your sequences in a matrix. This will need to be prepared, including setting of codon positions for protein-coding regions.
-
The form of the tab-delimited OTU (specimen voucher) ID code file is as follows. The first row
+
With these ready basic procedure is to then:
+
+
Export the matrix and feature table from within Mesquite. This will involve creating or choosing a sequence profile containing information about the properties of the sequences such as the genetic code, sequence description, etc.
+
Run tbl2asn to create the file to be submitted to GenBank.
+
+
Download tbl2asn and get it ready for use
+
To create the file for submission to GenBank, you will need to use the program tbl2asn. Information about this program is available from
Download tbl2asn, and put it in the same directory as the files that you will create in the export process (see below).
+
You may need to make the file executable. On a UNIX-based machine (MacOSX or Linux), open up a shell (e.g., Terminal on a Mac), cd into the directory containing the file, and then use a command like the following:
chmod +x mac.tbl2asn
+
Creating the file containing information about the paper
+
Go to the NCBI Submission Portal and create a Submission Template for your paper. This will contain information about your submission to GenBank. Once you have filled in the form, press the Create Template button at the bottom of the page. That will create a text file containing information about your paper, and that file will be downloaded to your computer. Move that file (which will likely be called "template.sbt.txt"), and move it into the same folder as the fasta files you created. You will only need to make this file once; the one file can be used for all of your submissions for that paper.
+
Creating the sample table
+
The form of the tab-delimited OTU (specimen voucher) ID code file containing the information about the samples is as follows. The first row
must begin with the word "code", followed by a tab-delimited list
of the official GenBank names of the fields that appear in each of the later
lines. For example,
@@ -203,12 +226,12 @@
Preparation of files for submission by Sequin
field, the latitude and longitude, and the information identifying the specimen
voucher, then this first line would appear as follows:
code organism authority identified-by country lat-lon specimen-voucher
-
(The black triangle, , represents
+
(The black triangle, , represents
a tab.)
The official GenBank names of the fields and the definition of those fields
is given on the Modifiers
- for FASTA Definition Lines page, with more information on the Sequin
- Help page. You may include whatever fields you need.
+ for FASTA Definition Lines page, with more information on the Sequin
+ Help page. You may include whatever fields you need.
On the following lines are the data about the specimens, one line
for each specimen. The first item in the line is and ID code. This ID code
could be your specimen voucher code, or some other unique identifying string.
@@ -230,53 +253,111 @@
Preparation of files for submission by Sequin
USA: Mississippi: Walthall Co., Tylertown 31.0414 N 90.1922 W Personal: DRMaddison : DNA1290
1633 Bembidion (Odontium) aenulum Bembidion aenulum Hayward David Maddison
USA: Iowa: Jones Co., Oxford Junction 41.99133 N 91.00671 W Personal: DRMaddison : DNA1633
-
-
-
Creating the FASTA file
-
Once you have completed the OTU ID code DB file, then in
- Mesquite open your file containing the sequences, and go to the Taxa List
+
Preparing the matrix and connecting the taxa to their metadata
+
For each matrix to be submitted, you will need to annotated the sequences appropriately.
+
In particular, the codon positions will need to be specified if any of the sequence are protein-coding. You can specify the codon positions in the List of Characters window in Mesquite. This does not necessarily require that the sequences be aligned, but it will be easier if they are. If they are not aligned, then each will need to be in the correct reading frame (which you can accomplish using the "Alter>Shift to Minimize Stop Codons" tool in Mesquite's matrix editor after you have specified the codon positions in general.
+
In addition, if there are distinct regions in the fragment that need to be specified in your GenBank submission (e.g., exons and introns, or multiple genes with intervening non-transcribed regions), then you will need to specify these using Character Groups, which you can do in Mesquite's List of Characters window.
+
You will also need to specify which taxon in your matrix corresponds to which entry in your sample table file. To do this, go to the Taxa List
Window (Taxa&Tree>List
- of
- Taxa). You will need to show two new columns in this table. Choose Columns>OTU
- Database and Columns>OTU ID Code. This will show those two columns. Select
- the entire table (with Select All), and touch on the title of the OTU ID code
+ of
+ Taxa). You will need to show two new columns in this table. Choose Columns>OTU
+ Database and Columns>OTU ID Code. This will show those two columns. Select
+ the entire table (with Select All), and touch on the title of the OTU ID code
DB column. A menu will appear in which you can choose to browse for your tab-delimited
- OTU ID code DB file. Select that file. The OTU ID code DB column should indicate
+ OTU ID code DB file. Select that file. The OTU ID code DB column should indicate
which
- OTU ID code DB file to use for each sequence. (In this example, all sequences
+ OTU ID code DB file to use for each sequence. (In this example, all sequences
are using the same OTU ID code DB file.)
Now you need to enter into the OTU code ID field the ID codes for each of the
sequences. In the example here, the OTU ID code for the first sequence
is 1290. This tells Mesquite to look
- in the OTU ID code DB file for the line whose code is 1290 to get the OTU
+ in the OTU ID code DB file for the line whose code is 1290 to get the OTU
information for that sequence. To enter ID codes, use the editing tool () select the entry, or select the sequence and
use the popup menu that appears when you touch on the OTU ID Code title at the
top of the column. Once you have entered all of the OTU ID codes, the Taxa List Window should look something
like this:
-
At this point, you are ready to export a FASTA file with your voucher information
- contained within it, ready to be imported in Sequin. Do this by choose File>Export,
- and in the dialog that appears, choose "FASTA (DNA/RNA) for GenBank Deposition".
+
Creating the FASTA file and feature table file needed by tbl2asn
+
At this point, you are ready to export the files needed by tbl2asn to create your GenBank submission.
+
Do this by choose File>Export,
+ and in the dialog that appears, choose "FASTA (DNA/RNA) for GenBank (tbl2asn)".
You will be queried for options:
-
-
-
Importing the FASTA file into Sequin and submitting your sequences
+
+
In this dialog box, you will need to choose a sequence profile and various other options. If you haven't created the relevant sequence profile, you should do that first. Sequence profiles are described in the following sections.
+
In addition to specifiying a sequence profile, you will need to specify various aspects of how Chromaseq formulates entries.
+
If you wish to have the OTU ID code added to the DEFINITION line (between the organismal specification and the description of the sequence), then check the "add OTU (Specimen) ID Code to DEFINITION" option. If you have that option checked, then the text you include in the next field will be included immediately in front of the ID code.
+
A GenBank submission requires that each submission be specified by a "seqID", a text string that must be unique for each sequence to be submitted. By default, Mesquite uses the taxon name, to which the gene fragment name can be appended, as the seqID. However, GenBank will automatically truncate the seqID if it is too long. If you have some important text at the end of the seqID that you don't want removed by GenBank, then yoiu can check the "if seqID is too long, shorten in middle" option.
+
If you are using character gropus to specify the product names for regions of your submission, you should check "use character group name as product name for coding regions" option.
+
Creating a sequence profile
+
A sequence profile stores information about a particular gene, gene fragment, or other region of DNA that you might wish to submit to GenBank. For example, if you have sequenced a region of the CAD gene, you might wish to create a sequence profile for that region. The metadata you include in the sequence profile will then be included along with the rest of your GenBank submission. This sequence profile is then saved by Chromaseq, and the next time you wish to submit sequences of that fragment, you can simply choose that profile from the pull-down menu.
+
To create a sequence profile, first press the Manage button in the main dialog box. The Sequence Profile Manager will appear:
+
+
To create a new profile, press "New..."; to edit the contents of a previously created profile, select it in the list and press "Edit...". The other buttons should be self-explanatory.
+
By pressing New or Edit, you will be presented with the dialog box in which you can enter data for the sequence profile.
+
+
You will need to enter data for the following fields:
+
Description of sequence: the text you enter in this field will be appended to the end of the DESCRIPTION field of GenBank
+
Location: This is the location of the source of the molecular data. The options are:
+
Genomic
+
Mitochondrion
+
Chloroplast
+
Apicoplast
+
Chromatophore
+
Chromoplast
+
Cyanelle
+
Endogenous_virus
+
Extrachromosomal
+
Hydrogenosome
+
Kinetoplast
+
Leucoplast
+
Macronuclear
+
Nucleomorph
+
Plasmid
+
Plastid
+
Proplastid
+
Proviral
+
+
Genetic Code: You will need to specify the genetic code for any protein-coding sequences. For non-coding regions, you can leave this to "The Standard Code".
+
Molecular type: This is the type of molecular data being submitted. The options are:
+
+
genomic DNA
+
genomic RNA
+
mRNA
+
tRNA
+
rRNA
+
other RNA
+
other DNA
+
transcribed RNA
+
viral cRNA
+
unassigned DNA
+
unassigned RNA
+
+
SeqID suffix: This should be short, and should uniquely distinguish the sequences in one matrix from those in a second matrix that you might submit. For example, it could be the gene name. This will be appended onto each taxon name to form the SeqID for the sequences in the matrix to be submitted.
+
The optional fields are:
+
Product name: If the entire fragment to be submitted includes genes for only one product, then you can include the product name here. As an alternative, you could specify character groups (see above) and check the "use character group name as product name for coding regions" option in the main export dialog box. For protein-coding regions, you must specify a product name one of these two ways.
+
Note: If you wish to include a note with each of the entries, then enter it in the notes field. For example, you could give details about the fragment of the gene sequenced, or other metadata of relevance to your project.
+
Once you are ready, press the Export button. We suggest that the file name you ask to create not include any spaces.
+
Sharing sequence profiles
+
The sequence profiles are stored in the "SequenceProfilesForGenBank" directory that is in the "Mesquite_Prefs" directory of your "Mesquite_Support_Files" directory. You can put copies of any of these files into the equivalent place on another computer to make those profiles available to Mesquite on that other computer.
+
Using tbl2asn
-
Download the latest version of Sequin.
-
In the Welcome to Sequin window, press Start New Submission
-
In the Submitting Authors window, enter the appropriate information for
- each of the 4 tabs. If you have more than one gene to submit, we recommend
- that you click back to the Submission tab, and chose File>Export Submitter
- Info, and save a file containing the entries. For the next gene, you can
- then choose File>Import Submitter Info and choose that file, saving you the
- effort of re-entering those data.
-
For standard phylogenetic matrices, in the Sequence Format window, choose Phylogenetic Study, and Sequence
- data format as FASTA.
-
In the Organism and Sequence window, choose Import Nucleotide FASTA
-
Struggle with the arcane interface of Sequin to complete your submission.
+
On the Mac or Linux, open up a UNIX shell. (On the Mac, you can start the application called Terminal in the Utilities folder in the Applications folder.) On Windows, open up the command line tool.
+
cd into the directory containing tbl2asn and all of the files.
+
type one of the following commands and hit Return, where you substitute "fileName.fsa" with the name of the FASTA file:
+
+
MacOSX: ./mac.tbl2asn -t template.sbt.txt -a s2 -V vb -i fileName.fsa
+
Windows: tbl2asn.exe -t template.sbt.txt -a s2 -V vb -i fileName.fsa
+
Linux: ./tbl2asn -t template.sbt.txt -a s2 -V vb -i fileName.fsa
once you have run tbl2asn, several files will be produced. Examine the errorsummary.val file for a summary of errors and warnings, and the other file that ends with ".val" (e.g., "fileName.val") for more detailed information about the errors and warnings. Examining the ".val" files will allow you to fix your files and repeat the process until the errors are eliminated. You will need to resolve all errors before you submit the .sqn file to GenBank.
+
If you wish to see the GenBank files as they would be formed, examing the .gbf files in a text editor.
+
Once all looks good, you can submit the sequences by sending the .sqn files to gb-sub@ncbi.nlm.nih.gov
+
+
@@ -298,6 +379,7 @@
Importing the FASTA file into Sequin and submitting your sequences
var PreparingDataPanel = null;
var CreditPanel = null;
var HelpPanel = null;
+var GenBankPanel = null;
var OtherFeaturesPanel = null;
var TechnicalPanel = null;
@@ -331,6 +413,11 @@
Importing the FASTA file into Sequin and submitting your sequences
This older system is built to submit sequences from one gene at a time. As Sequin is no longer supported by NCBI, this is a legacy system. The primary tool for submitting sequences using Chromaseq is that which uses tbl2asn.
+
To prepare
+ files for submission by Sequin, you will need the following:
+
+
A Mesquite file containing your sequences from one gene.
+
A tab-delimited text file containing information about each sequence to
+ be submitted. This file contains organism's name, authority, locality data,
+ etc. This is called the "OTU ID code Database" or "OTU ID code DB" file in Mesquite.
+
+
The form of the tab-delimited OTU (specimen voucher) ID code file is as follows. The first row
+ must begin with the word "code", followed by a tab-delimited list
+ of the official GenBank names of the fields that appear in each of the later
+ lines. For example,
+ if the fields to be included are the organismal name, the taxonomic authority,
+ the name of the person who identified the specimen, the country (locality)
+ field, the latitude and longitude, and the information identifying the specimen
+ voucher, then this first line would appear as follows:
+
code organism authority identified-by country lat-lon specimen-voucher
+
(The black triangle, , represents
+ a tab.)
+
The official GenBank names of the fields and the definition of those fields
+ is given on the Modifiers
+ for FASTA Definition Lines page, with more information on the Sequin
+ Help page. You may include whatever fields you need.
+
On the following lines are the data about the specimens, one line
+ for each specimen. The first item in the line is and ID code. This ID code
+ could be your specimen voucher code, or some other unique identifying string.
+ You will enter these codes in Mesquite for each sequence, which will allow
+ the system to associate the OTU ID code DB information with that particular sequence.
+ The following tab-delimited items in the line are the entries for that particular
+ specimen. For the example file with the header line shown above, here are two
+ lines that contain the information for specimen number 1290, and specimen number
+ 1633:
+
+1290 Bembidion (Odontium) paraenulum Bembidion paraenulum Maddison David Maddison
+ USA: Mississippi: Walthall Co., Tylertown 31.0414 N 90.1922 W Personal: DRMaddison : DNA1290
+1633 Bembidion (Odontium) aenulum Bembidion aenulum Hayward David Maddison
+ USA: Iowa: Jones Co., Oxford Junction 41.99133 N 91.00671 W Personal: DRMaddison : DNA1633
+
Each of these lines is shown extending over two lines, but that is only for ease of display on this web page. There are thus a total of three lines in this example OTU ID Code DB file:
+
+code organism authority identified-by country lat-lon specimen-voucher
+1290 Bembidion (Odontium) paraenulum Bembidion paraenulum Maddison David Maddison
+ USA: Mississippi: Walthall Co., Tylertown 31.0414 N 90.1922 W Personal: DRMaddison : DNA1290
+1633 Bembidion (Odontium) aenulum Bembidion aenulum Hayward David Maddison
+ USA: Iowa: Jones Co., Oxford Junction 41.99133 N 91.00671 W Personal: DRMaddison : DNA1633
+
+
+
Creating the FASTA file
+
Once you have completed the OTU ID code DB file, then in
+ Mesquite open your file containing the sequences, and go to the Taxa List
+ Window (Taxa&Tree>List
+ of
+ Taxa). You will need to show two new columns in this table. Choose Columns>OTU
+ Database and Columns>OTU ID Code. This will show those two columns. Select
+ the entire table (with Select All), and touch on the title of the OTU ID code
+ DB column. A menu will appear in which you can choose to browse for your tab-delimited
+ OTU ID code DB file. Select that file. The OTU ID code DB column should indicate
+ which
+ OTU ID code DB file to use for each sequence. (In this example, all sequences
+ are using the same OTU ID code DB file.)
+
Now you need to enter into the OTU code ID field the ID codes for each of the
+ sequences. In the example here, the OTU ID code for the first sequence
+ is 1290. This tells Mesquite to look
+ in the OTU ID code DB file for the line whose code is 1290 to get the OTU
+ information for that sequence. To enter ID codes, use the editing tool () select the entry, or select the sequence and
+ use the popup menu that appears when you touch on the OTU ID Code title at the
+ top of the column. Once you have entered all of the OTU ID codes, the Taxa List Window should look something
+ like this:
+
+
At this point, you are ready to export a FASTA file with your voucher information
+ contained within it, ready to be imported in Sequin. Do this by choose File>Export,
+ and in the dialog that appears, choose "FASTA (DNA/RNA) for Sequin".
+ You will be queried for options:
+
+
+
Importing the FASTA file into Sequin and submitting your sequences
+
+
Download the latest version of Sequin.
+
In the Welcome to Sequin window, press Start New Submission
+
In the Submitting Authors window, enter the appropriate information for
+ each of the 4 tabs. If you have more than one gene to submit, we recommend
+ that you click back to the Submission tab, and chose File>Export Submitter
+ Info, and save a file containing the entries. For the next gene, you can
+ then choose File>Import Submitter Info and choose that file, saving you the
+ effort of re-entering those data.
+
For standard phylogenetic matrices, in the Sequence Format window, choose Phylogenetic Study, and Sequence
+ data format as FASTA.
+
In the Organism and Sequence window, choose Import Nucleotide FASTA
+
Struggle with the arcane interface of Sequin to complete your submission.
The following sections provide introductory information about Chromaseq:
@@ -253,6 +264,7 @@
Chromaseq: a package for processing chromatograms and sequence data i
var PreparingDataPanel = null;
var CreditPanel = null;
var HelpPanel = null;
+var GenBankPanel = null;
var OtherFeaturesPanel = null;
var TechnicalPanel = null;
@@ -286,6 +298,11 @@
Chromaseq: a package for processing chromatograms and sequence data i
else
HelpPanel = new Spry.Widget.CollapsiblePanel("HelpPanel", {contentIsOpen: false});
+if (qsParm['GenBankPanel']=='open')
+ GenBankPanel = new Spry.Widget.CollapsiblePanel("GenBankPanel", {contentIsOpen: true});
+else
+ GenBankPanel = new Spry.Widget.CollapsiblePanel("GenBankPanel", {contentIsOpen: false});
+
if (qsParm['OtherFeaturesPanel']=='open')
OtherFeaturesPanel = new Spry.Widget.CollapsiblePanel("OtherFeaturesPanel", {contentIsOpen: true});
else
diff --git a/docs/informationStrips.html b/docs/informationStrips.html
index 79f5aee1..a578266d 100644
--- a/docs/informationStrips.html
+++ b/docs/informationStrips.html
@@ -41,8 +41,10 @@
- 885
- 17
+ 916
+ 18updateChromaseq
- 017
- Chromaseq version 1.31
+ 018
+ Chromaseq version 1.5This may take a while to download; please wait until a message appears saying it's finished.
Chromaseq is a package of Mesquite modules designed for analyzing chromatograms, by making contigs, allowing one to
- view chromatograms from within Mesquite, make base calls, etc., with the help of Phred and Phrap.
+ view chromatograms from within Mesquite, make base calls, etc., with the help of Phred and Phrap. It also provides tools
+ for submission of sequences to GenBank.
For more information about the features of Chromaseq, see the
Chromaseq web page. (3)
]]>
@@ -36,9 +37,9 @@
mesquitechromaseq
- https://github.com/MesquiteProject/Chromaseq/releases/download/1.31/chromaseq.1.31.zip
+ https://github.com/MesquiteProject/Chromaseq/releases/download/1.5/chromaseq.1.5.zipunzip
- 017
+ 018
What happens during chr
var PreparingDataPanel = null;
var CreditPanel = null;
var HelpPanel = null;
+var GenBankPanel = null;
var OtherFeaturesPanel = null;
var TechnicalPanel = null;
@@ -390,6 +402,11 @@
What happens during chr
else
HelpPanel = new Spry.Widget.CollapsiblePanel("HelpPanel", {contentIsOpen: false});
+if (qsParm['GenBankPanel']=='open')
+ GenBankPanel = new Spry.Widget.CollapsiblePanel("GenBankPanel", {contentIsOpen: true});
+else
+ GenBankPanel = new Spry.Widget.CollapsiblePanel("GenBankPanel", {contentIsOpen: false});
+
if (qsParm['OtherFeaturesPanel']=='open')
OtherFeaturesPanel = new Spry.Widget.CollapsiblePanel("OtherFeaturesPanel", {contentIsOpen: true});
else
diff --git a/docs/primerSites.html b/docs/primerSites.html
index 2e72cb90..e0d76c9e 100644
--- a/docs/primerSites.html
+++ b/docs/primerSites.html
@@ -41,8 +41,10 @@