-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Masks out positions in the genome which have nucleotides called in <50% of samples. This is especially important in genome builds as the terminal ends of segments are no longer terminal and thus sparse sequence data was resulting in artefactual partitioning of the tree. I've left the cattle-flu builds unchanged (i.e. no masking) but we should revisit this.
- Loading branch information
1 parent
732e38e
commit 898e581
Showing
4 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
|
||
import argparse | ||
from augur.io.sequences import read_sequences, write_sequences | ||
from Bio.Seq import MutableSeq | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description=__doc__) | ||
parser.add_argument('--alignment', type=str, required=True, help='genome alignment') | ||
parser.add_argument('--percentage', type=str, required=True, help='positions with less coverage than this will be masked') | ||
parser.add_argument('--output', type=str, required=True, help='masked genome alignment') | ||
|
||
args = parser.parse_args() | ||
|
||
# Store everything in memory | ||
alignment = list(read_sequences(args.alignment)) | ||
genome_size = len(alignment[0].seq) | ||
counts = [0 for _ in range(0, genome_size)] # zero-based | ||
valid_bases = set(list("ATGCatcg")) | ||
n_genomes = len(alignment) | ||
|
||
for sample in alignment: | ||
for idx, base in enumerate(sample.seq): | ||
if base in valid_bases: | ||
counts[idx] += 1 | ||
|
||
mask_bool = [c/n_genomes*100 < float(args.percentage) for c in counts] | ||
mask_sites = [i for i,b in enumerate(mask_bool) if b==True] | ||
|
||
print("Masking sites (zero-based):", mask_sites) | ||
print("Total number of sites to mask:", len(mask_sites)) | ||
|
||
for sample in alignment: | ||
sample.seq = MutableSeq(sample.seq) | ||
for idx in mask_sites: | ||
sample.seq[idx] = 'N' | ||
|
||
write_sequences(alignment, args.output) |