annotate flip_deletions.py @ 3:08de71d3ea76 draft default tip

planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7-dirty
author mvdbeek
date Fri, 27 Jan 2017 08:16:01 -0500
parents ff6683f8e9a1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
1 #! /usr/bin/python
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
2
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
3 from argparse import ArgumentParser
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
4 import sys
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
5
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
6 parser = ArgumentParser(description='Invert the TE deletion calls to give a consistent data format between TE insertions and deletions')
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
7 parser.add_argument('-s', '--samples', help='list of all sample names', nargs="+", required=True)
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
8 parser.add_argument('-d', '--deletions', help='merged TEPID deletions', required=True)
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
9 parser.add_argument('-r', '--reference', help='reference sample name, eg Col-0', required=True)
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
10 parser.add_argument('-o', '--output', help='output file name', required=True)
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
11 options = parser.parse_args()
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
12
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
13
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
14 def filter_del(options):
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
15 with open(options.deletions, 'r') as dels, open(options.output, 'w+') as outfile:
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
16 sample_names = options.samples
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
17 for line in dels:
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
18 line = line.strip().split('\t')
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
19 accessions = line[5]
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
20 sys.stderr.write(accessions)
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
21 sys.stderr.write(",".join(sample_names))
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
22 accessions = accessions.split(',')
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
23 coords = line[:4]
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
24 temp = [options.reference]
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
25 te = line[4]
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
26 for sample in sample_names:
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
27 if sample not in accessions:
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
28 temp.append(sample)
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
29 else:
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
30 pass
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
31 coords.pop(3) # remove strand
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
32 info = '\t'.join(coords) + '\t' + te + '\t' + ','.join(temp) + '\n'
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
33 outfile.write(info)
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
34
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
35
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
36 if __name__ == "__main__":
ff6683f8e9a1 planemo upload for repository https://github.com/ListerLab/TEPID commit 82fd0448ff5baa9822a388aee78753e4b1cd94d7
mvdbeek
parents:
diff changeset
37 filter_del(options)