File alignmentFile = FileUtils.createTempFile("output", ".sto");
File resultFile = FileUtils.createTempFile("input", ".sto");
- exportStockholm(seqs, alignmentFile.getAbsoluteFile(), null);
+ exportStockholm(seqs, alignmentFile.getAbsoluteFile(), null, false);
exportHmm(hmm, modelFile.getAbsoluteFile());
boolean ran = runCommand(modelFile, alignmentFile, resultFile);
SequenceI[] copyArray = copy.toArray(new SequenceI[copy.size()]);
Hashtable sequencesHash = stashSequences(copyArray);
- exportStockholm(copyArray, alignmentFile, ac);
+ exportStockholm(copyArray, alignmentFile, ac, false);
recoverSequences(sequencesHash, copy.toArray(new SequenceI[] {}));
AlignmentI al = af.getViewport().getAlignment();
AlignmentI copy = new Alignment(al);
deleteHmmSequences(copy);
- exportStockholm(copy.getSequencesArray(), databaseFile, null);
+
+ SequenceI[] seqs = copy.getSequencesArray();
+
+ // hmmsearch fails if duplicate sequence names in file
+ renameDuplicates(seqs);
+
+ exportStockholm(copy.getSequencesArray(), databaseFile, null, true);
}
args.add(getFilePath(hmmFile, true));
import java.io.BufferedReader;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
* @throws IOException
*/
public void exportStockholm(SequenceI[] seqs, File toFile,
- AnnotatedCollectionI annotated) throws IOException
+ AnnotatedCollectionI annotated, boolean removeSS)
+ throws IOException
{
if (seqs == null)
{
return;
}
AlignmentI newAl = new Alignment(seqs);
+
if (!newAl.isAligned())
{
newAl.padGaps();
}
}
+ for (SequenceI seq : newAl.getSequencesArray())
+ {
+ if (removeSS && seq.getAnnotation() != null)
+ {
+ for (AlignmentAnnotation ann : seq.getAnnotation())
+ {
+ // TODO investigate how to make hmmsearch and jackhmmer work with annotations
+ /*
+ if (ann.label.equals("Secondary Structure"))
+ {
+ seq.removeAlignmentAnnotation(ann);
+ }
+ */
+ seq.removeAlignmentAnnotation(ann);
+ }
+ }
+ }
+
StockholmFile file = new StockholmFile(newAl);
String output = file.print(seqs, false);
PrintWriter writer = new PrintWriter(toFile);
}
/**
- * Exports the given alignment withotu any anotations to a fasta file
- *
- * @param seqs
- * @param toFile
- */
- public void exportFasta(AlignmentI al, File toFile)
- {
- FastaFile file = new FastaFile();
-
- String output = file.print(al.getSequencesArray(), false);
- PrintWriter writer;
- try
- {
- writer = new PrintWriter(toFile);
- writer.println(output);
- writer.close();
- } catch (FileNotFoundException e)
- {
- e.printStackTrace();
- }
-
- }
-
- /**
* Answers the full path to the given hmmer executable, or null if file cannot
* be found or is not executable
*
}
}
}
+
+ void renameDuplicates(SequenceI[] seqs)
+ {
+ // rename duplicate sequences, hmmsearch fails db contains duplicates
+ for (int i = 0; i < seqs.length; i++)
+ {
+ boolean renamed = false;
+ for (int j = 0; j < seqs.length; j++)
+ {
+ renamed = true;
+ if (seqs[i].getName().equals(seqs[j].getName()) && i != j)
+ {
+ String range = "/" + seqs[j].getStart() + "-" + seqs[j].getEnd();
+ // setting sequence name to include range - to differentiate between
+ // sequences of the same name. Currently have to include the range twice
+ // because the range is removed (once) when setting the name
+ // TODO come up with a better way of doing this
+ seqs[j].setName(seqs[j].getName() + range + range);
+ }
+
+ }
+ if (renamed)
+ {
+ String range = "/" + seqs[i].getStart() + "-" + seqs[i].getEnd();
+ seqs[i].setName(seqs[i].getName() + range + range);
+ }
+ }
+ }
+
}
try
{
- File seqFile = FileUtils.createTempFile("seq", ".fa");
+ File seqFile = FileUtils.createTempFile("seq", ".sto");
File hitsAlignmentFile = FileUtils.createTempFile("hitAlignment",
".sto");
File searchOutputFile = FileUtils.createTempFile("searchOutput",
".txt");
- exportSequence(seq, seqFile.getAbsoluteFile());
+ exportStockholm(new SequenceI[] { seq }, seqFile.getAbsoluteFile(),
+ null, true);
boolean ran = runCommand(searchOutputFile, hitsAlignmentFile,
seqFile);
* no external database specified for search, so
* export current alignment as 'database' to search
*/
- databaseFile = FileUtils.createTempFile("database", ".fa");
+ databaseFile = FileUtils.createTempFile("database", ".sto");
AlignmentI al = af.getViewport().getAlignment();
AlignmentI copy = new Alignment(al);
+
deleteHmmSequences(copy);
- exportFasta(copy, databaseFile);
+
+ // jackhmmer fails if file contains duplicate sequence names
+ renameDuplicates(copy.getSequencesArray());
+
+ exportStockholm(copy.getSequencesArray(), databaseFile, null, true);
}
args.add(getFilePath(seqFile, true));