-
Notifications
You must be signed in to change notification settings - Fork 10
Filtering Alignments
WARNING: This documentation is outdated and will soon be updated.
Eoulsan define a ReadAlignmentsFilter
interface that allow to filter reads alignments. To handle read alignments use the picard library.
The ReadAlignmentsFilter
interface define a filterReadAlignments
method witch takes as unique argument a list with all the alignments for a read (a list of SAMRecord
objects). This method remove from the list the alignments that no pass the test. In the next sample, we assume that all the alignments for a read are together in the SAM file.
// Create the reader
final SAMFileReader inputSam =
new SAMFileReader(new FileInputStream("alignments.sam"));
// Define the filter
ReadAlignmentsFilter filter = new KeepOneMatchReadAlignmentsFilter();
String lastId = null;
// A list with all the alignments of a read
List<SAMRecord> records = new ArrayList<SAMRecord>();
for (SAMRecord samRecord : inputSam) {
String id = samRecord.getReadName();
if (id==null)
continue;
if (!id.equals(lastId)) {
// Filter the alignments for a same read
filter.filterReadAlignments(records);
// Print the filtered alignments
for (SAMRecord filteredSamRecord: records) {
System.out.println(filteredSamRecord);
}
// Clear the list of alignments
records.clear();
lastId = id;
}
alignments.add(samRecord);
}
reader.close();
The following filterReadAlignments()
method keep only one alignment by read (the first).
@Override
public void filterReadAlignments(final List<SAMRecord> records) {
if (records == null || records.size() < 2)
return;
final SAMRecord first = records.get(0);
records.clear();
records.add(first);
}
WARNING: filtersam step in Eoulsan 1.1 is not modular. The registering of a ReadAlignmentsFilter
will only have an effect in the next version of Eoulsan.
It is very easy to write a plug-in for the filtersam step of Eoulsan. In this section we will write a MyQualityReadAlignmentsFilter
class that filter on mean quality.
- First add
getName()
andgetDescription()
method to your new filter:
package com.example;
public class MyUniqueReadAlignmentsFilter extends AbstractReadAlignmentsFilter {
@Override
public String getName() {
return "myuniquealignment";
}
@Override
public String getDescription() {
return "My unique alignment ReadAlignmentFilter";
}
}
- Then add
setParameter
method that allow to configure our filter:
@Override
public void setParameter(final String key, final String value)
throws EoulsanException {
// This filter do not take parameter
// See the ReadFilter documention for more information about this method
}
- And an
init()
method to initialize the plug-in once all the parameters has been set. Here for our example, if no threshold has been set throw an exception.
@Override
public void init() {
// Do nothing
// See the ReadFilter documention for more information about this method
}
- Now we can add the
accept()
method:
@Override
public void filterReadAlignments(final List<SAMRecord> records) {
if (records == null || records.size() < 2)
return;
records.clear();
}
- Now our
ReadAlignmentsFilter
can compile and can be used in a standalone program but not as a filtersam plug-in. To enable ourReadAlignmentsFilter
as a plug-in we must register it by adding the full name of the class in the fr.ens.transcriptome.eoulsan.bio.readsfilters.ReadAlignmentsFilter text file in the META-INF/services directory. See the Writing Step Plugin for more information:
com.example.MyUniqueReadAlignmentsFilter