Search in sources :

Example 21 with Transcript

use of com.github.lindenb.jvarkit.util.bio.structure.Transcript in project jvarkit by lindenb.

the class BackLocate method run.

private void run(final PrintStream out, final BufferedReader in) throws IOException {
    final CharSplitter tab = CharSplitter.TAB;
    String line;
    while ((line = in.readLine()) != null) {
        if (line.startsWith("#") || StringUtils.isBlank(line))
            continue;
        final String[] tokens = JvarkitException.TokenErrors.atLeast(2, tab.split(line, 3));
        final String geneName = tokens[0].trim();
        if (StringUtils.isBlank(geneName))
            throw new IOException("Bad line. No gene in " + geneName);
        final String mut = tokens[1].trim();
        int x0 = 0, x1 = 0;
        while (x1 < mut.length() && Character.isLetter(mut.charAt(x1))) {
            ++x1;
        }
        String substr = mut.substring(x0, x1);
        final AminoAcids.AminoAcid aa1 = substr.length() == 1 ? AminoAcids.getAminoAcidFromOneLetterCode(substr.charAt(0)) : AminoAcids.getAminoAcidFromThreeLettersCode(substr);
        if (aa1 == null)
            throw new JvarkitException.UserError("Bad mutation " + mut + " (cannot parse left AA)");
        x0 = x1;
        while (x1 < mut.length() && Character.isDigit(mut.charAt(x1))) {
            ++x1;
        }
        substr = mut.substring(x0, x1);
        if (!StringUtils.isInteger(substr))
            throw new JvarkitException.UserError("Bad mutation " + mut + " (cannot parse position)");
        final int position1 = Integer.parseInt(substr);
        if (position1 == 0)
            throw new IOException("Bad position in protein (" + substr + ") in " + line);
        substr = mut.substring(x1);
        final AminoAcids.AminoAcid aa2 = substr.length() == 1 ? AminoAcids.getAminoAcidFromOneLetterCode(substr.charAt(0)) : AminoAcids.getAminoAcidFromThreeLettersCode(substr);
        if (aa2 == null)
            throw new JvarkitException.UserError("Bad mutation " + mut + " (cannot parse right AA)");
        final List<Transcript> transcripts = this.name2transcripts.get(geneName.toUpperCase());
        if (transcripts == null || transcripts.isEmpty()) {
            LOG.warn("no transcript found for " + geneName);
            continue;
        }
        for (final Transcript transcript : transcripts) {
            backLocate(out, transcript, geneName, aa1, aa2, position1, tokens.length > 2 ? tokens[2] : ".");
        }
    }
}
Also used : JvarkitException(com.github.lindenb.jvarkit.lang.JvarkitException) Transcript(com.github.lindenb.jvarkit.util.bio.structure.Transcript) CharSplitter(com.github.lindenb.jvarkit.lang.CharSplitter) AminoAcid(com.github.lindenb.jvarkit.util.bio.AminoAcids.AminoAcid) AminoAcids(com.github.lindenb.jvarkit.util.bio.AminoAcids) IOException(java.io.IOException)

Aggregations

Transcript (com.github.lindenb.jvarkit.util.bio.structure.Transcript)21 Parameter (com.beust.jcommander.Parameter)18 ContigNameConverter (com.github.lindenb.jvarkit.util.bio.fasta.ContigNameConverter)18 GtfReader (com.github.lindenb.jvarkit.util.bio.structure.GtfReader)18 Program (com.github.lindenb.jvarkit.util.jcommander.Program)18 Logger (com.github.lindenb.jvarkit.util.log.Logger)18 Path (java.nio.file.Path)18 List (java.util.List)18 Collectors (java.util.stream.Collectors)17 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)16 CloserUtil (htsjdk.samtools.util.CloserUtil)16 VariantContext (htsjdk.variant.variantcontext.VariantContext)15 Set (java.util.Set)14 SequenceDictionaryUtils (com.github.lindenb.jvarkit.util.bio.SequenceDictionaryUtils)13 Interval (htsjdk.samtools.util.Interval)13 VCFHeader (htsjdk.variant.vcf.VCFHeader)13 ArrayList (java.util.ArrayList)13 StringUtils (com.github.lindenb.jvarkit.lang.StringUtils)12 Launcher (com.github.lindenb.jvarkit.util.jcommander.Launcher)12 IntervalTreeMap (htsjdk.samtools.util.IntervalTreeMap)12